com.limegroup.gnutella
Class HostCatcher

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

public class HostCatcher
extends java.lang.Object

The host catcher. This peeks at pong messages coming on the network and snatches IP addresses of other Gnutella peers. IP addresses may also be added to it from a file (usually "gnutella.net"). The servent may then connect to these addresses as necessary to maintain full connectivity.

The HostCatcher currently prioritizes pongs as follows. Note that Ultrapeers with a private address is still highest priority; hopefully this may allow you to find local Ultrapeers.

  1. Ultrapeers. Ultrapeers are identified because the number of files they are sharing is an exact power of two--a dirty but effective hack.
  2. Normal pongs.
  3. Private addresses. This means that the host catcher will still work on private networks, although we will normally ignore private addresses.
HostCatcher also manages the list of GWebCache servers. YOU MUST CALL EXPIRE() TO START THE GBWEBCACHE BOOTSTRAPING PROCESS. This should be done when calling RouterService.connect().

Finally, HostCatcher maintains a list of "permanent" locations, based on average daily uptime. These are stored in the gnutella.net file. They are NOT bootstrap servers like router.limewire.com; LimeWire doesn't use those anymore.


Field Summary
static int GWEBCACHE_DELAY
          The number of milliseconds to wait after trying gnutella.net entries before resorting to GWebCache HOSTFILE requests.
 
Constructor Summary
HostCatcher()
          Creates a new HostCatcher instance with a constant setting for the host file location.
 
Method Summary
 boolean add(Endpoint e, boolean forceHighPriority)
          Adds an address to this, possibly ejecting other elements from the cache.
 boolean add(PingReply pr)
          Attempts to add a pong to this, possibly ejecting other elements from the cache.
 void clear()
           
 void doneWithConnect(Endpoint e, boolean success)
          Notifies this that the fetcher has finished attempting a connection to the given host.
 void expire()
          Notifies this that connect() has been called.
 Endpoint getAnEndpoint()
           
 java.util.Iterator getHosts()
          Returns an iterator of the hosts in this, in order of priority.
 int getNumHosts()
          Return the number of hosts, i.e., getNumUltrapeerHosts()+getNumNormalHosts()+getNumPrivateHosts().
 int getNumUltrapeerHosts()
          Returns the number of marked ultrapeer hosts.
 java.util.Iterator getUltrapeerHosts(int n)
          Returns an iterator of the (at most) n best ultrapeer endpoints of this.
 void initialize()
          Links the HostCatcher up with the other back end pieces, and, if quick connect is not specified in the SettingsManager, loads the hosts in the host list into the maybe set.
 void removeHost(java.lang.String host, int port)
          Remove unwanted or used entries
protected  void repOk()
          Checks invariants.
 void setAlwaysNotifyKnownHost(boolean notifyKnownHost)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

GWEBCACHE_DELAY

public static final int GWEBCACHE_DELAY
The number of milliseconds to wait after trying gnutella.net entries before resorting to GWebCache HOSTFILE requests.

See Also:
Constant Field Values
Constructor Detail

HostCatcher

public HostCatcher()
Creates a new HostCatcher instance with a constant setting for the host file location.

Method Detail

initialize

public void initialize()
Links the HostCatcher up with the other back end pieces, and, if quick connect is not specified in the SettingsManager, loads the hosts in the host list into the maybe set. (The likelys set is empty.) If filename does not exist, then no error message is printed and this is initially empty. The file is expected to contain a sequence of lines in the format ":port\n". Lines not in this format are silently ignored.


add

public boolean add(PingReply pr)
Attempts to add a pong to this, possibly ejecting other elements from the cache. This method used to be called "spy".

Parameters:
pr - the pong containing the address/port to add
Returns:
true iff pr was actually added

add

public boolean add(Endpoint e,
                   boolean forceHighPriority)
Adds an address to this, possibly ejecting other elements from the cache. This method is used when getting an address from headers instead of the normal ping reply.

Parameters:
forceHighPriority - true if this should always be of high priority
Returns:
true iff e was actually added

getAnEndpoint

public Endpoint getAnEndpoint()
                       throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

doneWithConnect

public void doneWithConnect(Endpoint e,
                            boolean success)
Notifies this that the fetcher has finished attempting a connection to the given host. This exists primarily to update the permanent host list with connection history.

Parameters:
e - the address/port, which should have been returned by getAnEndpoint
success - true if we successfully established a messaging connection to e, at least temporarily; false otherwise

getNumHosts

public int getNumHosts()
Return the number of hosts, i.e., getNumUltrapeerHosts()+getNumNormalHosts()+getNumPrivateHosts().


getNumUltrapeerHosts

public int getNumUltrapeerHosts()
Returns the number of marked ultrapeer hosts.


getHosts

public java.util.Iterator getHosts()
Returns an iterator of the hosts in this, in order of priority. This can be modified while iterating through the result, but the modifications will not be observed.


getUltrapeerHosts

public java.util.Iterator getUltrapeerHosts(int n)
Returns an iterator of the (at most) n best ultrapeer endpoints of this. It's not guaranteed that these are reachable. This can be modified while iterating through the result, but the modifications will not be observed.


removeHost

public void removeHost(java.lang.String host,
                       int port)
Remove unwanted or used entries


expire

public void expire()
Notifies this that connect() has been called. This may decide to give out bootstrap pongs if necessary.


clear

public void clear()

toString

public java.lang.String toString()

setAlwaysNotifyKnownHost

public void setAlwaysNotifyKnownHost(boolean notifyKnownHost)

repOk

protected void repOk()
Checks invariants. Very slow; method body should be enabled for testing purposes only.