Switch requestState to be a slice
This commit is contained in:
parent
f235c8ea51
commit
9eb80abc29
4
go.mod
4
go.mod
|
@ -12,7 +12,7 @@ require (
|
|||
github.com/anacrolix/dht/v2 v2.16.2-0.20220311024416-dd658f18fd51
|
||||
github.com/anacrolix/envpprof v1.2.1
|
||||
github.com/anacrolix/fuse v0.2.0
|
||||
github.com/anacrolix/generics v0.0.0-20220217222028-44932cf46edd
|
||||
github.com/anacrolix/generics v0.0.0-20220510042907-b50562b436ec
|
||||
github.com/anacrolix/go-libutp v1.2.0
|
||||
github.com/anacrolix/log v0.13.1
|
||||
github.com/anacrolix/missinggo v1.3.0
|
||||
|
@ -85,7 +85,7 @@ require (
|
|||
github.com/rs/dnscache v0.0.0-20210201191234-295bba877686 // indirect
|
||||
github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46 // indirect
|
||||
golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838 // indirect
|
||||
golang.org/x/exp v0.0.0-20220328175248-053ad81199eb // indirect
|
||||
golang.org/x/exp v0.0.0-20220428152302-39d4317da171 // indirect
|
||||
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
|
||||
|
|
12
go.sum
12
go.sum
|
@ -15,8 +15,6 @@ github.com/RoaringBitmap/roaring v0.9.4 h1:ckvZSX5gwCRaJYBNe7syNawCU5oruY9gQmjXl
|
|||
github.com/RoaringBitmap/roaring v0.9.4/go.mod h1:icnadbWcNyfEHlYdr+tDlOTih1Bf/h+rzPpv4sbomAA=
|
||||
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
|
||||
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
|
||||
github.com/ajwerner/btree v0.0.0-20211201061316-91c8b66ad617 h1:sxP5D87Mq99SZMHhYBmq1yY4AAVkfNY5Wn02B9crYs0=
|
||||
github.com/ajwerner/btree v0.0.0-20211201061316-91c8b66ad617/go.mod h1:q37NoqncT41qKc048STsifIt69LfUJ8SrWWcz/yam5k=
|
||||
github.com/ajwerner/btree v0.0.0-20211221152037-f427b3e689c0 h1:byYvvbfSo3+9efR4IeReh77gVs4PnNDR3AMOE9NJ7a0=
|
||||
github.com/ajwerner/btree v0.0.0-20211221152037-f427b3e689c0/go.mod h1:q37NoqncT41qKc048STsifIt69LfUJ8SrWWcz/yam5k=
|
||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
|
@ -28,8 +26,6 @@ github.com/alexflint/go-arg v1.4.2/go.mod h1:9iRbDxne7LcR/GSvEr7ma++GLpdIU1zrghf
|
|||
github.com/alexflint/go-scalar v1.0.0/go.mod h1:GpHzbCOZXEKMEcygYQ5n/aa4Aq84zbxjy3MxYW0gjYw=
|
||||
github.com/alexflint/go-scalar v1.1.0 h1:aaAouLLzI9TChcPXotr6gUhq+Scr8rl0P9P4PnltbhM=
|
||||
github.com/alexflint/go-scalar v1.1.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o=
|
||||
github.com/anacrolix/args v0.5.0 h1:bZCkbtn4QMB4ow2g34R/oqTFwrI6IojysKop6+ZcOSs=
|
||||
github.com/anacrolix/args v0.5.0/go.mod h1:Fj/N2PehEwTBE5t/V/9xgTcxDkuYQ+5IBoFw/8gkldI=
|
||||
github.com/anacrolix/args v0.5.1-0.20220509024600-c3b77d0b61ac h1:XWoepbk3zgOQ8jMO3vpOnohd6MfENPbFZPivB2L7myc=
|
||||
github.com/anacrolix/args v0.5.1-0.20220509024600-c3b77d0b61ac/go.mod h1:Fj/N2PehEwTBE5t/V/9xgTcxDkuYQ+5IBoFw/8gkldI=
|
||||
github.com/anacrolix/chansync v0.3.0 h1:lRu9tbeuw3wl+PhMu/r+JJCRu5ArFXIluOgdF0ao6/U=
|
||||
|
@ -43,8 +39,8 @@ github.com/anacrolix/envpprof v1.2.1 h1:25TJe6t/i0AfzzldiGFKCpD+s+dk8lONBcacJZB2
|
|||
github.com/anacrolix/envpprof v1.2.1/go.mod h1:My7T5oSqVfEn4MD4Meczkw/f5lSIndGAKu/0SM/rkf4=
|
||||
github.com/anacrolix/fuse v0.2.0 h1:pc+To78kI2d/WUjIyrsdqeJQAesuwpGxlI3h1nAv3Do=
|
||||
github.com/anacrolix/fuse v0.2.0/go.mod h1:Kfu02xBwnySDpH3N23BmrP3MDfwAQGRLUCj6XyeOvBQ=
|
||||
github.com/anacrolix/generics v0.0.0-20220217222028-44932cf46edd h1:u0sIIPDd4zM287UxlhCtIJURZyYsPQQAyZGBaO0nAy0=
|
||||
github.com/anacrolix/generics v0.0.0-20220217222028-44932cf46edd/go.mod h1:SommN0/3j+jrAnjopAZfqkREMGw59ELwloDcx6Y0KLA=
|
||||
github.com/anacrolix/generics v0.0.0-20220510042907-b50562b436ec h1:OnHX2MpnlLBBee06jcpL6eBppz766BnquXnZKH6iGgI=
|
||||
github.com/anacrolix/generics v0.0.0-20220510042907-b50562b436ec/go.mod h1:ff2rHB/joTV03aMSSn/AZNnaIpUw0h3njetGsaXcMy8=
|
||||
github.com/anacrolix/go-libutp v1.2.0 h1:sjxoB+/ARiKUR7IK/6wLWyADIBqGmu1fm0xo+8Yy7u0=
|
||||
github.com/anacrolix/go-libutp v1.2.0/go.mod h1:RrJ3KcaDcf9Jqp33YL5V/5CBEc6xMc7aJL8wXfuWL50=
|
||||
github.com/anacrolix/log v0.3.0/go.mod h1:lWvLTqzAnCWPJA08T2HCstZi0L1y2Wyvm3FJgwU9jwU=
|
||||
|
@ -359,8 +355,8 @@ golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0
|
|||
golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838 h1:71vQrMauZZhcTVK6KdYM+rklehEEwb3E+ZhaE5jrPrE=
|
||||
golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20220328175248-053ad81199eb h1:pC9Okm6BVmxEw76PUu0XUbOTQ92JX11hfvqTjAV3qxM=
|
||||
golang.org/x/exp v0.0.0-20220328175248-053ad81199eb/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
|
||||
golang.org/x/exp v0.0.0-20220428152302-39d4317da171 h1:TfdoLivD44QwvssI9Sv1xwa5DcL5XQr4au4sZ2F2NV4=
|
||||
golang.org/x/exp v0.0.0-20220428152302-39d4317da171/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
|
|
|
@ -1628,7 +1628,7 @@ func (c *Peer) deleteRequest(r RequestIndex) bool {
|
|||
if c.t.requestingPeer(r) != c {
|
||||
panic("only one peer should have a given request at a time")
|
||||
}
|
||||
delete(c.t.requestState, r)
|
||||
c.t.requestState[r] = requestState{}
|
||||
// c.t.iterPeers(func(p *Peer) {
|
||||
// if p.isLowOnRequests() {
|
||||
// p.updateRequests("Peer.deleteRequest")
|
||||
|
|
15
torrent.go
15
torrent.go
|
@ -143,7 +143,7 @@ type Torrent struct {
|
|||
|
||||
connsWithAllPieces map[*Peer]struct{}
|
||||
|
||||
requestState map[RequestIndex]requestState
|
||||
requestState []requestState
|
||||
// Chunks we've written to since the corresponding piece was last checked.
|
||||
dirtyChunks typedRoaring.Bitmap[RequestIndex]
|
||||
|
||||
|
@ -456,6 +456,7 @@ func (t *Torrent) pieceRequestOrderKey(i int) request_strategy.PieceRequestOrder
|
|||
// This seems to be all the follow-up tasks after info is set, that can't fail.
|
||||
func (t *Torrent) onSetInfo() {
|
||||
t.initPieceRequestOrder()
|
||||
MakeSliceWithLength(&t.requestState, t.numChunks())
|
||||
for i := range t.pieces {
|
||||
p := &t.pieces[i]
|
||||
// Need to add relativeAvailability before updating piece completion, as that may result in conns
|
||||
|
@ -474,7 +475,6 @@ func (t *Torrent) onSetInfo() {
|
|||
t.cl.event.Broadcast()
|
||||
close(t.gotMetainfoC)
|
||||
t.updateWantPeersEvent()
|
||||
t.requestState = make(map[RequestIndex]requestState)
|
||||
t.tryCreateMorePieceHashers()
|
||||
t.iterPeers(func(p *Peer) {
|
||||
p.onGotInfo(t.info)
|
||||
|
@ -925,7 +925,7 @@ func (t *Torrent) chunksPerRegularPiece() chunkIndexType {
|
|||
return t._chunksPerRegularPiece
|
||||
}
|
||||
|
||||
func (t *Torrent) numRequests() RequestIndex {
|
||||
func (t *Torrent) numChunks() RequestIndex {
|
||||
if t.numPieces() == 0 {
|
||||
return 0
|
||||
}
|
||||
|
@ -1490,7 +1490,7 @@ func (t *Torrent) assertPendingRequests() {
|
|||
}
|
||||
// var actual pendingRequests
|
||||
// if t.haveInfo() {
|
||||
// actual.m = make([]int, t.numRequests())
|
||||
// actual.m = make([]int, t.numChunks())
|
||||
// }
|
||||
// t.iterPeers(func(p *Peer) {
|
||||
// p.requestState.Requests.Iterate(func(x uint32) bool {
|
||||
|
@ -2064,7 +2064,9 @@ func (t *Torrent) pieceHashed(piece pieceIndex, passed bool, hashIoErr error) {
|
|||
}
|
||||
|
||||
func (t *Torrent) cancelRequestsForPiece(piece pieceIndex) {
|
||||
for ri := t.pieceRequestIndexOffset(piece); ri < t.pieceRequestIndexOffset(piece+1); ri++ {
|
||||
start := t.pieceRequestIndexOffset(piece)
|
||||
end := start + t.pieceNumChunks(piece)
|
||||
for ri := start; ri < end; ri++ {
|
||||
t.cancelRequest(ri)
|
||||
}
|
||||
}
|
||||
|
@ -2460,7 +2462,8 @@ func (t *Torrent) cancelRequest(r RequestIndex) *Peer {
|
|||
}
|
||||
// TODO: This is a check that an old invariant holds. It can be removed after some testing.
|
||||
//delete(t.pendingRequests, r)
|
||||
if _, ok := t.requestState[r]; ok {
|
||||
var zeroRequestState requestState
|
||||
if t.requestState[r] != zeroRequestState {
|
||||
panic("expected request state to be gone")
|
||||
}
|
||||
return p
|
||||
|
|
Loading…
Reference in New Issue