Commit 0bdc018c authored by hannahhoward's avatar hannahhoward

feat(peerrequestqueue): add target to queue

Add a peer id to an active partner queue
parent 0a309a17
...@@ -51,7 +51,7 @@ func (tl *prq) Push(to peer.ID, entries ...wantlist.Entry) { ...@@ -51,7 +51,7 @@ func (tl *prq) Push(to peer.ID, entries ...wantlist.Entry) {
defer tl.lock.Unlock() defer tl.lock.Unlock()
partner, ok := tl.partners[to] partner, ok := tl.partners[to]
if !ok { if !ok {
partner = newActivePartner() partner = newActivePartner(to)
tl.pQueue.Push(partner) tl.pQueue.Push(partner)
tl.partners[to] = partner tl.partners[to] = partner
} }
...@@ -137,13 +137,9 @@ func (tl *prq) Pop() *peerRequestTask { ...@@ -137,13 +137,9 @@ func (tl *prq) Pop() *peerRequestTask {
} }
if partner.IsIdle() { if partner.IsIdle() {
for target, testPartner := range tl.partners { target := partner.target
if testPartner == partner {
delete(tl.partners, target) delete(tl.partners, target)
delete(tl.frozen, target) delete(tl.frozen, target)
break
}
}
} else { } else {
tl.pQueue.Push(partner) tl.pQueue.Push(partner)
} }
...@@ -262,7 +258,7 @@ func wrapCmp(f func(a, b *peerRequestTask) bool) func(a, b pq.Elem) bool { ...@@ -262,7 +258,7 @@ func wrapCmp(f func(a, b *peerRequestTask) bool) func(a, b pq.Elem) bool {
} }
type activePartner struct { type activePartner struct {
target peer.ID
// Active is the number of blocks this peer is currently being sent // Active is the number of blocks this peer is currently being sent
// active must be locked around as it will be updated externally // active must be locked around as it will be updated externally
activelk sync.Mutex activelk sync.Mutex
...@@ -284,8 +280,9 @@ type activePartner struct { ...@@ -284,8 +280,9 @@ type activePartner struct {
taskQueue pq.PQ taskQueue pq.PQ
} }
func newActivePartner() *activePartner { func newActivePartner(target peer.ID) *activePartner {
return &activePartner{ return &activePartner{
target: target,
taskQueue: pq.New(wrapCmp(V1)), taskQueue: pq.New(wrapCmp(V1)),
activeBlocks: cid.NewSet(), activeBlocks: cid.NewSet(),
} }
......
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