Changeset 6436874


Ignore:
Timestamp:
Oct 30, 2010 3:28:29 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
f170baab
Parents:
c76058e
Message:
  • Only add wanted pieces to wanted list at startup
  • Make sure lastRequest is null when it should be
  • Logging tweaks
Location:
apps/i2psnark/java/src/org/klomp/snark
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • apps/i2psnark/java/src/org/klomp/snark/PeerCoordinator.java

    rc76058e r6436874  
    106106  {
    107107    // Make a list of pieces
     108    // FIXME synchronize, clear and re-add instead?
     109    // Don't replace something we are synchronizing on.
    108110    wantedPieces = new ArrayList();
    109111    BitField bitfield = storage.getBitField();
    110112    int[] pri = storage.getPiecePriorities();
    111113    for(int i = 0; i < metainfo.getPieces(); i++) {
    112       if (!bitfield.get(i)) {
     114      // only add if we don't have and the priority is >= 0
     115      if ((!bitfield.get(i)) &&
     116          (pri == null || pri[i] >= 0)) {
    113117        Piece p = new Piece(i);
    114118        if (pri != null)
  • apps/i2psnark/java/src/org/klomp/snark/PeerState.java

    rc76058e r6436874  
    5757  // Outstanding request
    5858  private final List<Request> outstandingRequests = new ArrayList();
     59  /** the tail (NOT the head) of the request queue */
    5960  private Request lastRequest = null;
    6061
     
    566567        }
    567568        int nextPiece = listener.wantPiece(peer, bitfield);
    568         if (_log.shouldLog(Log.DEBUG))
    569           _log.debug(peer + " want piece " + nextPiece);
    570             if (nextPiece != -1
    571                 && (lastRequest == null || lastRequest.piece != nextPiece))
    572               {
     569        if (nextPiece != -1
     570            && (lastRequest == null || lastRequest.piece != nextPiece)) {
     571                if (_log.shouldLog(Log.DEBUG))
     572                    _log.debug(peer + " want piece " + nextPiece);
    573573                // Fail safe to make sure we are interested
    574574                // When we transition into the end game we may not be interested...
     
    597597                lastRequest = req;
    598598                return true;
    599               }
    600       }
     599          } else {
     600                if (_log.shouldLog(Log.DEBUG))
     601                    _log.debug(peer + " no more pieces to request");
     602          }
     603      }
     604
     605    // failsafe
     606    if (outstandingRequests.isEmpty())
     607        lastRequest = null;
    601608
    602609    // If we are not in the end game, we may run out of things to request
Note: See TracChangeset for help on using the changeset viewer.