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

Hole Punching: Use node's addresses coherently #2966

Open
burdiyan opened this issue Sep 18, 2024 · 1 comment
Open

Hole Punching: Use node's addresses coherently #2966

burdiyan opened this issue Sep 18, 2024 · 1 comment

Comments

@burdiyan
Copy link
Contributor

This issue is a more scoped subset of the problems described in #2965.

The hole punching code doesn't use the addresses from the Libp2p host. Instead it only uses the observed addresses from Identify, and the addresses of the network interfaces.

Actually the "server" and the "client" parts of hole punching don't use the same set of addresses, as seen in the following code fragments:

func (s *Service) getPublicAddrs() []ma.Multiaddr {
addrs := removeRelayAddrs(s.ids.OwnObservedAddrs())
interfaceListenAddrs, err := s.host.Network().InterfaceListenAddresses()
if err != nil {
log.Debugf("failed to get to get InterfaceListenAddresses: %s", err)
} else {
addrs = append(addrs, interfaceListenAddrs...)
}
addrs = ma.Unique(addrs)
publicAddrs := make([]ma.Multiaddr, 0, len(addrs))
for _, addr := range addrs {
if manet.IsPublicAddr(addr) {
publicAddrs = append(publicAddrs, addr)
}
}
return publicAddrs
}
// DirectConnect is only exposed for testing purposes.
// TODO: find a solution for this.
func (s *Service) DirectConnect(p peer.ID) error {
<-s.hasPublicAddrsChan
s.holePuncherMx.Lock()
holePuncher := s.holePuncher
s.holePuncherMx.Unlock()

obsAddrs := removeRelayAddrs(hp.ids.OwnObservedAddrs())

I suggest to use host.Addrs() directly in both places, as those includes all the possible addresses, including the ones provided by the custom AddrsFactory.

@sukunrt
Copy link
Member

sukunrt commented Sep 26, 2024

@burdiyan Can you check if #2979 fixes your problem?

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

No branches or pull requests

2 participants