Пример #1
0
  synchronized void setInteresting(boolean interest) {
    if (interest != interesting) {
      if (_log.shouldLog(Log.DEBUG)) _log.debug(peer + " setInteresting(" + interest + ")");
      interesting = interest;
      out.sendInterest(interest);

      if (interesting && !choked)
        request(true); // we shouldnt have any pending requests, but if we do, resend them
    }
  }
Пример #2
0
  void chokeMessage(boolean choke) {
    if (_log.shouldLog(Log.DEBUG)) _log.debug(peer + " rcv " + (choke ? "" : "un") + "choked");

    boolean resend = choked && !choke;
    choked = choke;

    listener.gotChoke(peer, choke);

    if (interesting && !choked) request(resend);

    if (choked) {
      out.cancelRequestMessages();
      // old Roberts thrash us here, choke+unchoke right together
      // The only problem with returning the partials to the coordinator
      // is that chunks above a missing request are lost.
      // Future enhancements to PartialPiece could keep track of the holes.
      List<Request> pcs = returnPartialPieces();
      if (!pcs.isEmpty()) {
        if (_log.shouldLog(Log.DEBUG))
          _log.debug(peer + " got choked, returning partial pieces to the PeerCoordinator: " + pcs);
        listener.savePartialPieces(this.peer, pcs);
      }
    }
  }