Changeset 983e768


Ignore:
Timestamp:
Oct 27, 2010 1:29:27 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
571ad83
Parents:
b9af4a8
Message:
  • i2psnark:
    • Don't stay interested if we run out of pieces to request (thanks sponge)
    • Enhance debug mode to show requests
Location:
apps/i2psnark/java/src/org/klomp/snark
Files:
2 edited

Legend:

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

    rb9af4a8 r983e768  
    118118
    119119  /**
    120    * Returns socket (for debug printing)
     120   * @return socket debug string (for debug printing)
    121121   */
    122122  public String getSocket()
    123123  {
     124    if (state != null) {
     125        String r = state.getRequests();
     126        if (r != null)
     127            return sock.toString() + "<br>Requests: " + r;
     128    }
    124129    return sock.toString();
    125130  }
  • apps/i2psnark/java/src/org/klomp/snark/PeerState.java

    rb9af4a8 r983e768  
    5959  private Request lastRequest = null;
    6060
    61   // If we have te resend outstanding requests (true after we got choked).
    62   private boolean resend = false;
    63 
    6461  private final static int MAX_PIPELINE = 5;               // this is for outbound requests
    6562  private final static int MAX_PIPELINE_BYTES = 128*1024;  // this is for inbound requests
     
    9289        _log.debug(peer + " rcv " + (choke ? "" : "un") + "choked");
    9390
     91    boolean resend = choked && !choke;
    9492    choked = choke;
    95     if (choked)
    96       resend = true;
    9793
    9894    listener.gotChoke(peer, choke);
    9995
    100     if (!choked && interesting)
    101       request();
     96    if (interesting && !choked)
     97      request(resend);
    10298  }
    10399
     
    465461
    466462  // Starts or resumes requesting pieces.
    467   private void request()
     463  private void request(boolean resend)
    468464  {
    469465    // Are there outstanding requests that have to be resend?
     
    473469            out.sendRequests(outstandingRequests);
    474470        }
    475         resend = false;
    476471      }
    477472
     
    527522   * Starts requesting first chunk of next piece. Returns true if
    528523   * something has been added to the requests, false otherwise.
     524   * Caller should synchronize.
    529525   */
    530526  private boolean requestNextPiece()
     
    588584      }
    589585
     586    // If we are not in the end game, we may run out of things to request
     587    // because we are asking other peers. Set not-interesting now rather than
     588    // wait for those other requests to be satisfied via havePiece()
     589    if (interesting && lastRequest == null) {
     590        interesting = false;
     591        out.sendInterest(false);
     592        if (_log.shouldLog(Log.DEBUG))
     593            _log.debug(peer + " nothing more to request, now uninteresting");
     594    }
    590595    return false;
    591596  }
     
    602607
    603608        if (interesting && !choked)
    604           request();
     609          request(true);  // we shouldnt have any pending requests, but if we do, resend them
    605610      }
    606611  }
     
    628633        out.retransmitRequests(outstandingRequests);
    629634  }
     635
     636  /**
     637   *  debug
     638   *  @return string or null
     639   *  @since 0.8.1
     640   */
     641  synchronized String getRequests() {
     642      if (outstandingRequests.isEmpty())
     643          return null;
     644      else
     645          return outstandingRequests.toString();
     646  }
    630647}
Note: See TracChangeset for help on using the changeset viewer.