Methods Summary |
---|
private void | constructBuffer()
buffer = DirectByteBufferPool.getBuffer( DirectByteBuffer.AL_MSG_BT_HAND, 68 );
buffer.put( DirectByteBuffer.SS_MSG, (byte)PROTOCOL.length() );
buffer.put( DirectByteBuffer.SS_MSG, PROTOCOL.getBytes() );
buffer.put( DirectByteBuffer.SS_MSG, reserved_bytes );
buffer.put( DirectByteBuffer.SS_MSG, datahash_bytes );
buffer.put( DirectByteBuffer.SS_MSG, peer_id_bytes );
buffer.flip( DirectByteBuffer.SS_MSG );
|
public Message | deserialize(DirectByteBuffer data, byte version)
if( data == null ) {
throw new MessageException( "[" +getID() + "] decode error: data == null" );
}
if( data.remaining( DirectByteBuffer.SS_MSG ) != 68 ) {
throw new MessageException( "[" +getID() + "] decode error: payload.remaining[" +data.remaining( DirectByteBuffer.SS_MSG )+ "] != 68" );
}
if( data.get( DirectByteBuffer.SS_MSG ) != (byte)PROTOCOL.length() ) {
throw new MessageException( "[" +getID() + "] decode error: payload.get() != (byte)PROTOCOL.length()" );
}
byte[] header = new byte[ PROTOCOL.getBytes().length ];
data.get( DirectByteBuffer.SS_MSG, header );
if( !PROTOCOL.equals( new String( header ) ) ) {
throw new MessageException( "[" +getID() + "] decode error: invalid protocol given: " + new String( header ) );
}
byte[] reserved = new byte[ 8 ];
data.get( DirectByteBuffer.SS_MSG, reserved );
byte[] infohash = new byte[ 20 ];
data.get( DirectByteBuffer.SS_MSG, infohash );
byte[] peerid = new byte[ 20 ];
data.get( DirectByteBuffer.SS_MSG, peerid );
data.returnToPool();
return new BTHandshake( reserved, infohash, peerid, version );
|
public void | destroy()
if( buffer != null ) buffer.returnToPool();
|
public Message | getBaseMessage() return this;
|
public DirectByteBuffer[] | getData()
if( buffer == null ) {
constructBuffer();
}
return new DirectByteBuffer[]{ buffer };
|
public byte[] | getDataHash() return datahash_bytes;
|
public java.lang.String | getDescription()
if( description == null ) {
description = BTMessage.ID_BT_HANDSHAKE + " of dataID: " +ByteFormatter.nicePrint( datahash_bytes, true ) + " peerID: " +PeerClassifier.getPrintablePeerID( peer_id_bytes );
}
return description;
|
public java.lang.String | getFeatureID() return BTMessage.BT_FEATURE_ID;
|
public int | getFeatureSubID() return BTMessage.SUBID_BT_HANDSHAKE;
|
public java.lang.String | getID() return BTMessage.ID_BT_HANDSHAKE;
|
public byte[] | getIDBytes() return BTMessage.ID_BT_HANDSHAKE_BYTES;
|
public byte[] | getPeerId() return peer_id_bytes;
|
public int | getPriority() return RawMessage.PRIORITY_HIGH;
|
public DirectByteBuffer[] | getRawData()
if( buffer == null ) {
constructBuffer();
}
return new DirectByteBuffer[]{ buffer };
|
public byte[] | getReserved() return reserved_bytes;
|
public int | getType() return Message.TYPE_PROTOCOL_PAYLOAD;
|
public byte | getVersion() return version;
|
public boolean | isNoDelay() return true;
|
public Message[] | messagesToRemove() return null;
|