Methods Summary |
---|
public com.aelitis.azureus.core.peermanager.messaging.Message | deserialize(DirectByteBuffer data, byte version)
Map root = MessagingUtil.convertBencodedByteStreamToPayload( data, 100, getID() );
byte[] id = (byte[])root.get( "identity" );
if( id == null ) throw new MessageException( "id == null" );
if( id.length != 20 ) throw new MessageException( "id.length != 20: " +id.length );
byte[] raw_name = (byte[])root.get( "client" );
if( raw_name == null ) throw new MessageException( "raw_name == null" );
String name = new String( raw_name );
byte[] raw_ver = (byte[])root.get( "version" );
if( raw_ver == null ) throw new MessageException( "raw_ver == null" );
String client_version = new String( raw_ver );
Long tcp_lport = (Long)root.get( "tcp_port" );
if( tcp_lport == null ) { //old handshake
tcp_lport = new Long( 0 );
}
Long udp_lport = (Long)root.get( "udp_port" );
if( udp_lport == null ) { //old handshake
udp_lport = new Long( 0 );
}
Long udp2_lport = (Long)root.get( "udp2_port" );
if( udp2_lport == null ) { //old handshake
udp2_lport = udp_lport;
}
Long h_type = (Long)root.get( "handshake_type" );
if( h_type == null ) { //only 2307+ send type
h_type = new Long( HANDSHAKE_TYPE_PLAIN );
}
List raw_msgs = (List) root.get("messages");
if (raw_msgs == null) throw new MessageException("raw_msgs == null");
String[] ids = new String[raw_msgs.size()];
byte[] vers = new byte[raw_msgs.size()];
int pos = 0;
for (Iterator i = raw_msgs.iterator(); i.hasNext();) {
Map msg = (Map) i.next();
byte[] mid = (byte[]) msg.get("id");
if (mid == null) throw new MessageException("mid == null");
ids[pos] = new String(mid);
byte[] ver = (byte[]) msg.get("ver");
if (ver == null) throw new MessageException("ver == null");
if (ver.length != 1) throw new MessageException("ver.length != 1");
vers[pos] = ver[0];
pos++;
}
return new AZHandshake( id, name, client_version, tcp_lport.intValue(), udp_lport.intValue(), udp2_lport.intValue(), ids, vers, h_type.intValue(), version );
|
public void | destroy()
if( buffer != null ) buffer.returnToPool();
|
public java.lang.String | getClient() return client;
|
public java.lang.String | getClientVersion() return client_version;
|
public DirectByteBuffer[] | getData()
if( buffer == null ) {
Map payload_map = new HashMap();
//client info
payload_map.put( "identity", identity );
payload_map.put( "client", client );
payload_map.put( "version", client_version );
payload_map.put( "tcp_port", new Long( tcp_port ) );
payload_map.put( "udp_port", new Long( udp_port ) );
payload_map.put( "udp2_port", new Long( udp_non_data_port ) );
payload_map.put( "handshake_type", new Long( handshake_type ) );
//available message list
List message_list = new ArrayList();
for( int i=0; i < avail_ids.length; i++ ) {
String id = avail_ids[ i ];
byte ver = avail_versions[ i ];
if( id.equals( getID() )) continue; //skip ourself
Map msg = new HashMap();
msg.put( "id", id );
msg.put( "ver", new byte[]{ ver } );
message_list.add( msg );
}
payload_map.put( "messages", message_list );
// random padding if crypto
if ( handshake_type == AZHandshake.HANDSHAKE_TYPE_CRYPTO ){
payload_map.put( "pad", new byte[(int)( Math.random() * AZMessageFactory.AZ_HANDSHAKE_PAD_MAX )]);
}
buffer = MessagingUtil.convertPayloadToBencodedByteStream( payload_map, DirectByteBuffer.AL_MSG_AZ_HAND );
if( buffer.remaining( bss ) > 1200 ) System.out.println( "Generated AZHandshake size = " +buffer.remaining( bss )+ " bytes" );
}
return new DirectByteBuffer[]{ buffer };
|
public java.lang.String | getDescription()
if( description == null ) {
String msgs_desc = "";
for( int i=0; i < avail_ids.length; i++ ) {
String id = avail_ids[ i ];
byte ver = avail_versions[ i ];
if( id.equals( getID() ) ) continue; //skip ourself
msgs_desc += "[" +id+ ":" +ver+ "]";
}
description = getID()+ " from [" +ByteFormatter.nicePrint( identity, true )+ ", " +
client+ " " +client_version+ ", TCP/UDP ports " +tcp_port+ "/" +udp_port+ "/" + udp_non_data_port +
", handshake " + (getHandshakeType() == HANDSHAKE_TYPE_PLAIN ? "plain" : "crypto") +
"] supports " +msgs_desc;
}
return description;
|
public java.lang.String | getFeatureID() return AZMessage.AZ_FEATURE_ID;
|
public int | getFeatureSubID() return AZMessage.SUBID_AZ_HANDSHAKE;
|
public int | getHandshakeType() return handshake_type;
|
public java.lang.String | getID() return AZMessage.ID_AZ_HANDSHAKE;
|
public byte[] | getIDBytes() return AZMessage.ID_AZ_HANDSHAKE_BYTES;
|
public byte[] | getIdentity() return identity;
|
public java.lang.String[] | getMessageIDs() return avail_ids;
|
public byte[] | getMessageVersions() return avail_versions;
|
public int | getTCPListenPort() return tcp_port;
|
public int | getType() return Message.TYPE_PROTOCOL_PAYLOAD;
|
public int | getUDPListenPort() return udp_port;
|
public int | getUDPNonDataListenPort() return udp_non_data_port;
|
public byte | getVersion() return version;
|