Skip to content

Commit

Permalink
fix: allow punching undialable host public ip
Browse files Browse the repository at this point in the history
fixes #2913
  • Loading branch information
2color authored and MarcoPolo committed Aug 28, 2024
1 parent 65bc28b commit 4f049a3
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion p2p/protocol/holepunch/svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ func (s *Service) watchForPublicAddr() {
t := time.NewTimer(duration)
defer t.Stop()
for {
if containsPublicAddr(s.ids.OwnObservedAddrs()) {
// Use both host and observed to enable hole punching for undialable public ips that might not be observed
if containsPublicAddr(s.ids.OwnObservedAddrs()) || containsPublicAddr(s.host.Addrs()) {
log.Debug("Host now has a public address. Starting holepunch protocol.")
s.host.SetStreamHandler(Protocol, s.handleNewStream)
break
Expand Down Expand Up @@ -172,6 +173,7 @@ func (s *Service) incomingHolePunch(str network.Stream) (rtt time.Duration, remo
return 0, nil, nil, fmt.Errorf("received hole punch stream: %s", str.Conn().RemoteMultiaddr())
}
ownAddrs = removeRelayAddrs(s.ids.OwnObservedAddrs())
ownAddrs = append(ownAddrs, s.host.Addrs()...)
if s.filter != nil {
ownAddrs = s.filter.FilterLocal(str.Conn().RemotePeer(), ownAddrs)
}
Expand Down

0 comments on commit 4f049a3

Please sign in to comment.