Commit ae5dd23e authored by vyzo's avatar vyzo

mutex protect peersSeen map in FindPeersConnectedToPeer

parent d38a4477
......@@ -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 {
......@@ -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 {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment