-
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
addressservice: extract out addressing logic from basichost #3075
base: sukun/autorelay-event
Are you sure you want to change the base?
Conversation
d54166d
to
3dbd24d
Compare
5896f14
to
a9e6585
Compare
2b114a2
to
762a43e
Compare
The goal is to keep modifying it and removing the dependency on basichost by relying on events. At that point, we can expose this as a separate service usable by both basic and blank hosts
a9e6585
to
e3367f1
Compare
d77303e
to
e45fe9e
Compare
closes: #3057 rest of the work is in: #3075 Co-authored-by: wlynxg <[email protected]>
closes: #3057 rest of the work is in: #3075 Co-authored-by: wlynxg <[email protected]>
e45fe9e
to
5fcce02
Compare
Ideally, we should rewrite this to have the same semantics, opt into transports not opt out, as `libp2p.New`. But I need webtransport and webrtc support to write address inference tests for #3075 Depending on how disruptive this is to users, we can decide on whether to merge or drop this.
This adds support for `/webtransport` andn `/webrtc-direct` to GenSwarm. Ideally, we should rewrite this to have the same semantics, opt into transports not opt out, as `libp2p.New`. But I need webtransport and webrtc support to write address inference tests for #3075 Depending on how disruptive this is to users, we can decide on whether to merge or drop this.
This adds support for `/webtransport` andn `/webrtc-direct` to GenSwarm. Ideally, we should rewrite this to have the same semantics, opt into transports not opt out, as `libp2p.New`. But I need webtransport and webrtc support to write address inference tests for #3075 Depending on how disruptive this is to users, we can decide on whether to merge or drop this.
This adds support for `/webtransport` andn `/webrtc-direct` to GenSwarm. Ideally, we should rewrite this to have the same semantics, opt into transports not opt out, as `libp2p.New`. But I need webtransport and webrtc support to write address inference tests for #3075 Depending on how disruptive this is to users, we can decide on whether to merge or drop this.
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 know the worst bits of this code are just copied over from the previous implementation. So apologies for picking too much into those.
This is a good point to remove some of the idiosyncrasies here.
var p2pCircuitAddr = ma.StringCast("/p2p-circuit") | ||
|
||
// AllAddrs returns all the addresses the host is listening on except circuit addresses. | ||
func (a *addressService) AllAddrs() []ma.Multiaddr { |
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.
Maybe this should be called AllExceptCirucitAddrs
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.
Related. We should spend a bit of time thinking if these are the names we want
for these methods now while we're refactoring.
return finalAddrs | ||
} | ||
|
||
func (a *addressService) appendInterfaceAddrs(result []ma.Multiaddr, listenAddrs []ma.Multiaddr) []ma.Multiaddr { |
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, slight preference for s/result/dst
} | ||
|
||
// getAllPossibleLocalAddrs gives all the possible address returned for `conn.LocalAddr` correspoinding | ||
// to the `listenAddr` |
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'm having a hard time understanding this comment.
|
||
ar, err := autorelay.NewAutoRelay(h, opts.AutoRelayOpts...) | ||
if !h.disableSignedPeerRecord { |
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.
Why did you move this?
@@ -872,15 +734,7 @@ func (h *BasicHost) ConnManager() connmgr.ConnManager { | |||
// When used with AutoRelay, and if the host is not publicly reachable, | |||
// this will only have host's private, relay, and no public addresses. |
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 this comment still accurate?
select { | ||
case <-ticker.C: | ||
case <-a.addrsChangeChan: | ||
case <-a.autoRelayAddrsSub.Out(): |
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 want to use the event here?
} | ||
// Make a copy. Consumers can modify the slice elements | ||
addrs = slices.Clone(a.addrsFactory(addrs)) | ||
// Add certhashes for the addresses provided by the user via address factory. |
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 comment is wrong. The address factory is unused here.
ifaceAddrs := a.ifaceAddrs.All() | ||
if a.natmgr == nil || !a.natmgr.HasDiscoveredNAT() { | ||
if a.observedAddrsService != nil { | ||
result = append(result, a.observedAddrsService.OwnObservedAddrs()...) |
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.
Would it be better to use OwnObservedAddrFor per listen Addr? Seems surprising
that if we haven't discovered our nat we return all our observed addrs. Example:
It would be surprising if I called this method with just QUIC and got
back a tcp multiaddr.
if ip == nil || !manet.IsPublicAddr(ip) { | ||
continue | ||
} | ||
result = append(result, ma.Join(ip, extMaddrNoIP)) |
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.
So we expect to have a valid external port mapping from the nat service, but be given a private IP Address, and we expect the that second NAT somehow preserves that port mapping? Does this actually work?
// Use both for hole punching. | ||
addrs = append(addrs, a.observedAddrsService.OwnObservedAddrs()...) | ||
addrs = ma.Unique(addrs) | ||
return slices.DeleteFunc(addrs, func(a ma.Multiaddr) bool { return !manet.IsPublicAddr(a) }) |
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 there any sorting that we want to do here?
The goal is to keep modifying it and removing the dependency on basichost by relying on events. At that point, we can expose this as a separate service usable by both basic and blank hosts
Part of #2229