com.limegroup.gnutella.handshaking
Class HandshakeResponse

java.lang.Object
  extended bycom.limegroup.gnutella.handshaking.HandshakeResponse

public final class HandshakeResponse
extends java.lang.Object

This class contains the necessary information to form a response to a connection handshake. It contains a status code, a status message, and the headers to use in the response. There are only two ways to create a HandshakeResponse. 1) Create an instance which defaults the status code and status message to be "200 OK". Only the headers used in the response need to be passed in. 2) Create an instance with a custom status code, status message, and the headers used in the response.


Field Summary
static java.lang.String AUTHENTICATING
          Message indicating that we are trying to authenticate
static int DEFAULT_BAD_STATUS_CODE
          Default bad status code to be used while rejecting connections
static java.lang.String DEFAULT_BAD_STATUS_MESSAGE
          Default bad status message to be used while rejecting connections
static int OK
          The "default" status code in a connection handshake indicating that the handshake was successful and the connection can be established.
static java.lang.String OK_MESSAGE
          The "default" status message in a connection handshake indicating that the handshake was successful and the connection can be established.
static int SHIELDED
          The error code that a shielded leaf node should give to incoming connections.
static java.lang.String SHIELDED_MESSAGE
          The error message that a shielded leaf node should give to incoming connections.
static int SLOTS_FULL
          The error code that a node with no slots should give to incoming connections.
static java.lang.String SLOTS_FULL_MESSAGE
          The error message that a node with no slots should give to incoming connections.
static java.lang.String UNABLE_TO_AUTHENTICATE
          Message indicating that we are unable to authenticate
static int UNAUTHORIZED_CODE
          status code for unauthorized attempt
static java.lang.String UNAUTHORIZED_MESSAGE
          status message for unauthorized attempt
 
Method Summary
static HandshakeResponse createEmptyResponse()
          Creates an empty response with no headers.
static HandshakeResponse createResponse(java.util.Properties headers)
          Constructs the response from the other host during connection handshaking.
static HandshakeResponse createResponse(java.lang.String line, java.util.Properties headers)
          Constructs the response from the other host during connection handshaking.
 java.lang.String getDomainsAuthenticated()
          Returns the authenticated domains listed in the connection headers for this connection.
 byte getMaxTTL()
          Returns the maximum TTL that queries originating from us and sent from this connection should have.
 int getNumIntraUltrapeerConnections()
          Returns the number of intra-Ultrapeer connections this node maintains.
 java.lang.String getProperty(java.lang.String prop)
          Accessor for an individual property.
 int getStatusCode()
          Returns the response code.
 java.lang.String getStatusLine()
          Returns the status code and status message together used in a status line.
 java.lang.String getStatusMessage()
          Returns the status message.
 java.lang.String getUserAgent()
          Returns the vendor string reported by this connection, i.e., the USER_AGENT property, or null if it wasn't set.
 java.lang.String getVersion()
           
 java.lang.String getXTryUltrapeers()
          Accessor for the X-Try-Ultrapeers header.
 boolean hasLeafGuidance()
          Returns whether or not this host included leaf guidance, i.e., whether or not the host wrote: X-Ultrapeer-Needed: false
 boolean hasXTryUltrapeers()
          This is a convenience method to see if the connection passed the X-Try-Ultrapeer header.
 boolean isAccepted()
          Returns whether or not this connection was accepted -- whether or not the connection returned Gnutella/0.6 200 OK
 boolean isCrawler()
          Determines whether or not this handshake is from the crawler.
 boolean isDeflateAccepted()
          Returns whether or not this connection accepts deflate as an encoding.
 boolean isDeflateEnabled()
          Returns whether or not this connnection is encoded in deflate.
 boolean isDynamicQueryConnection()
          Returns whether or not the node on the other end of this connection uses dynamic querying.
 boolean isGoodLeaf()
          Returns whether or not this is connection passed the headers to be considered a "good" leaf.
 boolean isGoodUltrapeer()
          Returns whether or not this is connection passed the headers to be considered a "good" ultrapeer.
 boolean isGUESSCapable()
          Returns whether or not this connection is to a client supporting GUESS.
 boolean isGUESSUltrapeer()
          Returns whether or not this connection is to a ultrapeer supporting GUESS.
 boolean isHighDegreeConnection()
           
 boolean isLeaf()
          Returns true iff this connection wrote "X-Ultrapeer: false".
 boolean isQueryRoutingEnabled()
          True if the remote host supports query routing (QRP).
 boolean isTempConnection()
          Returns true iff this connection is a temporary connection as per the headers.
 boolean isUltrapeer()
          Returns true iff this connection wrote "X-Ultrapeer: true".
 boolean isUltrapeerQueryRoutingConnection()
          Returns whether or not this connection supports query routing between Ultrapeers at 1 hop.
 boolean notOKStatusCode()
          Tells if the status returned was OK or not.
 java.util.Properties props()
          Returns the headers as a Properties instance.
 boolean supportsGGEP()
          Returns true if this supports GGEP'ed messages.
 boolean supportsPongCaching()
          Returns whether or not this node supports pong caching.
 boolean supportsProbeQueries()
          Accessor for whether or not this connection supports TTL=1 probe queries.
 boolean supportsVendorMessages()
          Determines whether or not this node supports vendor messages.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

OK

public static final int OK
The "default" status code in a connection handshake indicating that the handshake was successful and the connection can be established.

See Also:
Constant Field Values

OK_MESSAGE

public static final java.lang.String OK_MESSAGE
The "default" status message in a connection handshake indicating that the handshake was successful and the connection can be established.

See Also:
Constant Field Values

SHIELDED

public static final int SHIELDED
The error code that a shielded leaf node should give to incoming connections.

See Also:
Constant Field Values

SHIELDED_MESSAGE

public static final java.lang.String SHIELDED_MESSAGE
The error message that a shielded leaf node should give to incoming connections.

See Also:
Constant Field Values

SLOTS_FULL

public static final int SLOTS_FULL
The error code that a node with no slots should give to incoming connections.

See Also:
Constant Field Values

SLOTS_FULL_MESSAGE

public static final java.lang.String SLOTS_FULL_MESSAGE
The error message that a node with no slots should give to incoming connections.

See Also:
Constant Field Values

DEFAULT_BAD_STATUS_CODE

public static final int DEFAULT_BAD_STATUS_CODE
Default bad status code to be used while rejecting connections

See Also:
Constant Field Values

DEFAULT_BAD_STATUS_MESSAGE

public static final java.lang.String DEFAULT_BAD_STATUS_MESSAGE
Default bad status message to be used while rejecting connections

See Also:
Constant Field Values

UNAUTHORIZED_CODE

public static final int UNAUTHORIZED_CODE
status code for unauthorized attempt

See Also:
Constant Field Values

UNAUTHORIZED_MESSAGE

public static final java.lang.String UNAUTHORIZED_MESSAGE
status message for unauthorized attempt

See Also:
Constant Field Values

UNABLE_TO_AUTHENTICATE

public static final java.lang.String UNABLE_TO_AUTHENTICATE
Message indicating that we are unable to authenticate

See Also:
Constant Field Values

AUTHENTICATING

public static final java.lang.String AUTHENTICATING
Message indicating that we are trying to authenticate

See Also:
Constant Field Values
Method Detail

createEmptyResponse

public static HandshakeResponse createEmptyResponse()
Creates an empty response with no headers. This is useful, for example, during connection handshaking when we haven't yet read any headers.

Returns:
a new, empty HandshakeResponse instance

createResponse

public static HandshakeResponse createResponse(java.util.Properties headers)
                                        throws java.io.IOException
Constructs the response from the other host during connection handshaking.

Returns:
a new HandshakeResponse instance with the headers sent by the other host
Throws:
java.io.IOException

createResponse

public static HandshakeResponse createResponse(java.lang.String line,
                                               java.util.Properties headers)
                                        throws java.io.IOException
Constructs the response from the other host during connection handshaking.

Parameters:
line - the status line received from the connecting host
headers - the headers received from the other host
Returns:
a new HandshakeResponse instance with the headers sent by the other host
Throws:
IOException - if the status line could not be parsed
java.io.IOException

getStatusCode

public int getStatusCode()
Returns the response code.


getStatusMessage

public java.lang.String getStatusMessage()
Returns the status message.

Returns:
the status message (e.g. "OK" , "Service Not Available" etc.)

notOKStatusCode

public boolean notOKStatusCode()
Tells if the status returned was OK or not.

Returns:
true, if the status returned was not the OK status, false otherwise

isAccepted

public boolean isAccepted()
Returns whether or not this connection was accepted -- whether or not the connection returned Gnutella/0.6 200 OK

Returns:
true if the server returned Gnutella/0.6 200 OK, otherwise false

getStatusLine

public java.lang.String getStatusLine()
Returns the status code and status message together used in a status line. (e.g., "200 OK", "503 Service Not Available")


props

public java.util.Properties props()
Returns the headers as a Properties instance.


getProperty

public java.lang.String getProperty(java.lang.String prop)
Accessor for an individual property.


getUserAgent

public java.lang.String getUserAgent()
Returns the vendor string reported by this connection, i.e., the USER_AGENT property, or null if it wasn't set.

Returns:
the vendor string, or null if unknown

getMaxTTL

public byte getMaxTTL()
Returns the maximum TTL that queries originating from us and sent from this connection should have. If the max TTL header is not present, the default TTL is assumed.

Returns:
the maximum TTL that queries sent to this connection should have -- this will always be 5 or less

getXTryUltrapeers

public java.lang.String getXTryUltrapeers()
Accessor for the X-Try-Ultrapeers header. If the header does not exist or is empty, this returns the emtpy string.

Returns:
the string of X-Try-Ultrapeer hosts, or the empty string if they do not exist

hasXTryUltrapeers

public boolean hasXTryUltrapeers()
This is a convenience method to see if the connection passed the X-Try-Ultrapeer header. This simply checks the existence of the header -- if the header was sent but is empty, this still returns true.

Returns:
true if this connection sent the X-Try-Ultrapeer header, otherwise false

hasLeafGuidance

public boolean hasLeafGuidance()
Returns whether or not this host included leaf guidance, i.e., whether or not the host wrote: X-Ultrapeer-Needed: false

Returns:
true if the other host returned X-Ultrapeer-Needed: false, otherwise false

getNumIntraUltrapeerConnections

public int getNumIntraUltrapeerConnections()
Returns the number of intra-Ultrapeer connections this node maintains.

Returns:
the number of intra-Ultrapeer connections this node maintains

isHighDegreeConnection

public boolean isHighDegreeConnection()

isGoodLeaf

public boolean isGoodLeaf()
Returns whether or not this is connection passed the headers to be considered a "good" leaf.

Returns:
true if this is considered a "good" leaf, otherwise false

isDeflateEnabled

public boolean isDeflateEnabled()
Returns whether or not this connnection is encoded in deflate.


isDeflateAccepted

public boolean isDeflateAccepted()
Returns whether or not this connection accepts deflate as an encoding.


isGoodUltrapeer

public boolean isGoodUltrapeer()
Returns whether or not this is connection passed the headers to be considered a "good" ultrapeer.

Returns:
true if this is considered a "good" ultrapeer, otherwise false

isUltrapeerQueryRoutingConnection

public boolean isUltrapeerQueryRoutingConnection()
Returns whether or not this connection supports query routing between Ultrapeers at 1 hop.

Returns:
true if this is an Ultrapeer connection that exchanges query routing tables with other Ultrapeers at 1 hop, otherwise false

isLeaf

public boolean isLeaf()
Returns true iff this connection wrote "X-Ultrapeer: false". This does NOT necessarily mean the connection is shielded.


isUltrapeer

public boolean isUltrapeer()
Returns true iff this connection wrote "X-Ultrapeer: true".


isGUESSCapable

public boolean isGUESSCapable()
Returns whether or not this connection is to a client supporting GUESS.

Returns:
true if the node on the other end of this connection supports GUESS, false otherwise

isGUESSUltrapeer

public boolean isGUESSUltrapeer()
Returns whether or not this connection is to a ultrapeer supporting GUESS.

Returns:
true if the node on the other end of this Ultrapeer connection supports GUESS, false otherwise

isTempConnection

public boolean isTempConnection()
Returns true iff this connection is a temporary connection as per the headers.


supportsGGEP

public boolean supportsGGEP()
Returns true if this supports GGEP'ed messages. GGEP'ed messages (e.g., big pongs) should only be sent along connections for which supportsGGEP()==true.


supportsVendorMessages

public boolean supportsVendorMessages()
Determines whether or not this node supports vendor messages.

Returns:
true if this node supports vendor messages, otherwise false

supportsPongCaching

public boolean supportsPongCaching()
Returns whether or not this node supports pong caching.

Returns:
true if this node supports pong caching, otherwise false

getDomainsAuthenticated

public java.lang.String getDomainsAuthenticated()
Returns the authenticated domains listed in the connection headers for this connection.

Returns:
the string of authenticated domains for this connection

getVersion

public java.lang.String getVersion()

isQueryRoutingEnabled

public boolean isQueryRoutingEnabled()
True if the remote host supports query routing (QRP). This is only meaningful in the context of leaf-supernode relationships.


isDynamicQueryConnection

public boolean isDynamicQueryConnection()
Returns whether or not the node on the other end of this connection uses dynamic querying.

Returns:
true if this node uses dynamic querying, otherwise false

supportsProbeQueries

public boolean supportsProbeQueries()
Accessor for whether or not this connection supports TTL=1 probe queries. These queries are treated separately from other queries. In particular, if a second query with the same GUID is received, it is not considered a duplicate.

Returns:
true if this connection supports probe queries, otherwise false

isCrawler

public boolean isCrawler()
Determines whether or not this handshake is from the crawler.

Returns:
true if this handshake is from the crawler, otherwise false

toString

public java.lang.String toString()