public class StandardBittorrentProtocol extends Object implements MessageHandler<Message>
Modifier and Type | Field and Description |
---|---|
static int |
BITFIELD_ID |
static int |
CANCEL_ID |
static int |
CHOKE_ID |
static int |
HAVE_ID |
static int |
INTERESTED_ID |
static int |
MESSAGE_LENGTH_PREFIX_SIZE
BitTorrent message prefix size in bytes.
|
static int |
MESSAGE_PREFIX_SIZE
BitTorrent message prefix size in bytes.
|
static int |
MESSAGE_TYPE_SIZE
BitTorrent message ID size in bytes.
|
static int |
NOT_INTERESTED_ID |
static int |
PIECE_ID |
static int |
REQUEST_ID |
static int |
UNCHOKE_ID |
Constructor and Description |
---|
StandardBittorrentProtocol(Map<Integer,MessageHandler<?>> extraHandlers) |
Modifier and Type | Method and Description |
---|---|
int |
decode(DecodingContext context,
ByteBufferView buffer)
Tries to decode message from the byte buffer.
|
boolean |
encode(EncodingContext context,
Message message,
ByteBuffer buffer)
Tries to encode the provided message and place the result into the byte buffer.
|
Collection<Class<? extends Message>> |
getSupportedTypes() |
Class<? extends Message> |
readMessageType(ByteBufferView buffer)
Tries to determine the message type based on the (part of the) message available in the byte buffer.
|
public static final int MESSAGE_LENGTH_PREFIX_SIZE
public static final int MESSAGE_TYPE_SIZE
public static final int MESSAGE_PREFIX_SIZE
public static final int CHOKE_ID
public static final int UNCHOKE_ID
public static final int INTERESTED_ID
public static final int NOT_INTERESTED_ID
public static final int HAVE_ID
public static final int BITFIELD_ID
public static final int REQUEST_ID
public static final int PIECE_ID
public static final int CANCEL_ID
@Inject public StandardBittorrentProtocol(Map<Integer,MessageHandler<?>> extraHandlers)
public Collection<Class<? extends Message>> getSupportedTypes()
getSupportedTypes
in interface Protocol<Message>
public final Class<? extends Message> readMessageType(ByteBufferView buffer)
Protocol
readMessageType
in interface Protocol<Message>
buffer
- Byte buffer of arbitrary length containing (a part of) the message.
Decoding should be performed starting with the current position of the buffer.public final int decode(DecodingContext context, ByteBufferView buffer)
MessageHandler
context
decode
in interface MessageHandler<Message>
context
- Message context. In case of success the decoded message must be put into this context.buffer
- Byte buffer of arbitrary length containing (a part of) the message.
Decoding should be performed starting with the current position of the buffer.public final boolean encode(EncodingContext context, Message message, ByteBuffer buffer)
MessageHandler
encode
in interface MessageHandler<Message>
context
- Encoding contextbuffer
- Byte buffer of arbitrary capacity.
Encoded message should be placed into the buffer starting with its current position.
Protocol should check if the buffer has sufficient space available, and return false
if it's not the case.Copyright © 2016–2021. All rights reserved.