From d4013c95dcd439f32a86487e9c532ea683ace030 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Fri, 21 Jul 2023 10:11:24 +0200 Subject: [PATCH] refactor(oohelperd): move code out of package main (#1189) This diff refactors the oohelperd implementation to move code out of package main. Specifically, we move most of the code from `./internal/cmd/oohelperd` to `./internal/oohelperd`. Thanks to this refactoring, we can reuse the implementation of the oohelperd for writing netem based integration tests. Part of https://github.com/ooni/probe/issues/2461 --------- Co-authored-by: kelmenhorst --- internal/cmd/oohelperd/handler.go | 118 ---------- internal/cmd/oohelperd/main.go | 106 +-------- internal/cmd/oohelperd/main_test.go | 5 + internal/{cmd => }/oohelperd/dns.go | 2 +- internal/{cmd => }/oohelperd/dns_test.go | 2 +- internal/oohelperd/handler.go | 219 +++++++++++++++++++ internal/{cmd => }/oohelperd/handler_test.go | 8 +- internal/{cmd => }/oohelperd/http.go | 2 +- internal/{cmd => }/oohelperd/http_test.go | 2 +- internal/{cmd => }/oohelperd/ipinfo.go | 2 +- internal/{cmd => }/oohelperd/ipinfo_test.go | 2 +- internal/{cmd => }/oohelperd/logging.go | 2 +- internal/{cmd => }/oohelperd/logging_test.go | 2 +- internal/{cmd => }/oohelperd/measure.go | 4 +- internal/{cmd => }/oohelperd/metrics.go | 2 +- internal/{cmd => }/oohelperd/quic.go | 2 +- internal/{cmd => }/oohelperd/tcptls.go | 2 +- internal/{cmd => }/oohelperd/tcptls_test.go | 2 +- 18 files changed, 244 insertions(+), 240 deletions(-) delete mode 100644 internal/cmd/oohelperd/handler.go rename internal/{cmd => }/oohelperd/dns.go (99%) rename internal/{cmd => }/oohelperd/dns_test.go (99%) create mode 100644 internal/oohelperd/handler.go rename internal/{cmd => }/oohelperd/handler_test.go (96%) rename internal/{cmd => }/oohelperd/http.go (99%) rename internal/{cmd => }/oohelperd/http_test.go (99%) rename internal/{cmd => }/oohelperd/ipinfo.go (99%) rename internal/{cmd => }/oohelperd/ipinfo_test.go (99%) rename internal/{cmd => }/oohelperd/logging.go (98%) rename internal/{cmd => }/oohelperd/logging_test.go (99%) rename internal/{cmd => }/oohelperd/measure.go (98%) rename internal/{cmd => }/oohelperd/metrics.go (98%) rename internal/{cmd => }/oohelperd/quic.go (99%) rename internal/{cmd => }/oohelperd/tcptls.go (99%) rename internal/{cmd => }/oohelperd/tcptls_test.go (98%) diff --git a/internal/cmd/oohelperd/handler.go b/internal/cmd/oohelperd/handler.go deleted file mode 100644 index 4e6f52aa5b..0000000000 --- a/internal/cmd/oohelperd/handler.go +++ /dev/null @@ -1,118 +0,0 @@ -package main - -// -// HTTP handler -// - -import ( - "context" - "encoding/json" - "fmt" - "io" - "net/http" - "sync/atomic" - "time" - - "github.com/ooni/probe-cli/v3/internal/model" - "github.com/ooni/probe-cli/v3/internal/netxlite" - "github.com/ooni/probe-cli/v3/internal/runtimex" - "github.com/ooni/probe-cli/v3/internal/version" -) - -// handler is an [http.Handler] implementing the Web -// Connectivity test helper HTTP API. -type handler struct { - // BaseLogger is the MANDATORY logger to use. - BaseLogger model.Logger - - // Indexer is the MANDATORY atomic integer used to assign an index to requests. - Indexer *atomic.Int64 - - // MaxAcceptableBody is the MANDATORY maximum acceptable response body. - MaxAcceptableBody int64 - - // Measure is the MANDATORY function that the handler should call - // for producing a response for a valid incoming request. - Measure func(ctx context.Context, config *handler, creq *model.THRequest) (*model.THResponse, error) - - // NewDialer is the MANDATORY factory to create a new Dialer. - NewDialer func(model.Logger) model.Dialer - - // NewHTTPClient is the MANDATORY factory to create a new HTTPClient. - NewHTTPClient func(model.Logger) model.HTTPClient - - // NewHTTP3Client is the MANDATORY factory to create a new HTTP3Client. - NewHTTP3Client func(model.Logger) model.HTTPClient - - // NewQUICDialer is the MANDATORY factory to create a new QUICDialer. - NewQUICDialer func(model.Logger) model.QUICDialer - - // NewResolver is the MANDATORY factory for creating a new resolver. - NewResolver func(model.Logger) model.Resolver - - // NewTLSHandshaker is the MANDATORY factory for creating a new TLS handshaker. - NewTLSHandshaker func(model.Logger) model.TLSHandshaker -} - -var _ http.Handler = &handler{} - -// ServeHTTP implements http.Handler. -func (h *handler) ServeHTTP(w http.ResponseWriter, req *http.Request) { - // track the number of in-flight requests - metricRequestsInflight.Inc() - defer metricRequestsInflight.Dec() - - // create and add the Server header - w.Header().Add("Server", fmt.Sprintf( - "oohelperd/%s ooniprobe-engine/%s", - version.Version, - version.Version, - )) - - // we only handle the POST method - if req.Method != "POST" { - metricRequestsCount.WithLabelValues("400", "bad_request_method").Inc() - w.WriteHeader(400) - return - } - - // read and parse request body - reader := io.LimitReader(req.Body, h.MaxAcceptableBody) - data, err := netxlite.ReadAllContext(req.Context(), reader) - if err != nil { - metricRequestsCount.WithLabelValues("400", "request_body_too_large").Inc() - w.WriteHeader(400) - return - } - var creq ctrlRequest - if err := json.Unmarshal(data, &creq); err != nil { - metricRequestsCount.WithLabelValues("400", "cannot_unmarshal_request_body").Inc() - w.WriteHeader(400) - return - } - - // measure the given input - started := time.Now() - cresp, err := h.Measure(req.Context(), h, &creq) - elapsed := time.Since(started) - - // track the time required to produce a response - metricWCTaskDurationSeconds.Observe(float64(elapsed.Seconds())) - - // handle the case of fundamental failure - if err != nil { - metricRequestsCount.WithLabelValues("400", "wctask_failed").Inc() - w.WriteHeader(400) - return - } - - // produce successful response. - // - // Note: we assume that json.Marshal cannot fail because it's a - // clearly-serializable data structure. - metricRequestsCount.WithLabelValues("200", "ok").Inc() - data, err = json.Marshal(cresp) - runtimex.PanicOnError(err, "json.Marshal failed") - w.Header().Add("Content-Type", "application/json") - w.Write(data) -} diff --git a/internal/cmd/oohelperd/main.go b/internal/cmd/oohelperd/main.go index 3d48afa401..f777157a15 100644 --- a/internal/cmd/oohelperd/main.go +++ b/internal/cmd/oohelperd/main.go @@ -7,28 +7,20 @@ import ( "fmt" "net" "net/http" - "net/http/cookiejar" "net/http/pprof" "os" "os/signal" "sync" - "sync/atomic" "syscall" "time" "github.com/apex/log" - "github.com/ooni/probe-cli/v3/internal/model" - "github.com/ooni/probe-cli/v3/internal/netxlite" + "github.com/ooni/probe-cli/v3/internal/oohelperd" "github.com/ooni/probe-cli/v3/internal/runtimex" "github.com/ooni/probe-cli/v3/internal/version" "github.com/prometheus/client_golang/prometheus/promhttp" - "golang.org/x/net/publicsuffix" ) -// maxAcceptableBodySize is the maximum acceptable body size for incoming -// API requests as well as when we're measuring webpages. -const maxAcceptableBodySize = 1 << 24 - var ( // apiEndpoint is the endpoint where we serve ooniprobe requests apiEndpoint = flag.String("api-endpoint", "127.0.0.1:8080", "API endpoint") @@ -58,16 +50,6 @@ var ( versionFlag = flag.Bool("version", false, "Prints version information on the stdout") ) -// newResolver creates a new [model.Resolver] suitable for serving -// requests coming from ooniprobe clients. -func newResolver(logger model.Logger) model.Resolver { - // Implementation note: pin to a specific resolver so we don't depend upon the - // default resolver configured by the box. Also, use an encrypted transport thus - // we're less vulnerable to any policy implemented by the box's provider. - resolver := netxlite.NewParallelDNSOverHTTPSResolver(logger, "https://dns.google/dns-query") - return resolver -} - // shutdown calls srv.Shutdown with a reasonably long timeout. The srv.Shutdown // function will immediately close any open listener and then will wait until // all pending connections are closed or the context has expired. By giving pending @@ -81,90 +63,6 @@ func shutdown(srv *http.Server, wg *sync.WaitGroup) { srv.Shutdown(ctx) } -// newCookieJar is the factory for constructing a new cookier jar. -func newCookieJar() *cookiejar.Jar { - // Implementation note: the [cookiejar.New] function always returns a - // nil error; hence, it's safe here to use [runtimex.Try1]. - return runtimex.Try1(cookiejar.New(&cookiejar.Options{ - PublicSuffixList: publicsuffix.List, - })) -} - -// newHTTPClientWithTransportFactory creates a new HTTP client. -func newHTTPClientWithTransportFactory( - logger model.Logger, - txpFactory func(model.DebugLogger, model.Resolver) model.HTTPTransport, -) model.HTTPClient { - // If the DoH resolver we're using insists that a given domain maps to - // bogons, make sure we're going to fail the HTTP measurement. - // - // The TCP measurements scheduler in ipinfo.go will also refuse to - // schedule TCP measurements for bogons. - // - // While this seems theoretical, as of 2022-08-28, I see: - // - // % host polito.it - // polito.it has address 192.168.59.6 - // polito.it has address 192.168.40.1 - // polito.it mail is handled by 10 mx.polito.it. - // - // So, it's better to consider this as a possible corner case. - reso := netxlite.MaybeWrapWithBogonResolver( - true, // enabled - newResolver(logger), - ) - - // fix: We MUST set a cookie jar for measuring HTTP. See - // https://github.com/ooni/probe/issues/2488 for additional - // context and pointers to the relevant measurements. - client := &http.Client{ - Transport: txpFactory(logger, reso), - CheckRedirect: nil, - Jar: newCookieJar(), - Timeout: 0, - } - - return netxlite.WrapHTTPClient(client) -} - -// newHandler constructs the [handler] used by [main]. -func newHandler() *handler { - return &handler{ - BaseLogger: log.Log, - Indexer: &atomic.Int64{}, - MaxAcceptableBody: maxAcceptableBodySize, - Measure: measure, - - NewHTTPClient: func(logger model.Logger) model.HTTPClient { - return newHTTPClientWithTransportFactory( - logger, - netxlite.NewHTTPTransportWithResolver, - ) - }, - - NewHTTP3Client: func(logger model.Logger) model.HTTPClient { - return newHTTPClientWithTransportFactory( - logger, - netxlite.NewHTTP3TransportWithResolver, - ) - }, - - NewDialer: func(logger model.Logger) model.Dialer { - return netxlite.NewDialerWithoutResolver(logger) - }, - NewQUICDialer: func(logger model.Logger) model.QUICDialer { - return netxlite.NewQUICDialerWithoutResolver( - netxlite.NewQUICListener(), - logger, - ) - }, - NewResolver: newResolver, - NewTLSHandshaker: func(logger model.Logger) model.TLSHandshaker { - return netxlite.NewTLSHandshakerStdlib(logger) - }, - } -} - func main() { // parse command line options flag.Parse() @@ -194,7 +92,7 @@ func main() { mux := http.NewServeMux() // add the main oohelperd handler to the mux - mux.Handle("/", newHandler()) + mux.Handle("/", oohelperd.NewHandler()) // create a listening server for serving ooniprobe requests srv := &http.Server{Addr: *apiEndpoint, Handler: mux} diff --git a/internal/cmd/oohelperd/main_test.go b/internal/cmd/oohelperd/main_test.go index 8aefe4da8b..335e07bb3b 100644 --- a/internal/cmd/oohelperd/main_test.go +++ b/internal/cmd/oohelperd/main_test.go @@ -15,6 +15,11 @@ import ( "github.com/ooni/probe-cli/v3/internal/runtimex" ) +type ( + ctrlRequest = model.THRequest + ctrlResponse = model.THResponse +) + func TestMainRunServerWorkingAsIntended(t *testing.T) { // let the kernel pick a random free port *apiEndpoint = "127.0.0.1:0" diff --git a/internal/cmd/oohelperd/dns.go b/internal/oohelperd/dns.go similarity index 99% rename from internal/cmd/oohelperd/dns.go rename to internal/oohelperd/dns.go index c7a1f2c83a..b56b9e20ee 100644 --- a/internal/cmd/oohelperd/dns.go +++ b/internal/oohelperd/dns.go @@ -1,4 +1,4 @@ -package main +package oohelperd // // DNS measurements diff --git a/internal/cmd/oohelperd/dns_test.go b/internal/oohelperd/dns_test.go similarity index 99% rename from internal/cmd/oohelperd/dns_test.go rename to internal/oohelperd/dns_test.go index 5a6b3e354b..fc5efacc4a 100644 --- a/internal/cmd/oohelperd/dns_test.go +++ b/internal/oohelperd/dns_test.go @@ -1,4 +1,4 @@ -package main +package oohelperd import ( "context" diff --git a/internal/oohelperd/handler.go b/internal/oohelperd/handler.go new file mode 100644 index 0000000000..15eda5435f --- /dev/null +++ b/internal/oohelperd/handler.go @@ -0,0 +1,219 @@ +package oohelperd + +// +// HTTP handler +// + +import ( + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "net/http/cookiejar" + "sync/atomic" + "time" + + "github.com/apex/log" + "github.com/ooni/probe-cli/v3/internal/model" + "github.com/ooni/probe-cli/v3/internal/netxlite" + "github.com/ooni/probe-cli/v3/internal/runtimex" + "github.com/ooni/probe-cli/v3/internal/version" + "golang.org/x/net/publicsuffix" +) + +// maxAcceptableBodySize is the maximum acceptable body size for incoming +// API requests as well as when we're measuring webpages. +const maxAcceptableBodySize = 1 << 24 + +// Handler is an [http.Handler] implementing the Web +// Connectivity test helper HTTP API. +type Handler struct { + // BaseLogger is the MANDATORY logger to use. + BaseLogger model.Logger + + // Indexer is the MANDATORY atomic integer used to assign an index to requests. + Indexer *atomic.Int64 + + // MaxAcceptableBody is the MANDATORY maximum acceptable response body. + MaxAcceptableBody int64 + + // Measure is the MANDATORY function that the handler should call + // for producing a response for a valid incoming request. + Measure func(ctx context.Context, config *Handler, creq *model.THRequest) (*model.THResponse, error) + + // NewDialer is the MANDATORY factory to create a new Dialer. + NewDialer func(model.Logger) model.Dialer + + // NewHTTPClient is the MANDATORY factory to create a new HTTPClient. + NewHTTPClient func(model.Logger) model.HTTPClient + + // NewHTTP3Client is the MANDATORY factory to create a new HTTP3Client. + NewHTTP3Client func(model.Logger) model.HTTPClient + + // NewQUICDialer is the MANDATORY factory to create a new QUICDialer. + NewQUICDialer func(model.Logger) model.QUICDialer + + // NewResolver is the MANDATORY factory for creating a new resolver. + NewResolver func(model.Logger) model.Resolver + + // NewTLSHandshaker is the MANDATORY factory for creating a new TLS handshaker. + NewTLSHandshaker func(model.Logger) model.TLSHandshaker +} + +var _ http.Handler = &Handler{} + +// NewHandler constructs the [handler]. +func NewHandler() *Handler { + return &Handler{ + BaseLogger: log.Log, + Indexer: &atomic.Int64{}, + MaxAcceptableBody: maxAcceptableBodySize, + Measure: measure, + + NewHTTPClient: func(logger model.Logger) model.HTTPClient { + return newHTTPClientWithTransportFactory( + logger, + netxlite.NewHTTPTransportWithResolver, + ) + }, + + NewHTTP3Client: func(logger model.Logger) model.HTTPClient { + return newHTTPClientWithTransportFactory( + logger, + netxlite.NewHTTP3TransportWithResolver, + ) + }, + + NewDialer: func(logger model.Logger) model.Dialer { + return netxlite.NewDialerWithoutResolver(logger) + }, + NewQUICDialer: func(logger model.Logger) model.QUICDialer { + return netxlite.NewQUICDialerWithoutResolver( + netxlite.NewQUICListener(), + logger, + ) + }, + NewResolver: newResolver, + NewTLSHandshaker: func(logger model.Logger) model.TLSHandshaker { + return netxlite.NewTLSHandshakerStdlib(logger) + }, + } +} + +// ServeHTTP implements http.Handler. +func (h *Handler) ServeHTTP(w http.ResponseWriter, req *http.Request) { + // track the number of in-flight requests + metricRequestsInflight.Inc() + defer metricRequestsInflight.Dec() + + // create and add the Server header + w.Header().Add("Server", fmt.Sprintf( + "oohelperd/%s ooniprobe-engine/%s", + version.Version, + version.Version, + )) + + // we only handle the POST method + if req.Method != "POST" { + metricRequestsCount.WithLabelValues("400", "bad_request_method").Inc() + w.WriteHeader(400) + return + } + + // read and parse request body + reader := io.LimitReader(req.Body, h.MaxAcceptableBody) + data, err := netxlite.ReadAllContext(req.Context(), reader) + if err != nil { + metricRequestsCount.WithLabelValues("400", "request_body_too_large").Inc() + w.WriteHeader(400) + return + } + var creq ctrlRequest + if err := json.Unmarshal(data, &creq); err != nil { + metricRequestsCount.WithLabelValues("400", "cannot_unmarshal_request_body").Inc() + w.WriteHeader(400) + return + } + + // measure the given input + started := time.Now() + cresp, err := h.Measure(req.Context(), h, &creq) + elapsed := time.Since(started) + + // track the time required to produce a response + metricWCTaskDurationSeconds.Observe(float64(elapsed.Seconds())) + + // handle the case of fundamental failure + if err != nil { + metricRequestsCount.WithLabelValues("400", "wctask_failed").Inc() + w.WriteHeader(400) + return + } + + // produce successful response. + // + // Note: we assume that json.Marshal cannot fail because it's a + // clearly-serializable data structure. + metricRequestsCount.WithLabelValues("200", "ok").Inc() + data, err = json.Marshal(cresp) + runtimex.PanicOnError(err, "json.Marshal failed") + w.Header().Add("Content-Type", "application/json") + w.Write(data) +} + +// newResolver creates a new [model.Resolver] suitable for serving +// requests coming from ooniprobe clients. +func newResolver(logger model.Logger) model.Resolver { + // Implementation note: pin to a specific resolver so we don't depend upon the + // default resolver configured by the box. Also, use an encrypted transport thus + // we're less vulnerable to any policy implemented by the box's provider. + resolver := netxlite.NewParallelDNSOverHTTPSResolver(logger, "https://dns.google/dns-query") + return resolver +} + +// newCookieJar is the factory for constructing a new cookier jar. +func newCookieJar() *cookiejar.Jar { + // Implementation note: the [cookiejar.New] function always returns a + // nil error; hence, it's safe here to use [runtimex.Try1]. + return runtimex.Try1(cookiejar.New(&cookiejar.Options{ + PublicSuffixList: publicsuffix.List, + })) +} + +// newHTTPClientWithTransportFactory creates a new HTTP client. +func newHTTPClientWithTransportFactory( + logger model.Logger, + txpFactory func(model.DebugLogger, model.Resolver) model.HTTPTransport, +) model.HTTPClient { + // If the DoH resolver we're using insists that a given domain maps to + // bogons, make sure we're going to fail the HTTP measurement. + // + // The TCP measurements scheduler in ipinfo.go will also refuse to + // schedule TCP measurements for bogons. + // + // While this seems theoretical, as of 2022-08-28, I see: + // + // % host polito.it + // polito.it has address 192.168.59.6 + // polito.it has address 192.168.40.1 + // polito.it mail is handled by 10 mx.polito.it. + // + // So, it's better to consider this as a possible corner case. + reso := netxlite.MaybeWrapWithBogonResolver( + true, // enabled + newResolver(logger), + ) + + // fix: We MUST set a cookie jar for measuring HTTP. See + // https://github.com/ooni/probe/issues/2488 for additional + // context and pointers to the relevant measurements. + client := &http.Client{ + Transport: txpFactory(logger, reso), + CheckRedirect: nil, + Jar: newCookieJar(), + Timeout: 0, + } + + return netxlite.WrapHTTPClient(client) +} diff --git a/internal/cmd/oohelperd/handler_test.go b/internal/oohelperd/handler_test.go similarity index 96% rename from internal/cmd/oohelperd/handler_test.go rename to internal/oohelperd/handler_test.go index fbe1405765..48a284e237 100644 --- a/internal/cmd/oohelperd/handler_test.go +++ b/internal/oohelperd/handler_test.go @@ -1,4 +1,4 @@ -package main +package oohelperd import ( "context" @@ -70,7 +70,7 @@ func TestHandlerWorkingAsIntended(t *testing.T) { // measureFn optionally allows overriding the default // value of the handler.Measure function measureFn func( - ctx context.Context, config *handler, creq *model.THRequest) (*model.THResponse, error) + ctx context.Context, config *Handler, creq *model.THRequest) (*model.THResponse, error) // reqBody is the request body to use reqBody io.Reader @@ -124,7 +124,7 @@ func TestHandlerWorkingAsIntended(t *testing.T) { parseBody: false, }, { name: "with reasonably good request", - measureFn: func(ctx context.Context, config *handler, creq *model.THRequest) (*model.THResponse, error) { + measureFn: func(ctx context.Context, config *Handler, creq *model.THRequest) (*model.THResponse, error) { cresp := &model.THResponse{} return cresp, nil }, @@ -151,7 +151,7 @@ func TestHandlerWorkingAsIntended(t *testing.T) { for _, expect := range expectations { t.Run(expect.name, func(t *testing.T) { // create handler and possibly override .Measure - handler := newHandler() + handler := NewHandler() if expect.measureFn != nil { handler.Measure = expect.measureFn } diff --git a/internal/cmd/oohelperd/http.go b/internal/oohelperd/http.go similarity index 99% rename from internal/cmd/oohelperd/http.go rename to internal/oohelperd/http.go index da7fae089a..a7331d985c 100644 --- a/internal/cmd/oohelperd/http.go +++ b/internal/oohelperd/http.go @@ -1,4 +1,4 @@ -package main +package oohelperd // // HTTP measurements diff --git a/internal/cmd/oohelperd/http_test.go b/internal/oohelperd/http_test.go similarity index 99% rename from internal/cmd/oohelperd/http_test.go rename to internal/oohelperd/http_test.go index 41c967c1e0..66a36b40f4 100644 --- a/internal/cmd/oohelperd/http_test.go +++ b/internal/oohelperd/http_test.go @@ -1,4 +1,4 @@ -package main +package oohelperd import ( "context" diff --git a/internal/cmd/oohelperd/ipinfo.go b/internal/oohelperd/ipinfo.go similarity index 99% rename from internal/cmd/oohelperd/ipinfo.go rename to internal/oohelperd/ipinfo.go index 24e5aaf6cc..23669f0afe 100644 --- a/internal/cmd/oohelperd/ipinfo.go +++ b/internal/oohelperd/ipinfo.go @@ -1,4 +1,4 @@ -package main +package oohelperd // // Generates IP and endpoint information. diff --git a/internal/cmd/oohelperd/ipinfo_test.go b/internal/oohelperd/ipinfo_test.go similarity index 99% rename from internal/cmd/oohelperd/ipinfo_test.go rename to internal/oohelperd/ipinfo_test.go index 5515c73b07..99aa4a6dba 100644 --- a/internal/cmd/oohelperd/ipinfo_test.go +++ b/internal/oohelperd/ipinfo_test.go @@ -1,4 +1,4 @@ -package main +package oohelperd import ( "net/url" diff --git a/internal/cmd/oohelperd/logging.go b/internal/oohelperd/logging.go similarity index 98% rename from internal/cmd/oohelperd/logging.go rename to internal/oohelperd/logging.go index cc140cafb3..dbb73bb3f6 100644 --- a/internal/cmd/oohelperd/logging.go +++ b/internal/oohelperd/logging.go @@ -1,4 +1,4 @@ -package main +package oohelperd // // Logging code diff --git a/internal/cmd/oohelperd/logging_test.go b/internal/oohelperd/logging_test.go similarity index 99% rename from internal/cmd/oohelperd/logging_test.go rename to internal/oohelperd/logging_test.go index 2008659995..bfaf93a2f3 100644 --- a/internal/cmd/oohelperd/logging_test.go +++ b/internal/oohelperd/logging_test.go @@ -1,4 +1,4 @@ -package main +package oohelperd import ( "testing" diff --git a/internal/cmd/oohelperd/measure.go b/internal/oohelperd/measure.go similarity index 98% rename from internal/cmd/oohelperd/measure.go rename to internal/oohelperd/measure.go index 8a1766b454..d47930aaf5 100644 --- a/internal/cmd/oohelperd/measure.go +++ b/internal/oohelperd/measure.go @@ -1,4 +1,4 @@ -package main +package oohelperd // // Top-level measurement algorithm @@ -24,7 +24,7 @@ type ( // measure performs the measurement described by the request and // returns the corresponding response or an error. -func measure(ctx context.Context, config *handler, creq *ctrlRequest) (*ctrlResponse, error) { +func measure(ctx context.Context, config *Handler, creq *ctrlRequest) (*ctrlResponse, error) { // create indexed logger logger := &prefixLogger{ indexstr: fmt.Sprintf("<#%d> ", config.Indexer.Add(1)), diff --git a/internal/cmd/oohelperd/metrics.go b/internal/oohelperd/metrics.go similarity index 98% rename from internal/cmd/oohelperd/metrics.go rename to internal/oohelperd/metrics.go index f8468b25ce..37e99b6e01 100644 --- a/internal/cmd/oohelperd/metrics.go +++ b/internal/oohelperd/metrics.go @@ -1,4 +1,4 @@ -package main +package oohelperd // // Metrics definitions diff --git a/internal/cmd/oohelperd/quic.go b/internal/oohelperd/quic.go similarity index 99% rename from internal/cmd/oohelperd/quic.go rename to internal/oohelperd/quic.go index 842ffc5064..471d1b423b 100644 --- a/internal/cmd/oohelperd/quic.go +++ b/internal/oohelperd/quic.go @@ -1,4 +1,4 @@ -package main +package oohelperd // // QUIC handshake measurements diff --git a/internal/cmd/oohelperd/tcptls.go b/internal/oohelperd/tcptls.go similarity index 99% rename from internal/cmd/oohelperd/tcptls.go rename to internal/oohelperd/tcptls.go index ec62d14382..3a76130709 100644 --- a/internal/cmd/oohelperd/tcptls.go +++ b/internal/oohelperd/tcptls.go @@ -1,4 +1,4 @@ -package main +package oohelperd // // TCP connect (and optionally TLS handshake) measurements diff --git a/internal/cmd/oohelperd/tcptls_test.go b/internal/oohelperd/tcptls_test.go similarity index 98% rename from internal/cmd/oohelperd/tcptls_test.go rename to internal/oohelperd/tcptls_test.go index a7f596a96c..6dac56cc19 100644 --- a/internal/cmd/oohelperd/tcptls_test.go +++ b/internal/oohelperd/tcptls_test.go @@ -1,4 +1,4 @@ -package main +package oohelperd import ( "testing"