Class BTHandshake
- java.lang.Object
-
- com.biglybt.core.peermanager.messaging.bittorrent.BTHandshake
-
- All Implemented Interfaces:
RawMessage
,BTMessage
,Message
public class BTHandshake extends java.lang.Object implements BTMessage, RawMessage
BitTorrent handshake message.
-
-
Field Summary
Fields Modifier and Type Field Description static byte[]
AZ_RESERVED
static int
AZ_RESERVED_MODE
private static byte[]
BT_RESERVED
static int
BT_RESERVED_MODE
private DirectByteBuffer
buffer
private byte[]
datahash_bytes
private java.lang.String
description
static boolean
FAST_EXTENSION_ENABLED
private static byte[]
LT_RESERVED
static int
LT_RESERVED_MODE
private byte[]
peer_id_bytes
static java.lang.String
PROTOCOL
private static byte[][]
RESERVED
private byte[]
reserved_bytes
private byte
version
-
Fields inherited from interface com.biglybt.core.peermanager.messaging.bittorrent.BTMessage
BT_FEATURE_ID, ID_BT_ALLOWED_FAST, ID_BT_ALLOWED_FAST_BYTES, ID_BT_BITFIELD, ID_BT_BITFIELD_BYTES, ID_BT_CANCEL, ID_BT_CANCEL_BYTES, ID_BT_CHOKE, ID_BT_CHOKE_BYTES, ID_BT_DHT_PORT, ID_BT_DHT_PORT_BYTES, ID_BT_HANDSHAKE, ID_BT_HANDSHAKE_BYTES, ID_BT_HASH_REJECT, ID_BT_HASH_REJECT_BYTES, ID_BT_HASH_REQUEST, ID_BT_HASH_REQUEST_BYTES, ID_BT_HASHES, ID_BT_HASHES_BYTES, ID_BT_HAVE, ID_BT_HAVE_ALL, ID_BT_HAVE_ALL_BYTES, ID_BT_HAVE_BYTES, ID_BT_HAVE_NONE, ID_BT_HAVE_NONE_BYTES, ID_BT_INTERESTED, ID_BT_INTERESTED_BYTES, ID_BT_KEEP_ALIVE, ID_BT_KEEP_ALIVE_BYTES, ID_BT_LT_EXT_MESSAGE, ID_BT_LT_EXT_MESSAGE_BYTES, ID_BT_PIECE, ID_BT_PIECE_BYTES, ID_BT_REJECT_REQUEST, ID_BT_REJECT_REQUEST_BYTES, ID_BT_REQUEST, ID_BT_REQUEST_BYTES, ID_BT_SUGGEST_PIECE, ID_BT_SUGGEST_PIECE_BYTES, ID_BT_UNCHOKE, ID_BT_UNCHOKE_BYTES, ID_BT_UNINTERESTED, ID_BT_UNINTERESTED_BYTES, SUBID_BT_ALLOWED_FAST, SUBID_BT_BITFIELD, SUBID_BT_CANCEL, SUBID_BT_CHOKE, SUBID_BT_DHT_PORT, SUBID_BT_HANDSHAKE, SUBID_BT_HASH_REJECT, SUBID_BT_HASH_REQUEST, SUBID_BT_HASHES, SUBID_BT_HAVE, SUBID_BT_HAVE_ALL, SUBID_BT_HAVE_NONE, SUBID_BT_INTERESTED, SUBID_BT_KEEP_ALIVE, SUBID_BT_LT_EXT_MESSAGE, SUBID_BT_PIECE, SUBID_BT_REJECT_REQUEST, SUBID_BT_REQUEST, SUBID_BT_SUGGEST_PIECE, SUBID_BT_UNCHOKE, SUBID_BT_UNINTERESTED, SUBID_MAX
-
Fields inherited from interface com.biglybt.core.peermanager.messaging.Message
TYPE_DATA_PAYLOAD, TYPE_PROTOCOL_PAYLOAD
-
Fields inherited from interface com.biglybt.core.networkmanager.RawMessage
PRIORITY_HIGH, PRIORITY_LOW, PRIORITY_NORMAL
-
-
Constructor Summary
Constructors Modifier Constructor Description private
BTHandshake(byte[] reserved, byte[] data_hash, byte[] peer_id, byte version)
BTHandshake(byte[] data_hash, byte[] peer_id, int reserved_mode, byte version)
Used for outgoing handshake message.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
constructBuffer()
Message
deserialize(DirectByteBuffer data, byte version)
Create a new instance of this message by decoding the given byte serialization.void
destroy()
Destroy the message; i.e.private static byte[]
duplicate(byte[] b)
Message
getBaseMessage()
Get the message this raw message is based upon.DirectByteBuffer[]
getData()
Get message payload data.byte[]
getDataHash()
java.lang.String
getDescription()
Get textual description of this particular message.java.lang.String
getFeatureID()
Get the main feature set name this message belongs to.int
getFeatureSubID()
Get the static message sub-id for the feature.java.lang.String
getID()
Get message id.byte[]
getIDBytes()
byte[]
getPeerId()
int
getPriority()
Get the message's queue priority.DirectByteBuffer[]
getRawData()
Get the message's raw data payload.byte[]
getReserved()
int
getType()
Get message type.byte
getVersion()
boolean
isNoDelay()
Is this a no-delay message.Message[]
messagesToRemove()
Get the yet-unsent message types that should be removed before queueing this message for sending.static void
setFastExtensionEnabled(boolean enabled)
static void
setMainlineDHTEnabled(boolean enabled)
void
setNoDelay()
Set no-delay for this message
-
-
-
Field Detail
-
PROTOCOL
public static final java.lang.String PROTOCOL
- See Also:
- Constant Field Values
-
BT_RESERVED
private static final byte[] BT_RESERVED
-
LT_RESERVED
private static final byte[] LT_RESERVED
-
AZ_RESERVED
public static final byte[] AZ_RESERVED
-
BT_RESERVED_MODE
public static final int BT_RESERVED_MODE
- See Also:
- Constant Field Values
-
LT_RESERVED_MODE
public static final int LT_RESERVED_MODE
- See Also:
- Constant Field Values
-
AZ_RESERVED_MODE
public static final int AZ_RESERVED_MODE
- See Also:
- Constant Field Values
-
RESERVED
private static final byte[][] RESERVED
-
FAST_EXTENSION_ENABLED
public static final boolean FAST_EXTENSION_ENABLED
- See Also:
- Constant Field Values
-
buffer
private DirectByteBuffer buffer
-
description
private java.lang.String description
-
reserved_bytes
private final byte[] reserved_bytes
-
datahash_bytes
private final byte[] datahash_bytes
-
peer_id_bytes
private final byte[] peer_id_bytes
-
version
private final byte version
-
-
Constructor Detail
-
BTHandshake
public BTHandshake(byte[] data_hash, byte[] peer_id, int reserved_mode, byte version)
Used for outgoing handshake message.- Parameters:
data_hash
-peer_id
-set_reserve_bit
-
-
BTHandshake
private BTHandshake(byte[] reserved, byte[] data_hash, byte[] peer_id, byte version)
-
-
Method Detail
-
setMainlineDHTEnabled
public static void setMainlineDHTEnabled(boolean enabled)
-
setFastExtensionEnabled
public static void setFastExtensionEnabled(boolean enabled)
-
duplicate
private static byte[] duplicate(byte[] b)
-
constructBuffer
private void constructBuffer()
-
getReserved
public byte[] getReserved()
-
getDataHash
public byte[] getDataHash()
-
getPeerId
public byte[] getPeerId()
-
getID
public java.lang.String getID()
Description copied from interface:Message
Get message id.
-
getIDBytes
public byte[] getIDBytes()
- Specified by:
getIDBytes
in interfaceMessage
-
getFeatureID
public java.lang.String getFeatureID()
Description copied from interface:Message
Get the main feature set name this message belongs to.- Specified by:
getFeatureID
in interfaceMessage
- Returns:
- feature id
-
getFeatureSubID
public int getFeatureSubID()
Description copied from interface:Message
Get the static message sub-id for the feature.- Specified by:
getFeatureSubID
in interfaceMessage
- Returns:
- sub id
-
getType
public int getType()
Description copied from interface:Message
Get message type.
-
getVersion
public byte getVersion()
- Specified by:
getVersion
in interfaceMessage
-
getDescription
public java.lang.String getDescription()
Description copied from interface:Message
Get textual description of this particular message.- Specified by:
getDescription
in interfaceMessage
- Returns:
- description
-
getData
public DirectByteBuffer[] getData()
Description copied from interface:Message
Get message payload data.
-
deserialize
public Message deserialize(DirectByteBuffer data, byte version) throws MessageException
Description copied from interface:Message
Create a new instance of this message by decoding the given byte serialization.- Specified by:
deserialize
in interfaceMessage
- Parameters:
data
- to deserialize- Returns:
- decoded message instance
- Throws:
MessageException
- if the decoding process fails NOTE: Does not auto-return given direct buffer on thrown exception.
-
getRawData
public DirectByteBuffer[] getRawData()
Description copied from interface:RawMessage
Get the message's raw data payload.- Specified by:
getRawData
in interfaceRawMessage
- Returns:
- data payload buffers
-
getPriority
public int getPriority()
Description copied from interface:RawMessage
Get the message's queue priority.- Specified by:
getPriority
in interfaceRawMessage
- Returns:
- priority
-
isNoDelay
public boolean isNoDelay()
Description copied from interface:RawMessage
Is this a no-delay message. No-delay messages are transmitted immediately, i.e. force-flushed out the transport.- Specified by:
isNoDelay
in interfaceRawMessage
- Returns:
- true if a no-delay message
-
setNoDelay
public void setNoDelay()
Description copied from interface:RawMessage
Set no-delay for this message- Specified by:
setNoDelay
in interfaceRawMessage
-
messagesToRemove
public Message[] messagesToRemove()
Description copied from interface:RawMessage
Get the yet-unsent message types that should be removed before queueing this message for sending.- Specified by:
messagesToRemove
in interfaceRawMessage
- Returns:
- message types; null if no types
-
destroy
public void destroy()
Description copied from interface:Message
Destroy the message; i.e. perform cleanup actions.
-
getBaseMessage
public Message getBaseMessage()
Description copied from interface:RawMessage
Get the message this raw message is based upon.- Specified by:
getBaseMessage
in interfaceRawMessage
- Returns:
- original message
-
-