com.limegroup.gnutella.messages
Class PingReply

java.lang.Object
  extended bycom.limegroup.gnutella.messages.Message
      extended bycom.limegroup.gnutella.messages.PingReply
All Implemented Interfaces:
java.lang.Comparable, java.io.Serializable

public class PingReply
extends Message
implements java.io.Serializable

A ping reply message, aka, "pong". This implementation provides a way to "mark" pongs as being from supernodes.

See Also:
Serialized Form

Field Summary
static int STANDARD_PAYLOAD_SIZE
          Constant for the standard size of the pong payload.
 
Fields inherited from class com.limegroup.gnutella.messages.Message
F_PING, F_PING_REPLY, F_PUSH, F_QUERY, F_QUERY_REPLY, F_ROUTE_TABLE_UPDATE, F_VENDOR_MESSAGE, F_VENDOR_MESSAGE_STABLE, N_MULTICAST, N_TCP, N_UDP, N_UNKNOWN, RECORD_STATS, SOFT_MAX
 
Method Summary
static PingReply create(byte[] guid, byte ttl)
          Creates a new PingReply for this host with the specified GUID and ttl.
static PingReply create(byte[] guid, byte ttl, int port, byte[] address)
          Creates a new PingReply for an external node -- the data in the reply will not contain data for this node.
static PingReply create(byte[] guid, byte ttl, int port, byte[] ip, long files, long kbytes)
          Creates a new pong with the specified data -- used primarily for testing!
static PingReply create(byte[] guid, byte ttl, int port, byte[] ip, long files, long kbytes, boolean isUltrapeer, int dailyUptime, boolean isGUESSCapable)
          Creates a new ping from scratch with ultrapeer and daily uptime extension data.
static PingReply createExternal(byte[] guid, byte ttl, int port, byte[] address, boolean ultrapeer)
          Creates a new PingReply for an external node -- the data in the reply will not contain data for this node.
static PingReply createExternal(byte[] guid, byte ttl, int port, byte[] address, int uptime, boolean ultrapeer)
          Creates a new PingReply for an external node -- the data in the reply will not contain data for this node.
static PingReply createFromNetwork(byte[] guid, byte ttl, byte hops, byte[] payload)
          Creates a new PingReply instance from the network.
static PingReply createGUESSReply(byte[] guid, byte ttl, Endpoint ep)
          Creates a new PingReply instance for a GUESS node.
static PingReply createGUESSReply(byte[] guid, byte ttl, int port, byte[] address)
          Creates a new PingReply instance for a GUESS node.
static PingReply createQueryKeyReply(byte[] guid, byte ttl, int port, byte[] ip, long sharedFiles, long sharedSize, boolean ultrapeer, QueryKey key)
          Creates a new PingReply for this host with the specified GUID, ttl, and query key.
static PingReply createQueryKeyReply(byte[] guid, byte ttl, QueryKey key)
          Creates a new PingReply for this host with the specified GUID, ttl, and query key.
 int getDailyUptime()
          Returns the average daily uptime in seconds from the GGEP payload.
 long getFiles()
          Accessor for the number of files shared, as reported in the pong.
 java.lang.String getIP()
          Returns the ip field in standard dotted decimal format, e.g., "127.0.0.1".
 byte[] getIPBytes()
          Returns the ip address bytes (MSB first)
 long getKbytes()
          Accessor for the number of kilobytes shared, as reported in the pong.
 int getPort()
          Accessor for the port reported in this pong.
 QueryKey getQueryKey()
          Returns the QueryKey (if any) associated with this pong.
 java.lang.String getVendor()
          Returns the 4-character vendor string associated with this Pong.
 int getVendorMajorVersion()
          Returns the major version number of the vendor returning this pong.
 int getVendorMinorVersion()
          Returns the minor version number of the vendor returning this pong.
 boolean hasGGEPExtension()
          Returns whether or not this pong has a GGEP extension.
static boolean isPowerOf2(int x)
           
 boolean isUltrapeer()
          Returns true if this message is "marked", i.e., likely from an Ultrapeer.
 PingReply mutateGUID(byte[] guid)
          Returns a new PingReply instance with all the same data as this, but with the specified GUID.
 void recordDrop()
          Records the dropping of this message in statistics.
 Message stripExtendedPayload()
          Returns a message identical to this but without any extended (typically GGEP) data.
 boolean supportsUnicast()
          Returns whether or not this host support unicast, GUESS-style queries.
 java.lang.String toString()
           
protected  void writePayload(java.io.OutputStream out)
           
 
Methods inherited from class com.limegroup.gnutella.messages.Message
compareTo, getCreationTime, getFunc, getGUID, getHops, getLength, getNetwork, getPriority, getTotalLength, getTTL, hop, isMulticast, isTCP, isUDP, isUnknownNetwork, makeGuid, read, read, read, read, read, readNullTerminatedBytes, repOk, setGUID, setHops, setPriority, setTTL, updateLength, write, writeGemExtension, writeGemExtension, writeGemExtensions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STANDARD_PAYLOAD_SIZE

public static final int STANDARD_PAYLOAD_SIZE
Constant for the standard size of the pong payload.

See Also:
Constant Field Values
Method Detail

create

public static PingReply create(byte[] guid,
                               byte ttl)
Creates a new PingReply for this host with the specified GUID and ttl.

Parameters:
guid - the Globally Unique Identifier (GUID) for this message
ttl - the time to live for this message

createQueryKeyReply

public static PingReply createQueryKeyReply(byte[] guid,
                                            byte ttl,
                                            QueryKey key)
Creates a new PingReply for this host with the specified GUID, ttl, and query key.

Parameters:
guid - the Globally Unique Identifier (GUID) for this message
ttl - the time to live for this message
key - the QueryKey for this reply

createQueryKeyReply

public static PingReply createQueryKeyReply(byte[] guid,
                                            byte ttl,
                                            int port,
                                            byte[] ip,
                                            long sharedFiles,
                                            long sharedSize,
                                            boolean ultrapeer,
                                            QueryKey key)
Creates a new PingReply for this host with the specified GUID, ttl, and query key.

Parameters:
guid - the Globally Unique Identifier (GUID) for this message
ttl - the time to live for this message
key - the QueryKey for this reply

create

public static PingReply create(byte[] guid,
                               byte ttl,
                               int port,
                               byte[] address)
Creates a new PingReply for an external node -- the data in the reply will not contain data for this node. In particular, the data fields are set to zero because we do not know these statistics for the other node.

Parameters:
guid - the Globally Unique Identifier (GUID) for this message
ttl - the time to live for this message
port - the port the remote host is listening on
address - the address of the node

createExternal

public static PingReply createExternal(byte[] guid,
                                       byte ttl,
                                       int port,
                                       byte[] address,
                                       boolean ultrapeer)
Creates a new PingReply for an external node -- the data in the reply will not contain data for this node. In particular, the data fields are set to zero because we do not know these statistics for the other node.

Parameters:
guid - the Globally Unique Identifier (GUID) for this message
ttl - the time to live for this message
port - the port the remote host is listening on
address - the address of the node
ultrapeer - whether or not we should mark this node as being an Ultrapeer

createExternal

public static PingReply createExternal(byte[] guid,
                                       byte ttl,
                                       int port,
                                       byte[] address,
                                       int uptime,
                                       boolean ultrapeer)
Creates a new PingReply for an external node -- the data in the reply will not contain data for this node. In particular, the data fields are set to zero because we do not know these statistics for the other node. This is primarily used for testing.

Parameters:
guid - the Globally Unique Identifier (GUID) for this message
ttl - the time to live for this message
port - the port the remote host is listening on
address - the address of the node
ultrapeer - whether or not we should mark this node as being an Ultrapeer

createGUESSReply

public static PingReply createGUESSReply(byte[] guid,
                                         byte ttl,
                                         Endpoint ep)
                                  throws java.net.UnknownHostException
Creates a new PingReply instance for a GUESS node. This method should only be called if the caller is sure that the given node is, in fact, a GUESS-capable node. This method is only used to create pongs for nodes other than ourselves.

Parameters:
guid - the Globally Unique Identifier (GUID) for this message
ttl - the time to live for this message
ep - the Endpoint instance containing data about the remote host
Throws:
java.net.UnknownHostException

createGUESSReply

public static PingReply createGUESSReply(byte[] guid,
                                         byte ttl,
                                         int port,
                                         byte[] address)
Creates a new PingReply instance for a GUESS node. This method should only be called if the caller is sure that the given node is, in fact, a GUESS-capable node. This method is only used to create pongs for nodes other than ourselves. Given that this reply is for a remote node, we do not know the data for number of shared files, etc, and so leave it blank.

Parameters:
guid - the Globally Unique Identifier (GUID) for this message
ttl - the time to live for this message
port - the port the remote host is listening on
address - the address of the node

create

public static PingReply create(byte[] guid,
                               byte ttl,
                               int port,
                               byte[] ip,
                               long files,
                               long kbytes)
Creates a new pong with the specified data -- used primarily for testing!

Parameters:
guid - the sixteen byte message GUID
ttl - the message TTL to use
port - my listening port. MUST fit in two signed bytes, i.e., 0 < port < 2^16.
ip - my listening IP address. MUST be in dotted-quad big-endian, format e.g. {18, 239, 0, 144}.
files - the number of files I'm sharing. Must fit in 4 unsigned bytes, i.e., 0 < files < 2^32.
kbytes - the total size of all files I'm sharing, in kilobytes. Must fit in 4 unsigned bytes, i.e., 0 < files < 2^32.

create

public static PingReply create(byte[] guid,
                               byte ttl,
                               int port,
                               byte[] ip,
                               long files,
                               long kbytes,
                               boolean isUltrapeer,
                               int dailyUptime,
                               boolean isGUESSCapable)
Creates a new ping from scratch with ultrapeer and daily uptime extension data.

Parameters:
guid - the sixteen byte message GUID
ttl - the message TTL to use
port - my listening port. MUST fit in two signed bytes, i.e., 0 < port < 2^16.
ip - my listening IP address. MUST be in dotted-quad big-endian, format e.g. {18, 239, 0, 144}.
files - the number of files I'm sharing. Must fit in 4 unsigned bytes, i.e., 0 < files < 2^32.
kbytes - the total size of all files I'm sharing, in kilobytes. Must fit in 4 unsigned bytes, i.e., 0 < files < 2^32.
isUltrapeer - true if this should be a marked ultrapeer pong, which sets kbytes to the nearest power of 2 not less than 8.
dailyUptime - my average daily uptime, in seconds, e.g., 3600 for one hour per day. Negative values mean "don't know". GGEP extension blocks are allocated if dailyUptime is non-negative.

mutateGUID

public PingReply mutateGUID(byte[] guid)
Returns a new PingReply instance with all the same data as this, but with the specified GUID.

Parameters:
guid - the guid to use for the new PingReply
Returns:
a new PingReply instance with the specified GUID and all of the data from this PingReply

createFromNetwork

public static PingReply createFromNetwork(byte[] guid,
                                          byte ttl,
                                          byte hops,
                                          byte[] payload)
                                   throws BadPacketException
Creates a new PingReply instance from the network.

Parameters:
guid - the Globally Unique Identifier (GUID) for this message
ttl - the time to live for this message
hops - the hops for this message
payload - the message payload
Throws:
BadPacketException - if the message is invalid for any reason
BadPacketException

writePayload

protected void writePayload(java.io.OutputStream out)
                     throws java.io.IOException
Specified by:
writePayload in class Message
Throws:
java.io.IOException

getPort

public int getPort()
Accessor for the port reported in this pong.

Returns:
the port number reported in the pong

getIP

public java.lang.String getIP()
Returns the ip field in standard dotted decimal format, e.g., "127.0.0.1". The most significant byte is written first.


getIPBytes

public byte[] getIPBytes()
Returns the ip address bytes (MSB first)


getFiles

public long getFiles()
Accessor for the number of files shared, as reported in the pong.

Returns:
the number of files reported shared

getKbytes

public long getKbytes()
Accessor for the number of kilobytes shared, as reported in the pong.

Returns:
the number of kilobytes reported shared

getDailyUptime

public int getDailyUptime()
Returns the average daily uptime in seconds from the GGEP payload. If the pong did not report a daily uptime, returns -1.

Returns:
the daily uptime reported in the pong, or -1 if the uptime was not present or could not be read

supportsUnicast

public boolean supportsUnicast()
Returns whether or not this host support unicast, GUESS-style queries.

Returns:
true if this host does support GUESS-style queries, otherwise false

getVendor

public java.lang.String getVendor()
Returns the 4-character vendor string associated with this Pong.

Returns:
the 4-character vendor code reported in the pong, or the empty string if no vendor code was successfully read

getVendorMajorVersion

public int getVendorMajorVersion()
Returns the major version number of the vendor returning this pong.

Returns:
the major version number of the vendor returning this pong, or -1 if the version could not be read

getVendorMinorVersion

public int getVendorMinorVersion()
Returns the minor version number of the vendor returning this pong.

Returns:
the minor version number of the vendor returning this pong, or -1 if the version could not be read

getQueryKey

public QueryKey getQueryKey()
Returns the QueryKey (if any) associated with this pong. May be null!

Returns:
the QueryKey for this pong, or null if no key was specified

hasGGEPExtension

public boolean hasGGEPExtension()
Returns whether or not this pong has a GGEP extension.

Returns:
true if the pong has a GGEP extension, otherwise false

stripExtendedPayload

public Message stripExtendedPayload()
Description copied from class: Message
Returns a message identical to this but without any extended (typically GGEP) data. Since Message's are mostly immutable, the returned message may alias parts of this; in fact the returned message could even be this. The caveat is that the hops and TTL field of Message can be mutated for efficiency reasons. Hence you must not call hop() on either this or the returned value. Typically this is not a problem, as hop() is called before forwarding/broadcasting a message.

Specified by:
stripExtendedPayload in class Message
Returns:
an instance of this without any dangerous extended payload

isUltrapeer

public boolean isUltrapeer()
Returns true if this message is "marked", i.e., likely from an Ultrapeer.

Returns:
true if this pong is marked as an Ultrapeer pong, otherwise false

isPowerOf2

public static boolean isPowerOf2(int x)

recordDrop

public void recordDrop()
Description copied from class: Message
Records the dropping of this message in statistics.

Specified by:
recordDrop in class Message

toString

public java.lang.String toString()
Overrides:
toString in class Message