com.limegroup.gnutella.guess
Class QueryKey

java.lang.Object
  extended bycom.limegroup.gnutella.guess.QueryKey

public final class QueryKey
extends java.lang.Object

Abstraction for a Query Key as detailed in the GUESS protocol spec. Provides: - encapsulation of (all, LW and non-LW) Query Keys - generation of Query Keys (hence, it contains the LimeWire QK Algorithm) A Query Key is a credential necessary to perform a GUESS Query. A Query Key instance is immutable. If you want to change the underlying generation algorithm, you need to change getQueryKey(ip, port, ....) and the two Secret inner classes (SecretKey and SecretPad).


Nested Class Summary
static class QueryKey.SecretKey
          The Key used in generating a QueryKey.
static class QueryKey.SecretPad
          Depending on the algorithm, this may be needed to derive a QueryKey (in addition to a SecretKey).
 
Field Summary
 int MAX_QK_SIZE_IN_BYTES
          As detailed by the GUESS spec.
 int MIN_QK_SIZE_IN_BYTES
          As detailed by the GUESS spec.
 
Method Summary
 boolean equals(java.lang.Object o)
           
static QueryKey.SecretKey generateSecretKey()
          Returns a new SecretKey to be used in generation of QueryKeys.
static QueryKey.SecretPad generateSecretPad()
          Returns a new SecretPad to be used in generation of QueryKeys.
static QueryKey getQueryKey(byte[] networkQK, boolean prepareForNet)
          Use this method to construct Query Keys that you get from network commerce.
static QueryKey getQueryKey(java.net.InetAddress ip, int port)
          Generates a QueryKey for a given IP:Port combo.
static QueryKey getQueryKey(java.net.InetAddress ip, int port, QueryKey.SecretKey secretKey, QueryKey.SecretPad secretPad)
          Generates a QueryKey for a given IP:Port combo.
 int hashCode()
           
 void prepareForNetwork()
          QueryKey's not generated by the static method getQueryKey(4) may not be prepared for network transport.
 java.lang.String toString()
          Returns a String with the QueryKey represented as a BigInteger.
 void write(java.io.OutputStream out)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MIN_QK_SIZE_IN_BYTES

public final int MIN_QK_SIZE_IN_BYTES
As detailed by the GUESS spec.

See Also:
Constant Field Values

MAX_QK_SIZE_IN_BYTES

public final int MAX_QK_SIZE_IN_BYTES
As detailed by the GUESS spec.

See Also:
Constant Field Values
Method Detail

prepareForNetwork

public void prepareForNetwork()
QueryKey's not generated by the static method getQueryKey(4) may not be prepared for network transport. Call this if you used the getQueryKey(1) method to construct it AND you want to send it someplace.


generateSecretKey

public static QueryKey.SecretKey generateSecretKey()
Returns a new SecretKey to be used in generation of QueryKeys.


generateSecretPad

public static QueryKey.SecretPad generateSecretPad()
Returns a new SecretPad to be used in generation of QueryKeys.


equals

public boolean equals(java.lang.Object o)

hashCode

public int hashCode()

write

public void write(java.io.OutputStream out)
           throws java.io.IOException
Throws:
java.io.IOException

toString

public java.lang.String toString()
Returns a String with the QueryKey represented as a BigInteger.


getQueryKey

public static QueryKey getQueryKey(byte[] networkQK,
                                   boolean prepareForNet)
                            throws java.lang.IllegalArgumentException
Use this method to construct Query Keys that you get from network commerce. If you are using this for testing purposes, be aware that QueryKey in QueryRequests cannot contain the GEM extension delimiter 0x1c or nulls - you can use the utility instance method prepareForNetwork() or send true as the second param...

Parameters:
networkQK - the bytes you want to make a QueryKey.
prepareForNet - true to prepare the QueryKey for net transport.
Throws:
java.lang.IllegalArgumentException

getQueryKey

public static QueryKey getQueryKey(java.net.InetAddress ip,
                                   int port)
Generates a QueryKey for a given IP:Port combo. For a given IP:Port combo, using a different SecretKey and/or SecretPad will result in a different QueryKey. The instance method prepareForNetwork() is called prior to returning the QueryKey.

Parameters:
ip - the IP address of the other node
port - the port of the other node

getQueryKey

public static QueryKey getQueryKey(java.net.InetAddress ip,
                                   int port,
                                   QueryKey.SecretKey secretKey,
                                   QueryKey.SecretPad secretPad)
Generates a QueryKey for a given IP:Port combo. For a given IP:Port combo, using a different SecretKey and/or SecretPad will result in a different QueryKey. The instance method prepareForNetwork() is called prior to returning the QueryKey.

Parameters:
ip - the IP address of the other node
port - the port of the other node