LimeWire Consolidated API

com.limegroup.gnutella
Interface ConnectionManager

All Superinterfaces:
ConnectionAcceptor, EventDispatcher<ConnectionLifecycleEvent,ConnectionLifecycleListener>, EventListener<GnutellaConnectionEvent>
All Known Implementing Classes:
ConnectionManagerImpl

public interface ConnectionManager
extends ConnectionAcceptor, EventDispatcher<ConnectionLifecycleEvent,ConnectionLifecycleListener>, EventListener<GnutellaConnectionEvent>

The list of all RoutedConnection's. Provides a factory method for creating user-requested outgoing connections, accepts incoming connections, and fetches "automatic" outgoing connections as needed. Creates threads for handling these connections when appropriate. Because this is the only list of all connections, it plays an important role in message broadcasting. For this reason, the code is highly tuned to avoid locking in the getInitializedConnections() methods. Adding and removing connections is a slower operation.

LimeWire follows the following connection strategy:
As a leaf, LimeWire will ONLY connect to 'good' Ultrapeers. The definition of good is constantly changing. For a current view of 'good', review HandshakeResponse.isGoodUltrapeer(). LimeWire leaves will NOT deny a connection to an ultrapeer even if they've reached their maximum desired number of connections (currently 3). This means that if 4 connections resolve simultaneously, the leaf will remain connected to all 4.
As an Ultrapeer, LimeWire will seek outgoing connections for 5 less than the number of it's desired peer slots. This is done so that newcomers on the network have a better chance of finding an ultrapeer with a slot open. LimeWire ultrapeers will allow ANY other ultrapeer to connect to it, and to ensure that the network does not become too LimeWire-centric, it reserves 3 slots for non-LimeWire peers. LimeWire ultrapeers will allow ANY leaf to connect, so long as there are atleast 15 slots open. Beyond that number, LimeWire will only allow 'good' leaves. To see what consitutes a good leaf, view HandshakeResponse.isGoodLeaf(). To ensure that the network does not remain too LimeWire-centric, it reserves 2 slots for non-LimeWire leaves.

ConnectionManager has methods to get up and downstream bandwidth, but it doesn't quite fit the BandwidthTracker interface.


Field Summary
static int CONNECT_BACK_REDUNDANT_REQUESTS
          How many connect back requests to send if we have a single connection
static int PREFERRED_CONNECTIONS_FOR_LEAF
          The number of connections leaves should maintain to Ultrapeers.
static int RESERVED_NON_LIMEWIRE_LEAVES
          The number of leaf connections reserved for non LimeWire clients.
 
Method Summary
 void acceptConnection(Socket socket)
          Create an incoming connection.
 boolean allowAnyConnection()
          Checks if there is any available slot of any kind.
 HandshakeStatus allowConnection(HandshakeResponse hr)
          Checks if the connection received can be accepted, based upon the type of connection (e.g.
 HandshakeStatus allowConnection(HandshakeResponse hr, boolean leaf)
          Returns true if this has slots for an incoming connection, without accounting for this' ultrapeer capabilities.
 HandshakeStatus allowConnectionAsLeaf(HandshakeResponse hr)
          Checks if the connection received can be accepted, based upon the type of connection (e.g.
 boolean allowLeafDemotion()
          Returns true if this can safely switch from Ultrapeer to leaf mode.
 boolean canSendConnectBack(Message.Network network)
           
 void connect()
          Connects to the network.
 void connectBackSent(Message.Network network)
          notification that a connect back request has been sent on the given network
 boolean connectionInitialized(RoutedConnection c)
          Marks a connection fully initialized, but only if that connection wasn't removed from the list of open connections during its initialization.
 void connectionInitializingIncoming(RoutedConnection c)
          Adds an incoming connection to the list of connections.
 int countConnectionsWithNMessages(int messageThreshold)
          Count how many connections have already received N messages
 void createConnectionAsynchronously(String hostname, int portnum, SocketsManager.ConnectType type)
          Create a new connection, allowing it to initialize and loop for messages on a new thread.
 void disconnect(boolean willTryToReconnect)
          Disconnects from the network.
 int getActiveConnectionMessages()
          Count up all the messages on active connections
 Endpoint getConnectedGUESSUltrapeer()
          Returns the Endpoint for an Ultrapeer connected via TCP, if available.
 List<RoutedConnection> getConnectedGUESSUltrapeers()
          Returns a List of Ultrapeers connected via TCP that are GUESS enabled.
 List<RoutedConnection> getConnections()
           
 long getCurrentAverageUptime()
          Returns this node's average connection time - in ms - including the current session.
 List<RoutedConnection> getInitializedClientConnections()
          Returns a list of this' initialized connections.
 List<RoutedConnection> getInitializedClientConnectionsMatchLocale(String loc)
          return a list of initialized client connection that matches the parameter String loc.
 List<RoutedConnection> getInitializedConnections()
          Returns a list of this' initialized connections.
 List<RoutedConnection> getInitializedConnectionsMatchLocale(String loc)
          return a list of initialized connection that matches the parameter String loc.
 float getMeasuredDownstreamBandwidth()
          Returns the downstream bandwidth in kbytes/sec between the last two calls to measureBandwidth.
 float getMeasuredUpstreamBandwidth()
          Returns the upstream bandwidth in kbytes/sec between the last two calls to measureBandwidth.
 int getNumClientSupernodeConnections()
           
 int getNumConnections()
           
 int getNumFetchingConnections()
          Returns the number of connections that are currently being fetched.
 int getNumFreeLeafSlots()
           
 int getNumFreeLimeWireLeafSlots()
           
 int getNumFreeLimeWireNonLeafSlots()
           
 int getNumFreeNonLeafSlots()
           
 int getNumInitializedClientConnections()
           
 int getNumInitializedConnections()
           
 int getNumLimeWireLocalePrefSlots()
           
 int getNumOldConnections()
           
 int getNumUltrapeerConnections()
           
 int getPreferredConnectionCount()
          Gets the number of preferred connections to maintain.
 Set<Connectable> getPushProxies()
          Accessor for the Set of push proxies for this node.
 boolean hasFreeSlots()
          Returns whether or not this node has any available connection slots.
 boolean hasSupernodeClientConnection()
          Returns true if this is a super node with a connection to a leaf.
 boolean isActiveSupernode()
          Tells whether or not we're actively being a supernode to anyone.
 boolean isBehindProxy()
           
 boolean isConnected()
          Returns whether or not the client has an established connection with another Gnutella client.
 boolean isConnectedTo(String hostName)
          Returns whether this (probably) has a connection to the given host.
 boolean isConnecting()
          Returns whether or not we are currently attempting to connect to the network.
 boolean isConnectingTo(IpPort host)
          Returns true if we're currently attempting to connect to a particular host.
 boolean isConnectionIdle()
          Determines if we're attempting to maintain the idle connection count.
 boolean isFullyConnected()
          Determines if we've reached our maximum number of preferred connections.
 boolean isLocaleMatched()
          Returns true if we've made a locale-matching connection (or don't want any at all).
 boolean isShieldedLeaf()
          Returns true if this is a leaf node with a connection to a ultrapeer.
 boolean isSupernode()
          True if this is currently or wants to be a supernode, otherwise false.
 boolean isSupernodeCapable()
          Return true if we are not a private address, have been ultrapeer capable in the past, and are not being shielded by anybody, we don't have UP mode disabled AND we are not exclusively a DHT node.
 void measureBandwidth()
          Takes a snapshot of the upstream and downstream bandwidth since the last call to measureBandwidth.
 void noInternetConnection()
          This method notifies the connection manager that the user does not have a live connection to the Internet to the best of our determination.
 void remove(RoutedConnection mc)
          Removes the specified connection from currently active connections, also removing this connection from routing tables and modifying active connection fetchers accordingly.
 boolean sendTCPConnectBackRequests()
          Sends a TCPConnectBack request to (up to) 2 connected Ultrapeers.
 boolean sendUDPConnectBackRequests(GUID cbGuid)
          Sends a UDPConnectBack request to (up to) 4 (and at least 2) connected Ultrapeers.
 void sendUpdatedCapabilities()
          Iterates over all the connections and sends the updated CapabilitiesVM down every one of them.
 void start()
          Links the ConnectionManager up with the other back end pieces and launches the ConnectionWatchdog and the initial ConnectionFetchers.
 boolean supernodeNeeded()
          Tells if this node thinks that more ultrapeers are needed on the network.
 void tryToBecomeAnUltrapeer(int demotionLimit)
          Notifies the connection manager that it should attempt to become an Ultrapeer.
 void updateQueryStatus(QueryStatusResponse stat)
          Sends a QueryStatusResponse message to as many Ultrapeers as possible.
 
Methods inherited from interface org.limewire.net.ConnectionAcceptor
acceptConnection, isBlocking
 
Methods inherited from interface com.limegroup.gnutella.util.EventDispatcher
addEventListener, dispatchEvent, removeEventListener
 
Methods inherited from interface org.limewire.listener.EventListener
handleEvent
 

Field Detail

PREFERRED_CONNECTIONS_FOR_LEAF

static final int PREFERRED_CONNECTIONS_FOR_LEAF
The number of connections leaves should maintain to Ultrapeers.

See Also:
Constant Field Values

CONNECT_BACK_REDUNDANT_REQUESTS

static final int CONNECT_BACK_REDUNDANT_REQUESTS
How many connect back requests to send if we have a single connection

See Also:
Constant Field Values

RESERVED_NON_LIMEWIRE_LEAVES

static final int RESERVED_NON_LIMEWIRE_LEAVES
The number of leaf connections reserved for non LimeWire clients. This is done to ensure that the network is not solely LimeWire centric.

See Also:
Constant Field Values
Method Detail

start

void start()
Links the ConnectionManager up with the other back end pieces and launches the ConnectionWatchdog and the initial ConnectionFetchers.


createConnectionAsynchronously

void createConnectionAsynchronously(String hostname,
                                    int portnum,
                                    SocketsManager.ConnectType type)
Create a new connection, allowing it to initialize and loop for messages on a new thread.


acceptConnection

void acceptConnection(Socket socket)
Create an incoming connection. If the connection can support asynchronous messaging, this method will return immediately. Otherwise, this will block forever while the connection handshakes and then loops for messages (it will return when the connection dies).


remove

void remove(RoutedConnection mc)
Removes the specified connection from currently active connections, also removing this connection from routing tables and modifying active connection fetchers accordingly.

Parameters:
mc - the RoutedConnection instance to remove

isSupernode

boolean isSupernode()
True if this is currently or wants to be a supernode, otherwise false.


isSupernodeCapable

boolean isSupernodeCapable()
Return true if we are not a private address, have been ultrapeer capable in the past, and are not being shielded by anybody, we don't have UP mode disabled AND we are not exclusively a DHT node.


isBehindProxy

boolean isBehindProxy()
Returns:
if we are currently using a http or socks4/5 proxy to connect.

isActiveSupernode

boolean isActiveSupernode()
Tells whether or not we're actively being a supernode to anyone.


isShieldedLeaf

boolean isShieldedLeaf()
Returns true if this is a leaf node with a connection to a ultrapeer. It is not required that the ultrapeer support query routing, though that is generally the case.


hasSupernodeClientConnection

boolean hasSupernodeClientConnection()
Returns true if this is a super node with a connection to a leaf.


hasFreeSlots

boolean hasFreeSlots()
Returns whether or not this node has any available connection slots. This is only relevant for Ultrapeers -- leaves will always return false to this call since they do not accept any incoming connections, at least for now.

Returns:
true if this node is an Ultrapeer with free leaf or Ultrapeer connections slots, otherwise false

isConnectedTo

boolean isConnectedTo(String hostName)
Returns whether this (probably) has a connection to the given host. This method is currently implemented by iterating through all connections and comparing addresses but not ports. (Incoming connections use ephemeral ports.) As a result, this test may conservatively return true even if this is not connected to host. Likewise, it may it mistakenly return false if host is a multihomed system. In the future, additional connection headers may make the test more precise.

Returns:
true if this is probably connected to host

isConnectingTo

boolean isConnectingTo(IpPort host)
Returns true if we're currently attempting to connect to a particular host. This checks both the Ip & Port.


getNumConnections

int getNumConnections()
Returns:
the number of connections, which is greater than or equal to the number of initialized connections.

getNumInitializedConnections

int getNumInitializedConnections()
Returns:
the number of initialized connections, which is less than or equals to the number of connections.

getNumInitializedClientConnections

int getNumInitializedClientConnections()
Returns:
the number of initializedclient connections, which is less than or equals to the number of connections.

getNumClientSupernodeConnections

int getNumClientSupernodeConnections()
Returns:
the number of initialized connections for which isClientSupernodeConnection is true.

getNumUltrapeerConnections

int getNumUltrapeerConnections()
Returns:
the number of ultrapeer -> ultrapeer connections.

getNumOldConnections

int getNumOldConnections()
Returns:
the number of old unrouted connections.

getNumFreeLeafSlots

int getNumFreeLeafSlots()
Returns:
the number of free leaf slots.

getNumFreeLimeWireLeafSlots

int getNumFreeLimeWireLeafSlots()
Returns:
the number of free leaf slots that LimeWires can connect to.

getNumFreeNonLeafSlots

int getNumFreeNonLeafSlots()
Returns:
the number of free non-leaf slots.

getNumFreeLimeWireNonLeafSlots

int getNumFreeLimeWireNonLeafSlots()
Returns:
the number of free non-leaf slots that LimeWires can connect to.

isLocaleMatched

boolean isLocaleMatched()
Returns true if we've made a locale-matching connection (or don't want any at all).


getNumLimeWireLocalePrefSlots

int getNumLimeWireLocalePrefSlots()
Returns:
the number of locale reserved slots to be filled An ultrapeer may not have Free LimeWire Non Leaf Slots but may still have free slots that are reserved for locales

isFullyConnected

boolean isFullyConnected()
Determines if we've reached our maximum number of preferred connections.


isConnected

boolean isConnected()
Returns whether or not the client has an established connection with another Gnutella client.

Returns:
true if the client is currently connected to another Gnutella client, false otherwise

isConnecting

boolean isConnecting()
Returns whether or not we are currently attempting to connect to the network.


measureBandwidth

void measureBandwidth()
Takes a snapshot of the upstream and downstream bandwidth since the last call to measureBandwidth.

See Also:
BandwidthTracker.measureBandwidth()

getMeasuredUpstreamBandwidth

float getMeasuredUpstreamBandwidth()
Returns the upstream bandwidth in kbytes/sec between the last two calls to measureBandwidth.

See Also:
BandwidthTracker.measureBandwidth()

getMeasuredDownstreamBandwidth

float getMeasuredDownstreamBandwidth()
Returns the downstream bandwidth in kbytes/sec between the last two calls to measureBandwidth.

See Also:
BandwidthTracker.measureBandwidth()

allowConnectionAsLeaf

HandshakeStatus allowConnectionAsLeaf(HandshakeResponse hr)
Checks if the connection received can be accepted, based upon the type of connection (e.g. client, ultrapeer, temporary etc).

Parameters:
c - The connection we received, for which to test if we have incoming slot.
Returns:
true, if we have incoming slot for the connection received, false otherwise

allowConnection

HandshakeStatus allowConnection(HandshakeResponse hr)
Checks if the connection received can be accepted, based upon the type of connection (e.g. client, ultrapeer, temporary etc).

Parameters:
c - The connection we received, for which to test if we have incoming slot.
Returns:
true, if we have incoming slot for the connection received, false otherwise

allowAnyConnection

boolean allowAnyConnection()
Checks if there is any available slot of any kind.

Returns:
true, if we have incoming slot of some kind, false otherwise

allowConnection

HandshakeStatus allowConnection(HandshakeResponse hr,
                                boolean leaf)
Returns true if this has slots for an incoming connection, without accounting for this' ultrapeer capabilities. More specifically: useragentHeader is used to prefer LimeWire and certain trusted vendors. outgoing is currently unused, but may be used to prefer incoming or outgoing connections in the forward.

Parameters:
outgoing - true if this is an outgoing connection; true if incoming
ultrapeerHeader - the value of the X-Ultrapeer header, or null if it was not written
useragentHeader - the value of the User-Agent header, or null if it was not written
Returns:
true if a connection of the given type is allowed

supernodeNeeded

boolean supernodeNeeded()
Tells if this node thinks that more ultrapeers are needed on the network. This method should be invoked on a ultrapeer only, as only ultrapeer may have required information to make informed decision.

Returns:
true, if more ultrapeers needed, false otherwise

getInitializedConnections

List<RoutedConnection> getInitializedConnections()
Returns a list of this' initialized connections.


getInitializedConnectionsMatchLocale

List<RoutedConnection> getInitializedConnectionsMatchLocale(String loc)
return a list of initialized connection that matches the parameter String loc. create a new linkedlist to return.


getInitializedClientConnections

List<RoutedConnection> getInitializedClientConnections()
Returns a list of this' initialized connections.


getInitializedClientConnectionsMatchLocale

List<RoutedConnection> getInitializedClientConnectionsMatchLocale(String loc)
return a list of initialized client connection that matches the parameter String loc. create a new linkedlist to return.


getConnections

List<RoutedConnection> getConnections()
Returns:
all of this' connections.

getPushProxies

Set<Connectable> getPushProxies()
Accessor for the Set of push proxies for this node. If there are no push proxies available, this will return an empty Set. Callers can take ownership of the returned set; the set might be immutable.

Returns:
a Set of push proxies with a maximum size of 4 TODO: should the set of pushproxy UPs be cached and updated as connections are killed and created?

sendTCPConnectBackRequests

boolean sendTCPConnectBackRequests()
Sends a TCPConnectBack request to (up to) 2 connected Ultrapeers.


sendUDPConnectBackRequests

boolean sendUDPConnectBackRequests(GUID cbGuid)
Sends a UDPConnectBack request to (up to) 4 (and at least 2) connected Ultrapeers.


updateQueryStatus

void updateQueryStatus(QueryStatusResponse stat)
Sends a QueryStatusResponse message to as many Ultrapeers as possible.

Parameters:
-

getConnectedGUESSUltrapeer

Endpoint getConnectedGUESSUltrapeer()
Returns the Endpoint for an Ultrapeer connected via TCP, if available.

Returns:
the Endpoint for an Ultrapeer connected via TCP if there is one, otherwise returns null

getConnectedGUESSUltrapeers

List<RoutedConnection> getConnectedGUESSUltrapeers()
Returns a List of Ultrapeers connected via TCP that are GUESS enabled.

Returns:
A non-null List of GUESS enabled, TCP connected Ultrapeers. The are represented as ManagedConnections.

connectionInitializingIncoming

void connectionInitializingIncoming(RoutedConnection c)
Adds an incoming connection to the list of connections. Note that the incoming connection has already been initialized before this method is invoked. Should only be called from a thread that has this' monitor. This is called from initializeExternallyGeneratedConnection, for incoming connections Default access for testing.


connectionInitialized

boolean connectionInitialized(RoutedConnection c)
Marks a connection fully initialized, but only if that connection wasn't removed from the list of open connections during its initialization. Should only be called from a thread that has this' monitor. Default access for testing.


sendUpdatedCapabilities

void sendUpdatedCapabilities()
Iterates over all the connections and sends the updated CapabilitiesVM down every one of them.


disconnect

void disconnect(boolean willTryToReconnect)
Disconnects from the network. Closes all connections and sets the number of connections to zero.

Parameters:
willTryToReconnect - Whether or not this is only a temporary disconnection

getCurrentAverageUptime

long getCurrentAverageUptime()
Returns this node's average connection time - in ms - including the current session.


connect

void connect()
Connects to the network. Ensures the number of messaging connections is non-zero and recontacts the pong server as needed.


allowLeafDemotion

boolean allowLeafDemotion()
Returns true if this can safely switch from Ultrapeer to leaf mode. Typically this means that we are an Ultrapeer and have no leaf connections.

Returns:
true if we will allow ourselves to become a leaf, otherwise false

tryToBecomeAnUltrapeer

void tryToBecomeAnUltrapeer(int demotionLimit)
Notifies the connection manager that it should attempt to become an Ultrapeer. If we already are an Ultrapeer, this will be ignored.

Parameters:
demotionLimit - the number of attempts by other Ultrapeers to demote us to a leaf that we should allow before giving up in the attempt to become an Ultrapeer

getPreferredConnectionCount

int getPreferredConnectionCount()
Gets the number of preferred connections to maintain.


isConnectionIdle

boolean isConnectionIdle()
Determines if we're attempting to maintain the idle connection count.


noInternetConnection

void noInternetConnection()
This method notifies the connection manager that the user does not have a live connection to the Internet to the best of our determination. In this case, we notify the user with a message and maintain any Gnutella hosts we have already tried instead of discarding them.


countConnectionsWithNMessages

int countConnectionsWithNMessages(int messageThreshold)
Count how many connections have already received N messages


getActiveConnectionMessages

int getActiveConnectionMessages()
Count up all the messages on active connections


canSendConnectBack

boolean canSendConnectBack(Message.Network network)
Returns:
true if a connect back request can be sent on the provided network

connectBackSent

void connectBackSent(Message.Network network)
notification that a connect back request has been sent on the given network


getNumFetchingConnections

int getNumFetchingConnections()
Returns the number of connections that are currently being fetched.


LimeWire Consolidated API

Copyright © 2009. All Rights Reserved.