LimeWire Consolidated API

com.limegroup.gnutella.dht
Class AbstractDHTController

java.lang.Object
  extended by com.limegroup.gnutella.dht.AbstractDHTController
All Implemented Interfaces:
DHTController
Direct Known Subclasses:
ActiveDHTNodeController, PassiveDHTNodeController

public abstract class AbstractDHTController
extends Object
implements DHTController

The controller for the LimeWire DHT. A node should connect to the DHT only if it has previously been designated as capable by the NodeAssigner or if it is forced to. Once the node is a DHT node (if EXCLUDE_ULTRAPEERS is set to true) it should not try to connect as an Ultrapeer.

The NodeAssigner should be the only class to have the authority to initialize the DHT and connect to the network.

This controller can be in one of the four following states:

Nodes are bootstrap in the following order:
  1. If we have received hosts from the Gnutella network, try them.
  2. Else try the persisted routing table (stored contacts from the last session).
  3. Else try the SIMPP list.
  4. Else start the node fetcher and wait for hosts coming from the network.
Warning: The methods in this class are NOT synchronized.

The current implementation is specific to the Mojito DHT.


Field Summary
protected  com.limegroup.gnutella.dht.DHTBootstrapper bootstrapper
          The DHT bootstrapper instance.
protected  MojitoDHT dht
          The instance of the DHT
protected  Log LOG
           
 
Constructor Summary
AbstractDHTController(Vendor vendor, Version version, EventDispatcher<DHTEvent,DHTEventListener> dispatcher, DHTManager.DHTMode mode, DHTControllerFacade dhtControllerFacade)
           
 
Method Summary
 void addActiveDHTNode(SocketAddress hostAddress)
          If this node is not bootstrapped, passes the given hostAddress on to the DHT bootstrapper.
protected  void addActiveDHTNode(SocketAddress hostAddress, boolean addToDHTNodeAdder)
          If this node is not bootstrapped, passes the given hostAddress to the DHT bootstrapper.
 void addContact(Contact node)
          Adds the given Contact to the local RouteTable
 void addPassiveDHTNode(SocketAddress hostAddress)
          If this node is not bootstrapped, the controller requests active DHT nodes from the given SocketAddress.
protected abstract  MojitoDHT createMojitoDHT(Vendor vendor, Version version)
          A factory method to create MojitoDHTs
 List<IpPort> getActiveDHTNodes(int maxNodes)
          Returns maxNodes number of active Node IP:Ports
 DHTManager.DHTMode getDHTMode()
          Returns the mode of the DHTController
 MojitoDHT getMojitoDHT()
          Returns this controller's Mojito DHT instance.
protected  List<IpPort> getMRSNodes(int numNodes, boolean excludeLocal)
          Returns a list of the Most Recently Seen nodes from the Mojito routing table.
protected  int getRouteTableVersion()
          Returns the current RouteTable version
 void handleConnectionLifecycleEvent(ConnectionLifecycleEvent evt)
          A callback method to notify the DHTController about ConnectionLifecycleEvents
 boolean isBootstrapped()
          Returns whether or not this node is bootstrapped
 boolean isRunning()
          Returns whether this Node is running or not
 boolean isWaitingForNodes()
          Returns whether this Node is waiting for Nodes or not
 void sendUpdatedCapabilities()
          Sends the updated CapabilitiesVM to our connections.
 void start()
          Start the Mojito DHT and connects it to the network in either passive mode, or active mode (if we are a Gnutella leaf node).
 void stop()
          Shuts down the DHT.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected final Log LOG

dht

protected final MojitoDHT dht
The instance of the DHT


bootstrapper

protected final com.limegroup.gnutella.dht.DHTBootstrapper bootstrapper
The DHT bootstrapper instance.

Constructor Detail

AbstractDHTController

public AbstractDHTController(Vendor vendor,
                             Version version,
                             EventDispatcher<DHTEvent,DHTEventListener> dispatcher,
                             DHTManager.DHTMode mode,
                             DHTControllerFacade dhtControllerFacade)
Method Detail

getRouteTableVersion

protected final int getRouteTableVersion()
Returns the current RouteTable version


createMojitoDHT

protected abstract MojitoDHT createMojitoDHT(Vendor vendor,
                                             Version version)
A factory method to create MojitoDHTs


getDHTMode

public DHTManager.DHTMode getDHTMode()
Description copied from interface: DHTController
Returns the mode of the DHTController

Specified by:
getDHTMode in interface DHTController

getActiveDHTNodes

public List<IpPort> getActiveDHTNodes(int maxNodes)
Description copied from interface: DHTController
Returns maxNodes number of active Node IP:Ports

Specified by:
getActiveDHTNodes in interface DHTController

handleConnectionLifecycleEvent

public void handleConnectionLifecycleEvent(ConnectionLifecycleEvent evt)
Description copied from interface: DHTController
A callback method to notify the DHTController about ConnectionLifecycleEvents

Specified by:
handleConnectionLifecycleEvent in interface DHTController

start

public void start()
Start the Mojito DHT and connects it to the network in either passive mode, or active mode (if we are a Gnutella leaf node). For the node to be either passive or active mode, it must meet certain bandwidth settings and must be able to receive solicited UDP (for example, non-firewalled).

The start preconditions are the following:

We are not already connected, AND


stop

public void stop()
Shuts down the DHT. If this is an active node, it sends the updated capabilities to its ultrapeers and stores the node's route table to a file (active.mojito). Otherwise, as a passive node, it saves a list of Most Recently Seen (MRS) nodes to bootstrap for the next session as long as there was at least two Contacts in the route table.

The persisted route table (stored contacts from the last session) is used as a secondary means to bootstrap, if the node didn't receive any hosts through the Gnutella network to bootstrap.

Specified by:
stop in interface DHTController

addActiveDHTNode

protected void addActiveDHTNode(SocketAddress hostAddress,
                                boolean addToDHTNodeAdder)
If this node is not bootstrapped, passes the given hostAddress to the DHT bootstrapper. If it is already bootstrapped, this randomly tries to add the node to the DHT routing table.

Parameters:
hostAddress - the SocketAddress of the DHT host.
addToDHTNodeAdder - true to add to the random node adder if the DHT is bootstrapped.

addActiveDHTNode

public void addActiveDHTNode(SocketAddress hostAddress)
Description copied from interface: DHTController
If this node is not bootstrapped, passes the given hostAddress on to the DHT bootstrapper. If the node is already bootstrapped, the controller randomly tries to add the node to the DHT routing table.

Specified by:
addActiveDHTNode in interface DHTController
Parameters:
hostAddress - the SocketAddress of the DHT host.

addPassiveDHTNode

public void addPassiveDHTNode(SocketAddress hostAddress)
Description copied from interface: DHTController
If this node is not bootstrapped, the controller requests active DHT nodes from the given SocketAddress.

Specified by:
addPassiveDHTNode in interface DHTController

addContact

public void addContact(Contact node)
Description copied from interface: DHTController
Adds the given Contact to the local RouteTable

Specified by:
addContact in interface DHTController

getMRSNodes

protected List<IpPort> getMRSNodes(int numNodes,
                                   boolean excludeLocal)
Returns a list of the Most Recently Seen nodes from the Mojito routing table.

Parameters:
numNodes - the number of nodes to return
excludeLocal - true to exclude the local node
Returns:
a list of DHT IpPorts

isRunning

public boolean isRunning()
Description copied from interface: DHTController
Returns whether this Node is running or not

Specified by:
isRunning in interface DHTController

isBootstrapped

public boolean isBootstrapped()
Description copied from interface: DHTController
Returns whether or not this node is bootstrapped

Specified by:
isBootstrapped in interface DHTController

isWaitingForNodes

public boolean isWaitingForNodes()
Description copied from interface: DHTController
Returns whether this Node is waiting for Nodes or not

Specified by:
isWaitingForNodes in interface DHTController

getMojitoDHT

public MojitoDHT getMojitoDHT()
Description copied from interface: DHTController
Returns this controller's Mojito DHT instance. NOTE: This is for internal use only and should be used only within the dht.impl package. The DHT should not be handled directly by external classes.

Specified by:
getMojitoDHT in interface DHTController

sendUpdatedCapabilities

public void sendUpdatedCapabilities()
Sends the updated CapabilitiesVM to our connections. This is used when a node has successfully bootstrapped to the network and wants to notify its Gnutella peers that they can now bootstrap off of him.

Specified by:
sendUpdatedCapabilities in interface DHTController

LimeWire Consolidated API

Copyright © 2009. All Rights Reserved.