399d2f65da
This commit introduce a measurement library that consists of refactored code from earlier websteps experiments. I am not going to add tests for the time being, because this library is still a bit in flux, as we finalize websteps. I will soon though commit documentation explaining in detail how to use it, which currrently is at https://github.com/ooni/probe-cli/pull/506 and adds a new directory to internal/tutorial. The core idea of this measurement library is to allow two measurement modes: 1. tracing, which is what we're currently doing now, and the tutorial shows how we can rewrite the measurement part of web connectivity with measurex using less code. Under a tracing approach, we construct a normal http.Client that however has tracing configured, we gather events for resolve, connect, TLS handshake, QUIC handshake, HTTP round trip, etc. and then we try to make sense of what happened from the events stream; 2. step-by-step, which is what websteps does, and basically means that after each operation you immediately write into a Measurement structure its results and immediately draw the conclusions on what seems odd (which later may become an anomaly if we see what the test helper measured). This library is also such that it produces a data format compatible with the current OONI spec. This work is part of https://github.com/ooni/probe/issues/1733.
68 lines
1.5 KiB
Go
68 lines
1.5 KiB
Go
package measurex
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
)
|
|
|
|
//
|
|
// Endpoint
|
|
//
|
|
// This file contains the definition of Endpoint and HTTPEndpoint
|
|
//
|
|
|
|
// EndpointNetwork is the network of an endpoint.
|
|
type EndpointNetwork string
|
|
|
|
const (
|
|
// NetworkTCP identifies endpoints using TCP.
|
|
NetworkTCP = EndpointNetwork("tcp")
|
|
|
|
// NetworkQUIC identifies endpoints using QUIC.
|
|
NetworkQUIC = EndpointNetwork("quic")
|
|
)
|
|
|
|
// Endpoint is an endpoint for a domain.
|
|
type Endpoint struct {
|
|
// Network is the network (e.g., "tcp", "quic")
|
|
Network EndpointNetwork
|
|
|
|
// Address is the endpoint address (e.g., "8.8.8.8:443")
|
|
Address string
|
|
}
|
|
|
|
// String converts an endpoint to a string (e.g., "8.8.8.8:443/tcp")
|
|
func (e *Endpoint) String() string {
|
|
return fmt.Sprintf("%s/%s", e.Address, e.Network)
|
|
}
|
|
|
|
// HTTPEndpoint is an HTTP/HTTPS/HTTP3 endpoint.
|
|
type HTTPEndpoint struct {
|
|
// Domain is the endpoint domain (e.g., "dns.google").
|
|
Domain string
|
|
|
|
// Network is the network (e.g., "tcp" or "quic").
|
|
Network EndpointNetwork
|
|
|
|
// Address is the endpoint address (e.g., "8.8.8.8:443").
|
|
Address string
|
|
|
|
// SNI is the SNI to use (only used with URL.scheme == "https").
|
|
SNI string
|
|
|
|
// ALPN is the ALPN to use (only used with URL.scheme == "https").
|
|
ALPN []string
|
|
|
|
// URL is the endpoint URL.
|
|
URL *url.URL
|
|
|
|
// Header contains request headers.
|
|
Header http.Header
|
|
}
|
|
|
|
// String converts an HTTP endpoint to a string (e.g., "8.8.8.8:443/tcp")
|
|
func (e *HTTPEndpoint) String() string {
|
|
return fmt.Sprintf("%s/%s", e.Address, e.Network)
|
|
}
|