Commit 95f6e624 authored by hannahhoward's avatar hannahhoward

feat(wantlist): remove trash field

put trash field only where it is needed, in peer request queues
parent 78386f0e
......@@ -60,7 +60,7 @@ func (tl *prq) Push(to peer.ID, entries ...*wantlist.Entry) {
defer partner.activelk.Unlock()
var priority int
newEntries := make([]*wantlist.Entry, 0, len(entries))
newEntries := make([]*peerRequestTaskEntry, 0, len(entries))
for _, entry := range entries {
if partner.activeBlocks.Has(entry.Cid) {
continue
......@@ -75,7 +75,7 @@ func (tl *prq) Push(to peer.ID, entries ...*wantlist.Entry) {
if entry.Priority > priority {
priority = entry.Priority
}
newEntries = append(newEntries, entry)
newEntries = append(newEntries, &peerRequestTaskEntry{entry, false})
}
if len(newEntries) == 0 {
......@@ -86,7 +86,7 @@ func (tl *prq) Push(to peer.ID, entries ...*wantlist.Entry) {
Entries: newEntries,
Target: to,
created: time.Now(),
Done: func(e []*wantlist.Entry) {
Done: func(e []*peerRequestTaskEntry) {
tl.lock.Lock()
for _, entry := range e {
partner.TaskDone(entry.Cid)
......@@ -117,10 +117,10 @@ func (tl *prq) Pop() *peerRequestTask {
for partner.taskQueue.Len() > 0 && partner.freezeVal == 0 {
out = partner.taskQueue.Pop().(*peerRequestTask)
newEntries := make([]*wantlist.Entry, 0, len(out.Entries))
newEntries := make([]*peerRequestTaskEntry, 0, len(out.Entries))
for _, entry := range out.Entries {
delete(tl.taskMap, taskEntryKey{out.Target, entry.Cid})
if entry.Trash {
if entry.trash {
continue
}
partner.requests--
......@@ -150,7 +150,7 @@ func (tl *prq) Remove(k cid.Cid, p peer.ID) {
// remove the task "lazily"
// simply mark it as trash, so it'll be dropped when popped off the
// queue.
entry.Trash = true
entry.trash = true
break
}
}
......@@ -197,13 +197,18 @@ func (tl *prq) thawRound() {
}
}
type peerRequestTaskEntry struct {
*wantlist.Entry
// trash in a book-keeping field
trash bool
}
type peerRequestTask struct {
Entries []*wantlist.Entry
Entries []*peerRequestTaskEntry
Priority int
Target peer.ID
// A callback to signal that this task has been completed
Done func([]*wantlist.Entry)
Done func([]*peerRequestTaskEntry)
// created marks the time that the task was added to the queue
created time.Time
......
......@@ -19,9 +19,6 @@ type Wantlist struct {
type Entry struct {
Cid cid.Cid
Priority int
// Trash in a book-keeping field
Trash bool
}
type sessionTrackedEntry struct {
......
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