Example #1
0
File: Peer.java Project: hilbix/i2p
  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);
      }
    }
  }
Example #2
0
File: Peer.java Project: hilbix/i2p
 /** @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();
 }
Example #3
0
File: Peer.java Project: hilbix/i2p
 /** Retransmit outstanding requests if necessary */
 public void retransmitRequests() {
   PeerState s = state;
   if (s != null) s.retransmitRequests();
 }
Example #4
0
File: Peer.java Project: hilbix/i2p
 /** Send keepalive */
 public void keepAlive() {
   PeerState s = state;
   if (s != null) s.keepAlive();
 }
Example #5
0
File: Peer.java Project: hilbix/i2p
 /**
  * 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);
 }
Example #6
0
File: Peer.java Project: hilbix/i2p
 /**
  * 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);
 }
Example #7
0
File: Peer.java Project: hilbix/i2p
 /**
  * Update the request queue. Call after adding wanted pieces.
  *
  * @since 0.8.1
  */
 void request() {
   PeerState s = state;
   if (s != null) s.addRequest();
 }
Example #8
0
File: Peer.java Project: hilbix/i2p
 /**
  * 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);
 }
Example #9
0
File: Peer.java Project: hilbix/i2p
 /**
  * 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);
 }
Example #10
0
File: Peer.java Project: hilbix/i2p
 /** Tell the peer we have another piece. */
 public void have(int piece) {
   PeerState s = state;
   if (s != null) s.havePiece(piece);
 }
Example #11
0
File: Peer.java Project: hilbix/i2p
 /**
  * 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);
 }