diff --git a/decision/peer_request_queue.go b/decision/peer_request_queue.go index c7aaf553..0fa78c8a 100644 --- a/decision/peer_request_queue.go +++ b/decision/peer_request_queue.go @@ -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 diff --git a/wantlist/wantlist.go b/wantlist/wantlist.go index 118a19ff..1da4ed97 100644 --- a/wantlist/wantlist.go +++ b/wantlist/wantlist.go @@ -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 {