-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
autorelay: send addresses on eventbus; dont wrap address factory #3071
base: master
Are you sure you want to change the base?
Conversation
b920ac5
to
2b114a2
Compare
2b114a2
to
762a43e
Compare
} | ||
|
||
if err := cfg.addAutoNAT(bh); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't need a started host?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. It only needs the host to open a new stream and event bus.
@@ -9,6 +9,9 @@ import ( | |||
|
|||
// This function cleans up a relay's address set to remove private addresses and curtail | |||
// addrsplosion. | |||
// TODO: Remove this, we don't need this. The current method tries to select the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we removing this for this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should bound the number of addresses we re-advertise (which I'm assuming this
code does).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will remove this in a follow up PR. Not related to the current change.
@@ -328,6 +340,21 @@ func NewHost(n network.Network, opts *HostOpts) (*BasicHost, error) { | |||
} | |||
} | |||
|
|||
if opts.EnableAutoRelay { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be in config.go as part of an fx constructor for autorelay. Start should
be managed in the lifecycle there as well.
// Make a copy. Consumers can modify the slice elements | ||
addrs := slices.Clone(h.AddrsFactory(h.AllAddrs())) | ||
if h.autoNat != nil && h.autorelay != nil && h.autoNat.Status() == network.ReachabilityPrivate { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check should be status != network.ReachabilityPublic instead. The current
code has this bug as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will take this up in a separate PR:
#3172 (comment)
@@ -109,6 +110,8 @@ type BasicHost struct { | |||
autoNat autonat.AutoNAT | |||
|
|||
autonatv2 *autonatv2.AutoNAT | |||
addrSub event.Subscription | |||
autorelay *autorelay.AutoRelay |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need autorelay here if we can get the relay addrs via the eventbus
@@ -808,3 +815,34 @@ func (rf *relayFinder) resetMetrics() { | |||
rf.metricsTracer.RelayAddressCount(0) | |||
rf.metricsTracer.ScheduledWorkUpdated(&scheduledWorkTimes{}) | |||
} | |||
|
|||
func haveAddrsDiff(a, b []ma.Multiaddr) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should change this to areSortedAddrsDifferent
and uphold the invariant that
we maintain sorted addresses. That way this becomes O(n) instead of O(n^2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! thanks.
return rf.cachedAddrs | ||
} | ||
|
||
// This function computes the relay addrs when our status is private. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We run the relayfinder on unknown status as well. We should just say not public.
peerChan <- peer.AddrInfo{ID: r1.ID(), Addrs: r1.Addrs()} | ||
cl.AdvanceBy(time.Second) | ||
|
||
require.Eventually(t, func() bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer require.EventuallyWithT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it for the fact that it collects errors and returns the last one?
Part of #2229