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-peertaskqueue
Commits
f09820a0
Commit
f09820a0
authored
Jun 12, 2019
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge pull request #7 from ipfs/fix/no-extra-freeze
fix(peertaskqueue): don't freeze for node that does not exist
parent
41fab2da
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
14 deletions
+22
-14
peertaskqueue.go
peertaskqueue.go
+12
-11
peertaskqueue_test.go
peertaskqueue_test.go
+8
-2
peertracker/peertracker.go
peertracker/peertracker.go
+2
-1
No files found.
peertaskqueue.go
View file @
f09820a0
...
...
@@ -169,19 +169,20 @@ func (ptq *PeerTaskQueue) Remove(identifier peertask.Identifier, p peer.ID) {
ptq
.
lock
.
Lock
()
peerTracker
,
ok
:=
ptq
.
peerTrackers
[
p
]
if
ok
{
peerTracker
.
Remove
(
identifier
)
// we now also 'freeze' that partner. If they sent us a cancel for a
// block we were about to send them, we should wait a short period of time
// to make sure we receive any other in-flight cancels before sending
// them a block they already potentially have
if
!
ptq
.
ignoreFreezing
{
if
!
peerTracker
.
IsFrozen
()
{
ptq
.
frozenPeers
[
p
]
=
struct
{}{}
if
peerTracker
.
Remove
(
identifier
)
{
// we now also 'freeze' that partner. If they sent us a cancel for a
// block we were about to send them, we should wait a short period of time
// to make sure we receive any other in-flight cancels before sending
// them a block they already potentially have
if
!
ptq
.
ignoreFreezing
{
if
!
peerTracker
.
IsFrozen
()
{
ptq
.
frozenPeers
[
p
]
=
struct
{}{}
}
peerTracker
.
Freeze
()
}
peerTracker
.
Freeze
()
ptq
.
pQueue
.
Update
(
peerTracker
.
Index
())
}
ptq
.
pQueue
.
Update
(
peerTracker
.
Index
())
}
ptq
.
lock
.
Unlock
()
}
...
...
peertaskqueue_test.go
View file @
f09820a0
...
...
@@ -92,7 +92,7 @@ func TestFreezeUnfreeze(t *testing.T) {
// now, pop off four tasks, there should be one from each
matchNTasks
(
t
,
ptq
,
4
,
a
.
Pretty
(),
b
.
Pretty
(),
c
.
Pretty
(),
d
.
Pretty
())
ptq
.
Remove
(
peertask
.
Task
{
Identifier
:
"1"
}
,
b
)
ptq
.
Remove
(
"1"
,
b
)
// b should be frozen, causing it to get skipped in the rotation
matchNTasks
(
t
,
ptq
,
3
,
a
.
Pretty
(),
c
.
Pretty
(),
d
.
Pretty
())
...
...
@@ -101,6 +101,12 @@ func TestFreezeUnfreeze(t *testing.T) {
matchNTasks
(
t
,
ptq
,
1
,
b
.
Pretty
())
// remove none existent task
ptq
.
Remove
(
"-1"
,
b
)
// b should not be frozen
matchNTasks
(
t
,
ptq
,
4
,
a
.
Pretty
(),
b
.
Pretty
(),
c
.
Pretty
(),
d
.
Pretty
())
}
func
TestFreezeUnfreezeNoFreezingOption
(
t
*
testing
.
T
)
{
...
...
@@ -124,7 +130,7 @@ func TestFreezeUnfreezeNoFreezingOption(t *testing.T) {
// now, pop off four tasks, there should be one from each
matchNTasks
(
t
,
ptq
,
4
,
a
.
Pretty
(),
b
.
Pretty
(),
c
.
Pretty
(),
d
.
Pretty
())
ptq
.
Remove
(
peertask
.
Task
{
Identifier
:
"1"
}
,
b
)
ptq
.
Remove
(
"1"
,
b
)
// b should be frozen, causing it to get skipped in the rotation
matchNTasks
(
t
,
ptq
,
4
,
a
.
Pretty
(),
b
.
Pretty
(),
c
.
Pretty
(),
d
.
Pretty
())
...
...
peertracker/peertracker.go
View file @
f09820a0
...
...
@@ -179,12 +179,13 @@ func (p *PeerTracker) PopBlock() *peertask.TaskBlock {
}
// Remove removes the task with the given identifier from this peers queue
func
(
p
*
PeerTracker
)
Remove
(
identifier
peertask
.
Identifier
)
{
func
(
p
*
PeerTracker
)
Remove
(
identifier
peertask
.
Identifier
)
bool
{
taskBlock
,
ok
:=
p
.
taskMap
[
identifier
]
if
ok
{
taskBlock
.
MarkPrunable
(
identifier
)
p
.
numTasks
--
}
return
ok
}
// Freeze increments the freeze value for this peer. While a peer is frozen
...
...
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