Exemplo n.º 1
0
  public void bitfield(byte[] bitfield, Peer peer) {

    for (int i = 0; i < metafile.getPieces().size(); i++) {
      if (peer.hasPiece(i) && !torrentDisk.isCompleted(i)) {
        peer.setAmInterested(true);
        return;
      }
    }
  }
Exemplo n.º 2
0
  // This function notifies that peer has just sent an amInterested message
  public void have(int index, Peer peer) {

    if (!torrentDisk.isCompleted(index)) {
      peer.setAmInterested(true);
      if (!peer.isAmChoked()) {
        addRequests(peer);
      }
    }
  }
Exemplo n.º 3
0
  private void addRequests(Peer peer) {
    Request request = null;

    int[] piecesFrequencies = peersManager.getPiecesFrequencies();

    while (peer.getUnfulfilledRequestNumber() < maxUnfulfilledRequestNumber
        && (request = pieceChooser.getNextBlockRequest(peer, piecesFrequencies)) != null) {
      peer.sendMessage(request);
    }
    if (request == null && peer.getUnfulfilledRequestNumber() == 0) {
      peer.setAmInterested(false);
    }
  }