java.lang.Object
org.klomp.snark.PeerConnectionIn
- All Implemented Interfaces:
Runnable
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final LogLogger for this class.private final DataInputStreamThe stream read from the peer.private static final longFlood guard: length of the counting window.private final booleanTrue when running outside the router.(package private) longLast rcvd.private static final intFlood guard: maximum inbound messages per window, generous to tolerate bursts.private static final intLargest complete message accepted, in bytes.private final PeerThe peer being read from.private booleanSet to end the read loop.private ThreadThe thread reading messages, null once stopped.Constructor Summary
ConstructorsConstructorDescriptionPeerConnectionIn(Peer peer, DataInputStream din) Create a handler for incoming messages from a peer.Method Summary
Modifier and TypeMethodDescription(package private) voidDisconnect from the peer and release resources.private static intminLengthFor(byte type) The minimum complete message length in bytes for a message type, including the type byte.voidrun()Read and dispatch incoming BitTorrent messages until disconnect.
Field Details
_log
Logger for this class.peer
The peer being read from.din
The stream read from the peer.MAX_MSG_SIZE
private static final int MAX_MSG_SIZELargest complete message accepted, in bytes. The biggest is the piece message, the request size (32K) plus 9; the bitfield message could exceed it only if Storage.MAX_PIECES / 8 grew past the current 625.MAX_MESSAGES_PER_WINDOW
private static final int MAX_MESSAGES_PER_WINDOWFlood guard: maximum inbound messages per window, generous to tolerate bursts.- See Also:
FLOOD_WINDOW_MS
private static final long FLOOD_WINDOW_MSFlood guard: length of the counting window.- See Also:
thread
The thread reading messages, null once stopped.quit
private volatile boolean quitSet to end the read loop.isStandalone
private final boolean isStandaloneTrue when running outside the router.lastRcvd
long lastRcvdLast rcvd.
Constructor Details
PeerConnectionIn
Create a handler for incoming messages from a peer.- Parameters:
peer- the remote peer this connection belongs todin- the stream positioned at the start of the peer's message stream
Method Details
minLengthFor
private static int minLengthFor(byte type) The minimum complete message length in bytes for a message type, including the type byte. Messages with variable-length data (PIECE, BITFIELD, EXTENSION) have a minimum of just their fixed header.- Parameters:
type- the message type byte- Returns:
- the minimum length for the given type
disconnect
void disconnect()Disconnect from the peer and release resources.run