public class Peer extends Object implements Comparable<Peer>, BandwidthListener
Modifier and Type | Field and Description |
---|---|
protected Log |
_log |
(package private) static long |
CHECK_PERIOD |
(package private) MagnetState |
magnetState
shared across all peers on this torrent
|
protected MetaInfo |
metainfo
will start out null in magnet mode
|
(package private) static int |
RATE_DEPTH |
(package private) PeerState |
state
`
Keeps state for in/out connections.
|
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 |
getDownBWLimit()
Current limit in Bps
|
long |
getDownloaded()
Returns the number of bytes that have been downloaded.
|
long |
getDownloadRate()
The average rate in Bps
|
Map<String,BEValue> |
getHandshakeMap() |
long |
getInactiveTime() |
MagnetState |
getMagnetState()
Shared state across all peers, callers must sync on returned object
|
long |
getMaxInactiveTime() |
int |
getMaxPipeline() |
PeerID |
getPeerID()
Returns the id of the peer.
|
long |
getPexLastSent()
when did we last send pex peers?
|
String |
getSocket() |
(package private) int |
getTotalCommentsSent() |
long |
getUpBWLimit()
Current limit in Bps
|
long |
getUploaded()
Returns the number of bytes that have been uploaded.
|
long |
getUploadRate()
Returns the average rate in Bps
|
long |
getWhenConnected()
when did handshake complete?
|
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
|
boolean |
isWebPeer() |
void |
keepAlive()
Send keepalive
|
boolean |
overDownBWLimit()
Are we currently over the limit?
|
boolean |
overUpBWLimit()
Is snark as a whole over its limit?
|
(package private) void |
request()
Update the request queue.
|
void |
retransmitRequests()
Retransmit outstanding requests if necessary
|
void |
runConnection(I2PSnarkUtil util,
PeerListener listener,
BandwidthListener bwl,
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 |
setPexLastSent(long now)
when did we last send pex peers?
|
(package private) void |
setRateHistory()
Push the total uploaded/downloaded onto a RATE_DEPTH deep stack
Resets the downloaded and uploaded counters to zero.
|
(package private) void |
setTotalCommentsSent(int count) |
boolean |
shouldRequest(int size)
Should we request this many bytes?
|
boolean |
shouldRequest(Peer peer,
int size)
Should we request this many bytes?
|
boolean |
shouldSend(int size)
Should we send this many bytes?
Do NOT call uploaded() after this.
|
boolean |
supportsFast() |
String |
toString()
Returns the String representation of the peerID.
|
void |
uploaded(int size)
Increment the counter.
|
protected final Log _log
protected MetaInfo metainfo
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, BandwidthListener bwl, 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 setHandshakeMap(Map<String,BEValue> map)
map
- non-nullpublic int getMaxPipeline()
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)
downloaded
in interface BandwidthListener
public void uploaded(int size)
uploaded
in interface BandwidthListener
public long getDownloaded()
resetCounters()
which is called every CHECK_PERIOD by PeerCheckerTask.public long getUploaded()
resetCounters()
which is called every CHECK_PERIOD by PeerCheckerTask.public long getUploadRate()
getUploadRate
in interface BandwidthListener
public long getDownloadRate()
BandwidthListener
getDownloadRate
in interface BandwidthListener
public boolean shouldSend(int size)
shouldSend
in interface BandwidthListener
public boolean shouldRequest(int size)
public boolean shouldRequest(Peer peer, int size)
shouldRequest
in interface BandwidthListener
public long getUpBWLimit()
getUpBWLimit
in interface BandwidthListener
public boolean overUpBWLimit()
overUpBWLimit
in interface BandwidthListener
public long getDownBWLimit()
getDownBWLimit
in interface BandwidthListener
public boolean overDownBWLimit()
overDownBWLimit
in interface BandwidthListener
void setRateHistory()
public long getInactiveTime()
public long getMaxInactiveTime()
public void keepAlive()
public void retransmitRequests()
public int completed()
public boolean isCompleted()
int getTotalCommentsSent()
void setTotalCommentsSent(int count)
public boolean isWebPeer()
public long getWhenConnected()
public long getPexLastSent()
public void setPexLastSent(long now)