Exemple #1
0
  void disconnect() {
    PeerState s = state;
    if (s != null) {
      // try to save partial piece
      if (this.deregister) {
        PeerListener p = s.listener;
        if (p != null) {
          List<PartialPiece> pcs = s.returnPartialPieces();
          if (!pcs.isEmpty()) p.savePartialPieces(this, pcs);
          // now covered by savePartialPieces
          // p.markUnrequested(this);
        }
      }
      state = null;

      PeerConnectionIn in = s.in;
      if (in != null) in.disconnect();
      PeerConnectionOut out = s.out;
      if (out != null) out.disconnect();
      PeerListener pl = s.listener;
      if (pl != null) pl.disconnected(this);
    }
    I2PSocket csock = sock;
    sock = null;
    if ((csock != null) && (!csock.isClosed())) {
      try {
        csock.close();
      } catch (IOException ioe) {
        _log.warn("Error disconnecting " + toString(), ioe);
      }
    }
  }
Exemple #2
0
 /** @return socket debug string (for debug printing) */
 public String getSocket() {
   if (state != null) {
     String r = state.getRequests();
     if (r != null) return sock.toString() + "<br>Requests: " + r;
   }
   return sock.toString();
 }
Exemple #3
0
 /** Retransmit outstanding requests if necessary */
 public void retransmitRequests() {
   PeerState s = state;
   if (s != null) s.retransmitRequests();
 }
Exemple #4
0
 /** Send keepalive */
 public void keepAlive() {
   PeerState s = state;
   if (s != null) s.keepAlive();
 }
Exemple #5
0
 /**
  * Sets whether or not we are choking the peer. Defaults to true. When choke is false and the peer
  * requests some pieces we upload them, otherwise requests of this peer are ignored.
  */
 public void setChoking(boolean choke) {
   PeerState s = state;
   if (s != null) s.setChoking(choke);
 }
Exemple #6
0
 /**
  * Sets whether or not we are interested in pieces from this peer. Defaults to false. When
  * interest is true and this peer unchokes us then we start downloading from it. Has no effect
  * when not connected.
  *
  * @deprecated unused
  */
 public void setInteresting(boolean interest) {
   PeerState s = state;
   if (s != null) s.setInteresting(interest);
 }
Exemple #7
0
 /**
  * Update the request queue. Call after adding wanted pieces.
  *
  * @since 0.8.1
  */
 void request() {
   PeerState s = state;
   if (s != null) s.addRequest();
 }
Exemple #8
0
 /**
  * Are we currently requesting the piece?
  *
  * @deprecated deadlocks
  * @since 0.8.1
  */
 boolean isRequesting(int p) {
   PeerState s = state;
   return s != null && s.isRequesting(p);
 }
Exemple #9
0
 /**
  * Tell the other side that we are no longer interested in any of the outstanding requests (if
  * any) for this piece.
  *
  * @since 0.8.1
  */
 void cancel(int piece) {
   PeerState s = state;
   if (s != null) s.cancelPiece(piece);
 }
Exemple #10
0
 /** Tell the peer we have another piece. */
 public void have(int piece) {
   PeerState s = state;
   if (s != null) s.havePiece(piece);
 }
Exemple #11
0
 /**
  * Switch from magnet mode to normal mode
  *
  * @since 0.8.4
  */
 public void setMetaInfo(MetaInfo meta) {
   metainfo = meta;
   PeerState s = state;
   if (s != null) s.setMetaInfo(meta);
 }