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
dms3
go-bitswap
Commits
434e0f41
Commit
434e0f41
authored
Feb 20, 2019
by
hannahhoward
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(peermanager): race fix
fix remaining issues for race detector in peer manager
parent
97bc28b9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
13 deletions
+8
-13
peermanager/peermanager.go
peermanager/peermanager.go
+8
-13
No files found.
peermanager/peermanager.go
View file @
434e0f41
...
...
@@ -56,11 +56,12 @@ func New(ctx context.Context, createPeerQueue PeerQueueFactory) *PeerManager {
// ConnectedPeers returns a list of peers this PeerManager is managing.
func
(
pm
*
PeerManager
)
ConnectedPeers
()
[]
peer
.
ID
{
pm
.
peerQueuesLk
.
RLock
()
defer
pm
.
peerQueuesLk
.
RUnlock
()
peers
:=
make
([]
peer
.
ID
,
0
,
len
(
pm
.
peerQueues
))
pm
.
iterate
(
func
(
p
peer
.
ID
,
_
P
eerQueue
)
{
for
p
:=
range
pm
.
p
eerQueue
s
{
peers
=
append
(
peers
,
p
)
}
)
}
return
peers
}
...
...
@@ -96,9 +97,11 @@ func (pm *PeerManager) Disconnected(p peer.ID) {
// if targets is nil, it sends to all.
func
(
pm
*
PeerManager
)
SendMessage
(
entries
[]
*
bsmsg
.
Entry
,
targets
[]
peer
.
ID
,
from
uint64
)
{
if
len
(
targets
)
==
0
{
pm
.
iterate
(
func
(
_
peer
.
ID
,
p
PeerQueue
)
{
pm
.
peerQueuesLk
.
RLock
()
for
_
,
p
:=
range
pm
.
peerQueues
{
p
.
AddMessage
(
entries
,
from
)
})
}
pm
.
peerQueuesLk
.
RUnlock
()
}
else
{
for
_
,
t
:=
range
targets
{
p
:=
pm
.
getOrCreate
(
t
)
...
...
@@ -118,11 +121,3 @@ func (pm *PeerManager) getOrCreate(p peer.ID) PeerQueue {
pm
.
peerQueuesLk
.
Unlock
()
return
pq
}
func
(
pm
*
PeerManager
)
iterate
(
iterateFn
func
(
peer
.
ID
,
PeerQueue
))
{
pm
.
peerQueuesLk
.
RLock
()
for
p
,
pq
:=
range
pm
.
peerQueues
{
iterateFn
(
p
,
pq
)
}
pm
.
peerQueuesLk
.
RUnlock
()
}
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