-
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
Conversation
2b114a2
to
762a43e
Compare
@@ -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.
p2p/host/basic/basic_host.go
Outdated
@@ -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.
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.
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.
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 don't think I understand. Could you use fx.Populate
?
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.
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.
p2p/host/basic/basic_host.go
Outdated
// 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)
762a43e
to
24204d9
Compare
8da42b0
to
7acb441
Compare
fdafe16
to
58eceee
Compare
58eceee
to
d27d90e
Compare
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.
Just a couple small comments
p2p/host/basic/basic_host.go
Outdated
updateLocalIPv4Backoff backoff.ExpBackoff | ||
updateLocalIPv6Backoff backoff.ExpBackoff | ||
filteredInterfaceAddrs []ma.Multiaddr | ||
allInterfaceAddrs []ma.Multiaddr | ||
|
||
relayAddrs atomic.Value |
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.
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)) |
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.
Let's change .addCertHashes
to always return a copy, and remove this.
Otherwise we end up making two copies.
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'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 { |
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.
may as well do this check in the loop above too.
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 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): |
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.
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.
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.
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:] { |
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.
nit, this can move out of the eventually loop
Part of #2229