ooni-probe-cli/internal/engine/probeservices
Simone Basso eed51978ca
refactor(httpx): hide the real APIClient (#648)
As mentioned in https://github.com/ooni/probe/issues/1951, one of
the main issues I did see with httpx.APIClient is that in some cases
it's used in a very fragile way by probeservices.Client.

This happens in psiphon.go and tor.go, where we create a copy of
the APIClient and then modify it's Authorization field.

If we ever refactor probeservices.Client to take a pointer to
httpx.Client, we are now mutating the httpx.Client.

Of course, we don't want that to happen.

This diff attempts to address such a problem as follows:

1. we create a new APIClientTemplate type that holds the same
fields of an APIClient and allows to build an APIClient

2. we modify every user of APIClient to use APIClientTemplate

3. when we need an APIClient, we build it from the corresponding
template and, when we need to use a specific Authorization, we
use a build factory that sets APIClient.Authorization

4. we hide APIClient by renaming it apiClient and by defining
an interface called APIClient that allows to use it

So, now the codebase always uses the opaque APIClient interface to
issue API calls and always uses the APIClientTemplate to build an
opaque APIClient.

Boom! We have separated construction from usage and we are not
mutating in weird ways the APIClient anymore.
2022-01-05 14:15:42 +01:00
..
testorchestra chore: merge probe-engine into probe-cli (#201) 2021-02-02 12:05:47 +01:00
benchselect.go refactor: interfaces and data types into the model package (#642) 2022-01-03 13:53:23 +01:00
bouncer_test.go chore: merge probe-engine into probe-cli (#201) 2021-02-02 12:05:47 +01:00
bouncer.go refactor(httpx): hide the real APIClient (#648) 2022-01-05 14:15:42 +01:00
checkin_test.go refactor: interfaces and data types into the model package (#642) 2022-01-03 13:53:23 +01:00
checkin.go refactor(httpx): hide the real APIClient (#648) 2022-01-05 14:15:42 +01:00
checkreportid_test.go refactor(httpx): hide the real APIClient (#648) 2022-01-05 14:15:42 +01:00
checkreportid.go refactor(httpx): hide the real APIClient (#648) 2022-01-05 14:15:42 +01:00
collector_test.go refactor: interfaces and data types into the model package (#642) 2022-01-03 13:53:23 +01:00
collector.go refactor(httpx): hide the real APIClient (#648) 2022-01-05 14:15:42 +01:00
login_test.go chore: merge probe-engine into probe-cli (#201) 2021-02-02 12:05:47 +01:00
login.go refactor(httpx): hide the real APIClient (#648) 2022-01-05 14:15:42 +01:00
measurementmeta_test.go refactor(httpx): hide the real APIClient (#648) 2022-01-05 14:15:42 +01:00
measurementmeta.go refactor(httpx): hide the real APIClient (#648) 2022-01-05 14:15:42 +01:00
metadata_test.go chore: merge probe-engine into probe-cli (#201) 2021-02-02 12:05:47 +01:00
metadata.go chore: merge probe-engine into probe-cli (#201) 2021-02-02 12:05:47 +01:00
probeservices_test.go refactor: interfaces and data types into the model package (#642) 2022-01-03 13:53:23 +01:00
probeservices.go refactor(httpx): hide the real APIClient (#648) 2022-01-05 14:15:42 +01:00
psiphon_test.go chore: merge probe-engine into probe-cli (#201) 2021-02-02 12:05:47 +01:00
psiphon.go refactor(httpx): hide the real APIClient (#648) 2022-01-05 14:15:42 +01:00
README.md chore: merge probe-engine into probe-cli (#201) 2021-02-02 12:05:47 +01:00
register_test.go chore: merge probe-engine into probe-cli (#201) 2021-02-02 12:05:47 +01:00
register.go refactor(httpx): hide the real APIClient (#648) 2022-01-05 14:15:42 +01:00
statefile_test.go refactor: flatten and separate (#353) 2021-06-04 10:34:18 +02:00
statefile.go refactor: interfaces and data types into the model package (#642) 2022-01-03 13:53:23 +01:00
tor_test.go refactor(httpx): improve and modernize (1/n) (#647) 2022-01-05 12:48:32 +01:00
tor.go refactor(httpx): hide the real APIClient (#648) 2022-01-05 14:15:42 +01:00
urls_test.go refactor: interfaces and data types into the model package (#642) 2022-01-03 13:53:23 +01:00
urls.go refactor(httpx): hide the real APIClient (#648) 2022-01-05 14:15:42 +01:00

Package github.com/ooni/probe-engine/probeservices

This package contains code to contact OONI probe services.

The probe services are HTTPS endpoints distributed across a bunch of data centres implementing a bunch of OONI APIs. When started, OONI will benchmark the available probe services and select the fastest one. Eventually all the possible OONI APIs will run as probe services.