com.limegroup.gnutella.bootstrap
Class BootstrapServerManager

java.lang.Object
  extended bycom.limegroup.gnutella.bootstrap.BootstrapServerManager

public class BootstrapServerManager
extends java.lang.Object

A list of GWebCache servers. Provides methods to fetch address addresses from these servers, find the addresses of more such servers, and update the addresses of these and other servers.

Information on the GWebCache protocol can be found at http://zero-g.net/gwebcache/specs.html


Field Summary
static int MAX_HOSTS_PER_REQUEST
          The maximum number of hosts to try per request.
static int UPDATE_DELAY_MSEC
          The amount of time in milliseconds between update requests.
 
Constructor Summary
BootstrapServerManager(HostCatcher catcher)
           
 
Method Summary
 void addBootstrapServer(BootstrapServer server)
          Adds server to this.
 void fetchBootstrapServersAsync()
          Asynchronously fetches other bootstrap URLs and stores them in this.
 void fetchEndpointsAsync()
          Asynchronously fetches host addresses from bootstrap servers and stores them in the HostCatcher.
 java.util.Iterator getBootstrapServers()
          Returns an iterator of the bootstrap servers in this, each as a BootstrapServer, in any order.
protected  int randomServer()
          Returns an random valid index of SERVERS.
 void sendUpdatesAsync(Endpoint myIP)
          Asynchronously sends an update message to a cache.
protected  int size()
          Returns the number of servers in this.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_HOSTS_PER_REQUEST

public static int MAX_HOSTS_PER_REQUEST
The maximum number of hosts to try per request. Prevents us from consuming all hosts if disconnected. Non-final for testing.


UPDATE_DELAY_MSEC

public static int UPDATE_DELAY_MSEC
The amount of time in milliseconds between update requests. Public and non-final for testing purposes.

Constructor Detail

BootstrapServerManager

public BootstrapServerManager(HostCatcher catcher)
Parameters:
catcher - where to deposit fetched endpoints.
Method Detail

addBootstrapServer

public void addBootstrapServer(BootstrapServer server)
Adds server to this.


getBootstrapServers

public java.util.Iterator getBootstrapServers()
Returns an iterator of the bootstrap servers in this, each as a BootstrapServer, in any order. To prevent ConcurrentModification problems, the caller should hold this' lock while using the iterator.

Returns:
an Iterator of BootstrapServer.

fetchBootstrapServersAsync

public void fetchBootstrapServersAsync()
Asynchronously fetches other bootstrap URLs and stores them in this. Stops after getting "enough" endpoints or exhausting all caches. Uses the "urlfile=1" message.


fetchEndpointsAsync

public void fetchEndpointsAsync()
Asynchronously fetches host addresses from bootstrap servers and stores them in the HostCatcher. Stops after getting "enough" endpoints or exhausting all caches. Does nothing if another endpoint request is in progress. Uses the "hostfile=1" message.


sendUpdatesAsync

public void sendUpdatesAsync(Endpoint myIP)
Asynchronously sends an update message to a cache. May do nothing if nothing to update. Uses the "url" and "ip" messages.

Parameters:
myIP - my listening address and port
Throws:
NullPointerException - if the ip param is null

randomServer

protected int randomServer()
Returns an random valid index of SERVERS. Protected so we can override in test cases. PRECONDITION: SERVERS.size>0.


size

protected int size()
Returns the number of servers in this.