ooni-probe-cli/internal
Simone Basso c2ea0b4704
feat(webconnectivity): try all the available THs (#980)
We introduce a fork of internal/httpx, named internal/httpapi, where there is a clear split between the concept of an API endpoint (such as https://0.th.ooni.org/) and of an API descriptor (such as using `GET` to access /api/v1/test-list/url).

Additionally, httpapi allows to create a SequenceCaller that tries to call a given API descriptor using multiple API endpoints. The SequenceCaller will stop once an endpoint works or when all the available endpoints have been tried unsuccessfully.

The definition of "success" is the following: we consider "failure" any error that occurs during the HTTP round trip or when reading the response body. We DO NOT consider "failure" errors (1) when parsing the input URL; (2) when the server returns >= 400; (3) when the server returns a string that does not parse as valid JSON. The idea of this classification of failures is that we ONLY want to retry when we see what looks like a network error that may be caused by (collateral or targeted) censorship.

We take advantage of the availability of this new package and we refactor web_connectivity@v0.4 and web_connectivity@v0.5 to use a SequenceCaller for calling the web connectivity TH API. This means that we will now try all the available THs advertised by the backend rather than just selecting and using the first one provided by the backend.

Because this diff is designed to be backported to the `release/3.16` branch, we have omitted additional changes to always use httpapi where we are currently using httpx. Yet, to remind ourselves about the need to do that, we have deprecated the httpx package. We will rewrite all the code currently using httpx to use httpapi as part of future work.

It is also worth noting that httpapi will allow us to refactor the backend code such that (1) we remove code to select a backend URL endpoint at the beginning and (2) we try several endpoints. The design of the code is such that we can add to the mix some endpoints using as `http.Client` a special client using a tunnel. This will allow us to automatically fallback backend queries.

Closes https://github.com/ooni/probe/issues/2353.

Related to https://github.com/ooni/probe/issues/1519.
2022-11-21 16:28:53 +01:00
..
atomicx doc: cleanup and improve for recently moved pkgs (#354) 2021-06-04 11:39:00 +02:00
bytecounter refactor(netx): move construction logic outside package (#798) 2022-06-05 21:22:27 +02:00
cmd fix(E2E): ensure miniooni.bash is WAI (#972) 2022-10-08 13:14:11 +02:00
database feat: introduce database type (#982) 2022-11-16 15:51:41 +01:00
engine feat(webconnectivity): try all the available THs (#980) 2022-11-21 16:28:53 +01:00
experiment/webconnectivity feat(webconnectivity): try all the available THs (#980) 2022-11-21 16:28:53 +01:00
fsx refactor: merge dnsx and errorsx into netxlite (#517) 2021-09-28 12:42:01 +02:00
geoipx refactor: spin geoipx off geolocate (#893) 2022-08-28 20:00:25 +02:00
httpapi feat(webconnectivity): try all the available THs (#980) 2022-11-21 16:28:53 +01:00
httpx feat(webconnectivity): try all the available THs (#980) 2022-11-21 16:28:53 +01:00
humanize fix(all): introduce and use iox.CopyContext (#380) 2021-06-15 13:44:28 +02:00
kvstore refactor: interfaces and data types into the model package (#642) 2022-01-03 13:53:23 +01:00
legacy/assetsdir cleanup: move legacy from internal/engine to internal (#759) 2022-05-25 10:19:03 +02:00
logx fix(webconnectivity@v0.5): fetch HTTP only using system-resolver addrs (#935) 2022-09-05 13:33:59 +02:00
measurex refactor(datafmt): use "udp" instead of "quic" (#946) 2022-09-08 17:19:59 +02:00
measurexlite feat(webconnectivity@v0.5): get a webpage whenever possible (#950) 2022-09-11 22:12:48 +02:00
mlablocate cleanup: remove redundant HTTPClient definition (#643) 2022-01-03 16:47:54 +01:00
mlablocatev2 cleanup: remove redundant HTTPClient definition (#643) 2022-01-03 16:47:54 +01:00
model feat: reintroduce the tproxy functionality (#975) 2022-10-12 17:38:33 +02:00
multierror doc: cleanup and improve for recently moved pkgs (#354) 2021-06-04 11:39:00 +02:00
netxlite feat: reintroduce the tproxy functionality (#975) 2022-10-12 17:38:33 +02:00
oonirun feat(miniooni): run local oonirun v2 descriptor (#966) 2022-09-29 11:43:23 +02:00
platform feat: add support for OpenBSD (#703) 2022-03-08 12:25:33 +01:00
ptx feat(miniooni): implement torsf tunnel (#921) 2022-10-03 16:52:20 +02:00
randx doc: improve and reference existing bug in the code (#356) 2021-06-04 12:50:23 +02:00
registry feat: port-filtering experiment (#891) 2022-09-14 19:54:43 +02:00
runtimex feat(oonirun): improve tests (#915) 2022-08-31 18:40:27 +02:00
scrubber refactor: interfaces and data types into the model package (#642) 2022-01-03 13:53:23 +01:00
shellx refactor: interfaces and data types into the model package (#642) 2022-01-03 13:53:23 +01:00
stuninput refactor: create common package for holding STUN input (#631) 2021-12-03 14:45:25 +01:00
testingx feat: tlsping and tcpping using step-by-step (#815) 2022-07-01 12:22:22 +02:00
torlogs feat: re-implement the vanilla_tor experiment (#718) 2022-05-10 15:43:28 +02:00
tracex refactor(datafmt): use "udp" instead of "quic" (#946) 2022-09-08 17:19:59 +02:00
tunnel feat(miniooni): implement torsf tunnel (#921) 2022-10-03 16:52:20 +02:00
tutorial refactor(datafmt): use "udp" instead of "quic" (#946) 2022-09-08 17:19:59 +02:00
version chore: set version to 3.17.0-alpha (#939) 2022-09-07 15:12:06 +02:00
README.md doc: mention step-by-step design document 2022-06-17 11:02:54 +02:00

Directory github.com/ooni/probe-cli/internal

This directory contains private Go packages.

Useful commands

You can read the Go documentation of a package by using go doc -all.

For example:

go doc -all ./internal/netxlite

You can get a graph of the dependencies using kisielk/godepgraph.

For example:

godepgraph -s -novendor -p golang.org,gitlab.com ./internal/engine | dot -Tpng -o deps.png

You can further tweak which packages to exclude by appending prefixes to the list passed to the -p flag.

Tutorials

The tutorial package contains tutorials on writing new experiments, using measurements libraries, and networking code.

Network extensions

This section briefly describes the overall design of the network extensions (aka netx) inside ooni/probe-cli. In OONI, we have two distinct but complementary needs:

  1. speaking with our backends or accessing other services useful to bootstrap OONI probe and perform measurements;

  2. implementing network experiments.

We originally implemented these functionality into a separate repository: ooni/netx. The original design document still provides a good overview of the problems we wanted to solve. The newer dd-002-step-by-step.md design document describes the current architecture (as of 2022-06-17) and the future trajectory for netx.

The general idea of netx has always been to provide interfaces replacing standard library objects that we could further wrap to perform network measurements without deviating from the normal APIs expected by Go programmers.

For example,

type Dialer interface {
	DialContext(ctx context.Context, network, address string) (net.Conn, error)
}

is a generic dialer that could be a &net.Dialer{} but could also be a saving dialer that saves the results of dial events. So, you could write something like:

saver := &Saver{}
var dialer Dialer = NewDialer()
dialer = saver.WrapDialer(dialer)
conn, err := dialer.DialContext(ctx, network, address)
events := saver.ExtractEvents()

In short, with the original netx you could write measurement code resembling ordinary Go code but you could also save network events from which to derive whether there was censorship.

Since then, the architecture itself has evolved and netx has been merged into ooni/probe-engine and later ooni/probe-cli. As of 2022-06-06, these are the fundamental netx packages:

  • model/netx.go: contains the interfaces and structs patterned after the Go standard library used by netx;

  • netxlite: implements error wrapping (i.e., mapping Go errors to OONI errors), enforces timeouts, and generally ensures that we're using a stdlib-like network API that meet all our constraints and requirements (e.g., logging);

  • bytecounter: provides support for counting the number of bytes consumed by network interactions;

  • multierror: defines an error type that contains a list of errors for representing the results of operations where multiple sub-operations may fail (e.g., TCP connect fails for all the IP addresses associated with a domain name);

  • tracex: support for collecting events during operations such as TCP connect, QUIC handshake, HTTP round trip. Collecting events allows us to analyze such events and determine whether there was blocking. This measurement strategy is called tracing because we wrap fundamental types (e.g., a dialer or an HTTP transport) to save the result of each operation into a "list of events" type called `Saver;

  • engine/netx: code surviving from the original netx implementation that we're still using for measuring. Issue ooni/probe#2121 describes a slow refactoring process where we'll move code outside of netx and inside netxlite or other packages. We are currently experimenting with step-by-step measurements, an alternative measurement approach where we break down operations in simpler building blocks. This alternative approach may eventually make netx obsolete.