| Modifier and Type | Field and Description |
|---|---|
(package private) long | lastSentLast send time. |
(package private) static int | MAX_PREFETCH_INFLIGHTMax uncompleted prefetches per connection; bounds pinned buffers to depth x 16KB. |
| Constructor and Description |
|---|
PeerConnectionOut(Peer peer,
DataOutputStream dout)Creates a new outgoing connection handler. |
| Modifier and Type | Method and Description |
|---|---|
(package private) void | cancelRequest(int piece,
int begin,
int length)Called by the PeerState when the other side doesn't want this request to be handled anymore. |
(package private) void | cancelRequestMessages()Remove all Request messages from the queue. |
(package private) void | cancelRequestMessages(int piece)Remove Request messages for a piece from the queue. |
void | disconnect()Disconnect and close the output stream. |
(package private) boolean | hasPendingPiece()Whether a PIECE message is still queued, i.e. |
(package private) Message | headPiece()The first queued PIECE message in send order. |
(package private) int | prefetchInFlight()Current number of uncompleted prefetch loads for this connection. |
(package private) int | queuedBytes()Returns the total bytes of piece messages currently queued. |
(package private) static void | recordLoad(long ms)Record a deferred-load duration. |
(package private) void | retransmitRequests(List<Request> requests)Retransmit requests that haven't been received within REQ_TIMEOUT. |
void | run()Pull messages from the send queue and deliver to the peer. |
(package private) void | sendAlive()Queue a keepalive message if the queue is empty. |
(package private) void | sendAllowedFast(int piece)Queue an allowed fast message (BEP 6). |
(package private) void | sendBitfield(BitField bitfield)Queue a bitfield, have_all, or have_none message as appropriate. |
(package private) void | sendCancel(Request req)Send a cancel message and remove any matching request from the queue. |
(package private) void | sendChoke(boolean choke)Queue a choke or unchoke message, cancelling any pending inverse. |
(package private) void | sendExtension(int id,
byte[] bytes)Queue an extension message. |
(package private) void | sendHave(int piece)Queue a have message for the given piece. |
(package private) void | sendInterest(boolean interest)Queue an interested or not-interested message, cancelling any pending inverse. |
(package private) void | sendPiece(int piece,
int begin,
int length,
DataLoader loader)Queue a piece message with a callback to load the data from disk when required. |
(package private) void | sendPort(int port)Queue a port message. |
(package private) void | sendReject(int piece,
int begin,
int length)Queue a reject message. |
(package private) void | sendRequest(Request req)Queue a request message, checking for duplicates. |
(package private) void | sendRequests(List<Request> requests)Send all requests in the list. |
void | startup()Start the sender thread. |
long lastSent
static volatile int MAX_PREFETCH_INFLIGHT
public PeerConnectionOut(Peer peer, DataOutputStream dout)
peer - the peerdout - the output stream to send messages onvoid cancelRequest(int piece,
int begin,
int length)piece - the piece numberbegin - the offset within the piecelength - the length of the requestvoid cancelRequestMessages()
void cancelRequestMessages(int piece)
piece - the piece indexpublic void disconnect()
boolean hasPendingPiece()
Message headPiece()
int prefetchInFlight()
int queuedBytes()
static void recordLoad(long ms)
Message.sendMessage(DataOutputStream).ms - load duration in millisecondsvoid retransmitRequests(List<Request> requests)
requests - the list of outstanding requestspublic void run()
void sendAlive()
void sendAllowedFast(int piece)
void sendBitfield(BitField bitfield)
bitfield - the bitfield to sendvoid sendCancel(Request req)
req - the request to cancelvoid sendChoke(boolean choke)
choke - true to choke, false to unchokevoid sendExtension(int id,
byte[] bytes)void sendHave(int piece)
piece - the piece numbervoid sendInterest(boolean interest)
interest - true for interested, false for not-interestedvoid sendPiece(int piece,
int begin,
int length,
DataLoader loader)void sendPort(int port)
void sendReject(int piece,
int begin,
int length)void sendRequest(Request req)
req - the request to sendvoid sendRequests(List<Request> requests)
requests - the list of requests to sendpublic void startup()