@@ -28,15 +28,19 @@ import (
2828 "github.com/prometheus/client_golang/prometheus"
2929)
3030
31- const outlineModuleName = "outline"
31+ const (
32+ outlineModuleName = "outline"
33+ replayCacheCtxKey = "outline_replay_cache"
34+ metricsCtxKey = "outline_metrics"
35+ )
3236
3337func init () {
3438 replayCache := outline .NewReplayCache (0 )
3539 caddy .RegisterModule (ModuleRegistration {
3640 ID : outlineModuleName ,
3741 New : func () caddy.Module {
3842 app := new (OutlineApp )
39- app .ReplayCache = replayCache
43+ app .replayCache = replayCache
4044 return app
4145 },
4246 })
@@ -48,10 +52,11 @@ type ShadowsocksConfig struct {
4852
4953type OutlineApp struct {
5054 ShadowsocksConfig * ShadowsocksConfig `json:"shadowsocks,omitempty"`
55+ Handlers ConnectionHandlers `json:"connection_handlers,omitempty"`
5156
52- ReplayCache outline.ReplayCache
5357 logger * slog.Logger
54- Metrics outline.ServiceMetrics
58+ replayCache outline.ReplayCache
59+ metrics outline.ServiceMetrics
5560 buildInfo * prometheus.GaugeVec
5661}
5762
@@ -71,7 +76,7 @@ func (app *OutlineApp) Provision(ctx caddy.Context) error {
7176 app .logger .Info ("provisioning app instance" )
7277
7378 if app .ShadowsocksConfig != nil {
74- if err := app .ReplayCache .Resize (app .ShadowsocksConfig .ReplayHistory ); err != nil {
79+ if err := app .replayCache .Resize (app .ShadowsocksConfig .ReplayHistory ); err != nil {
7580 return fmt .Errorf ("failed to configure replay history with capacity %d: %v" , app .ShadowsocksConfig .ReplayHistory , err )
7681 }
7782 }
@@ -83,6 +88,14 @@ func (app *OutlineApp) Provision(ctx caddy.Context) error {
8388 app .buildInfo .WithLabelValues ("dev" ).Set (1 )
8489 // TODO: Add replacement metrics for `shadowsocks_keys` and `shadowsocks_ports`.
8590
91+ ctx = ctx .WithValue (replayCacheCtxKey , app .replayCache )
92+ ctx = ctx .WithValue (metricsCtxKey , app .metrics )
93+
94+ err := app .Handlers .Provision (ctx )
95+ if err != nil {
96+ return err
97+ }
98+
8699 return nil
87100}
88101
@@ -104,7 +117,7 @@ func (app *OutlineApp) defineMetrics() error {
104117 if err != nil {
105118 return err
106119 }
107- app .Metrics , err = registerCollector (r , metrics )
120+ app .metrics , err = registerCollector (r , metrics )
108121 if err != nil {
109122 return err
110123 }
0 commit comments