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
1e42bbab
Commit
1e42bbab
authored
Sep 26, 2019
by
Dirk McCormick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: rename IsDontHave to KnowBlockSize
parent
32af156d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
192 additions
and
192 deletions
+192
-192
peertask/peertask.go
peertask/peertask.go
+8
-8
peertracker/peertracker.go
peertracker/peertracker.go
+4
-4
peertracker/peertracker_test.go
peertracker/peertracker_test.go
+180
-180
No files found.
peertask/peertask.go
View file @
1e42bbab
...
...
@@ -37,13 +37,13 @@ type Identifier interface{}
// Task is a single task to be executed as part of a task block.
type
Task
struct
{
Identifier
Identifier
Priority
int
IsWantBlock
bool
IsDontHave
bool
SendDontHave
bool
Size
int
Uuid
uuid
.
UUID
Identifier
Identifier
Priority
int
IsWantBlock
bool
KnowBlockSize
bool
SendDontHave
bool
Size
int
Uuid
uuid
.
UUID
}
// QueueTask contains a Task, and also some bookkeeping information.
...
...
@@ -60,7 +60,7 @@ func (t *QueueTask) ReplaceWith(replacement *QueueTask) {
t
.
Priority
=
replacement
.
Priority
t
.
IsWantBlock
=
replacement
.
IsWantBlock
t
.
SendDontHave
=
replacement
.
SendDontHave
t
.
IsDontHav
e
=
replacement
.
IsDontHav
e
t
.
KnowBlockSiz
e
=
replacement
.
KnowBlockSiz
e
t
.
Size
=
replacement
.
Size
}
...
...
peertracker/peertracker.go
View file @
1e42bbab
...
...
@@ -129,9 +129,9 @@ func (p *PeerTracker) PushTasks(tasks []peertask.Task) {
}
// If we now know the size of the block, update the existing entry
if
existingTask
.
IsDontHav
e
&&
!
task
.
IsDontHav
e
{
if
!
existingTask
.
KnowBlockSiz
e
&&
task
.
KnowBlockSiz
e
{
existingTask
.
Size
=
task
.
Size
existingTask
.
IsDontHave
=
fals
e
existingTask
.
KnowBlockSize
=
tru
e
}
// We can replace a want-have with a want-block
...
...
@@ -259,7 +259,7 @@ func (p *PeerTracker) taskHasMoreInfoThanActiveTasks(task peertask.Task) bool {
if
task
.
Identifier
==
at
.
Identifier
{
taskWithIdExists
=
true
if
!
at
.
IsDontHav
e
{
if
at
.
KnowBlockSiz
e
{
haveSize
=
true
}
...
...
@@ -282,7 +282,7 @@ func (p *PeerTracker) taskHasMoreInfoThanActiveTasks(task peertask.Task) bool {
// If there is no size information for the CID and the new task has
// size information, the new task is better
if
!
haveSize
&&
!
task
.
IsDontHav
e
{
if
!
haveSize
&&
task
.
KnowBlockSiz
e
{
return
true
}
...
...
peertracker/peertracker_test.go
View file @
1e42bbab
...
...
@@ -22,12 +22,12 @@ func TestPushPop(t *testing.T) {
tasks
:=
[]
peertask
.
Task
{
peertask
.
Task
{
Identifier
:
"1"
,
Priority
:
1
,
IsWantBlock
:
true
,
IsDontHave
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"1"
,
Priority
:
1
,
IsWantBlock
:
true
,
KnowBlockSize
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
},
}
tracker
.
PushTasks
(
tasks
)
...
...
@@ -46,28 +46,28 @@ func TestPushPopSizeAndOrder(t *testing.T) {
tasks
:=
[]
peertask
.
Task
{
peertask
.
Task
{
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
true
,
IsDontHave
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
true
,
KnowBlockSize
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
},
peertask
.
Task
{
Identifier
:
"2"
,
Priority
:
20
,
IsWantBlock
:
true
,
IsDontHave
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"2"
,
Priority
:
20
,
IsWantBlock
:
true
,
KnowBlockSize
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
},
peertask
.
Task
{
Identifier
:
"3"
,
Priority
:
15
,
IsWantBlock
:
true
,
IsDontHave
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"3"
,
Priority
:
15
,
IsWantBlock
:
true
,
KnowBlockSize
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
},
}
tracker
.
PushTasks
(
tasks
)
...
...
@@ -104,28 +104,28 @@ func TestRemove(t *testing.T) {
tasks
:=
[]
peertask
.
Task
{
peertask
.
Task
{
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
true
,
IsDontHave
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
true
,
KnowBlockSize
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
},
peertask
.
Task
{
Identifier
:
"2"
,
Priority
:
20
,
IsWantBlock
:
true
,
IsDontHave
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"2"
,
Priority
:
20
,
IsWantBlock
:
true
,
KnowBlockSize
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
},
peertask
.
Task
{
Identifier
:
"3"
,
Priority
:
15
,
IsWantBlock
:
true
,
IsDontHave
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"3"
,
Priority
:
15
,
IsWantBlock
:
true
,
KnowBlockSize
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
},
}
tracker
.
PushTasks
(
tasks
)
...
...
@@ -145,28 +145,28 @@ func TestRemoveMulti(t *testing.T) {
tasks
:=
[]
peertask
.
Task
{
peertask
.
Task
{
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
true
,
IsDontHave
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
true
,
KnowBlockSize
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
},
peertask
.
Task
{
Identifier
:
"1"
,
Priority
:
20
,
IsWantBlock
:
false
,
IsDontHave
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"1"
,
Priority
:
20
,
IsWantBlock
:
false
,
KnowBlockSize
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
},
peertask
.
Task
{
Identifier
:
"2"
,
Priority
:
15
,
IsWantBlock
:
true
,
IsDontHave
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"2"
,
Priority
:
15
,
IsWantBlock
:
true
,
KnowBlockSize
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
},
}
tracker
.
PushTasks
(
tasks
)
...
...
@@ -186,28 +186,28 @@ func TestRemoveActive(t *testing.T) {
tasks
:=
[]
peertask
.
Task
{
peertask
.
Task
{
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
true
,
IsDontHave
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
true
,
KnowBlockSize
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
},
peertask
.
Task
{
Identifier
:
"1"
,
Priority
:
20
,
IsWantBlock
:
false
,
IsDontHave
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"1"
,
Priority
:
20
,
IsWantBlock
:
false
,
KnowBlockSize
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
},
peertask
.
Task
{
Identifier
:
"2"
,
Priority
:
15
,
IsWantBlock
:
true
,
IsDontHave
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"2"
,
Priority
:
15
,
IsWantBlock
:
true
,
KnowBlockSize
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
},
}
...
...
@@ -238,20 +238,20 @@ func TestPushHaveVsBlock(t *testing.T) {
partner
:=
testutil
.
GeneratePeers
(
1
)[
0
]
wantHave
:=
peertask
.
Task
{
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
false
,
IsDontHave
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
false
,
KnowBlockSize
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
}
wantBlock
:=
peertask
.
Task
{
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
true
,
IsDontHave
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
true
,
KnowBlockSize
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
}
runTestCase
:=
func
(
tasks
[]
peertask
.
Task
,
expIsWantBlock
bool
)
{
...
...
@@ -282,36 +282,36 @@ func TestPushSizeInfo(t *testing.T) {
partner
:=
testutil
.
GeneratePeers
(
1
)[
0
]
wantBlock
:=
peertask
.
Task
{
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
true
,
IsDontHave
:
fals
e
,
SendDontHave
:
false
,
Size
:
20
,
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
true
,
KnowBlockSize
:
tru
e
,
SendDontHave
:
false
,
Size
:
20
,
}
wantBlockDontHave
:=
peertask
.
Task
{
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
true
,
IsDontHave
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
true
,
KnowBlockSize
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
}
wantHave
:=
peertask
.
Task
{
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
false
,
IsDontHave
:
fals
e
,
SendDontHave
:
false
,
Size
:
30
,
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
false
,
KnowBlockSize
:
tru
e
,
SendDontHave
:
false
,
Size
:
30
,
}
wantHaveDontHave
:=
peertask
.
Task
{
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
false
,
IsDontHave
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
false
,
KnowBlockSize
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
}
runTestCase
:=
func
(
tasks
[]
peertask
.
Task
,
expSize
int
)
{
...
...
@@ -340,20 +340,20 @@ func TestPushHaveVsBlockActive(t *testing.T) {
partner
:=
testutil
.
GeneratePeers
(
1
)[
0
]
wantHave
:=
peertask
.
Task
{
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
false
,
IsDontHave
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
false
,
KnowBlockSize
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
}
wantBlock
:=
peertask
.
Task
{
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
true
,
IsDontHave
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
true
,
KnowBlockSize
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
}
runTestCase
:=
func
(
tasks
[]
peertask
.
Task
,
expCount
int
)
{
...
...
@@ -384,36 +384,36 @@ func TestPushSizeInfoActive(t *testing.T) {
partner
:=
testutil
.
GeneratePeers
(
1
)[
0
]
wantBlock
:=
peertask
.
Task
{
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
true
,
IsDontHave
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
true
,
KnowBlockSize
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
}
wantBlockDontHave
:=
peertask
.
Task
{
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
true
,
IsDontHave
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
true
,
KnowBlockSize
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
}
wantHave
:=
peertask
.
Task
{
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
false
,
IsDontHave
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
false
,
KnowBlockSize
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
}
wantHaveDontHave
:=
peertask
.
Task
{
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
false
,
IsDontHave
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
false
,
KnowBlockSize
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
}
runTestCase
:=
func
(
tasks
[]
peertask
.
Task
,
expCount
int
)
{
...
...
@@ -448,28 +448,28 @@ func TestReplaceTaskThatIsActiveAndPending(t *testing.T) {
partner
:=
testutil
.
GeneratePeers
(
1
)[
0
]
wantBlock
:=
peertask
.
Task
{
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
true
,
IsDontHave
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
true
,
KnowBlockSize
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
}
wantHave
:=
peertask
.
Task
{
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
false
,
IsDontHave
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
false
,
KnowBlockSize
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
}
wantHaveDontHave
:=
peertask
.
Task
{
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
false
,
IsDontHave
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
false
,
KnowBlockSize
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
}
tracker
:=
New
(
partner
)
...
...
@@ -500,20 +500,20 @@ func TestTaskDone(t *testing.T) {
partner
:=
testutil
.
GeneratePeers
(
1
)[
0
]
wantHave
:=
peertask
.
Task
{
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
false
,
IsDontHave
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
false
,
KnowBlockSize
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
}
wantBlock
:=
peertask
.
Task
{
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
true
,
IsDontHave
:
fals
e
,
SendDontHave
:
false
,
Size
:
10
,
Identifier
:
"1"
,
Priority
:
10
,
IsWantBlock
:
true
,
KnowBlockSize
:
tru
e
,
SendDontHave
:
false
,
Size
:
10
,
}
runTestCase
:=
func
(
tasks
[]
peertask
.
Task
,
expCount
int
)
{
...
...
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