Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sukunrt
Copy link
Member

@sukunrt sukunrt commented Nov 29, 2024

Part of #2229

@sukunrt sukunrt force-pushed the sukun/autorelay-event branch from 2b114a2 to 762a43e Compare December 3, 2024 08:39
@p-shahi p-shahi mentioned this pull request Dec 16, 2024
26 tasks
@p-shahi p-shahi mentioned this pull request Dec 26, 2024
20 tasks
@MarcoPolo MarcoPolo mentioned this pull request Jan 29, 2025
22 tasks
@MarcoPolo MarcoPolo self-requested a review February 3, 2025 16:57
}

if err := cfg.addAutoNAT(bh); err != nil {
Copy link
Collaborator

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?

Copy link
Member Author

@sukunrt sukunrt Feb 6, 2025

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
Copy link
Collaborator

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?

Copy link
Collaborator

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).

Copy link
Member Author

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 {
Copy link
Collaborator

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 {
Copy link
Collaborator

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

Copy link
Member Author

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
Copy link
Collaborator

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 {
Copy link
Collaborator

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)

Copy link
Member Author

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.
Copy link
Collaborator

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.

p2p/host/autorelay/relay_finder.go Show resolved Hide resolved
p2p/host/autorelay/autorelay_test.go Show resolved Hide resolved
peerChan <- peer.AddrInfo{ID: r1.ID(), Addrs: r1.Addrs()}
cl.AdvanceBy(time.Second)

require.Eventually(t, func() bool {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer require.EventuallyWithT

Copy link
Member Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants