ucr.core
Class Message

java.lang.Object
  extended byucr.core.Message
Direct Known Subclasses:
SearchMessage, SearchReplyMessage, TraceMessage, TraceReplyMessage

public abstract class Message
extends java.lang.Object

Abstract base class for GNUTella messages


Field Summary
protected  GUID guid
           
protected  byte hops
           
protected  Connection originatingConnection
           
protected  short[] payload
           
protected  int payloadSize
           
(package private) static short QUERY
           
(package private) static short QUERYREPLY
           
static int SIZE
           
(package private) static int SIZE_QUERY_PAYLOAD
           
(package private) static int SIZE_QUERYREPLY_PAYLOAD
           
(package private) static short TRACE
           
(package private) static short TRACEREPLY
           
protected  byte ttl
           
protected  short type
           
 
Constructor Summary
(package private) Message(GUID guid, int type)
          Construct a message with a specific guid
(package private) Message(int type)
          Constructs a new message
(package private) Message(short[] rawMessage, Connection originatingConnection)
          Constructs a message from data read from network
 
Method Summary
(package private)  void addPayload(byte[] payload)
          Add a payload to the message
(package private)  void addPayload(short[] payload)
          Add a payload to the message
(package private)  byte[] getByteArray()
          Produces a byte[] suitable for GNUTELLA network
 GUID getGUID()
          Query the GUID
 int getHops()
          Get the hop count for this message
 Connection getOriginatingConnection()
          Get the connection that was the source for this message
(package private)  short[] getPayload()
          Retrieve the message payload
 int getPayloadLength()
          Query the payload size for this message
 int getTTL()
          Get the Time to live for the message
(package private)  int getType()
          Query the type of message
(package private)  void setGUID(GUID guid)
          Apply a guid to the message
 void setHops(byte hops)
          Set the hop count for this message, seven is the recommended maximum
 void setTTL(byte ttl)
          Set the ttl value for the message
 java.lang.String toRawString()
          Returns a String containing the flattened message
 java.lang.String toString()
          String representation of the message
(package private)  boolean validatePayloadSize()
          Checks validity of a payloads size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SIZE

public static final int SIZE
See Also:
Constant Field Values

TRACE

static final short TRACE
See Also:
Constant Field Values

TRACEREPLY

static final short TRACEREPLY
See Also:
Constant Field Values

QUERY

static final short QUERY
See Also:
Constant Field Values

QUERYREPLY

static final short QUERYREPLY
See Also:
Constant Field Values

SIZE_QUERY_PAYLOAD

static final int SIZE_QUERY_PAYLOAD
See Also:
Constant Field Values

SIZE_QUERYREPLY_PAYLOAD

static final int SIZE_QUERYREPLY_PAYLOAD
See Also:
Constant Field Values

originatingConnection

protected Connection originatingConnection

guid

protected GUID guid

type

protected short type

ttl

protected byte ttl

hops

protected byte hops

payload

protected short[] payload

payloadSize

protected int payloadSize
Constructor Detail

Message

Message(int type)
Constructs a new message

Parameters:
type - function type

Message

Message(GUID guid,
        int type)
Construct a message with a specific guid

Parameters:
guid - of the message
type - of the message

Message

Message(short[] rawMessage,
        Connection originatingConnection)
Constructs a message from data read from network

Parameters:
rawMessage - bytes
Method Detail

getType

int getType()
Query the type of message

Returns:
type

getGUID

public GUID getGUID()
Query the GUID

Returns:
16 byte array

setGUID

void setGUID(GUID guid)
Apply a guid to the message

Parameters:
guid - new guid

getTTL

public int getTTL()
Get the Time to live for the message


setTTL

public void setTTL(byte ttl)
Set the ttl value for the message


getHops

public int getHops()
Get the hop count for this message


setHops

public void setHops(byte hops)
Set the hop count for this message, seven is the recommended maximum


addPayload

void addPayload(short[] payload)
Add a payload to the message

Parameters:
payload - payload for the message

addPayload

void addPayload(byte[] payload)
Add a payload to the message

Parameters:
payload - payload for the message

getPayloadLength

public int getPayloadLength()
Query the payload size for this message


getPayload

short[] getPayload()
Retrieve the message payload

Returns:
payload

getByteArray

byte[] getByteArray()
Produces a byte[] suitable for GNUTELLA network


validatePayloadSize

boolean validatePayloadSize()
Checks validity of a payloads size

Returns:
true if valid, false otherwise

toString

public java.lang.String toString()
String representation of the message


toRawString

public java.lang.String toRawString()
Returns a String containing the flattened message

Returns:
message string

getOriginatingConnection

public Connection getOriginatingConnection()
Get the connection that was the source for this message

Returns:
originating connection or null if this Message was not read from the network