Skip to content

Commit

Permalink
broadcast and small file fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mh0lt committed May 25, 2024
1 parent 84f7dea commit a2dbbfe
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions webseed-peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,25 @@ func (ws *webseedPeer) requester(i int) {
pendingRequests = 16
}

ws.maxRequesters = pendingRequests
ws.requesterCond.Broadcast()
if ws.maxRequesters != pendingRequests {
ws.maxRequesters = pendingRequests
ws.requesterCond.Broadcast()
}
}

}

if !restart {
if !(ws.peer.t.dataDownloadDisallowed.Bool() || ws.peer.t.Complete.Bool()) {
if ws.updateRequestor == nil {
ws.updateRequestor = time.AfterFunc(webpeerUnchokeTimerDuration, func() { requestUpdate(ws) })
timerDuration := webpeerUnchokeTimerDuration

// Don't wait for small files
if ws.peer.t.NumPieces() == 1 && ws.peer.requestState.Requests.GetCardinality() == 0 {
timerDuration = 0
}

ws.updateRequestor = time.AfterFunc(timerDuration, func() { requestUpdate(ws) })
}
}

Expand Down Expand Up @@ -230,12 +239,17 @@ func requestUpdate(ws *webseedPeer) {

ws.updateRequestor = nil

ws.peer.logger.Levelf(log.Debug, "requestUpdate %d (p=%d,d=%d,n=%d) active(c=%d,m=%d,w=%d) complete(%d/%d) restart(%v)",

Check failure on line 242 in webseed-peer.go

View workflow job for this annotation

GitHub Actions / bench (1.21)

(github.com/anacrolix/log.Logger).Levelf format %v reads arg #10, but call has 9 args

Check failure on line 242 in webseed-peer.go

View workflow job for this annotation

GitHub Actions / test-386 (1.21)

(github.com/anacrolix/log.Logger).Levelf format %v reads arg #10, but call has 9 args

Check failure on line 242 in webseed-peer.go

View workflow job for this annotation

GitHub Actions / test (1.21, windows-latest)

(github.com/anacrolix/log.Logger).Levelf format %v reads arg #10, but call has 9 args

Check failure on line 242 in webseed-peer.go

View workflow job for this annotation

GitHub Actions / test (1.21, macos-latest)

(github.com/anacrolix/log.Logger).Levelf format %v reads arg #10, but call has 9 args

Check failure on line 242 in webseed-peer.go

View workflow job for this annotation

GitHub Actions / test-benchmarks (1.21)

(github.com/anacrolix/log.Logger).Levelf format %v reads arg #10, but call has 9 args

Check failure on line 242 in webseed-peer.go

View workflow job for this annotation

GitHub Actions / test (1.21, ubuntu-latest)

(github.com/anacrolix/log.Logger).Levelf format %v reads arg #10, but call has 9 args
ws.processedRequests, int(ws.peer.requestState.Requests.GetCardinality()), len(ws.peer.getDesiredRequestState().Requests.requestIndexes),
ws.nominalMaxRequests(), len(ws.activeRequests), ws.maxActiveRequests, ws.waiting, ws.peer.t.numPiecesCompleted(), ws.peer.t.NumPieces())

if !ws.peer.closed.IsSet() {
numPieces := uint64(ws.peer.t.NumPieces())
numCompleted := ws.peer.t._completedPieces.GetCardinality()

if numCompleted < numPieces {
if ws.peer.isLowOnRequests() && time.Since(ws.peer.lastRequestUpdate) > webpeerUnchokeTimerDuration {
// Don't wait for small files
if ws.peer.isLowOnRequests() && (numPieces == 1 || time.Since(ws.peer.lastRequestUpdate) > webpeerUnchokeTimerDuration) {
// if the number of incomplete pieces is less than five adjust this peers
// lastUsefulChunkReceived to ensure that it can steal from non web peers
// this is to help ensure completion - we may want to add a head call
Expand Down

0 comments on commit a2dbbfe

Please sign in to comment.