org.klomp.snark

## Class PeerConnectionOut

- java.lang.Object
- - org.klomp.snark.PeerConnectionOut

- All Implemented Interfaces:
    Runnable

      class PeerConnectionOut
      extends Object
      implements Runnable

  Manages outgoing BitTorrent protocol messages to a peer.
  This class maintains a queue of outgoing messages and handles bandwidth limiting, message prioritization, and reliable delivery to the peer.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `(package private) long` | `lastSent`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PeerConnectionOut(Peer peer, DataOutputStream dout)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    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()`
    `(package private) int` | `queuedBytes()`
    `(package private) void` | `retransmitRequests(List<Request> requests)`
    `void` | `run()` Continuesly monitors for more outgoing messages that have to be send.
    `(package private) void` | `sendAlive()`
    `(package private) void` | `sendBitfield(BitField bitfield)`
    `(package private) void` | `sendCancel(Request req)` send cancel
    `(package private) void` | `sendChoke(boolean choke)`
    `(package private) void` | `sendExtension(int id, byte[] bytes)`
    `(package private) void` | `sendHave(int piece)`
    `(package private) void` | `sendInterest(boolean interest)`
    `(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)`
    `(package private) void` | `sendReject(int piece, int begin, int length)`
    `(package private) void` | `sendRequest(Request req)`
    `(package private) void` | `sendRequests(List<Request> requests)`
    `void` | `startup()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### lastSent

          long lastSent

  - ### Constructor Detail

    - #### PeerConnectionOut

          public PeerConnectionOut(Peer peer,
                                   DataOutputStream dout)

  - ### Method Detail

    - #### cancelRequest

          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. Removes any pending Piece Message from out send queue. Does not send a cancel message.

    - #### cancelRequestMessages

          void cancelRequestMessages()

      Remove all Request messages from the queue. Does not send a cancel message.

    - #### disconnect

          public void disconnect()

    - #### queuedBytes

          int queuedBytes()

    - #### retransmitRequests

          void retransmitRequests(List<Request> requests)

    - #### run

          public void run()

      Continuesly monitors for more outgoing messages that have to be send. Stops if quit is true or an IOException occurs.
      Specified by:
        `run` in interface `Runnable`

    - #### sendAlive

          void sendAlive()

    - #### sendBitfield

          void sendBitfield(BitField bitfield)

    - #### sendCancel

          void sendCancel(Request req)

      send cancel

    - #### sendChoke

          void sendChoke(boolean choke)

    - #### sendExtension

          void sendExtension(int id,
                             byte[] bytes)

    - #### sendHave

          void sendHave(int piece)

    - #### sendInterest

          void sendInterest(boolean interest)

    - #### sendPiece

          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.

    - #### sendPort

          void sendPort(int port)

    - #### sendReject

          void sendReject(int piece,
                          int begin,
                          int length)

    - #### sendRequest

          void sendRequest(Request req)

    - #### sendRequests

          void sendRequests(List<Request> requests)

    - #### startup

          public void startup()