public class Peer extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Peer.Builder |
| Modifier and Type | Method and Description |
|---|---|
void |
addBlockRequest(int pieceIndex,
int byteOffset,
int blockLength,
PeerDirection type)
Adds a download or upload job to the peer.
|
void |
addModuleInfo(Object infoObject)
Registers the
IModule peer specific information based on the class |
void |
addStrike(int i)
Adds an amount of strikes to the peer
|
void |
cancelBlockRequest(int pieceIndex,
int byteOffset,
int blockLength,
PeerDirection type)
Removes the download or upload job from the peer.
|
void |
checkDisconnect() |
int |
countHavePieces()
Gets the amount of pieces this peer has
|
void |
discardAllBlockRequests()
Cancels all pieces
|
boolean |
equals(Object o) |
BitTorrentSocket |
getBitTorrentSocket()
Gets the socket handler which handles the socket of this peer
|
String |
getClientName()
Gets the client name as reported by the BEP #10 extension if supported.
|
int |
getFreeWorkTime()
Calculates the amount of blocks we can request without overflowing the peer and without slowing us down.
|
LocalDateTime |
getLastActivity()
Gets the time at which the last byte has been read or written to the socket.
|
<T> Optional<T> |
getModuleInfo(Class<T> infoClass)
Gets the info object registered with
addModuleInfo(Object) |
int |
getRequestLimit()
Gets the amount of requests we are allowed to make to this peer
|
Torrent |
getTorrent()
Gets the torrent to which this peer is linked.
|
int |
getWorkQueueSize(PeerDirection direction)
Gets the amount of pieces the client still needs to send
|
boolean |
hasExtension(int index,
int bit)
Checks if the
extensionBytes has the given bit set for the extension which is part of the extension bytes in the handshake |
int |
hashCode() |
boolean |
hasPiece(int pieceIndex)
Checks if the peer has the piece with the given index
|
boolean |
isChoked(PeerDirection direction)
Checks if the client is choked.
|
boolean |
isInterested(PeerDirection direction)
Checks if the client is interested.
|
void |
onReceivedBlock(int pieceIndex,
int byteOffset)
Indicates that we've successfully received the requested block from the peer.
|
void |
onTorrentPhaseChange()
A callback method which gets invoked when the torrent starts a new phase
|
void |
queueNextPieceForSending()
Requests to queue the next piece in the socket for sending
|
void |
setAbsoluteRequestLimit(int absoluteRequestLimit)
Sets the amount of requests this peer can support at most
|
void |
setChoked(PeerDirection direction,
boolean choked)
Sets if this peer is choked or not.
|
void |
setClientName(String clientName)
Sets the client as reported by the Client in BEP #10.
|
void |
setHavingPiece(int pieceIndex)
Registers that this peer has the given piece
|
void |
setInterested(PeerDirection direction,
boolean interested)
Sets if this peer is interested or not.
|
void |
setRequestLimit(int requestLimit)
Sets the amount of requests we think this peer can handle properly.
This amount will be limited by absoluteRequestLimit |
String |
toString() |
public void addModuleInfo(Object infoObject)
IModule peer specific information based on the classinfoObject - The object to addIllegalStateException - when the class is already registered.public <T> Optional<T> getModuleInfo(Class<T> infoClass)
addModuleInfo(Object)infoClass - The type of information which is storedOptional.empty() when not present.public boolean hasExtension(int index,
int bit)
extensionBytes has the given bit set for the extension which is part of the extension bytes in the handshakeindex - The index wihtin the extension bytes.bit - The bit to test.public void checkDisconnect()
public void addBlockRequest(int pieceIndex,
int byteOffset,
int blockLength,
PeerDirection type)
MessageBlock for the given block.pieceIndex - The index of the requested piece.byteOffset - The offset in bytes within the piece.blockLength - The amount of bytes requested.type - The direction of the request.public void cancelBlockRequest(int pieceIndex,
int byteOffset,
int blockLength,
PeerDirection type)
MessageCancel for the given block.pieceIndex - The index of the requested piece.byteOffset - The offset in bytes within the piece.blockLength - The amount of bytes requested.type - The direction of the request.public void onReceivedBlock(int pieceIndex,
int byteOffset)
pieceIndex - The index of the requested piece.byteOffset - The offset in bytes within the piece.public void setClientName(String clientName)
clientName - The name of the client.public String getClientName()
public void onTorrentPhaseChange()
public int getFreeWorkTime()
public int getWorkQueueSize(PeerDirection direction)
public void discardAllBlockRequests()
public void setHavingPiece(int pieceIndex)
pieceIndex - the piece to marked as "have"public boolean hasPiece(int pieceIndex)
pieceIndex - the piece to check forpublic LocalDateTime getLastActivity()
public Torrent getTorrent()
public void addStrike(int i)
i - The amount of strikes to add.public void setAbsoluteRequestLimit(int absoluteRequestLimit)
absoluteRequestLimit - The absolute maximum amount of outstanding requests the peer supports.public void setRequestLimit(int requestLimit)
absoluteRequestLimitrequestLimit - The new limit.public void setChoked(PeerDirection direction, boolean choked)
direction - The side of the connection is being changedchoked - The choke statepublic void setInterested(PeerDirection direction, boolean interested)
direction - The side of the connection is being changedinterested - The interested statepublic int getRequestLimit()
public boolean isInterested(PeerDirection direction)
direction - The direction to check for.true when the peer for the given direction is in the choke state.public boolean isChoked(PeerDirection direction)
direction - The direction to check for.true when the peer for the given direction is in the choke state.public int countHavePieces()
public BitTorrentSocket getBitTorrentSocket()
public void queueNextPieceForSending()
Copyright © 2016. All rights reserved.