Remove unused request strategy code
This commit is contained in:
parent
1bc84e316f
commit
30375615b3
|
@ -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.
|
||||
|
|
|
@ -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()
|
||||
}))
|
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue