From 30375615b3560f8cd51acdd027e7d908c13a2057 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sat, 11 Dec 2021 14:14:24 +1100 Subject: [PATCH] Remove unused request strategy code --- request-strategy/order.go | 26 ------------ request-strategy/order_test.go | 72 ---------------------------------- request-strategy/peer.go | 27 ------------- 3 files changed, 125 deletions(-) delete mode 100644 request-strategy/order_test.go diff --git a/request-strategy/order.go b/request-strategy/order.go index 4068ed4d..0fa51698 100644 --- a/request-strategy/order.go +++ b/request-strategy/order.go @@ -43,32 +43,6 @@ func pieceOrderLess(i, j pieceOrderInput) multiless.Computation { }) } -type requestsPeer struct { - Peer - nextState PeerNextRequestState - requestablePiecesRemaining int -} - -func (rp *requestsPeer) canFitRequest() bool { - return int(rp.nextState.Requests.GetCardinality()) < rp.MaxRequests -} - -func (rp *requestsPeer) addNextRequest(r RequestIndex) { - if !rp.nextState.Requests.CheckedAdd(r) { - panic("should only add once") - } -} - -type peersForPieceRequests struct { - requestsInPiece int - *requestsPeer -} - -func (me *peersForPieceRequests) addNextRequest(r RequestIndex) { - me.requestsPeer.addNextRequest(r) - me.requestsInPiece++ -} - var packageExpvarMap = expvar.NewMap("request-strategy") // Calls f with requestable pieces in order. diff --git a/request-strategy/order_test.go b/request-strategy/order_test.go deleted file mode 100644 index bcac41d1..00000000 --- a/request-strategy/order_test.go +++ /dev/null @@ -1,72 +0,0 @@ -package request_strategy - -import ( - "encoding/gob" - "testing" - - "github.com/RoaringBitmap/roaring" - qt "github.com/frankban/quicktest" - "github.com/google/go-cmp/cmp" -) - -func init() { - gob.Register(chunkIterRange(0)) - gob.Register(sliceChunksIter{}) -} - -type chunkIterRange ChunkIndex - -func (me chunkIterRange) Iter(f func(ChunkIndex)) { - for offset := ChunkIndex(0); offset < ChunkIndex(me); offset += 1 { - f(offset) - } -} - -type sliceChunksIter []ChunkIndex - -func chunkIter(offsets ...ChunkIndex) ChunksIter { - return sliceChunksIter(offsets) -} - -func (offsets sliceChunksIter) Iter(f func(ChunkIndex)) { - for _, offset := range offsets { - f(offset) - } -} - -func requestSetFromSlice(rs ...RequestIndex) (ret roaring.Bitmap) { - ret.AddMany(rs) - return -} - -func init() { - gob.Register(intPeerId(0)) -} - -type intPeerId int - -func (i intPeerId) Uintptr() uintptr { - return uintptr(i) -} - -var hasAllRequests = func() (all roaring.Bitmap) { - all.AddRange(0, roaring.MaxRange) - return -}() - -func checkNumRequestsAndInterest(c *qt.C, next PeerNextRequestState, num uint64, interest bool) { - addressableBm := next.Requests - c.Check(addressableBm.GetCardinality(), qt.ContentEquals, num) - c.Check(next.Interested, qt.Equals, interest) -} - -func checkResultsRequestsLen(t *testing.T, reqs roaring.Bitmap, l uint64) { - qt.Check(t, reqs.GetCardinality(), qt.Equals, l) -} - -var peerNextRequestStateChecker = qt.CmpEquals( - cmp.Transformer( - "bitmap", - func(bm roaring.Bitmap) []uint32 { - return bm.ToArray() - })) diff --git a/request-strategy/peer.go b/request-strategy/peer.go index b031d28e..be870636 100644 --- a/request-strategy/peer.go +++ b/request-strategy/peer.go @@ -1,8 +1,6 @@ package request_strategy import ( - "time" - "github.com/RoaringBitmap/roaring" ) @@ -10,28 +8,3 @@ type PeerNextRequestState struct { Interested bool Requests roaring.Bitmap } - -type PeerId interface { - Uintptr() uintptr -} - -type Peer struct { - Pieces roaring.Bitmap - MaxRequests int - ExistingRequests roaring.Bitmap - Choking bool - PieceAllowedFast roaring.Bitmap - DownloadRate float64 - Age time.Duration - // This is passed back out at the end, so must support equality. Could be a type-param later. - Id PeerId -} - -// TODO: This might be used in more places I think. -func (p *Peer) canRequestPiece(i pieceIndex) bool { - return (!p.Choking || p.PieceAllowedFast.Contains(uint32(i))) && p.HasPiece(i) -} - -func (p *Peer) HasPiece(i pieceIndex) bool { - return p.Pieces.Contains(uint32(i)) -} -- 2.48.1