com.limegroup.gnutella
Class RouteTable

java.lang.Object
  extended bycom.limegroup.gnutella.RouteTable

public final class RouteTable
extends java.lang.Object

The reply routing table. Given a GUID from a reply message header, this tells you where to route the reply. It is mutable mapping from globally unique 16-byte message IDs to connections. Old mappings may be purged without warning, preferably using a FIFO policy. This class makes a distinction between not having a mapping for a GUID and mapping that GUID to null (in the case of a removed ReplyHandler).

This class can also optionally keep track of the number of reply bytes routed per guid. This can be useful for implementing fair flow-control strategies.


Nested Class Summary
static class RouteTable.ReplyRoutePair
          The return value from getReplyHandler.
 
Constructor Summary
RouteTable(int seconds, int maxSize)
          Creates a new route table with enough space to hold the last seconds to 2*seconds worth of entries, or maxSize elements, whichever is smaller [sic].
 
Method Summary
 boolean getAndSetTTL(byte[] guid, byte getTTL, byte setTTL)
          Synchronizes a TTL get test with a set test.
 ReplyHandler getReplyHandler(byte[] guid)
          Looks up the reply route for a given guid.
 RouteTable.ReplyRoutePair getReplyHandler(byte[] guid, int replyBytes, short numReplies)
          Looks up the reply route and route volume for a given guid, incrementing the count of bytes routed for that GUID.
 void removeReplyHandler(ReplyHandler replyHandler)
          Clears references to a given ReplyHandler.
 ResultCounter routeReply(byte[] guid, ReplyHandler replyHandler)
          Adds a new routing entry.
 void setTTL(ResultCounter entry, byte ttl)
          Optional operation - if you want to remember the TTL associated with a counter, in order to allow for extendable execution, you can set the TTL a message (guid).
 java.lang.String toString()
           
 ResultCounter tryToRouteReply(byte[] guid, ReplyHandler replyHandler)
          Adds a new routing entry if one doesn't exist.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RouteTable

public RouteTable(int seconds,
                  int maxSize)
Creates a new route table with enough space to hold the last seconds to 2*seconds worth of entries, or maxSize elements, whichever is smaller [sic]. Typically maxSize is very large, and serves only as a guarantee to prevent worst case behavior. Actually 2*maxSize elements can be held in this in the worst case.

Method Detail

routeReply

public ResultCounter routeReply(byte[] guid,
                                ReplyHandler replyHandler)
Adds a new routing entry.

Returns:
the RouteTableEntry entered into the routing tables, or null if it could not be entered

tryToRouteReply

public ResultCounter tryToRouteReply(byte[] guid,
                                     ReplyHandler replyHandler)
Adds a new routing entry if one doesn't exist.


setTTL

public void setTTL(ResultCounter entry,
                   byte ttl)
Optional operation - if you want to remember the TTL associated with a counter, in order to allow for extendable execution, you can set the TTL a message (guid).

Parameters:
ttl - should be greater than 0.
Throws:
java.lang.IllegalArgumentException - thrown if !(ttl > 0), or if entry is null or is not something I recognize. So only put in what I dole out.

getAndSetTTL

public boolean getAndSetTTL(byte[] guid,
                            byte getTTL,
                            byte setTTL)
Synchronizes a TTL get test with a set test.

Parameters:
getTTL - the ttl you want getTTL() to be in order to setTTL().
setTTL - the ttl you want to setTTL() if getTTL() was correct.
Returns:
true if the TTL was set as you desired.
Throws:
java.lang.IllegalArgumentException - if getTTL or setTTL is less than 1, or if setTTL < getTTL

getReplyHandler

public ReplyHandler getReplyHandler(byte[] guid)
Looks up the reply route for a given guid.


getReplyHandler

public RouteTable.ReplyRoutePair getReplyHandler(byte[] guid,
                                                 int replyBytes,
                                                 short numReplies)
Looks up the reply route and route volume for a given guid, incrementing the count of bytes routed for that GUID.


removeReplyHandler

public void removeReplyHandler(ReplyHandler replyHandler)
Clears references to a given ReplyHandler.


toString

public java.lang.String toString()