Commit 131b9df7 authored by Steven Allen's avatar Steven Allen

give peers more weight when actively participating in a session

parent 401b87dd
......@@ -14,8 +14,10 @@ import (
var log = logging.Logger("bitswap")
const (
maxOptimizedPeers = 32
reservePeers = 2
maxOptimizedPeers = 32
reservePeers = 2
unoptimizedTagValue = 5 // tag value for "unoptimized" session peers.
optimizedTagValue = 10 // tag value for "optimized" session peers.
)
// PeerTagger is an interface for tagging peers with metadata
......@@ -131,7 +133,7 @@ func (spm *SessionPeerManager) run(ctx context.Context) {
}
}
func (spm *SessionPeerManager) tagPeer(p peer.ID) {
func (spm *SessionPeerManager) tagPeer(p peer.ID, value int) {
spm.tagger.TagPeer(p, spm.tag, 10)
}
......@@ -173,7 +175,7 @@ func (pfm *peerFoundMessage) handle(spm *SessionPeerManager) {
if _, ok := spm.activePeers[p]; !ok {
spm.activePeers[p] = false
spm.unoptimizedPeersArr = append(spm.unoptimizedPeersArr, p)
spm.tagPeer(p)
spm.tagPeer(p, unoptimizedTagValue)
}
}
......@@ -182,17 +184,16 @@ type peerResponseMessage struct {
}
func (prm *peerResponseMessage) handle(spm *SessionPeerManager) {
p := prm.p
isOptimized, ok := spm.activePeers[p]
if !ok {
spm.activePeers[p] = true
spm.tagPeer(p)
if isOptimized {
spm.removeOptimizedPeer(p)
} else {
if isOptimized {
spm.removeOptimizedPeer(p)
} else {
spm.activePeers[p] = true
spm.activePeers[p] = true
spm.tagPeer(p, optimizedTagValue)
// transition from unoptimized.
if ok {
spm.removeUnoptimizedPeer(p)
}
}
......
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