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
97bc28b9
Commit
97bc28b9
authored
Feb 20, 2019
by
hannahhoward
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(peermanager): fix disconnect race
Keep all of disconnection in a mutex
parent
d8454fe8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
20 deletions
+6
-20
peermanager/peermanager.go
peermanager/peermanager.go
+6
-20
No files found.
peermanager/peermanager.go
View file @
97bc28b9
...
...
@@ -77,20 +77,19 @@ func (pm *PeerManager) Connected(p peer.ID, initialEntries []*wantlist.Entry) {
// Disconnected is called to remove a peer from the pool.
func
(
pm
*
PeerManager
)
Disconnected
(
p
peer
.
ID
)
{
pq
,
ok
:=
pm
.
get
(
p
)
pm
.
peerQueuesLk
.
Lock
()
pq
,
ok
:=
pm
.
peerQueues
[
p
]
if
!
ok
{
// TODO: log error?
if
!
ok
||
pq
.
RefDecrement
()
{
pm
.
peerQueuesLk
.
Unlock
()
return
}
if
pq
.
RefDecrement
()
{
return
}
delete
(
pm
.
peerQueues
,
p
)
pm
.
peerQueuesLk
.
Unlock
()
pq
.
Shutdown
()
pm
.
remove
(
p
)
}
// SendMessage is called to send a message to all or some peers in the pool;
...
...
@@ -108,13 +107,6 @@ func (pm *PeerManager) SendMessage(entries []*bsmsg.Entry, targets []peer.ID, fr
}
}
func
(
pm
*
PeerManager
)
get
(
p
peer
.
ID
)
(
PeerQueue
,
bool
)
{
pm
.
peerQueuesLk
.
RLock
()
pq
,
ok
:=
pm
.
peerQueues
[
p
]
pm
.
peerQueuesLk
.
RUnlock
()
return
pq
,
ok
}
func
(
pm
*
PeerManager
)
getOrCreate
(
p
peer
.
ID
)
PeerQueue
{
pm
.
peerQueuesLk
.
Lock
()
pq
,
ok
:=
pm
.
peerQueues
[
p
]
...
...
@@ -127,12 +119,6 @@ func (pm *PeerManager) getOrCreate(p peer.ID) PeerQueue {
return
pq
}
func
(
pm
*
PeerManager
)
remove
(
p
peer
.
ID
)
{
pm
.
peerQueuesLk
.
Lock
()
delete
(
pm
.
peerQueues
,
p
)
pm
.
peerQueuesLk
.
Unlock
()
}
func
(
pm
*
PeerManager
)
iterate
(
iterateFn
func
(
peer
.
ID
,
PeerQueue
))
{
pm
.
peerQueuesLk
.
RLock
()
for
p
,
pq
:=
range
pm
.
peerQueues
{
...
...
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