basichost: use autonatv2 to verify reachability#3231
Conversation
01ace3a to
44a53e9
Compare
44a53e9 to
4020bb4
Compare
6c3df6a to
fb5c929
Compare
This introduces `addrsReachabilityTracker` that tracks reachability on a set of addresses. It probes reachability for addresses periodically and has an exponential backoff in case there are too many errors or we don't have any valid autonatv2 peer. There's no smartness in the address selection logic currently. We just test all provided addresses. It also doesn't use the addresses provided by `AddrsFactory`, so currently there's no way to get a user provided address tested for reachability, something that would be a problem for dns addresses. I intend to introduce an alternative to `AddrsFactory`, something like, `AnnounceAddrs(addrs []ma.Multiaddr)` that's just appended to the set of addresses that we have, and check reachability for those addresses. There's only one method exposed in the BasicHost right now that's `ReachableAddrs() []ma.Multiaddr` that returns the host's reachable addrs. Users can also use the event `EvtHostReachableAddrsChanged` to be notified when any addrs reachability changes.
fb5c929 to
818a700
Compare
MarcoPolo
left a comment
There was a problem hiding this comment.
I took a glance, but this is a lot. I get that the core logic is pretty straightforward which is nice, but there's a lot of plumbing required. It might be nicer if this weren't in the basic host package so it could be evaluated along a stricter API boundary.
It would also be nice if we could add some fuzz/invariant tests to the reachability tracker.
5c32430 to
abf1bdf
Compare
abf1bdf to
0b46ec6
Compare
MarcoPolo
left a comment
There was a problem hiding this comment.
After these comments, I think this is good! This is a lot of plumbing. Thanks for being careful about it and adding a lot of tests :)
| // - context is completed | ||
| // - there are too many consecutive failures from the client | ||
| // - the client has no valid peers to probe | ||
| func runProbes(ctx context.Context, concurrency int, addrsTracker *probeManager, client autonatv2Client) bool { |
There was a problem hiding this comment.
This feels like it should be a method on addrsReachabilityTracker after
probeManager is consolidated to it.
There was a problem hiding this comment.
Okay, can we make this a method on probeManager at least?
104d6a0 to
44c871a
Compare
44c871a to
9f7bf58
Compare
9f7bf58 to
1f0f310
Compare
1f0f310 to
d048ba7
Compare
| // - context is completed | ||
| // - there are too many consecutive failures from the client | ||
| // - the client has no valid peers to probe | ||
| func runProbes(ctx context.Context, concurrency int, addrsTracker *probeManager, client autonatv2Client) bool { |
There was a problem hiding this comment.
Okay, can we make this a method on probeManager at least?
MarcoPolo
left a comment
There was a problem hiding this comment.
Minor things, but looks good. Feel free to merge after addressing the nits.
cf01834 to
3beeed0
Compare
This introduces
addrsReachabilityTrackerthat tracks reachability ona set of addresses. It probes reachability for addresses periodically
and has an exponential backoff in case there are too many errors
or we don't have any valid autonatv2 peer.
There's no smartness in the address selection logic currently. We just
test all provided addresses. It also doesn't use the addresses provided
by
AddrsFactory, so currently there's no way to get a user providedaddress tested for reachability, something that would be a problem for
dns addresses. I intend to introduce an alternative to
AddrsFactory, something like,AnnounceAddrs(addrs []ma.Multiaddr)that's just appended to the set of addresses that we have, and check
reachability for those addresses.
There's only one method exposed in the BasicHost right now that's
ReachableAddrs() []ma.Multiaddrthat returns the host's reachableaddrs. Users can also use the event
EvtHostReachableAddrsChangedto be notified when any addrs reachability changes.