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

Merged
merged 3 commits into from
Feb 18, 2025

Conversation

sukunrt
Copy link
Member

@sukunrt sukunrt commented Nov 29, 2024

Part of #2229

@sukunrt sukunrt force-pushed the sukun/autorelay-event branch 2 times, most recently 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
20 tasks
@MarcoPolo MarcoPolo self-requested a review February 3, 2025 16:57
@@ -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.

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem with this structure is that currently there's no way to get the autorelay object once it's constructed for debugging or any other reason.

I'm changing it though, let's make this change if we end up wanting access to this for debugging purposes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think I understand. Could you use fx.Populate?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for fx.Populate, but that will need #2962

My point was. Once you create a host, host, err := libp2p.New(), There's no way to access the AutoRelay object now for debugging purposes.

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

@sukunrt sukunrt force-pushed the sukun/autorelay-event branch from 762a43e to 24204d9 Compare February 7, 2025 14:51
@sukunrt sukunrt force-pushed the sukun/autorelay-event branch 3 times, most recently from 8da42b0 to 7acb441 Compare February 7, 2025 15:29
@sukunrt sukunrt requested a review from MarcoPolo February 7, 2025 15:46
@sukunrt sukunrt force-pushed the sukun/autorelay-event branch 2 times, most recently from fdafe16 to 58eceee Compare February 7, 2025 15:49
@sukunrt sukunrt force-pushed the sukun/autorelay-event branch from 58eceee to d27d90e Compare February 7, 2025 18:06
Copy link
Collaborator

@MarcoPolo MarcoPolo left a comment

Choose a reason for hiding this comment

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

Just a couple small comments

updateLocalIPv4Backoff backoff.ExpBackoff
updateLocalIPv6Backoff backoff.ExpBackoff
filteredInterfaceAddrs []ma.Multiaddr
allInterfaceAddrs []ma.Multiaddr

relayAddrs atomic.Value
Copy link
Collaborator

Choose a reason for hiding this comment

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

Slight preference to using the atomic.Pointer type since it's a little nicer to use.

addrs = append(addrs, relayAddrs...)
}
}
addrs = slices.Clone(h.AddrsFactory(addrs))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's change .addCertHashes to always return a copy, and remove this.
Otherwise we end up making two copies.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll take that in a separate PR.

rf.metricsTracer.RelayAddressUpdated()
// Sort the addresses. We depend on this order for checking diffs to send address update events.
slices.SortStableFunc(raddrs, func(a, b ma.Multiaddr) int { return bytes.Compare(a.Bytes(), b.Bytes()) })
if len(raddrs) > maxRelayAddrs {
Copy link
Collaborator

Choose a reason for hiding this comment

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

may as well do this check in the loop above too.

Copy link
Member Author

Choose a reason for hiding this comment

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

We need to sort before limiting to the desired value to keep the list stable.

ready := make(chan struct{}, 1)
for _, conn := range conns {
go func(conn network.Conn) {
select {
case <-rf.host.IDService().IdentifyWait(conn):
case <-hi.IDService().IdentifyWait(conn):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ideally we'd do something like the draft conntracker logic to see which connections supports relaying. In practice this is probably fine as a relay server likely relays on all connections.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, this is tricky indeed. It needs #2693 and maybe the ability to connect only on specific transports and not on everything in the peerstore.

e := <-sub.Out()
evt := e.(event.EvtAutoRelayAddrsUpdated)
relayIds := []peer.ID{}
for _, r := range relays[1:] {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit, this can move out of the eventually loop

@sukunrt sukunrt merged commit 914331b into master Feb 18, 2025
9 checks passed
@MarcoPolo MarcoPolo mentioned this pull request Feb 25, 2025
19 tasks
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