Skip to content

Commit

Permalink
feat(wantlist): remove trash field
Browse files Browse the repository at this point in the history
put trash field only where it is needed, in peer request queues


This commit was moved from ipfs/go-bitswap@95f6e62
  • Loading branch information
hannahhoward committed Feb 20, 2019
1 parent 3100483 commit 81c5613
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
21 changes: 13 additions & 8 deletions bitswap/decision/peer_request_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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--
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions bitswap/wantlist/wantlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 81c5613

Please sign in to comment.