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); } } }
/** @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(); }
/** Retransmit outstanding requests if necessary */ public void retransmitRequests() { PeerState s = state; if (s != null) s.retransmitRequests(); }
/** Send keepalive */ public void keepAlive() { PeerState s = state; if (s != null) s.keepAlive(); }
/** * 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); }
/** * 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); }
/** * Update the request queue. Call after adding wanted pieces. * * @since 0.8.1 */ void request() { PeerState s = state; if (s != null) s.addRequest(); }
/** * 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); }
/** * 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); }
/** Tell the peer we have another piece. */ public void have(int piece) { PeerState s = state; if (s != null) s.havePiece(piece); }
/** * 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); }