jBittorrentAPI
Class Message_HS

java.lang.Object
  extended by jBittorrentAPI.Message
      extended by jBittorrentAPI.Message_HS

public class Message_HS
extends Message

Represent a Handshake message according to Bittorrent Protocol. It has the form: - # pstrlen: string length of , as a single raw byte - - # pstr: string identifier of the protocol - - # reserved: eight (8) reserved bytes - - # info_hash: 20-byte SHA1 hash of the info key in the metainfo file - - # peer_id: 20-byte string used as a unique ID for the client -


Field Summary
private  byte[] fileID
           
private  byte[] length
           
private  byte[] peerID
           
private  byte[] protocol
           
private  byte[] reserved
           
 
Fields inherited from class jBittorrentAPI.Message
type
 
Constructor Summary
Message_HS()
          Creates an empty HS message
Message_HS(byte[] infoHash, byte[] peerID)
          Creates a HS message with the given infoHash and peerID and default values
Message_HS(byte[] length, byte[] protocol, byte[] reserved, byte[] fileID, byte[] peerID)
          Create a HS message with all given parameters
 
Method Summary
 byte[] generate()
          Generate the byte array representing the whole message that can then be transmitted
 byte[] getFileID()
          Return the infoHash as a byte array
 byte getLength()
          Return the length of the protocol string as a byte
 byte[] getPeerID()
          Return the peerID as a byte array
 byte[] getProtocol()
          Return the protocol string as a byte array
 byte[] getReserved()
          Return the reserved bytes as a byte array
 void setData(byte[] length, byte[] protocol, byte[] reserved, byte[] fileID, byte[] peerID)
          Set the values of the fields according to the parameters
 java.lang.String toString()
          Display the message in a readable format
 
Methods inherited from class jBittorrentAPI.Message
getPriority, getType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

fileID

private byte[] fileID

length

private byte[] length

peerID

private byte[] peerID

protocol

private byte[] protocol

reserved

private byte[] reserved
Constructor Detail

Message_HS

public Message_HS()
Creates an empty HS message


Message_HS

public Message_HS(byte[] infoHash,
                  byte[] peerID)
Creates a HS message with the given infoHash and peerID and default values

Parameters:
infoHash - byte[]
peerID - byte[]

Message_HS

public Message_HS(byte[] length,
                  byte[] protocol,
                  byte[] reserved,
                  byte[] fileID,
                  byte[] peerID)
Create a HS message with all given parameters

Parameters:
length - byte[]
protocol - byte[]
reserved - byte[]
fileID - byte[]
peerID - byte[]
Method Detail

generate

public byte[] generate()
Generate the byte array representing the whole message that can then be transmitted

Specified by:
generate in class Message
Returns:
byte[]

getFileID

public byte[] getFileID()
Return the infoHash as a byte array

Returns:
byte[]

getLength

public byte getLength()
Return the length of the protocol string as a byte

Returns:
byte

getPeerID

public byte[] getPeerID()
Return the peerID as a byte array

Returns:
byte[]

getProtocol

public byte[] getProtocol()
Return the protocol string as a byte array

Returns:
byte[]

getReserved

public byte[] getReserved()
Return the reserved bytes as a byte array

Returns:
byte[]

setData

public void setData(byte[] length,
                    byte[] protocol,
                    byte[] reserved,
                    byte[] fileID,
                    byte[] peerID)
Set the values of the fields according to the parameters

Parameters:
length - byte[]
protocol - byte[]
reserved - byte[]
fileID - byte[]
peerID - byte[]

toString

public java.lang.String toString()
Display the message in a readable format

Overrides:
toString in class java.lang.Object
Returns:
String