diff --git a/worker/host.go b/worker/host.go index 2aa97d57a..86e92ce27 100644 --- a/worker/host.go +++ b/worker/host.go @@ -52,10 +52,10 @@ type ( acc *account bus Bus contractSpendingRecorder ContractSpendingRecorder + interactionRecorder HostInteractionRecorder logger *zap.SugaredLogger transportPool *transportPoolV3 priceTables *priceTables - interactionRecorder HostInteractionRecorder } ) @@ -70,6 +70,7 @@ func (w *worker) Host(hk types.PublicKey, fcid types.FileContractID, siamuxAddr acc: w.accounts.ForHost(hk), bus: w.bus, contractSpendingRecorder: w.contractSpendingRecorder, + interactionRecorder: w.hostInteractionRecorder, logger: w.logger.Named(hk.String()[:4]), fcid: fcid, siamuxAddr: siamuxAddr, @@ -77,7 +78,6 @@ func (w *worker) Host(hk types.PublicKey, fcid types.FileContractID, siamuxAddr accountKey: w.accounts.deriveAccountKey(hk), transportPool: w.transportPoolV3, priceTables: w.priceTables, - interactionRecorder: w.hostInteractionRecorder, } } diff --git a/worker/interactions.go b/worker/interactions.go index a011cc0d4..dfe8c4017 100644 --- a/worker/interactions.go +++ b/worker/interactions.go @@ -3,11 +3,9 @@ package worker import ( "context" "fmt" - "net/http" "sync" "time" - "go.sia.tech/jape" "go.sia.tech/renterd/hostdb" "go.uber.org/zap" ) @@ -42,18 +40,6 @@ var ( _ HostInteractionRecorder = (*hostInteractionRecorder)(nil) ) -func interactionMiddleware(ir HostInteractionRecorder, routes map[string]jape.Handler) map[string]jape.Handler { - for route, handler := range routes { - routes[route] = jape.Adapt(func(h http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - ctx := context.WithValue(r.Context(), keyInteractionRecorder, ir) - h.ServeHTTP(w, r.WithContext(ctx)) - }) - })(handler) - } - return routes -} - func (w *worker) initHostInteractionRecorder(flushInterval time.Duration) { if w.hostInteractionRecorder != nil { panic("HostInteractionRecorder already initialized") // developer error diff --git a/worker/worker.go b/worker/worker.go index c76329aeb..5ed7e8a05 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -1323,7 +1323,7 @@ func New(masterKey [32]byte, id string, b Bus, contractLockingDuration, busFlush // Handler returns an HTTP handler that serves the worker API. func (w *worker) Handler() http.Handler { - return jape.Mux(interactionMiddleware(w.hostInteractionRecorder, map[string]jape.Handler{ + return jape.Mux(map[string]jape.Handler{ "GET /account/:hostkey": w.accountHandlerGET, "GET /id": w.idHandlerGET, @@ -1351,7 +1351,7 @@ func (w *worker) Handler() http.Handler { "PUT /multipart/*path": w.multipartUploadHandlerPUT, "GET /state": w.stateHandlerGET, - })) + }) } // Shutdown shuts down the worker.