Commit fd0e1ff6 authored by Dirk McCormick's avatar Dirk McCormick

fix: log unexpected condition in peerWantManager.prepareSendWants()

parent 7348b26c
...@@ -4,12 +4,15 @@ import ( ...@@ -4,12 +4,15 @@ import (
"context" "context"
"sync" "sync"
logging "github.com/ipfs/go-log"
"github.com/ipfs/go-metrics-interface" "github.com/ipfs/go-metrics-interface"
cid "github.com/ipfs/go-cid" cid "github.com/ipfs/go-cid"
peer "github.com/libp2p/go-libp2p-core/peer" peer "github.com/libp2p/go-libp2p-core/peer"
) )
var log = logging.Logger("bs:peermgr")
// PeerQueue provides a queue of messages to be sent for a single peer. // PeerQueue provides a queue of messages to be sent for a single peer.
type PeerQueue interface { type PeerQueue interface {
AddBroadcastWantHaves([]cid.Cid) AddBroadcastWantHaves([]cid.Cid)
......
...@@ -86,35 +86,44 @@ func (pwm *peerWantManager) prepareSendWants(p peer.ID, wantBlocks []cid.Cid, wa ...@@ -86,35 +86,44 @@ func (pwm *peerWantManager) prepareSendWants(p peer.ID, wantBlocks []cid.Cid, wa
resWantHvs := make([]cid.Cid, 0) resWantHvs := make([]cid.Cid, 0)
// Get the existing want-blocks and want-haves for the peer // Get the existing want-blocks and want-haves for the peer
if pws, ok := pwm.peerWants[p]; ok { pws, ok := pwm.peerWants[p]
// Iterate over the requested want-blocks
for _, c := range wantBlocks { if !ok {
// If the want-block hasn't been sent to the peer // In practice this should never happen:
if !pws.wantBlocks.Has(c) { // - PeerManager calls addPeer() as soon as the peer connects
// Record that the CID was sent as a want-block // - PeerManager calls removePeer() as soon as the peer disconnects
pws.wantBlocks.Add(c) // - All calls to PeerWantManager are locked
log.Errorf("prepareSendWants() called with peer %s but peer not found in peerWantManager", string(p))
return resWantBlks, resWantHvs
}
// Add the CID to the results // Iterate over the requested want-blocks
resWantBlks = append(resWantBlks, c) for _, c := range wantBlocks {
// If the want-block hasn't been sent to the peer
if !pws.wantBlocks.Has(c) {
// Record that the CID was sent as a want-block
pws.wantBlocks.Add(c)
// Make sure the CID is no longer recorded as a want-have // Add the CID to the results
pws.wantHaves.Remove(c) resWantBlks = append(resWantBlks, c)
// Increment the count of want-blocks // Make sure the CID is no longer recorded as a want-have
pwm.wantBlockGauge.Inc() pws.wantHaves.Remove(c)
}
// Increment the count of want-blocks
pwm.wantBlockGauge.Inc()
} }
}
// Iterate over the requested want-haves // Iterate over the requested want-haves
for _, c := range wantHaves { for _, c := range wantHaves {
// If the CID has not been sent as a want-block or want-have // If the CID has not been sent as a want-block or want-have
if !pws.wantBlocks.Has(c) && !pws.wantHaves.Has(c) { if !pws.wantBlocks.Has(c) && !pws.wantHaves.Has(c) {
// Record that the CID was sent as a want-have // Record that the CID was sent as a want-have
pws.wantHaves.Add(c) pws.wantHaves.Add(c)
// Add the CID to the results // Add the CID to the results
resWantHvs = append(resWantHvs, c) resWantHvs = append(resWantHvs, c)
}
} }
} }
......
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