diff --git a/bitswap/client/internal/session/sentwantblockstracker.go b/bitswap/client/internal/session/sentwantblockstracker.go deleted file mode 100644 index 0dfe0630b..000000000 --- a/bitswap/client/internal/session/sentwantblockstracker.go +++ /dev/null @@ -1,33 +0,0 @@ -package session - -import ( - cid "github.com/ipfs/go-cid" - peer "github.com/libp2p/go-libp2p/core/peer" -) - -// sentWantBlocksTracker keeps track of which peers we've sent a want-block to -type sentWantBlocksTracker struct { - sentWantBlocks map[peer.ID]map[cid.Cid]struct{} -} - -func newSentWantBlocksTracker() *sentWantBlocksTracker { - return &sentWantBlocksTracker{ - sentWantBlocks: make(map[peer.ID]map[cid.Cid]struct{}), - } -} - -func (s *sentWantBlocksTracker) addSentWantBlocksTo(p peer.ID, ks []cid.Cid) { - cids, ok := s.sentWantBlocks[p] - if !ok { - cids = make(map[cid.Cid]struct{}, len(ks)) - s.sentWantBlocks[p] = cids - } - for _, c := range ks { - cids[c] = struct{}{} - } -} - -func (s *sentWantBlocksTracker) haveSentWantBlockTo(p peer.ID, c cid.Cid) bool { - _, ok := s.sentWantBlocks[p][c] - return ok -} diff --git a/bitswap/client/internal/session/sentwantblockstracker_test.go b/bitswap/client/internal/session/sentwantblockstracker_test.go deleted file mode 100644 index 7e4435fd8..000000000 --- a/bitswap/client/internal/session/sentwantblockstracker_test.go +++ /dev/null @@ -1,28 +0,0 @@ -package session - -import ( - "testing" - - "github.com/ipfs/go-test/random" -) - -func TestSendWantBlocksTracker(t *testing.T) { - peers := random.Peers(2) - cids := random.Cids(2) - swbt := newSentWantBlocksTracker() - - if swbt.haveSentWantBlockTo(peers[0], cids[0]) { - t.Fatal("expected not to have sent anything yet") - } - - swbt.addSentWantBlocksTo(peers[0], cids) - if !swbt.haveSentWantBlockTo(peers[0], cids[0]) { - t.Fatal("expected to have sent cid to peer") - } - if !swbt.haveSentWantBlockTo(peers[0], cids[1]) { - t.Fatal("expected to have sent cid to peer") - } - if swbt.haveSentWantBlockTo(peers[1], cids[0]) { - t.Fatal("expected not to have sent cid to peer") - } -} diff --git a/bitswap/client/internal/session/sessionwantsender.go b/bitswap/client/internal/session/sessionwantsender.go index 682561551..ba7e8b0c5 100644 --- a/bitswap/client/internal/session/sessionwantsender.go +++ b/bitswap/client/internal/session/sessionwantsender.go @@ -94,8 +94,6 @@ type sessionWantSender struct { wants map[cid.Cid]*wantInfo // Keeps track of how many consecutive DONT_HAVEs a peer has sent peerConsecutiveDontHaves map[peer.ID]int - // Tracks which peers we have send want-block to - swbt *sentWantBlocksTracker // Tracks the number of blocks each peer sent us peerRspTrkr *peerResponseTracker // Sends wants to peers @@ -124,7 +122,6 @@ func newSessionWantSender(sid uint64, pm PeerManager, spm SessionPeerManager, ca changes: make(chan change, changesBufferSize), wants: make(map[cid.Cid]*wantInfo), peerConsecutiveDontHaves: make(map[peer.ID]int), - swbt: newSentWantBlocksTracker(), peerRspTrkr: newPeerResponseTracker(), pm: pm, @@ -406,14 +403,10 @@ func (sws *sessionWantSender) processUpdates(updates []update) []cid.Cid { // Update the block presence for the peer sws.updateWantBlockPresence(c, upd.from) - // Check if the DONT_HAVE is in response to a want-block - // (could also be in response to want-have) - if sws.swbt.haveSentWantBlockTo(upd.from, c) { - // If we were waiting for a response from this peer, clear - // sentTo so that we can send the want to another peer - if sentTo, ok := sws.getWantSentTo(c); ok && sentTo == upd.from { - sws.setWantSentTo(c, "") - } + // If we were waiting for a response from this peer, clear + // sentTo so that we can send the want to another peer + if sentTo, ok := sws.getWantSentTo(c); ok && sentTo == upd.from { + sws.setWantSentTo(c, "") } } } @@ -577,11 +570,6 @@ func (sws *sessionWantSender) sendNextWants(newlyAvailable []peer.ID) { func (sws *sessionWantSender) sendWants(sends allWants) { // For each peer we're sending a request to for p, snd := range sends { - // Piggyback some other want-haves onto the request to the peer - for _, c := range sws.getPiggybackWantHaves(p, snd.wantBlocks) { - snd.wantHaves.Add(c) - } - // Send the wants to the peer. // Note that the PeerManager ensures that we don't sent duplicate // want-haves / want-blocks to a peer, and that want-blocks take @@ -595,24 +583,7 @@ func (sws *sessionWantSender) sendWants(sends allWants) { } // Inform the session that we've sent the wants sws.onSend(p, wblks, whaves) - - // Record which peers we send want-block to - sws.swbt.addSentWantBlocksTo(p, wblks) - } -} - -// getPiggybackWantHaves gets the want-haves that should be piggybacked onto -// a request that we are making to send want-blocks to a peer -func (sws *sessionWantSender) getPiggybackWantHaves(p peer.ID, wantBlocks *cid.Set) []cid.Cid { - var whs []cid.Cid - for c := range sws.wants { - // Don't send want-have if we're already sending a want-block - // (or have previously) - if !wantBlocks.Has(c) && !sws.swbt.haveSentWantBlockTo(p, c) { - whs = append(whs, c) - } } - return whs } // newlyExhausted filters the list of keys for wants that have not already