| Modifier and Type | Field and Description |
|---|---|
(package private) long | lastSentlast send time |
| 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. |
void | disconnect()Disconnect and close the output stream. |
(package private) int | queuedBytes()Returns the total bytes of piece messages currently queued. |
(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 | 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. |
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()
public void disconnect()
int queuedBytes()
void retransmitRequests(List<Request> requests)
requests - the list of outstanding requestspublic void run()
void sendAlive()
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()