1. Fix tests on go 1.15 by avoiding `string(i)`.
2. Fix the autorelay test by making relays announce fake "public" addresses. I'm
not sure how this worked before.
Previously, we'd construct addresses like `/ip4/.../udp/...` instead of
`/ip4/.../udp/.../quic` because we'd use mapped addr (ip + transport + port)
instead of the full external address (ip + transport + port + other
transports...).
* fix: use all interface addresses when we can't find the default route
* fix: don't add advertise unspecified addresses
* fix: resolve addresses before looking up observed addresses
* fix: only advertise global unicast
* fix: filter link-local addresses from advertisement
* test: fix basic host addr tests
Before, we would:
1. Receive a "listen close" event from an event handler, after the teardown started.
2. Try to add a child process to handle the event. This would block because we
were in the teardown.
3. In the teardown, try to unregister the event handler and deadlock
I've now:
* Removed the teardown.
* Switched to a single event loop.
Ideally, we'd remove goprocess entirely. But we'd need to refactor natmgr.
fixes#933
We switched `listenAddrs` from the _interface_ addresses to the raw addresses we
were listening on. Unfortunately, we needed the resolved addresses later in the
function when resolving port mappings.
Alternative to #963. Instead of using atomics, this patch ensures that all state
changes are performed on the main thread. It also:
* Threads the context through explicitly to make sure fields changed by the main
thread are never read by the handler goroutines. This isn't strictly necessary
but it makes it easier to reason about.
* Uses a callback to signal "on done". There may be cleaner ways to do this (I
hate callbacks), but this nicely decouples the peer handler from the main loop.
fixes#963
Previously, we'd keep addresses discovered through the DHT for up to 2
minutes (temporary TTL) and previously seen addresses (recently connected) for
up to 10 minutes (the TTL).
1. Make sure to downgrade both connected and recently connected addresses to the
"temporary" ttl before adding new addresses.
2. Finally, downgrade addresses with the temporary TTL to 0.
This could be more efficient with a better peerstore abstraction, but this is
better than nothing.
In #917, we started dropping additional address observations if we had multiple
for the same transport set. However, on further consideration, this isn't quite
correct. We _want_ to keep additional observations for multiple IP addresses.
The real issue is many observations for different ports.
So this patch simply changes the key with which we group observations from
"address protocols" to "address without the port" (well, with the port set to
0).
Otherwise, if we're not creating new connections, we'll eventually forget them.
Up until now, this wasn't _too_ much of an issue because our peers would still
remember our addresses. However, we now _tell_ our connected peers when our
addresses change. That means we'll tell our peers to forget where we are,
preventing anyone from finding us.