@@ -121,7 +121,7 @@ public void AddRequests (IReadOnlyList<IPeerWithMessaging> peers)
121
121
foreach ( var supportsFastPeer in new [ ] { true , false } ) {
122
122
for ( int i = 0 ; i < 4 ; i ++ ) {
123
123
foreach ( var peer in fastestPeers . Where ( p => p . SupportsFastPeer == supportsFastPeer ) ) {
124
- AddRequests ( peer , peers , HighPriorityPieceIndex , Math . Min ( HighPriorityPieceIndex + 1 , bitfield . Length - 1 ) , 2 , ( i + 1 ) * 2 ) ;
124
+ AddRequests ( peer , peers , HighPriorityPieceIndex , Math . Min ( HighPriorityPieceIndex + 1 , bitfield . Length - 1 ) , 2 , preferredMaxRequests : ( i + 1 ) * 2 ) ;
125
125
}
126
126
}
127
127
}
@@ -136,19 +136,20 @@ public void AddRequests (IPeerWithMessaging peer, IReadOnlyList<IPeerWithMessagi
136
136
// The first two pieces in the high priority set should be requested multiple times to ensure fast delivery
137
137
var pieceCount = TorrentData . PieceCount ( ) ;
138
138
for ( int i = HighPriorityPieceIndex ; i < pieceCount && i <= HighPriorityPieceIndex + 1 ; i ++ )
139
- AddRequests ( peer , allPeers , HighPriorityPieceIndex , HighPriorityPieceIndex , 2 ) ;
139
+ AddRequests ( peer , allPeers , HighPriorityPieceIndex , HighPriorityPieceIndex , 2 , preferredMaxRequests : 4 ) ;
140
140
141
141
var lowPriorityEnd = Math . Min ( pieceCount - 1 , HighPriorityPieceIndex + LowPriorityCount - 1 ) ;
142
- AddRequests ( peer , allPeers , HighPriorityPieceIndex , lowPriorityEnd , 1 ) ;
142
+ AddRequests ( peer , allPeers , HighPriorityPieceIndex , lowPriorityEnd , 1 , preferredMaxRequests : 3 ) ;
143
+ AddRequests ( peer , allPeers , 0 , pieceCount - 1 , 1 , preferredMaxRequests : 2 ) ;
143
144
}
144
145
145
- void AddRequests ( IPeerWithMessaging peer , IReadOnlyList < IPeerWithMessaging > allPeers , int startPieceIndex , int endPieceIndex , int maxDuplicates , int ? preferredMaxRequests = null )
146
+ void AddRequests ( IPeerWithMessaging peer , IReadOnlyList < IPeerWithMessaging > allPeers , int startPieceIndex , int endPieceIndex , int maxDuplicates , int preferredMaxRequests )
146
147
{
147
148
if ( ! peer . CanRequestMorePieces )
148
149
return ;
149
150
150
151
int preferredRequestAmount = peer . PreferredRequestAmount ( TorrentData . PieceLength ) ;
151
- var maxRequests = Math . Min ( preferredMaxRequests ?? 3 , peer . MaxPendingRequests ) ;
152
+ var maxRequests = Math . Min ( preferredMaxRequests , peer . MaxPendingRequests ) ;
152
153
153
154
if ( peer . AmRequestingPiecesCount >= maxRequests )
154
155
return ;
@@ -185,23 +186,13 @@ void AddRequests (IPeerWithMessaging peer, IReadOnlyList<IPeerWithMessaging> all
185
186
MutableBitField filtered = null ;
186
187
while ( peer . AmRequestingPiecesCount < maxRequests ) {
187
188
filtered ??= GenerateAlreadyHaves ( ) . Not ( ) . And ( peer . BitField ) ;
188
- IList < BlockInfo > request = PriorityPick ( peer , filtered , allPeers , preferredRequestAmount , 0 , TorrentData . PieceCount ( ) - 1 ) ;
189
+ IList < BlockInfo > request = PriorityPick ( peer , filtered , allPeers , preferredRequestAmount , startPieceIndex , endPieceIndex ) ;
189
190
if ( request != null && request . Count > 0 )
190
191
peer . EnqueueRequests ( request ) ;
191
192
else
192
193
break ;
193
194
}
194
195
}
195
-
196
- if ( ! peer . IsChoking && peer . AmRequestingPiecesCount == 0 ) {
197
- while ( peer . AmRequestingPiecesCount < maxRequests ) {
198
- BlockInfo ? request = Picker . ContinueAnyExistingRequest ( peer , HighPriorityPieceIndex , TorrentData . PieceCount ( ) - 1 , 1 ) ;
199
- if ( request != null )
200
- peer . EnqueueRequest ( request . Value ) ;
201
- else
202
- break ;
203
- }
204
- }
205
196
}
206
197
207
198
MutableBitField GenerateAlreadyHaves ( )
@@ -234,18 +225,15 @@ IList<BlockInfo> PriorityPick (IPeer peer, BitField available, IReadOnlyList<IPe
234
225
return bundle ;
235
226
}
236
227
237
- if ( endIndex < HighPriorityPieceIndex )
238
- return null ;
239
-
240
228
var lowPriorityEndIndex = Math . Min ( HighPriorityPieceIndex + LowPriorityCount , endIndex ) ;
241
229
if ( ( bundle = LowPriorityPicker . PickPiece ( peer , available , otherPeers , count , HighPriorityPieceIndex , lowPriorityEndIndex ) ) != null )
242
230
return bundle ;
243
231
244
232
// If we're downloading from the 'not important at all' section, queue up at most 2.
245
- if ( peer . AmRequestingPiecesCount > 2 )
246
- return null ;
233
+ if ( peer . AmRequestingPiecesCount < 2 )
234
+ return LowPriorityPicker . PickPiece ( peer , available , otherPeers , count , startIndex , endIndex ) ;
247
235
248
- return LowPriorityPicker . PickPiece ( peer , available , otherPeers , count , HighPriorityPieceIndex , endIndex ) ;
236
+ return null ;
249
237
}
250
238
251
239
/// <summary>
0 commit comments