Skip to content

Commit

Permalink
Merge pull request #887 from libp2p/feat/betterMockAddresses
Browse files Browse the repository at this point in the history
deprioritize unspecified addresses in mock connections
  • Loading branch information
willscott committed Apr 14, 2020
2 parents 3d825d8 + 81302e9 commit 6f4961b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion p2p/net/mock/mock_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
ma "github.com/multiformats/go-multiaddr"
manet "github.com/multiformats/go-multiaddr-net"
)

// conn represents one side's perspective of a
Expand Down Expand Up @@ -44,7 +45,15 @@ func newConn(p process.Process, ln, rn *peernet, l *link, dir network.Direction)
c.stat = network.Stat{Direction: dir}

c.localAddr = ln.ps.Addrs(ln.peer)[0]
c.remoteAddr = rn.ps.Addrs(rn.peer)[0]
for _, a := range rn.ps.Addrs(rn.peer) {
if !manet.IsIPUnspecified(a) {
c.remoteAddr = a
break
}
}
if c.remoteAddr == nil {
c.remoteAddr = rn.ps.Addrs(rn.peer)[0]
}

c.localPrivKey = ln.ps.PrivKey(ln.peer)
c.remotePubKey = rn.ps.PubKey(rn.peer)
Expand Down

0 comments on commit 6f4961b

Please sign in to comment.