Commit 1e42bbab authored by Dirk McCormick's avatar Dirk McCormick

refactor: rename IsDontHave to KnowBlockSize

parent 32af156d
......@@ -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.IsDontHave = replacement.IsDontHave
t.KnowBlockSize = replacement.KnowBlockSize
t.Size = replacement.Size
}
......
......@@ -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.IsDontHave && !task.IsDontHave {
if !existingTask.KnowBlockSize && task.KnowBlockSize {
existingTask.Size = task.Size
existingTask.IsDontHave = false
existingTask.KnowBlockSize = true
}
// 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.IsDontHave {
if at.KnowBlockSize {
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.IsDontHave {
if !haveSize && task.KnowBlockSize {
return true
}
......
......@@ -22,12 +22,12 @@ func TestPushPop(t *testing.T) {
tasks := []peertask.Task{
peertask.Task{
Identifier: "1",
Priority: 1,
IsWantBlock: true,
IsDontHave: false,
SendDontHave: false,
Size: 10,
Identifier: "1",
Priority: 1,
IsWantBlock: true,
KnowBlockSize: true,
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: false,
SendDontHave: false,
Size: 10,
Identifier: "1",
Priority: 10,
IsWantBlock: true,
KnowBlockSize: true,
SendDontHave: false,
Size: 10,
},
peertask.Task{
Identifier: "2",
Priority: 20,
IsWantBlock: true,
IsDontHave: false,
SendDontHave: false,
Size: 10,
Identifier: "2",
Priority: 20,
IsWantBlock: true,
KnowBlockSize: true,
SendDontHave: false,
Size: 10,
},
peertask.Task{
Identifier: "3",
Priority: 15,
IsWantBlock: true,
IsDontHave: false,
SendDontHave: false,
Size: 10,
Identifier: "3",
Priority: 15,
IsWantBlock: true,
KnowBlockSize: true,
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: false,
SendDontHave: false,
Size: 10,
Identifier: "1",
Priority: 10,
IsWantBlock: true,
KnowBlockSize: true,
SendDontHave: false,
Size: 10,
},
peertask.Task{
Identifier: "2",
Priority: 20,
IsWantBlock: true,
IsDontHave: false,
SendDontHave: false,
Size: 10,
Identifier: "2",
Priority: 20,
IsWantBlock: true,
KnowBlockSize: true,
SendDontHave: false,
Size: 10,
},
peertask.Task{
Identifier: "3",
Priority: 15,
IsWantBlock: true,
IsDontHave: false,
SendDontHave: false,
Size: 10,
Identifier: "3",
Priority: 15,
IsWantBlock: true,
KnowBlockSize: true,
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: false,
SendDontHave: false,
Size: 10,
Identifier: "1",
Priority: 10,
IsWantBlock: true,
KnowBlockSize: true,
SendDontHave: false,
Size: 10,
},
peertask.Task{
Identifier: "1",
Priority: 20,
IsWantBlock: false,
IsDontHave: false,
SendDontHave: false,
Size: 10,
Identifier: "1",
Priority: 20,
IsWantBlock: false,
KnowBlockSize: true,
SendDontHave: false,
Size: 10,
},
peertask.Task{
Identifier: "2",
Priority: 15,
IsWantBlock: true,
IsDontHave: false,
SendDontHave: false,
Size: 10,
Identifier: "2",
Priority: 15,
IsWantBlock: true,
KnowBlockSize: true,
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: false,
SendDontHave: false,
Size: 10,
Identifier: "1",
Priority: 10,
IsWantBlock: true,
KnowBlockSize: true,
SendDontHave: false,
Size: 10,
},
peertask.Task{
Identifier: "1",
Priority: 20,
IsWantBlock: false,
IsDontHave: false,
SendDontHave: false,
Size: 10,
Identifier: "1",
Priority: 20,
IsWantBlock: false,
KnowBlockSize: true,
SendDontHave: false,
Size: 10,
},
peertask.Task{
Identifier: "2",
Priority: 15,
IsWantBlock: true,
IsDontHave: false,
SendDontHave: false,
Size: 10,
Identifier: "2",
Priority: 15,
IsWantBlock: true,
KnowBlockSize: true,
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: false,
SendDontHave: false,
Size: 10,
Identifier: "1",
Priority: 10,
IsWantBlock: false,
KnowBlockSize: true,
SendDontHave: false,
Size: 10,
}
wantBlock := peertask.Task{
Identifier: "1",
Priority: 10,
IsWantBlock: true,
IsDontHave: false,
SendDontHave: false,
Size: 10,
Identifier: "1",
Priority: 10,
IsWantBlock: true,
KnowBlockSize: true,
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: false,
SendDontHave: false,
Size: 20,
Identifier: "1",
Priority: 10,
IsWantBlock: true,
KnowBlockSize: true,
SendDontHave: false,
Size: 20,
}
wantBlockDontHave := peertask.Task{
Identifier: "1",
Priority: 10,
IsWantBlock: true,
IsDontHave: true,
SendDontHave: false,
Size: 10,
Identifier: "1",
Priority: 10,
IsWantBlock: true,
KnowBlockSize: false,
SendDontHave: false,
Size: 10,
}
wantHave := peertask.Task{
Identifier: "1",
Priority: 10,
IsWantBlock: false,
IsDontHave: false,
SendDontHave: false,
Size: 30,
Identifier: "1",
Priority: 10,
IsWantBlock: false,
KnowBlockSize: true,
SendDontHave: false,
Size: 30,
}
wantHaveDontHave := peertask.Task{
Identifier: "1",
Priority: 10,
IsWantBlock: false,
IsDontHave: true,
SendDontHave: false,
Size: 10,
Identifier: "1",
Priority: 10,
IsWantBlock: false,
KnowBlockSize: false,
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: false,
SendDontHave: false,
Size: 10,
Identifier: "1",
Priority: 10,
IsWantBlock: false,
KnowBlockSize: true,
SendDontHave: false,
Size: 10,
}
wantBlock := peertask.Task{
Identifier: "1",
Priority: 10,
IsWantBlock: true,
IsDontHave: false,
SendDontHave: false,
Size: 10,
Identifier: "1",
Priority: 10,
IsWantBlock: true,
KnowBlockSize: true,
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: false,
SendDontHave: false,
Size: 10,
Identifier: "1",
Priority: 10,
IsWantBlock: true,
KnowBlockSize: true,
SendDontHave: false,
Size: 10,
}
wantBlockDontHave := peertask.Task{
Identifier: "1",
Priority: 10,
IsWantBlock: true,
IsDontHave: true,
SendDontHave: false,
Size: 10,
Identifier: "1",
Priority: 10,
IsWantBlock: true,
KnowBlockSize: false,
SendDontHave: false,
Size: 10,
}
wantHave := peertask.Task{
Identifier: "1",
Priority: 10,
IsWantBlock: false,
IsDontHave: false,
SendDontHave: false,
Size: 10,
Identifier: "1",
Priority: 10,
IsWantBlock: false,
KnowBlockSize: true,
SendDontHave: false,
Size: 10,
}
wantHaveDontHave := peertask.Task{
Identifier: "1",
Priority: 10,
IsWantBlock: false,
IsDontHave: true,
SendDontHave: false,
Size: 10,
Identifier: "1",
Priority: 10,
IsWantBlock: false,
KnowBlockSize: false,
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: false,
SendDontHave: false,
Size: 10,
Identifier: "1",
Priority: 10,
IsWantBlock: true,
KnowBlockSize: true,
SendDontHave: false,
Size: 10,
}
wantHave := peertask.Task{
Identifier: "1",
Priority: 10,
IsWantBlock: false,
IsDontHave: false,
SendDontHave: false,
Size: 10,
Identifier: "1",
Priority: 10,
IsWantBlock: false,
KnowBlockSize: true,
SendDontHave: false,
Size: 10,
}
wantHaveDontHave := peertask.Task{
Identifier: "1",
Priority: 10,
IsWantBlock: false,
IsDontHave: true,
SendDontHave: false,
Size: 10,
Identifier: "1",
Priority: 10,
IsWantBlock: false,
KnowBlockSize: false,
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: false,
SendDontHave: false,
Size: 10,
Identifier: "1",
Priority: 10,
IsWantBlock: false,
KnowBlockSize: true,
SendDontHave: false,
Size: 10,
}
wantBlock := peertask.Task{
Identifier: "1",
Priority: 10,
IsWantBlock: true,
IsDontHave: false,
SendDontHave: false,
Size: 10,
Identifier: "1",
Priority: 10,
IsWantBlock: true,
KnowBlockSize: true,
SendDontHave: false,
Size: 10,
}
runTestCase := func(tasks []peertask.Task, expCount int) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment