|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.limegroup.gnutella.messages.Message
A Gnutella message (packet). This class is abstract; subclasses implement specific messages such as search requests.
All messages have message IDs, function IDs, TTLs, hops taken, and data length. Messages come in two flavors: requests (ping, search) and replies (pong, search results). Message are mostly immutable; only the TTL, hops, and priority field can be changed.
Field Summary | |
static byte |
F_PING
|
static byte |
F_PING_REPLY
|
static byte |
F_PUSH
|
static byte |
F_QUERY
|
static byte |
F_QUERY_REPLY
|
static byte |
F_ROUTE_TABLE_UPDATE
|
static byte |
F_VENDOR_MESSAGE
|
static byte |
F_VENDOR_MESSAGE_STABLE
|
static int |
N_MULTICAST
|
static int |
N_TCP
|
static int |
N_UDP
|
static int |
N_UNKNOWN
|
protected static boolean |
RECORD_STATS
Constant for whether or not to record stats. |
static byte |
SOFT_MAX
Cached soft max ttl -- if the TTL+hops is greater than SOFT_MAX, the TTL is set to SOFT_MAX-hops. |
Constructor Summary | |
protected |
Message(byte[] guid,
byte func,
byte ttl,
byte hops,
int length)
Same as above, but caller specifies TTL and number of hops. |
protected |
Message(byte[] guid,
byte func,
byte ttl,
byte hops,
int length,
int network)
Same as above, but caller specifies the network. |
protected |
Message(byte func,
byte ttl,
int length)
|
Method Summary | |
int |
compareTo(java.lang.Object message)
Returns a negative value if this is of lesser priority than message, positive value if of higher priority, or zero if of same priority. |
long |
getCreationTime()
Returns the system time (i.e., the result of System.currentTimeMillis()) this was instantiated. |
byte |
getFunc()
|
byte[] |
getGUID()
|
byte |
getHops()
|
int |
getLength()
Returns the length of this' payload, in bytes. |
int |
getNetwork()
|
int |
getPriority()
Returns this user-defined priority. |
int |
getTotalLength()
Returns the total length of this, in bytes |
byte |
getTTL()
|
byte |
hop()
|
boolean |
isMulticast()
|
boolean |
isTCP()
|
boolean |
isUDP()
|
boolean |
isUnknownNetwork()
|
static byte[] |
makeGuid()
Same as GUID.makeGUID. |
static Message |
read(java.io.InputStream in)
Reads a Gnutella message from the specified input stream. |
static Message |
read(java.io.InputStream in,
byte softMax)
|
static Message |
read(java.io.InputStream in,
byte[] buf,
byte softMax)
|
static Message |
read(java.io.InputStream in,
byte[] buf,
int network,
byte softMax)
|
static Message |
read(java.io.InputStream in,
int network)
|
protected byte[] |
readNullTerminatedBytes(java.io.InputStream is)
|
abstract void |
recordDrop()
Records the dropping of this message in statistics. |
protected void |
repOk()
Rep. |
protected void |
setGUID(GUID guid)
Sets the guid for this message. |
void |
setHops(byte hops)
If the hops is less than zero, throws IllegalArgumentException. |
void |
setPriority(int priority)
Set this user-defined priority for flow-control purposes. |
void |
setTTL(byte ttl)
If ttl is less than zero, throws IllegalArgumentException. |
abstract Message |
stripExtendedPayload()
Returns a message identical to this but without any extended (typically GGEP) data. |
java.lang.String |
toString()
|
protected void |
updateLength(int l)
Updates length of this' payload, in bytes. |
void |
write(java.io.OutputStream out)
|
protected boolean |
writeGemExtension(java.io.OutputStream os,
boolean addPrefixDelimiter,
byte[] extBytes)
|
protected boolean |
writeGemExtension(java.io.OutputStream os,
boolean addPrefixDelimiter,
java.lang.String ext)
|
protected boolean |
writeGemExtensions(java.io.OutputStream os,
boolean addPrefixDelimiter,
java.util.Iterator iter)
|
protected abstract void |
writePayload(java.io.OutputStream out)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final byte F_PING
public static final byte F_PING_REPLY
public static final byte F_PUSH
public static final byte F_QUERY
public static final byte F_QUERY_REPLY
public static final byte F_ROUTE_TABLE_UPDATE
public static final byte F_VENDOR_MESSAGE
public static final byte F_VENDOR_MESSAGE_STABLE
public static final int N_UNKNOWN
public static final int N_TCP
public static final int N_UDP
public static final int N_MULTICAST
public static final byte SOFT_MAX
protected static final boolean RECORD_STATS
Constructor Detail |
protected Message(byte func, byte ttl, int length)
protected Message(byte[] guid, byte func, byte ttl, byte hops, int length)
protected Message(byte[] guid, byte func, byte ttl, byte hops, int length, int network)
Method Detail |
public static byte[] makeGuid()
protected void repOk()
public static Message read(java.io.InputStream in) throws BadPacketException, java.io.IOException
in
- the InputStream instance containing message data
BadPacketException
- if the message is not considered
valid for any reason
IOException
- if there is any IO problem reading the
message
BadPacketException
java.io.IOException
public static Message read(java.io.InputStream in, byte softMax) throws BadPacketException, java.io.IOException
BadPacketException
java.io.IOException
public static Message read(java.io.InputStream in, int network) throws BadPacketException, java.io.IOException
BadPacketException
java.io.IOException
public static Message read(java.io.InputStream in, byte[] buf, byte softMax) throws BadPacketException, java.io.IOException
BadPacketException
java.io.IOException
public static Message read(java.io.InputStream in, byte[] buf, int network, byte softMax) throws BadPacketException, java.io.IOException
network
- the network this was received from.
BadPacketException
java.io.IOException
public void write(java.io.OutputStream out) throws java.io.IOException
java.io.IOException
protected abstract void writePayload(java.io.OutputStream out) throws java.io.IOException
java.io.IOException
protected boolean writeGemExtension(java.io.OutputStream os, boolean addPrefixDelimiter, byte[] extBytes) throws java.io.IOException
java.io.IOException
protected boolean writeGemExtension(java.io.OutputStream os, boolean addPrefixDelimiter, java.lang.String ext) throws java.io.IOException
java.io.IOException
protected boolean writeGemExtensions(java.io.OutputStream os, boolean addPrefixDelimiter, java.util.Iterator iter) throws java.io.IOException
java.io.IOException
protected byte[] readNullTerminatedBytes(java.io.InputStream is) throws java.io.IOException
java.io.IOException
public int getNetwork()
public boolean isMulticast()
public boolean isUDP()
public boolean isTCP()
public boolean isUnknownNetwork()
public byte[] getGUID()
public byte getFunc()
public byte getTTL()
public void setTTL(byte ttl) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
protected void setGUID(GUID guid)
guid
- The guid to be setpublic void setHops(byte hops) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public byte getHops()
public int getLength()
protected void updateLength(int l)
public int getTotalLength()
public byte hop()
public long getCreationTime()
public int getPriority()
public void setPriority(int priority)
public abstract Message stripExtendedPayload()
public int compareTo(java.lang.Object message)
compareTo
in interface java.lang.Comparable
java.lang.ClassCastException
- message not an instance of Messagepublic java.lang.String toString()
public abstract void recordDrop()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |