com.limegroup.gnutella.routing
Class QueryRouteTable

java.lang.Object
  extended bycom.limegroup.gnutella.routing.QueryRouteTable

public class QueryRouteTable
extends java.lang.Object

A list of query keywords that a connection can respond to, as well as the minimum TTL for a response. More formally, a QueryRouteTable is a (possibly infinite!) list of keyword TTL pairs, [ <keyword_1, ttl_1>, ..., <keywordN, ttl_N> ]

10/08/2002 - A day after Susheel's birthday, he decided to change this class for the heck of it. Kidding. Functionality has been changed so that keyword depth is 'constant' - meaning that if a keyword is added, then any contains query regarding that keyword will return true. This is because this general idea of QRTs is only used in a specialized way in LW - namely, UPs use it for their leaves ONLY, so the depth is always 1. If you looking for a keyword and it is in the table, a leaf MAY have it, so return true. This only needed a one line change. This class is NOT synchronized.


Field Summary
static byte DEFAULT_INFINITY
          The suggested default max table TTL.
static int DEFAULT_TABLE_SIZE
          The suggested default table size.
static byte KEYWORD_ABSENT
          What should come across the wire if a keyword is absent.
static byte KEYWORD_NO_CHANGE
          What should come across the wire if a keyword status is unchanged.
static byte KEYWORD_PRESENT
          What should come across the wire if a keyword is present.
static int MAX_PATCH_SIZE
          The maximum size of patch messages, in bytes.
 
Constructor Summary
QueryRouteTable()
          Creates a QueryRouteTable with default sizes.
QueryRouteTable(int size)
          Creates a new QueryRouteTable instance with the specified size.
 
Method Summary
 void add(java.lang.String filename)
          For all keywords k in filename, adds to this.
 void addAll(QueryRouteTable qrt)
          For all in qrt, adds to this.
 void addIndivisible(java.lang.String iString)
           
 boolean contains(QueryRequest qr)
          Returns true if a response could be generated for qr.
 java.util.List encode(QueryRouteTable prev)
          Stub for calling encode(QueryRouteTable, true).
 java.util.List encode(QueryRouteTable prev, boolean allowCompression)
          Returns an List of RouteTableMessage that will convey the state of this.
 boolean equals(java.lang.Object o)
          True if o is a QueryRouteTable with the same entries of this.
 double getPercentFull()
          Returns the percentage of slots used in this QueryRouteTable's BitTable.
 int hashCode()
           
 void patch(PatchTableMessage patch)
          Adds the specified patch message to this query routing table.
 void reset(ResetTableMessage rtm)
          Resets this QueryRouteTable to the specified size with no data.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_INFINITY

public static final byte DEFAULT_INFINITY
The suggested default max table TTL.

See Also:
Constant Field Values

KEYWORD_PRESENT

public static final byte KEYWORD_PRESENT
What should come across the wire if a keyword is present.

See Also:
Constant Field Values

KEYWORD_ABSENT

public static final byte KEYWORD_ABSENT
What should come across the wire if a keyword is absent.

See Also:
Constant Field Values

KEYWORD_NO_CHANGE

public static final byte KEYWORD_NO_CHANGE
What should come across the wire if a keyword status is unchanged.

See Also:
Constant Field Values

DEFAULT_TABLE_SIZE

public static final int DEFAULT_TABLE_SIZE
The suggested default table size.

See Also:
Constant Field Values

MAX_PATCH_SIZE

public static final int MAX_PATCH_SIZE
The maximum size of patch messages, in bytes.

See Also:
Constant Field Values
Constructor Detail

QueryRouteTable

public QueryRouteTable()
Creates a QueryRouteTable with default sizes.


QueryRouteTable

public QueryRouteTable(int size)
Creates a new QueryRouteTable instance with the specified size. This QueryRouteTable will be completely empty with no keywords -- no queries will have hits in this route table until patch messages are received.

Parameters:
size - the size of the query routing table
Method Detail

getPercentFull

public double getPercentFull()
Returns the percentage of slots used in this QueryRouteTable's BitTable. The return value is from 0 to 100.


contains

public boolean contains(QueryRequest qr)
Returns true if a response could be generated for qr. Note that a return value of true does not necessarily mean that a response will be generated--just that it could. It is assumed that qr's TTL has already been decremented, i.e., is the outbound not inbound TTL.


add

public void add(java.lang.String filename)
For all keywords k in filename, adds to this.


addIndivisible

public void addIndivisible(java.lang.String iString)

addAll

public void addAll(QueryRouteTable qrt)
For all in qrt, adds to this. (This is useful for unioning lots of route tables for propoagation.)


equals

public boolean equals(java.lang.Object o)
True if o is a QueryRouteTable with the same entries of this.


hashCode

public int hashCode()

toString

public java.lang.String toString()

reset

public void reset(ResetTableMessage rtm)
Resets this QueryRouteTable to the specified size with no data. This is done when a RESET message is received.

Parameters:
rtm - the ResetTableMessage containing the size to reset the table to

patch

public void patch(PatchTableMessage patch)
           throws BadPacketException
Adds the specified patch message to this query routing table.

Parameters:
patch - the PatchTableMessage containing the new data to add
Throws:
BadPacketException - if the sequence number or size is incorrect
BadPacketException

encode

public java.util.List encode(QueryRouteTable prev)
Stub for calling encode(QueryRouteTable, true).


encode

public java.util.List encode(QueryRouteTable prev,
                             boolean allowCompression)
Returns an List of RouteTableMessage that will convey the state of this. If that is null, this will include a reset. Otherwise it will include only those messages needed to to convert that to this. More formally, for any non-null QueryRouteTable's m and that, the following holds:
 for (Iterator iter=m.encode(); iter.hasNext(); ) 
    prev.update((RouteTableUpdate)iter.next());
 Assert.that(prev.equals(m));