Commit Graph

1196 Commits

Author SHA1 Message Date
Simone Basso
c740be987b
refactor(tracex): do not depend on strings for event names (#777)
Rather than matching a string, match a type.

This is more robust considering future refactorings.

We're confident the names did not change in _this_ refactoring
because we're still testing the same strings in the tests.

Part of https://github.com/ooni/probe/issues/2121
2022-06-01 14:32:16 +02:00
Simone Basso
8f7e3803eb
feat(netxlite): implement DNSTransport wrapping (#776)
Acknowledge that transports MAY be used in isolation (i.e., outside
of a Resolver) and add support for wrapping.

Ensure that every factory that creates an unwrapped type is named
accordingly to hopefully ensure there are no surprises.

Implement DNSTransport wrapping and use a technique similar to the
one used by Dialer to customize the DNSTransport while constructing
more complex data types (e.g., a specific resolver).

Ensure that the stdlib resolver's own "getaddrinfo" transport (1)
is wrapped and (2) could be extended during construction.

This work is part of my ongoing effort to bring to this repository
websteps-illustrated changes relative to netxlite.

Ref issue: https://github.com/ooni/probe/issues/2096
2022-06-01 11:10:08 +02:00
Simone Basso
923d81cdee
refactor(netxlite): introduce the getaddrinfo transport (#775)
This diff modifies the system resolver to use a getaddrinf transport.

Obviously the transport is a fake, but its existence will allow us
to observe DNS events more naturally.

A lookup using the system resolver would be a ANY lookup that will
contain all the resolved IP addresses into the same response.

This change was also part of websteps-illustrated, albeit the way in
which I did it there was less clean than what we have here.

Ref issue: https://github.com/ooni/probe/issues/2096
2022-06-01 09:59:44 +02:00
Simone Basso
7e0b47311d
refactor(netxlite): better integration with tracex (#774)
Rather than passing functions to construct complex objects such
as Dialer and QUICDialer, pass interface implementations.

Ensure that a nil implementation does not cause harm.

Make Saver implement the correct interface either directly or
indirectly. We need to implement the correct interface indirectly
for TCP conns (or connected UDP sockets) because we have two
distinct use cases inside netx: observing just the connect event
and observing just the I/O events.

With this change, the construction of composed Dialers and
QUICDialers is greatly simplified and more obvious.

Part of https://github.com/ooni/probe/issues/2121
2022-06-01 08:31:20 +02:00
Simone Basso
f4f3ed7c42
refactor(tracex): start applying recent code conventions (#773)
The code that is now into the tracex package was written a long
time ago, so let's start to make it more in line with the coding
style of packages that were written more recently.

I didn't apply all the changes I'd like to apply in a single diff
and for now I am committing just this diff.

Broadly, what we need to do is:

1. improve documentation

2. ~always use pointer receivers (object receives have the issue
that they are not mutable by accident meaning that you can mutate
them but their state do not change after the call returns, which
is potentially a source of bugs in case you later refactor to use
a pointer receiver, so always use pointer receivers)

3. ~always avoid embedding (let's say we want to avoid embedding
for types we define and it's instead fine to embed types that are
defined in the stdlib: if later we add a new method, we will not
see a broken build and we'll probably forget to add the new method
to all wrappers -- conversely, if we're wrapping rather than
embedding, we'll see a broken build and act accordingly)

4. prefer unit tests and group tests by type being tested rather
than using a flat structure for tests

There's a coverage slippage that I'll compensate in a follow-up diff where I'll focus on unit testing.

Reference issue: https://github.com/ooni/probe/issues/2121
2022-06-01 07:44:54 +02:00
Simone Basso
bbcd2e2280
refactor(netx): merge archival, trace, and the savers (#772)
This diff creates a new package under netx called tracex that
contains everything we need to perform measurements using events
tracing and postprocessing (which is the technique with which
we implement most network experiments).

The general idea here is to (1) create a unique package out of
all of these packages; (2) clean up the code a bit (improve tests,
docs, apply more recent code patterns); (3) move the resulting
code as a toplevel package inside of internal.

Once this is done, netx can be further refactored to avoid
subpackages and we can search for more code to salvage/refactor.

See https://github.com/ooni/probe/issues/2121
2022-05-31 21:53:01 +02:00
Simone Basso
dd5655eaee
refactor(netxlite): allow easy QUIC dialer chain customization (#771)
Like the previous diff, but for creating QUIC dialers.

See https://github.com/ooni/probe/issues/2121.
2022-05-31 20:28:25 +02:00
Simone Basso
69fd0c5119
refactor(netxlite): allow easy dialer chain customization (#770)
This diff modifies the construction of a dialer to allow one
to insert custom dialer wrappers into the dialers chain.

The point of the chain in which we allow custom wrappers is the
optimal one for connect, read, and write measurements.

This new design is better than the previous netx design since
we don't need to construct the whole chain manually now.

The work in this diff is part of the effort to make engine/netx
just a tiny wrapper around netxlite.

See https://github.com/ooni/probe/issues/2121.
2022-05-31 20:02:11 +02:00
Simone Basso
e4f10eeac2
refactor: continue to simplify engine/netx (#769)
The objective of this diff is to simplify the code inside engine/netx
while moving more bits of code inside netxlite.

See https://github.com/ooni/probe/issues/2121
2022-05-31 08:11:07 +02:00
Simone Basso
3265bc670a
refactor(ndt7): use netxlite rather than netx (#768)
This diff required us to move some code around, but no major
change actually happened, except better tests.

While there, I also slightly refactored ndt7's implementation and
removed the ProxyURL setting, which was actually unused.

See https://github.com/ooni/probe/issues/2121
2022-05-30 23:14:07 +02:00
Simone Basso
314c3c934d
refactor(session.go): replace engine/netx with netxlite (#767)
This diff replaces engine/netx code with netxlite code in
the engine/session.go file. To this end, we needed to move
some code from engine/netx to netxlite. While there, we
did review and improve the unit tests.

A notable change in this diff is (or seems to be) that in
engine/session.go we're not filtering for bogons anymore so
that, in principle, we could believe a resolver returning
to us bogon IP addresses for OONI services. However, I did
not bother with changing bogons filtering because the
sessionresolver package is already filtering for bogons,
so it is actually okay to avoid doing that again the
session.go code. See:

https://github.com/ooni/probe-cli/blob/v3.15.0-alpha.1/internal/engine/internal/sessionresolver/resolvermaker.go#L88

There are two reference issues for this cleanup:

1. https://github.com/ooni/probe/issues/2115

2. https://github.com/ooni/probe/issues/2121
2022-05-30 22:00:45 +02:00
Simone Basso
595d0744db
netxlite: do not call netgo the CGO_ENABLED=0 resolver (#766)
In https://github.com/ooni/probe/issues/2029#issuecomment-1140805266, we
explained why calling it "netgo" would be incorrect.

In other words, we can get the platform's `getaddrinfo` as long as
we're not cross compiling. We do cross compile `ooniprobe`, actually
it's not even possible to cross compile it.

For increased accuracy, we should stop cross compiling `miniooni`
as well, so it would also directly use `getaddrinfo`.

This diff fixes at the same time ooni/probe-cli and ooni/spec
and we'll open two pull requests in parallel.
2022-05-30 10:06:53 +02:00
Simone Basso
f3912188e1
getaddrinfo: fix CGO_ENABLED=0 and record resolver type (#765)
After https://github.com/ooni/probe-cli/pull/764, the build for
CGO_ENABLED=0 has been broken for miniooni:

https://github.com/ooni/probe-cli/runs/6636995859?check_suite_focus=true

Likewise, it's not possible to run tests with CGO_ENABLED=0.

To make tests work with `CGO_ENABLED=0`, I needed to sacrifice some
unit tests run for the CGO case. It is not fully clear to me what was happening
here, but basically `getaddrinfo_cgo_test.go` was compiled with CGO
being disabled, even though the ``//go:build cgo` flag was specified.

Additionally, @hellais previously raised a valid point in the review
of https://github.com/ooni/probe-cli/pull/698:

> Another issue we should consider is that, if I understand how
> this works correctly, depending on whether or not we have built
> with CGO_ENABLED=0 on or not, we are going to be measuring
> things in a different way (using our cgo inspired getaddrinfo
> implementation or using netgo). This might present issues when
> analyzing or interpreting the data.
>
> Do we perhaps want to add some field to the output data format that
> gives us an indication of which DNS resolution code was used to
> generate the the metric?

This comment is relevant to the current commit because
https://github.com/ooni/probe-cli/pull/698 is the previous
iteration of https://github.com/ooni/probe-cli/pull/764.

So, while fixing the build and test issues, let us also distinguish
between the CGO_ENABLED=1 and CGO_ENABLED=0 cases.

Before this commit, OONI used "system" to indicate the case where
we were using net.DefaultResolver. This behavior dates back to the
Measurement Kit days. While it is true that ooni/probe-engine and
ooni/probe-cli could have been using netgo in the past when we
said "system" as the resolver, it also seems reasonable to continue
to use "system" top indicate getaddrinfo.

So, the choice here is basically to use "netgo" from now on to
indicate the cases in which we were built with CGO_ENABLED=0.

This change will need to be documented into ooni/spec along with
the introduction of the `android_dns_cache_no_data` error.

## Checklist

- [x] I have read the [contribution guidelines](https://github.com/ooni/probe-cli/blob/master/CONTRIBUTING.md)
- [x] reference issue for this pull request: https://github.com/ooni/probe/issues/2029
- [x] if you changed anything related how experiments work and you need to reflect these changes in the ooni/spec repository, please link to the related ooni/spec pull request: https://github.com/ooni/spec/pull/242
2022-05-30 07:34:25 +02:00
Simone Basso
cf6dbe48e0
netxlite: call getaddrinfo and handle platform-specific oddities (#764)
This commit changes our system resolver to call getaddrinfo directly when CGO is enabled. This change allows us to:

1. obtain the CNAME easily

2. obtain the real getaddrinfo retval

3. handle platform specific oddities such as `EAI_NODATA`
returned on Android devices

See https://github.com/ooni/probe/issues/2029 and https://github.com/ooni/probe/issues/2029#issuecomment-1140258729 in particular.

See https://github.com/ooni/probe/issues/2033 for documentation regarding the desire to see `getaddrinfo`'s retval.

See https://github.com/ooni/probe/issues/2118 for possible follow-up changes.
2022-05-28 15:10:30 +02:00
Simone Basso
62bd62ece1
fix(dnsoverudp): allow to cancel async round trip immediately (#763)
To this end, we need to refactor the implementation to give the
DNSOverUDPChannel owenership over the net.Conn.

Once this happens, DNSOverUDPChannel.Close closes the conn.

When the conn is closed, the background goroutine will terminate
immediately because any blocking I/O operation will be immediately
unblocked and return net.ErrClosed.

See https://github.com/ooni/probe/issues/2099#issuecomment-1139066946
2022-05-26 23:49:14 +02:00
Simone Basso
16f7407b13
feat(netxlite): observe additional DNS-over-UDP responses (#762)
This diff introduces support for observing additional DNS-over-UDP
responses in some censored environments (e.g. China).

After some uncertainty around whether to use connected or unconnected
UDP sockets, I eventually settled for connected.

Here's a recap:

|                         | connected | unconnected |
| ----------------------- | --------- | ----------- |
| see ICMP errors         | ✔️         |           |
| responses from any server |         | ✔️           |

Because most if not all DNS resolvers expect answers from exactly
the same servers to which they sent the query, I would say that
it's more important to have some limited ability of observing the
effect of ICMP errors (e.g., host_unreachable when we set a low
TTL and send out a query to a server).

Therefore, my choice was to modify the existing DNS-over-UDP transport.

Here's an overview of the changes:

1. introduce a new API for performing an async round trip that returns
a channel wrapper where all responses are posted. The channel will not ever
be closed, so the reader needs to use select for safely reading. If the
reader users the wrapper's Next or TryNextResponses methods, these details
do not matter because they already implement a safe reading pattern.

2. the async round trip API performs the round trip in the background
and stops processing when it sees the first error.

3. the background running code will use an overall deadline derived
from the DNSTransport.IOTimeout field to know when to stop.

4. the background running code will additionally stop running if
noone is reading the channel and there are no empty slots in the
channel's buffer.

5. the RoundTrip method has been rewritten in terms of the async API.

The design I'm using here implements the proposal for async round
trips defined at https://github.com/ooni/probe/issues/2099. I have
chosen not to make all transports async because the DNS transport
seems the only transport that needs to also work in async mode.

While there, I noticed that we were not propagating CloseIdleConnection
to the underlying dialer, which was potentially wrong, so I did it.
2022-05-26 20:09:00 +02:00
Simone Basso
01a513a496
refactor: DNSTransport I/Os DNS messages (#760)
This diff refactors the DNSTransport model to receive in input a DNSQuery and return in output a DNSResponse.

The design of DNSQuery and DNSResponse takes into account the use case of a transport using getaddrinfo, meaning that we don't need to serialize and deserialize messages when using getaddrinfo.

The current codebase does not use a getaddrinfo transport, but I wrote one such a transport in the Websteps Winter 2021 prototype (https://github.com/bassosimone/websteps-illustrated/).

The design conversation that lead to producing this diff is https://github.com/ooni/probe/issues/2099
2022-05-25 17:03:58 +02:00
Simone Basso
7a0a156aec
Spring cleanup: remove unused/unneded code (#761)
* cleanup: remove the archival package

See https://github.com/ooni/probe/issues/2116

* cleanup: remove websteps fall 2021 edition

See https://github.com/ooni/probe/issues/2116

* cleanup: remove JavaScript based testing framework

https://github.com/ooni/probe/issues/2116

* cleanup: remove the unused ooapi package

See https://github.com/ooni/probe/issues/2116
2022-05-25 13:21:39 +02:00
Simone Basso
8b0815efab
cleanup: move legacy from internal/engine to internal (#759)
No functional change.

See https://github.com/ooni/probe/issues/2115
2022-05-25 10:19:03 +02:00
Simone Basso
2d721baa91
cleanup: merge httpheader and httpfailure into model (#758)
These two small packages could easily be merged into the model
package, since they're clearly model-like packages.

Part of https://github.com/ooni/probe/issues/2115
2022-05-25 09:54:50 +02:00
Simone Basso
928de50145
cleanup: minor Readme.md tweaks and changes (#757) 2022-05-25 09:22:35 +02:00
Simone Basso
09523f8efb
cleanup(geolocate): use netxlite rather than netx (#756)
See https://github.com/ooni/probe/issues/2114
2022-05-25 09:12:02 +02:00
Simone Basso
d922bd9afc
cleanup: mark more integration tests as !short mode (#755)
The objective is to make PR checks run much faster.

See https://github.com/ooni/probe/issues/2113 for context.

Regarding netxlite's tests:

Checking for every commit on master or on a release branch is
good enough and makes pull requests faster than one minute since
netxlite for windows is now 1m slower than coverage.

We're losing some coverage but coverage from integration tests
is not so good anyway, so I'm not super sad about this loss.
2022-05-24 21:01:15 +02:00
Simone Basso
6924d1ad81
refactor: only use shaping dialer for ndt7 and dash (#754)
See https://github.com/ooni/probe/issues/2112 for context.

While there, run `go fix -fix buildtag ./...`
2022-05-24 18:23:42 +02:00
Simone Basso
b68b8e1e8f
fix({simplequic,tls}ping): default SNI to URL's hostname (#753)
See https://github.com/ooni/probe/issues/2111
2022-05-24 16:29:13 +02:00
Simone Basso
83cf447edd
fix(oonimkall): export CheckInConfig.RunType (#752)
This commit cherry-picks e3e3b61 from release/3.15.

See https://github.com/ooni/probe/issues/2110 for context.
2022-05-23 18:41:34 +02:00
Simone Basso
c8f91983ca
fix(Readme.md): go1.18.2 is now required
Building with go1.17 would still probably work, but in going
forward it will not, and it's better anyway to specify the exact
version with which we expect people to build.
2022-05-23 07:15:08 +02:00
Simone Basso
ebc00a95fe
refactor: use ooni/oocrypto instead of ooni/go (#751)
Rather than building for Android using ooni/go, we're now using
ooni/oocryto as the TLS dependency. Such a repository only forks
crypto/tls and some minor crypto packages and includes the
same set of patches that we have been using in ooni/go.

This new strategy should be better than the previous one in
terms of building for Android, because we can use the vanilla
go1.18.2 build. It also seems that it is easier to track and
merge from upstream with ooni/oocrypto than it is with ooni/go.

Should this assessment be wrong, we can revert back to the
previous scenario where we used ooni/go.

See https://github.com/ooni/probe/issues/2106 for extra context.
2022-05-22 19:53:37 +02:00
Simone Basso
a1df3b4070
chore: upgrade to go1.18.2 (#750)
I have not upgraded ooni/go yet because I am also checking whether it
would be possible instead to use ooni/oocrypto as documented in the
https://github.com/ooni/probe/issues/2106 issue.

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

Closes https://github.com/ooni/probe/issues/2077
2022-05-22 18:11:37 +02:00
Simone Basso
395961c4da
chore: we're not hacking on v3.16.0-alpha (#749)
See https://github.com/ooni/probe/issues/2100
2022-05-20 20:03:48 +02:00
Simone Basso
a4bdc6dea0
fix(mk): use NDK version that works with gomobile (#748)
The one we were using previously does not work, so use the LTS
rather than using the latest non-LTS stable.

Part of https://github.com/ooni/probe/issues/2100
2022-05-20 13:06:50 +02:00
Simone Basso
6713fc6bc6
cleanup(geolocate): remove IP lookuppers blocked by sanctions (#747)
Closes https://github.com/ooni/probe/issues/2104
2022-05-20 12:43:56 +02:00
Simone Basso
e5d59e834e
chore: update the user-agent used for measuring (#746)
See https://github.com/ooni/probe/issues/2100
2022-05-20 12:43:37 +02:00
Simone Basso
f626a015c9
feat(ooniprobe): add vanilla_tor to experimental (#745)
While there make vanilla_tor only run in unattended mode.

While there also make torsf unattended-mode only.

See https://github.com/ooni/probe/issues/2101

See https://github.com/ooni/probe/issues/2057
2022-05-20 11:47:22 +02:00
Simone Basso
733ce44292
chore(mk): update the version of the tools we use (#744)
See https://github.com/ooni/probe/issues/2100
2022-05-19 22:09:54 +02:00
Simone Basso
1a7234e0f1
chore: run go generate ./... (#743)
See https://github.com/ooni/probe/issues/2100
2022-05-19 20:44:39 +02:00
Simone Basso
518511de67
chore: update all dependencies (#742)
See https://github.com/ooni/probe/issues/2100

See also https://github.com/ooni/probe/issues/2069: we needed to
retain the original version of bifurcation/mint as explained in there.
2022-05-19 18:59:39 +02:00
Simone Basso
dc641784c3
chore: upgrade to ooni/probe-assets v0.9.0 (#741)
See https://github.com/ooni/probe/issues/2100
2022-05-19 16:42:50 +02:00
Simone Basso
5c2f031163
chore: use go1.17.10 (#740)
See https://github.com/ooni/probe/issues/2100
2022-05-19 14:41:36 +02:00
Simone Basso
30e1ed9f40
fix(ooniprobe show): correctly handle % in the JSON (#738)
This diff fixes the way in which we print JSON results inside
`ooniprobe show <ID>` by using the "%s" fmt specifier rather than
using the JSON string itself as the format string.

See https://github.com/ooni/probe/issues/2082

FWIW, `ooniprobe show --batch <ID>` was already WAI.
2022-05-18 16:56:13 +02:00
DecFox
cced980387
fix(webconnectivity): pass TestHelpers to measurement (#736)
* Passed the TestHelpers field to RunAsyc and MeasureAsync. This reflects the test_helpers in the measurement.

* Spec already contains the correct output.

See  https://github.com/ooni/probe/issues/2073

Co-authored-by: decfox <decfox>
2022-05-18 15:46:08 +02:00
stergem
143fd498d5
fix(ooniprobe): remove empty measurements directories (#720)
See https://github.com/ooni/probe/issues/2090

Co-authored-by: Simone Basso <bassosimone@gmail.com>
2022-05-18 15:32:38 +02:00
Simone Basso
1f83c19853
fix(backend api): re-enable previosuly disabled tests (#737)
See https://github.com/ooni/probe/issues/2098
2022-05-18 11:31:46 +02:00
Simone Basso
7c45f7b88c
fix(netxlite): ensure we only accept DNS responses (#735)
Previously, the DNS decoder did not check whether it was parsing
a DNS query or a DNS response, which was wrong.

As a side note, it seems I am using "reply" in the codebase instead
of "response". The latter seems correct DNS terminology.

This diff has been extracted from 9249d14f80

See https://github.com/ooni/probe/issues/2096.
2022-05-16 11:17:30 +02:00
Simone Basso
ce052b665e
feat(netxlite): implements NS queries (#734)
This diff has been extracted from eb0bf38957.

See https://github.com/ooni/probe/issues/2096.

While there, skip the broken tests caused by issue
https://github.com/ooni/probe/issues/2098.
2022-05-16 10:46:53 +02:00
Simone Basso
c1b06a2d09
fix(netxlite): prefer composition over embedding (#733)
This diff has been extracted and adapted from 8848c8c516

The reason to prefer composition over embedding is that we want the
build to break if we add new methods to interfaces we define. If the build
does not break, we may forget about wrapping methods we should
actually be wrapping. I noticed this issue inside netxlite when I was working
on websteps-illustrated and I added support for NS and PTR queries.

See https://github.com/ooni/probe/issues/2096

While there, perform comprehensive netxlite code review
and apply minor changes and improve the docs.
2022-05-15 19:25:27 +02:00
Simone Basso
9d2301cae2
fix(netxlite): reject replies with wrong queryID (#732)
This diff has been extracted from c2f7ccab0e

See https://github.com/ooni/probe/issues/2096

While there, export DecodeReply to decode a raw reply without
interpreting the Rcode or parsing the results, which seems a
nice extra feature to have to more flexibly parse DNS replies
in other parts of the codebase.
2022-05-14 19:38:46 +02:00
Simone Basso
f5b801ae95
refactor(netxlite): add Transport suffix to DNS transports (#731)
This diff has been extracted from c2f7ccab0e

See https://github.com/ooni/probe/issues/2096
2022-05-14 17:38:31 +02:00
Simone Basso
6c388d2c61
netxlite: factor common code for parsing UDPAddr (#730)
This diff has been extracted from c2f7ccab0e

See https://github.com/ooni/probe/issues/2096
2022-05-14 17:15:08 +02:00
Simone Basso
2238908afe
cleanup(quic): wait for handshake completion in netxlite (#729)
See https://github.com/ooni/probe/issues/2097
2022-05-14 16:32:32 +02:00