public class Peer extends Object implements Comparable<Peer>
Modifier and Type | Field and Description |
---|---|
(package private) static long |
CHECK_PERIOD |
(package private) MagnetState |
magnetState
shared across all peers on this torrent
|
(package private) static int |
RATE_DEPTH |
(package private) PeerState |
state |
Constructor and 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.
|
Modifier and Type | Method and Description |
---|---|
(package private) void |
cancel(int piece)
Tell the other side that we are no longer interested in any of
the outstanding requests (if any) for this piece.
|
int |
compareTo(Peer p)
Deprecated.
unused?
|
int |
completed()
Return how much the peer has
|
(package private) void |
disconnect() |
void |
disconnect(boolean deregister)
Disconnects this peer if it was connected.
|
void |
downloaded(int size)
Increment the counter.
|
boolean |
equals(Object o)
Two Peers are equal when they have the same PeerID.
|
Destination |
getDestination() |
long |
getDownloaded()
Returns the number of bytes that have been downloaded.
|
long |
getDownloadRate() |
Map<String,BEValue> |
getHandshakeMap() |
long |
getInactiveTime() |
MagnetState |
getMagnetState()
Shared state across all peers, callers must sync on returned object
|
PeerID |
getPeerID()
Returns the id of the peer.
|
String |
getSocket() |
long |
getUploaded()
Returns the number of bytes that have been uploaded.
|
long |
getUploadRate()
Returns the 4-minute-average rate in Bps
|
int |
hashCode()
The hash code of a Peer is the hash code of the peerID.
|
void |
have(int piece)
Tell the peer we have another piece.
|
boolean |
isChoked()
Whether or not the peer choked us.
|
boolean |
isChoking()
Whether or not we are choking the peer.
|
boolean |
isCompleted()
Return if a peer is a seeder
|
boolean |
isConnected() |
boolean |
isIncoming()
Is this an incoming connection?
For RPC
|
boolean |
isInterested()
Whether or not the peer is interested in pieces we have.
|
boolean |
isInteresting()
Whether or not the peer has pieces we want from it.
|
(package private) boolean |
isRequesting(int p)
Deprecated.
deadlocks
|
void |
keepAlive()
Send keepalive
|
(package private) void |
request()
Update the request queue.
|
void |
resetCounters()
Resets the downloaded and uploaded counters to zero.
|
void |
retransmitRequests()
Retransmit outstanding requests if necessary
|
void |
runConnection(I2PSnarkUtil util,
PeerListener listener,
BitField bitfield,
MagnetState mState,
boolean uploadOnly)
Runs the connection to the other peer.
|
void |
sendExtension(int type,
byte[] payload) |
void |
setChoking(boolean choke)
Sets whether or not we are choking the peer.
|
void |
setHandshakeMap(Map<String,BEValue> map) |
void |
setInteresting(boolean interest)
Deprecated.
unused
|
void |
setMetaInfo(MetaInfo meta)
Switch from magnet mode to normal mode
|
void |
setRateHistory(long up,
long down)
Push the total uploaded/downloaded onto a RATE_DEPTH deep stack
|
boolean |
supportsFast() |
String |
toString()
Returns the String representation of the peerID.
|
void |
uploaded(int size)
Increment the counter.
|
volatile PeerState state
MagnetState magnetState
static final long CHECK_PERIOD
static final int RATE_DEPTH
public Peer(PeerID peerID, byte[] my_id, byte[] infohash, MetaInfo metainfo)
metainfo
- null if in magnet modepublic Peer(I2PSocket sock, InputStream in, OutputStream out, byte[] my_id, byte[] infohash, MetaInfo metainfo) throws IOException
metainfo
- null if in magnet modeIOException
- when an error occurred during the handshake.public boolean isIncoming()
public PeerID getPeerID()
public String toString()
public String getSocket()
public int hashCode()
public boolean equals(Object o)
@Deprecated public int compareTo(Peer p)
compareTo
in interface Comparable<Peer>
public void runConnection(I2PSnarkUtil util, PeerListener listener, BitField bitfield, MagnetState mState, boolean uploadOnly)
uploadOnly
- if we are complete with skipped files, i.e. a partial seedpublic boolean supportsFast()
public Destination getDestination()
public MagnetState getMagnetState()
public void sendExtension(int type, byte[] payload)
public void setMetaInfo(MetaInfo meta)
public boolean isConnected()
public void disconnect(boolean deregister)
void disconnect()
public void have(int piece)
void cancel(int piece)
@Deprecated boolean isRequesting(int p)
void request()
public boolean isInterested()
@Deprecated public void setInteresting(boolean interest)
public boolean isInteresting()
public void setChoking(boolean choke)
public boolean isChoking()
public boolean isChoked()
public void downloaded(int size)
public void uploaded(int size)
public long getDownloaded()
resetCounters()
/public long getUploaded()
resetCounters()
/public void resetCounters()
public long getInactiveTime()
public void keepAlive()
public void retransmitRequests()
public int completed()
public boolean isCompleted()
public void setRateHistory(long up, long down)
public long getUploadRate()
public long getDownloadRate()