Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-kad-dht
Commits
ae5dd23e
Commit
ae5dd23e
authored
Apr 29, 2018
by
vyzo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mutex protect peersSeen map in FindPeersConnectedToPeer
parent
d38a4477
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
0 deletions
+4
-0
routing.go
routing.go
+4
-0
No files found.
routing.go
View file @
ae5dd23e
...
...
@@ -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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment