Skip to content

Commit

Permalink
Merge pull request ipfs#143 from libp2p/fix/issue-142
Browse files Browse the repository at this point in the history
Fix panic in FindPeersConnectedToPeer
  • Loading branch information
vyzo authored Apr 30, 2018
2 parents d38a447 + caa9098 commit f7ccd97
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gx/lastpubver
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.2: QmT9TxakNKCHg3uBcLnNzBSBhhACvqH8tRzJvYZjUevrvE
4.0.3: QmSAaZBCtay8ssHG7SzBQgmrMnxZUTR4e1cZJqqiQFveZ5
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,5 @@
"license": "MIT",
"name": "go-libp2p-kad-dht",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
"version": "4.0.2"
"version": "4.0.3"
}

4 changes: 4 additions & 0 deletions routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ func (dht *IpfsDHT) FindPeersConnectedToPeer(ctx context.Context, id peer.ID) (<

peerchan := make(chan *pstore.PeerInfo, asyncQueryBuffer)
peersSeen := make(map[peer.ID]struct{})
var peersSeenMx sync.Mutex

peers := dht.routingTable.NearestPeers(kb.ConvertPeerID(id), AlphaValue)
if len(peers) == 0 {
Expand All @@ -524,10 +525,13 @@ func (dht *IpfsDHT) FindPeersConnectedToPeer(ctx context.Context, id peer.ID) (<
pi := pb.PBPeerToPeerInfo(pbp)

// skip peers already seen
peersSeenMx.Lock()
if _, found := peersSeen[pi.ID]; found {
peersSeenMx.Unlock()
continue
}
peersSeen[pi.ID] = struct{}{}
peersSeenMx.Unlock()

// if peer is connected, send it to our client.
if pb.Connectedness(*pbp.Connection) == inet.Connected {
Expand Down

0 comments on commit f7ccd97

Please sign in to comment.