Package org.klomp.snark
Class Peer
- java.lang.Object
- 
- org.klomp.snark.Peer
 
- 
- All Implemented Interfaces:
- Comparable<Peer>
 - Direct Known Subclasses:
- WebPeer
 
 public class Peer extends Object implements Comparable<Peer> 
- 
- 
Field SummaryFields Modifier and Type Field Description protected Log_log(package private) static longCHECK_PERIOD(package private) MagnetStatemagnetStateshared across all peers on this torrentprotected MetaInfometainfowill start out null in magnet mode(package private) static intRATE_DEPTH(package private) PeerStatestate` Keeps state for in/out connections.
 - 
Constructor SummaryConstructors Constructor Description Peer(I2PSocket sock, InputStream in, OutputStream out, byte[] my_id, byte[] infohash, MetaInfo metainfo)Incoming connection.Peer(PeerID peerID, byte[] my_id, byte[] infohash, MetaInfo metainfo)Outgoing connection.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description (package private) voidcancel(int piece)Tell the other side that we are no longer interested in any of the outstanding requests (if any) for this piece.intcompareTo(Peer p)Deprecated.unused?intcompleted()Return how much the peer has(package private) voiddisconnect()voiddisconnect(boolean deregister)Disconnects this peer if it was connected.voiddownloaded(int size)Increment the counter.booleanequals(Object o)Two Peers are equal when they have the same PeerID.DestinationgetDestination()longgetDownloaded()Returns the number of bytes that have been downloaded.longgetDownloadRate()Map<String,BEValue>getHandshakeMap()longgetInactiveTime()MagnetStategetMagnetState()Shared state across all peers, callers must sync on returned objectlonggetMaxInactiveTime()intgetMaxPipeline()PeerIDgetPeerID()Returns the id of the peer.StringgetSocket()(package private) intgetTotalCommentsSent()longgetUploaded()Returns the number of bytes that have been uploaded.longgetUploadRate()Returns the 4-minute-average rate in BpsinthashCode()The hash code of a Peer is the hash code of the peerID.voidhave(int piece)Tell the peer we have another piece.booleanisChoked()Whether or not the peer choked us.booleanisChoking()Whether or not we are choking the peer.booleanisCompleted()Return if a peer is a seederbooleanisConnected()booleanisIncoming()Is this an incoming connection? For RPCbooleanisInterested()Whether or not the peer is interested in pieces we have.booleanisInteresting()Whether or not the peer has pieces we want from it.(package private) booleanisRequesting(int p)Deprecated.deadlocksbooleanisWebPeer()voidkeepAlive()Send keepalive(package private) voidrequest()Update the request queue.voidresetCounters()Resets the downloaded and uploaded counters to zero.voidretransmitRequests()Retransmit outstanding requests if necessaryvoidrunConnection(I2PSnarkUtil util, PeerListener listener, BitField bitfield, MagnetState mState, boolean uploadOnly)Runs the connection to the other peer.voidsendExtension(int type, byte[] payload)voidsetChoking(boolean choke)Sets whether or not we are choking the peer.voidsetHandshakeMap(Map<String,BEValue> map)voidsetInteresting(boolean interest)Deprecated.unusedvoidsetMetaInfo(MetaInfo meta)Switch from magnet mode to normal modevoidsetRateHistory(long up, long down)Push the total uploaded/downloaded onto a RATE_DEPTH deep stack(package private) voidsetTotalCommentsSent(int count)booleansupportsFast()StringtoString()Returns the String representation of the peerID.voiduploaded(int size)Increment the counter.
 
- 
- 
- 
Field Detail- 
_logprotected final Log _log 
 - 
metainfoprotected MetaInfo metainfo will start out null in magnet mode
 - 
statevolatile PeerState state ` Keeps state for in/out connections. Non-null when the handshake was successful, the connection setup and runs. Do not access directly. All actions should be through Peer methods.
 - 
magnetStateMagnetState magnetState shared across all peers on this torrent
 - 
CHECK_PERIODstatic final long CHECK_PERIOD - See Also:
- Constant Field Values
 
 - 
RATE_DEPTHstatic final int RATE_DEPTH - See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
Peerpublic Peer(PeerID peerID, byte[] my_id, byte[] infohash, MetaInfo metainfo) Outgoing connection. Creates a disconnected peer given a PeerID, your own id and the relevant MetaInfo.- Parameters:
- metainfo- null if in magnet mode
 
 - 
Peerpublic Peer(I2PSocket sock, InputStream in, OutputStream out, byte[] my_id, byte[] infohash, MetaInfo metainfo) throws IOException Incoming connection. Creates a unconnected peer from the input and output stream got from the socket. Note that the complete handshake (which can take some time or block indefinitely) is done in the calling Thread to get the remote peer id. To completely start the connection call the connect() method.- Parameters:
- metainfo- null if in magnet mode
- Throws:
- IOException- when an error occurred during the handshake.
 
 
- 
 - 
Method Detail- 
isIncomingpublic boolean isIncoming() Is this an incoming connection? For RPC- Since:
- 0.9.30
 
 - 
getPeerIDpublic PeerID getPeerID() Returns the id of the peer.
 - 
toStringpublic String toString() Returns the String representation of the peerID.
 - 
getSocketpublic String getSocket() - Returns:
- socket debug string (for debug printing)
 
 - 
hashCodepublic int hashCode() The hash code of a Peer is the hash code of the peerID.
 - 
equalspublic boolean equals(Object o) Two Peers are equal when they have the same PeerID. All other properties are ignored.
 - 
compareTo@Deprecated public int compareTo(Peer p) Deprecated.unused?Compares the PeerIDs.- Specified by:
- compareToin interface- Comparable<Peer>
 
 - 
runConnectionpublic void runConnection(I2PSnarkUtil util, PeerListener listener, BitField bitfield, MagnetState mState, boolean uploadOnly) Runs the connection to the other peer. This method does not return until the connection is terminated. When the connection is correctly started the connected() method of the given PeerListener is called. If the connection ends or the connection could not be setup correctly the disconnected() method is called. If the given BitField is non-null it is send to the peer as first message.- Parameters:
- uploadOnly- if we are complete with skipped files, i.e. a partial seed
 
 - 
supportsFastpublic boolean supportsFast() - Since:
- 0.9.21
 
 - 
getDestinationpublic Destination getDestination() - Since:
- 0.8.4
 
 - 
getMagnetStatepublic MagnetState getMagnetState() Shared state across all peers, callers must sync on returned object- Returns:
- non-null
- Since:
- 0.8.4
 
 - 
setHandshakeMappublic void setHandshakeMap(Map<String,BEValue> map) - Parameters:
- map- non-null
- Since:
- 0.8.4
 
 - 
getMaxPipelinepublic int getMaxPipeline() - Returns:
- min of PeerState.MIN_PIPELINE, max of PeerState.MAX_PIPELINE
- Since:
- 0.9.47
 
 - 
sendExtensionpublic void sendExtension(int type, byte[] payload)- Since:
- 0.8.4
 
 - 
setMetaInfopublic void setMetaInfo(MetaInfo meta) Switch from magnet mode to normal mode- Since:
- 0.8.4
 
 - 
isConnectedpublic boolean isConnected() 
 - 
disconnectpublic void disconnect(boolean deregister) Disconnects this peer if it was connected. If deregister is true, PeerListener.disconnected() will be called when the connection is completely terminated. Otherwise the connection is silently terminated.
 - 
disconnectvoid disconnect() 
 - 
havepublic void have(int piece) Tell the peer we have another piece.
 - 
cancelvoid cancel(int piece) 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
 
 - 
isRequesting@Deprecated boolean isRequesting(int p) Deprecated.deadlocksAre we currently requesting the piece?- Since:
- 0.8.1
 
 - 
requestvoid request() Update the request queue. Call after adding wanted pieces.- Since:
- 0.8.1
 
 - 
isInterestedpublic boolean isInterested() Whether or not the peer is interested in pieces we have. Returns false if not connected.
 - 
setInteresting@Deprecated public void setInteresting(boolean interest) Deprecated.unusedSets 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.
 - 
isInterestingpublic boolean isInteresting() Whether or not the peer has pieces we want from it. Returns false if not connected.
 - 
setChokingpublic void setChoking(boolean choke) 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.
 - 
isChokingpublic boolean isChoking() Whether or not we are choking the peer. Returns true when not connected.
 - 
isChokedpublic boolean isChoked() Whether or not the peer choked us. Returns true when not connected.
 - 
downloadedpublic void downloaded(int size) Increment the counter.- Since:
- 0.8.4
 
 - 
uploadedpublic void uploaded(int size) Increment the counter.- Since:
- 0.8.4
 
 - 
getDownloadedpublic long getDownloaded() Returns the number of bytes that have been downloaded. Can be reset to zero withresetCounters()which is called every CHECK_PERIOD by PeerCheckerTask.
 - 
getUploadedpublic long getUploaded() Returns the number of bytes that have been uploaded. Can be reset to zero withresetCounters()which is called every CHECK_PERIOD by PeerCheckerTask.
 - 
resetCounterspublic void resetCounters() Resets the downloaded and uploaded counters to zero.
 - 
getInactiveTimepublic long getInactiveTime() 
 - 
getMaxInactiveTimepublic long getMaxInactiveTime() - Since:
- 0.9.36
 
 - 
keepAlivepublic void keepAlive() Send keepalive
 - 
retransmitRequestspublic void retransmitRequests() Retransmit outstanding requests if necessary
 - 
completedpublic int completed() Return how much the peer has- Returns:
- number of completed pieces (not bytes)
 
 - 
isCompletedpublic boolean isCompleted() Return if a peer is a seeder
 - 
setRateHistorypublic void setRateHistory(long up, long down)Push the total uploaded/downloaded onto a RATE_DEPTH deep stack
 - 
getUploadRatepublic long getUploadRate() Returns the 4-minute-average rate in Bps
 - 
getDownloadRatepublic long getDownloadRate() 
 - 
getTotalCommentsSentint getTotalCommentsSent() - Since:
- 0.9.31
 
 - 
setTotalCommentsSentvoid setTotalCommentsSent(int count) - Since:
- 0.9.31
 
 - 
isWebPeerpublic boolean isWebPeer() - Returns:
- false
- Since:
- 0.9.49
 
 
- 
 
-