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

addressservice: extract out addressing logic from basichost #3075

Open
wants to merge 6 commits into
base: sukun/autorelay-event
Choose a base branch
from

Conversation

sukunrt
Copy link
Member

@sukunrt sukunrt commented Dec 1, 2024

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

@sukunrt sukunrt force-pushed the sukun/address-service-1 branch from d54166d to 3dbd24d Compare December 1, 2024 13:38
@sukunrt sukunrt force-pushed the sukun/address-service-1 branch 5 times, most recently from 5896f14 to a9e6585 Compare December 2, 2024 14:29
@sukunrt sukunrt force-pushed the sukun/autorelay-event branch from 2b114a2 to 762a43e Compare December 3, 2024 08:39
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
@sukunrt sukunrt force-pushed the sukun/address-service-1 branch from a9e6585 to e3367f1 Compare December 3, 2024 08:45
@sukunrt sukunrt force-pushed the sukun/address-service-1 branch 4 times, most recently from d77303e to e45fe9e Compare December 3, 2024 16:59
@sukunrt sukunrt requested a review from MarcoPolo December 3, 2024 17:03
sukunrt added a commit that referenced this pull request Dec 8, 2024
closes: #3057
rest of the work is in: #3075

Co-authored-by: wlynxg <[email protected]>
sukunrt added a commit that referenced this pull request Dec 8, 2024
closes: #3057
rest of the work is in: #3075

Co-authored-by: wlynxg <[email protected]>
@p-shahi p-shahi mentioned this pull request Dec 16, 2024
26 tasks
@p-shahi p-shahi mentioned this pull request Dec 26, 2024
21 tasks
@sukunrt sukunrt force-pushed the sukun/address-service-1 branch from e45fe9e to 5fcce02 Compare December 30, 2024 15:49
sukunrt added a commit that referenced this pull request Dec 30, 2024
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.
sukunrt added a commit that referenced this pull request Dec 30, 2024
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.
sukunrt added a commit that referenced this pull request Dec 30, 2024
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.
sukunrt added a commit that referenced this pull request Dec 30, 2024
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.
@MarcoPolo MarcoPolo mentioned this pull request Jan 29, 2025
21 tasks
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.

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

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

Copy link
Collaborator

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

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

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

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

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

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

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

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

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?

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