ooni-probe-cli/internal/measurex/endpoint.go
Simone Basso b78b9aca51
refactor(datafmt): use "udp" instead of "quic" (#946)
This diff changes the data format to prefer "udp" to "quic" everywhere we were previously using "quic".

Previously, the code inconsistently used "quic" for operations where we knew we were using "quic" and "udp" otherwise (e.g., for generic operations like ReadFrom).

While it would be more correct to say that a specific HTTP request used "quic" rather than "udp", using "udp" consistently allows one to see how distinct events such as ReadFrom and an handshake all refer to the same address, port, and protocol triple. Therefore, this change makes it easier to programmatically unpack a single measurement and create endpoint stats.

Before implementing this change, I discussed the problem with @hellais who mentioned that ooni/data is not currently using the "quic" string anywhere. I know that ooni/pipeline also doesn't rely on this string. The only users of this feature have been research-oriented experiments such as urlgetter, for which such a change would actually be acceptable.

See https://github.com/ooni/probe/issues/2238 and https://github.com/ooni/spec/pull/262.
2022-09-08 17:19:59 +02:00

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")
// NetworkUDP identifies endpoints using UDP.
NetworkUDP = EndpointNetwork("udp")
)
// Endpoint is an endpoint for a domain.
type Endpoint struct {
// Network is the network (e.g., "tcp", "udp")
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 "udp").
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)
}