Skip to content
This repository was archived by the owner on Feb 1, 2023. It is now read-only.

Commit b51c20e

Browse files
committed
feat(wantlist): remove trash field
put trash field only where it is needed, in peer request queues
1 parent 577685b commit b51c20e

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

decision/peer_request_queue.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (tl *prq) Push(to peer.ID, entries ...*wantlist.Entry) {
6060
defer partner.activelk.Unlock()
6161

6262
var priority int
63-
newEntries := make([]*wantlist.Entry, 0, len(entries))
63+
newEntries := make([]*peerRequestTaskEntry, 0, len(entries))
6464
for _, entry := range entries {
6565
if partner.activeBlocks.Has(entry.Cid) {
6666
continue
@@ -75,7 +75,7 @@ func (tl *prq) Push(to peer.ID, entries ...*wantlist.Entry) {
7575
if entry.Priority > priority {
7676
priority = entry.Priority
7777
}
78-
newEntries = append(newEntries, entry)
78+
newEntries = append(newEntries, &peerRequestTaskEntry{entry, false})
7979
}
8080

8181
if len(newEntries) == 0 {
@@ -86,7 +86,7 @@ func (tl *prq) Push(to peer.ID, entries ...*wantlist.Entry) {
8686
Entries: newEntries,
8787
Target: to,
8888
created: time.Now(),
89-
Done: func(e []*wantlist.Entry) {
89+
Done: func(e []*peerRequestTaskEntry) {
9090
tl.lock.Lock()
9191
for _, entry := range e {
9292
partner.TaskDone(entry.Cid)
@@ -117,10 +117,10 @@ func (tl *prq) Pop() *peerRequestTask {
117117
for partner.taskQueue.Len() > 0 && partner.freezeVal == 0 {
118118
out = partner.taskQueue.Pop().(*peerRequestTask)
119119

120-
newEntries := make([]*wantlist.Entry, 0, len(out.Entries))
120+
newEntries := make([]*peerRequestTaskEntry, 0, len(out.Entries))
121121
for _, entry := range out.Entries {
122122
delete(tl.taskMap, taskEntryKey{out.Target, entry.Cid})
123-
if entry.Trash {
123+
if entry.trash {
124124
continue
125125
}
126126
partner.requests--
@@ -150,7 +150,7 @@ func (tl *prq) Remove(k cid.Cid, p peer.ID) {
150150
// remove the task "lazily"
151151
// simply mark it as trash, so it'll be dropped when popped off the
152152
// queue.
153-
entry.Trash = true
153+
entry.trash = true
154154
break
155155
}
156156
}
@@ -197,13 +197,18 @@ func (tl *prq) thawRound() {
197197
}
198198
}
199199

200+
type peerRequestTaskEntry struct {
201+
*wantlist.Entry
202+
// trash in a book-keeping field
203+
trash bool
204+
}
200205
type peerRequestTask struct {
201-
Entries []*wantlist.Entry
206+
Entries []*peerRequestTaskEntry
202207
Priority int
203208
Target peer.ID
204209

205210
// A callback to signal that this task has been completed
206-
Done func([]*wantlist.Entry)
211+
Done func([]*peerRequestTaskEntry)
207212

208213
// created marks the time that the task was added to the queue
209214
created time.Time

wantlist/wantlist.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ type Wantlist struct {
1919
type Entry struct {
2020
Cid cid.Cid
2121
Priority int
22-
23-
// Trash in a book-keeping field
24-
Trash bool
2522
}
2623

2724
type sessionTrackedEntry struct {

0 commit comments

Comments
 (0)