- Only add wanted pieces to wanted list at startup
- Make sure lastRequest is null when it should be - Logging tweaks
This commit is contained in:
@ -105,11 +105,15 @@ public class PeerCoordinator implements PeerListener
|
||||
public void setWantedPieces()
|
||||
{
|
||||
// Make a list of pieces
|
||||
// FIXME synchronize, clear and re-add instead?
|
||||
// Don't replace something we are synchronizing on.
|
||||
wantedPieces = new ArrayList();
|
||||
BitField bitfield = storage.getBitField();
|
||||
int[] pri = storage.getPiecePriorities();
|
||||
for(int i = 0; i < metainfo.getPieces(); i++) {
|
||||
if (!bitfield.get(i)) {
|
||||
// only add if we don't have and the priority is >= 0
|
||||
if ((!bitfield.get(i)) &&
|
||||
(pri == null || pri[i] >= 0)) {
|
||||
Piece p = new Piece(i);
|
||||
if (pri != null)
|
||||
p.setPriority(pri[i]);
|
||||
|
@ -56,6 +56,7 @@ class PeerState
|
||||
|
||||
// Outstanding request
|
||||
private final List<Request> outstandingRequests = new ArrayList();
|
||||
/** the tail (NOT the head) of the request queue */
|
||||
private Request lastRequest = null;
|
||||
|
||||
private final static int MAX_PIPELINE = 5; // this is for outbound requests
|
||||
@ -565,11 +566,10 @@ class PeerState
|
||||
}
|
||||
}
|
||||
int nextPiece = listener.wantPiece(peer, bitfield);
|
||||
if (nextPiece != -1
|
||||
&& (lastRequest == null || lastRequest.piece != nextPiece)) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug(peer + " want piece " + nextPiece);
|
||||
if (nextPiece != -1
|
||||
&& (lastRequest == null || lastRequest.piece != nextPiece))
|
||||
{
|
||||
// Fail safe to make sure we are interested
|
||||
// When we transition into the end game we may not be interested...
|
||||
if (!interesting) {
|
||||
@ -596,9 +596,16 @@ class PeerState
|
||||
out.sendRequest(req);
|
||||
lastRequest = req;
|
||||
return true;
|
||||
} else {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug(peer + " no more pieces to request");
|
||||
}
|
||||
}
|
||||
|
||||
// failsafe
|
||||
if (outstandingRequests.isEmpty())
|
||||
lastRequest = null;
|
||||
|
||||
// If we are not in the end game, we may run out of things to request
|
||||
// because we are asking other peers. Set not-interesting now rather than
|
||||
// wait for those other requests to be satisfied via havePiece()
|
||||
|
Reference in New Issue
Block a user