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
c7e7afca
Commit
c7e7afca
authored
Jun 03, 2020
by
Dirk McCormick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: ensure conns are unprotected on shutdown
parent
ba0f59c3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
4 deletions
+22
-4
internal/sessionpeermanager/sessionpeermanager.go
internal/sessionpeermanager/sessionpeermanager.go
+7
-2
internal/sessionpeermanager/sessionpeermanager_test.go
internal/sessionpeermanager/sessionpeermanager_test.go
+15
-2
No files found.
internal/sessionpeermanager/sessionpeermanager.go
View file @
c7e7afca
...
...
@@ -78,7 +78,7 @@ func (spm *SessionPeerManager) ProtectConnection(p peer.ID) {
return
}
spm
.
tagger
.
Protect
(
p
,
fmt
.
Sprintf
(
"%d"
,
spm
.
id
))
spm
.
tagger
.
Protect
(
p
,
spm
.
protectedTag
(
))
}
// RemovePeer removes the peer from the SessionPeerManager.
...
...
@@ -93,7 +93,7 @@ func (spm *SessionPeerManager) RemovePeer(p peer.ID) bool {
delete
(
spm
.
peers
,
p
)
spm
.
tagger
.
UntagPeer
(
p
,
spm
.
tag
)
spm
.
tagger
.
Unprotect
(
p
,
fmt
.
Sprintf
(
"%d"
,
spm
.
id
))
spm
.
tagger
.
Unprotect
(
p
,
spm
.
protectedTag
(
))
log
.
Debugw
(
"Bitswap: removed peer from session"
,
"session"
,
spm
.
id
,
"peer"
,
p
,
"peerCount"
,
len
(
spm
.
peers
))
return
true
...
...
@@ -145,5 +145,10 @@ func (spm *SessionPeerManager) Shutdown() {
// connections to those peers
for
p
:=
range
spm
.
peers
{
spm
.
tagger
.
UntagPeer
(
p
,
spm
.
tag
)
spm
.
tagger
.
Unprotect
(
p
,
spm
.
protectedTag
())
}
}
func
(
spm
*
SessionPeerManager
)
protectedTag
()
string
{
return
fmt
.
Sprintf
(
"%d"
,
spm
.
id
)
}
internal/sessionpeermanager/sessionpeermanager_test.go
View file @
c7e7afca
...
...
@@ -62,6 +62,9 @@ func (fpt *fakePeerTagger) Unprotect(p peer.ID, tag string) bool {
if
tags
,
ok
:=
fpt
.
protectedPeers
[
p
];
ok
{
delete
(
tags
,
tag
)
if
len
(
tags
)
==
0
{
delete
(
fpt
.
protectedPeers
,
p
)
}
return
len
(
tags
)
>
0
}
...
...
@@ -270,8 +273,10 @@ func TestProtectConnection(t *testing.T) {
func
TestShutdown
(
t
*
testing
.
T
)
{
peers
:=
testutil
.
GeneratePeers
(
2
)
fpt
:=
&
fakePeerTagger
{}
spm
:=
New
(
1
,
fpt
)
fpt
:=
newFakePeerTagger
()
sid
:=
uint64
(
1
)
sidstr
:=
fmt
.
Sprintf
(
"%d"
,
sid
)
spm
:=
New
(
sid
,
fpt
)
spm
.
AddPeer
(
peers
[
0
])
spm
.
AddPeer
(
peers
[
1
])
...
...
@@ -279,9 +284,17 @@ func TestShutdown(t *testing.T) {
t
.
Fatal
(
"Expected to have tagged two peers"
)
}
spm
.
ProtectConnection
(
peers
[
0
])
if
_
,
ok
:=
fpt
.
protectedPeers
[
peers
[
0
]][
sidstr
];
!
ok
{
t
.
Fatal
(
"Expected peer to be protected"
)
}
spm
.
Shutdown
()
if
len
(
fpt
.
taggedPeers
)
!=
0
{
t
.
Fatal
(
"Expected to have untagged all peers"
)
}
if
len
(
fpt
.
protectedPeers
)
!=
0
{
t
.
Fatal
(
"Expected to have unprotected all peers"
)
}
}
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