class PeerState extends Object implements DataLoader
| Modifier and Type | Field and Description |
|---|---|
(package private) BitField | bitfieldthe pieces the peer has. |
(package private) boolean | chokedWhether the peer has choked us |
(package private) boolean | chokingWhether we are choking the peer |
(package private) PeerConnectionIn | inInbound connection |
(package private) boolean | interestedWhether the peer is interested in us |
(package private) boolean | interestingWhether we are interested in the peer |
(package private) PeerListener | listenerFixme, used by Peer.disconnect() to get to the coordinator |
static int | MAX_PIPELINEMaximum request pipeline depth for outbound requests. |
static int | MIN_PIPELINEMinimum request pipeline depth for outbound requests. |
(package private) PeerConnectionOut | outOutbound connection |
static int | PARTSIZEChunk size for outbound piece requests. |
| Constructor and Description |
|---|
PeerState(Peer peer,
PeerListener listener,
BandwidthListener bwl,
MetaInfo metainfo,
PeerConnectionIn in,
PeerConnectionOut out) |
| Modifier and Type | Method and Description |
|---|---|
(package private) void | addRequest()Adds a new request to the outstanding requests list. |
(package private) void | allowedFastMessage(int piece)BEP 6 Ignored for now |
(package private) void | bitfieldMessage(byte[] bitmap)Handle a bitfield message from the peer |
(package private) void | cancelMessage(int piece,
int begin,
int length)Handle a cancel message from the peer |
(package private) void | cancelPiece(int piece)Tell the other side that we are no longer interested in any of the outstanding requests (if
any) for this piece. |
(package private) void | chokeMessage(boolean choke)Handle a choke or unchoke message from the peer |
(package private) void | extensionMessage(int id,
byte[] bs)Handle an extension message from the peer. |
(package private) BandwidthListener | getBandwidthListener()Returns the bandwidth listener for this peer state. |
(package private) Request | getOutstandingRequest(int piece,
int begin,
int length)Called when a piece message is being processed by the incoming connection. |
(package private) String | getRequests()debug |
(package private) void | haveMessage(boolean isAll)BEP 6 |
(package private) void | haveMessage(int piece)Handle a have message from the peer |
(package private) void | havePiece(int piece)We now have this piece. |
(package private) void | interestedMessage(boolean interest)Handle an interested or uninterested message from the peer |
(package private) void | keepAlive()Send a keepalive message to the peer. |
(package private) void | keepAliveMessage()Handle a keepalive message from the peer |
ByteArray | loadData(int piece,
int begin,
int length)This is the callback that PeerConnectionOut calls |
(package private) void | pieceMessage(Request req)Called when a full chunk (i.e. |
(package private) void | portMessage(int port)Handle a port message from the peer. |
(package private) void | rejectMessage(int piece,
int begin,
int length)BEP 6 |
(package private) void | requestMessage(int piece,
int begin,
int length)Handle a request message from the peer |
(package private) void | retransmitRequests()Retransmit outstanding requests if necessary. |
(package private) List<Request> | returnPartialPieces()Get partial pieces, give them back to PeerCoordinator. |
(package private) void | setChoking(boolean choke)Sets whether or not we are choking the peer. |
(package private) void | setInteresting(boolean interest)Sets whether or not we are interested in pieces from this peer. |
void | setMetaInfo(MetaInfo meta)Switch from magnet mode to normal mode. |
(package private) void | suggestMessage(int piece)BEP 6 Treated as "have" for now |
(package private) void | unknownMessage(int type,
byte[] bs)Handle an unknown message type from the peer. |
(package private) void | uploaded(int size)Called when some bytes have left the outgoing connection. |
BitField bitfield
volatile boolean choked
volatile boolean choking
final PeerConnectionIn in
volatile boolean interested
volatile boolean interesting
final PeerListener listener
public static final int MAX_PIPELINE
public static final int MIN_PIPELINE
final PeerConnectionOut out
public static final int PARTSIZE
PeerState(Peer peer, PeerListener listener, BandwidthListener bwl, MetaInfo metainfo, PeerConnectionIn in, PeerConnectionOut out)
metainfo - null if in magnet modevoid addRequest()
This is called from several places:
By getOutstandingRequest() when the first part of a chunk comes in By havePiece() when somebody got a new piece completed By chokeMessage() when we receive an unchoke By setInteresting() when we are now interested By PeerCoordinator.updatePiecePriorities()
void allowedFastMessage(int piece)
void bitfieldMessage(byte[] bitmap)
void cancelMessage(int piece,
int begin,
int length)void cancelPiece(int piece)
void chokeMessage(boolean choke)
void extensionMessage(int id,
byte[] bs)id - the extension message IDbs - the message payloadBandwidthListener getBandwidthListener()
Request getOutstandingRequest(int piece, int begin, int length)
String getRequests()
void haveMessage(boolean isAll)
isAll - true for have_all, false for have_nonevoid haveMessage(int piece)
void havePiece(int piece)
void interestedMessage(boolean interest)
void keepAlive()
void keepAliveMessage()
public ByteArray loadData(int piece, int begin, int length)
loadData in interface DataLoaderRuntimeException - on IOE getting the datavoid pieceMessage(Request req)
This may block quite a while if it is the last chunk for a piece, as it calls the listener, who stores the piece and then calls havePiece for every peer on the torrent (including us).
void portMessage(int port)
port - the port numbervoid rejectMessage(int piece,
int begin,
int length)void requestMessage(int piece,
int begin,
int length)void retransmitRequests()
List<Request> returnPartialPieces()
void setChoking(boolean choke)
choke - true to choke, false to unchokevoid setInteresting(boolean interest)
interest - true if interestedpublic void setMetaInfo(MetaInfo meta)
meta - non-nullvoid suggestMessage(int piece)
void unknownMessage(int type,
byte[] bs)type - the message type bytebs - the message payloadvoid uploaded(int size)