FileDocCategorySizeDatePackage
ADVHandshake.javaAPI DocAzureus 3.0.3.44096Sun Mar 04 21:08:16 GMT 2007com.aelitis.azureus.core.peermanager.messaging.advanced

ADVHandshake

public class ADVHandshake extends Object implements ADVMessage
BitTorrent handshake message.

Fields Summary
private byte
version
private DirectByteBuffer
buffer
private String
description
Constructors Summary
public ADVHandshake(byte _version)

  
  
  
         //TODO
	  version = _version;
    /*
    for( int i=0; i < reserved.length; i++ ) {  //locate any reserved bits
      for( int x=7; x >= 0; x-- ) {
        byte b = (byte) (reserved[i] >> x);
        int val = b & 0x01;
        if( val == 1 ) {
          String id = new String(peer_id);
          
          if( id.startsWith( "-AZ23" ) )  break;
          if( id.startsWith( "exbc" ) )  break;
          if( id.startsWith( "FUTB" ) )  break;
          
          System.out.println( "BT_HANDSHAKE:: reserved bit @ [" +i+ "/" +(7 - x)+ "] for [" +id+ "]" );
        }
      }
    }
    */
    
  
Methods Summary
private voidconstructBuffer()

    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 Messagedeserialize(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" );
    }
    
    
    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 ADVHandshake(version);
  
public voiddestroy()

    if( buffer != null )  buffer.returnToPool();    
  
public DirectByteBuffer[]getData()

 
    if( buffer == null ) {
      constructBuffer();
    }
    
    return new DirectByteBuffer[]{ buffer };
  
public java.lang.StringgetDescription()

    if( description == null ) {
      description = getID();
    }
    
    return description; 
  
public java.lang.StringgetFeatureID()

  return ADVMessage.ADV_FEATURE_ID;  
public intgetFeatureSubID()

  return ADVMessage.SUBID_ADV_HANDSHAKE;  
public java.lang.StringgetID()

  return ADVMessage.ID_ADV_HANDSHAKE;  
public byte[]getIDBytes()

  return ADVMessage.ID_ADV_HANDSHAKE_BYTES;  
public intgetType()

  return Message.TYPE_PROTOCOL_PAYLOAD;  
public bytegetVersion()

 return version;