Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
include the peer ID in the hole punch map key
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Jul 3, 2021
1 parent 62696b5 commit 6125e62
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (l *listener) Accept() (tpt.CapableConn, error) {
}

// return through active hole punching if any
key := sess.RemoteAddr().String()
key := holePunchKey(sess.RemoteAddr(), conn.remotePeerID)
var wasHolePunch bool
l.transport.holePunchingMx.Lock()
holePunch, ok := l.transport.holePunching[key]
Expand Down
10 changes: 7 additions & 3 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (t *transport) Dial(ctx context.Context, raddr ma.Multiaddr, p peer.ID) (tp

if simConnect, _ := n.GetSimultaneousConnect(ctx); simConnect {
if bytes.Compare([]byte(t.localPeer), []byte(p)) < 0 {
return t.holePunch(ctx, network, addr)
return t.holePunch(ctx, network, addr, p)
}
}

Expand Down Expand Up @@ -225,7 +225,7 @@ func (t *transport) Dial(ctx context.Context, raddr ma.Multiaddr, p peer.ID) (tp
return conn, nil
}

func (t *transport) holePunch(ctx context.Context, network string, addr *net.UDPAddr) (tpt.CapableConn, error) {
func (t *transport) holePunch(ctx context.Context, network string, addr *net.UDPAddr, p peer.ID) (tpt.CapableConn, error) {
pconn, err := t.connManager.Dial(network, addr)
if err != nil {
return nil, err
Expand All @@ -235,7 +235,7 @@ func (t *transport) holePunch(ctx context.Context, network string, addr *net.UDP
ctx, cancel := context.WithTimeout(ctx, HolePunchTimeout)
defer cancel()

key := addr.String()
key := holePunchKey(addr, p)
t.holePunchingMx.Lock()
if _, ok := t.holePunching[key]; ok {
t.holePunchingMx.Unlock()
Expand Down Expand Up @@ -344,3 +344,7 @@ func (t *transport) Protocols() []int {
func (t *transport) String() string {
return "QUIC"
}

func holePunchKey(addr net.Addr, id peer.ID) string {
return addr.String() + "__" + id.String()
}

0 comments on commit 6125e62

Please sign in to comment.