LimeWire Consolidated API

com.limegroup.gnutella
Class ConnectionManagerImpl

java.lang.Object
  extended by com.limegroup.gnutella.ConnectionManagerImpl
All Implemented Interfaces:
ConnectionManager, EventDispatcher<ConnectionLifecycleEvent,ConnectionLifecycleListener>, Service, EventListener<GnutellaConnectionEvent>, ConnectionAcceptor

public class ConnectionManagerImpl
extends Object
implements ConnectionManager, Service

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
 
Fields inherited from interface com.limegroup.gnutella.ConnectionManager
CONNECT_BACK_REDUNDANT_REQUESTS, PREFERRED_CONNECTIONS_FOR_LEAF, RESERVED_NON_LIMEWIRE_LEAVES
 
Constructor Summary
ConnectionManagerImpl(NetworkManager networkManager, com.google.inject.Provider<HostCatcher> hostCatcher, com.google.inject.Provider<ConnectionDispatcher> connectionDispatcher, ScheduledExecutorService backgroundExecutor, com.google.inject.Provider<SimppManager> simppManager, CapabilitiesVMFactory capabilitiesVMFactory, RoutedConnectionFactory managedConnectionFactory, com.google.inject.Provider<QueryUnicaster> queryUnicaster, SocketsManager socketsManager, ConnectionServices connectionServices, com.google.inject.Provider<NodeAssigner> nodeAssigner, com.google.inject.Provider<IPFilter> ipFilter, ConnectionCheckerManager connectionCheckerManager, PingRequestFactory pingRequestFactory, NetworkInstanceUtils networkInstanceUtils)
           
 
Method Summary
 void acceptConnection(Socket socket)
          Create an incoming connection.
 void acceptConnection(String word, Socket socket)
          Notification that a new incoming socket has been opened.
 void addEventListener(ConnectionLifecycleListener listener)
          Registers a listener for ConnectionLifeCycleEvents
 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.
 void dispatchEvent(ConnectionLifecycleEvent event)
          Dispatches a ConnectionLifecycleEvent to any registered listeners
 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.
 String getServiceName()
           
 void handleEvent(GnutellaConnectionEvent event)
          Notification that an event has occurred and should be handled.
 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.
 void initialize()
           
 boolean isActiveSupernode()
          Tells whether or not we're actively being a supernode to anyone.
 boolean isBehindProxy()
           
 boolean isBlocking()
          Returns true, if ConnectionAcceptor.acceptConnection(String, Socket) needs to be invoked in a separate thread.
 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.
 void removeEventListener(ConnectionLifecycleListener listener)
          unregisters a listener for ConnectionLifeCycleEvents
 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.
 void stop()
           
 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 class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionManagerImpl

@Inject
public ConnectionManagerImpl(NetworkManager networkManager,
                                    com.google.inject.Provider<HostCatcher> hostCatcher,
                                    com.google.inject.Provider<ConnectionDispatcher> connectionDispatcher,
                                    ScheduledExecutorService backgroundExecutor,
                                    com.google.inject.Provider<SimppManager> simppManager,
                                    CapabilitiesVMFactory capabilitiesVMFactory,
                                    RoutedConnectionFactory managedConnectionFactory,
                                    com.google.inject.Provider<QueryUnicaster> queryUnicaster,
                                    SocketsManager socketsManager,
                                    ConnectionServices connectionServices,
                                    com.google.inject.Provider<NodeAssigner> nodeAssigner,
                                    com.google.inject.Provider<IPFilter> ipFilter,
                                    ConnectionCheckerManager connectionCheckerManager,
                                    PingRequestFactory pingRequestFactory,
                                    NetworkInstanceUtils networkInstanceUtils)
Method Detail

start

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

Specified by:
start in interface ConnectionManager
Specified by:
start in interface Service

getServiceName

public String getServiceName()
Specified by:
getServiceName in interface Service

initialize

public void initialize()
Specified by:
initialize in interface Service

stop

public void stop()
Specified by:
stop in interface Service

createConnectionAsynchronously

public 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.

Specified by:
createConnectionAsynchronously in interface ConnectionManager

acceptConnection

public void acceptConnection(String word,
                             Socket socket)
Description copied from interface: ConnectionAcceptor
Notification that a new incoming socket has been opened.

Specified by:
acceptConnection in interface ConnectionAcceptor
Parameters:
word - first word that arrived on the wire
socket - the newly opened socket.

acceptConnection

public 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).

Specified by:
acceptConnection in interface ConnectionManager

remove

public 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.

Specified by:
remove in interface ConnectionManager
Parameters:
mc - the RoutedConnection instance to remove

isBlocking

public boolean isBlocking()
Description copied from interface: ConnectionAcceptor
Returns true, if ConnectionAcceptor.acceptConnection(String, Socket) needs to be invoked in a separate thread.

Specified by:
isBlocking in interface ConnectionAcceptor

isSupernode

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

Specified by:
isSupernode in interface ConnectionManager

isSupernodeCapable

public 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.

Specified by:
isSupernodeCapable in interface ConnectionManager

isBehindProxy

public boolean isBehindProxy()
Specified by:
isBehindProxy in interface ConnectionManager
Returns:
if we are currently using a http or socks4/5 proxy to connect.

isActiveSupernode

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

Specified by:
isActiveSupernode in interface ConnectionManager

isShieldedLeaf

public 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.

Specified by:
isShieldedLeaf in interface ConnectionManager

hasSupernodeClientConnection

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

Specified by:
hasSupernodeClientConnection in interface ConnectionManager

hasFreeSlots

public 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.

Specified by:
hasFreeSlots in interface ConnectionManager
Returns:
true if this node is an Ultrapeer with free leaf or Ultrapeer connections slots, otherwise false

isConnectedTo

public 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.

Specified by:
isConnectedTo in interface ConnectionManager
Returns:
true if this is probably connected to host

isConnectingTo

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

Specified by:
isConnectingTo in interface ConnectionManager

getNumFetchingConnections

public int getNumFetchingConnections()
Description copied from interface: ConnectionManager
Returns the number of connections that are currently being fetched.

Specified by:
getNumFetchingConnections in interface ConnectionManager

getNumConnections

public int getNumConnections()
Specified by:
getNumConnections in interface ConnectionManager
Returns:
the number of connections, which is greater than or equal to the number of initialized connections.

getNumInitializedConnections

public int getNumInitializedConnections()
Specified by:
getNumInitializedConnections in interface ConnectionManager
Returns:
the number of initialized connections, which is less than or equals to the number of connections.

getNumInitializedClientConnections

public int getNumInitializedClientConnections()
Specified by:
getNumInitializedClientConnections in interface ConnectionManager
Returns:
the number of initializedclient connections, which is less than or equals to the number of connections.

getNumClientSupernodeConnections

public int getNumClientSupernodeConnections()
Specified by:
getNumClientSupernodeConnections in interface ConnectionManager
Returns:
the number of initialized connections for which isClientSupernodeConnection is true.

getNumUltrapeerConnections

public int getNumUltrapeerConnections()
Specified by:
getNumUltrapeerConnections in interface ConnectionManager
Returns:
the number of ultrapeer -> ultrapeer connections.

getNumOldConnections

public int getNumOldConnections()
Specified by:
getNumOldConnections in interface ConnectionManager
Returns:
the number of old unrouted connections.

getNumFreeLeafSlots

public int getNumFreeLeafSlots()
Specified by:
getNumFreeLeafSlots in interface ConnectionManager
Returns:
the number of free leaf slots.

getNumFreeLimeWireLeafSlots

public int getNumFreeLimeWireLeafSlots()
Specified by:
getNumFreeLimeWireLeafSlots in interface ConnectionManager
Returns:
the number of free leaf slots that LimeWires can connect to.

getNumFreeNonLeafSlots

public int getNumFreeNonLeafSlots()
Specified by:
getNumFreeNonLeafSlots in interface ConnectionManager
Returns:
the number of free non-leaf slots.

getNumFreeLimeWireNonLeafSlots

public int getNumFreeLimeWireNonLeafSlots()
Specified by:
getNumFreeLimeWireNonLeafSlots in interface ConnectionManager
Returns:
the number of free non-leaf slots that LimeWires can connect to.

isLocaleMatched

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

Specified by:
isLocaleMatched in interface ConnectionManager

getNumLimeWireLocalePrefSlots

public int getNumLimeWireLocalePrefSlots()
Specified by:
getNumLimeWireLocalePrefSlots in interface ConnectionManager
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

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

Specified by:
isFullyConnected in interface ConnectionManager

isConnected

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

Specified by:
isConnected in interface ConnectionManager
Returns:
true if the client is currently connected to another Gnutella client, false otherwise

isConnecting

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

Specified by:
isConnecting in interface ConnectionManager

measureBandwidth

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

Specified by:
measureBandwidth in interface ConnectionManager
See Also:
BandwidthTracker.measureBandwidth()

getMeasuredUpstreamBandwidth

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

Specified by:
getMeasuredUpstreamBandwidth in interface ConnectionManager
See Also:
BandwidthTracker.measureBandwidth()

getMeasuredDownstreamBandwidth

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

Specified by:
getMeasuredDownstreamBandwidth in interface ConnectionManager
See Also:
BandwidthTracker.measureBandwidth()

allowConnectionAsLeaf

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

Specified by:
allowConnectionAsLeaf in interface ConnectionManager
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

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

Specified by:
allowConnection in interface ConnectionManager
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

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

Specified by:
allowAnyConnection in interface ConnectionManager
Returns:
true, if we have incoming slot of some kind, false otherwise

allowConnection

public 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.

Specified by:
allowConnection in interface ConnectionManager
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

public 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.

Specified by:
supernodeNeeded in interface ConnectionManager
Returns:
true, if more ultrapeers needed, false otherwise

getInitializedConnections

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

Specified by:
getInitializedConnections in interface ConnectionManager

getInitializedConnectionsMatchLocale

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

Specified by:
getInitializedConnectionsMatchLocale in interface ConnectionManager

getInitializedClientConnections

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

Specified by:
getInitializedClientConnections in interface ConnectionManager

getInitializedClientConnectionsMatchLocale

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

Specified by:
getInitializedClientConnectionsMatchLocale in interface ConnectionManager

getConnections

public List<RoutedConnection> getConnections()
Specified by:
getConnections in interface ConnectionManager
Returns:
all of this' connections.

getPushProxies

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

Specified by:
getPushProxies in interface ConnectionManager
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

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

Specified by:
sendTCPConnectBackRequests in interface ConnectionManager

sendUDPConnectBackRequests

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

Specified by:
sendUDPConnectBackRequests in interface ConnectionManager

updateQueryStatus

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

Specified by:
updateQueryStatus in interface ConnectionManager
Parameters:
-

getConnectedGUESSUltrapeer

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

Specified by:
getConnectedGUESSUltrapeer in interface ConnectionManager
Returns:
the Endpoint for an Ultrapeer connected via TCP if there is one, otherwise returns null

getConnectedGUESSUltrapeers

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

Specified by:
getConnectedGUESSUltrapeers in interface ConnectionManager
Returns:
A non-null List of GUESS enabled, TCP connected Ultrapeers. The are represented as ManagedConnections.

connectionInitializingIncoming

public 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.

Specified by:
connectionInitializingIncoming in interface ConnectionManager

connectionInitialized

public 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.

Specified by:
connectionInitialized in interface ConnectionManager

sendUpdatedCapabilities

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

Specified by:
sendUpdatedCapabilities in interface ConnectionManager

disconnect

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

Specified by:
disconnect in interface ConnectionManager
Parameters:
willTryToReconnect - Whether or not this is only a temporary disconnection

getCurrentAverageUptime

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

Specified by:
getCurrentAverageUptime in interface ConnectionManager

connect

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

Specified by:
connect in interface ConnectionManager

allowLeafDemotion

public 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.

Specified by:
allowLeafDemotion in interface ConnectionManager
Returns:
true if we will allow ourselves to become a leaf, otherwise false

tryToBecomeAnUltrapeer

public 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.

Specified by:
tryToBecomeAnUltrapeer in interface ConnectionManager
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

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

Specified by:
getPreferredConnectionCount in interface ConnectionManager

isConnectionIdle

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

Specified by:
isConnectionIdle in interface ConnectionManager

noInternetConnection

public 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.

Specified by:
noInternetConnection in interface ConnectionManager

addEventListener

public void addEventListener(ConnectionLifecycleListener listener)
Registers a listener for ConnectionLifeCycleEvents

Specified by:
addEventListener in interface EventDispatcher<ConnectionLifecycleEvent,ConnectionLifecycleListener>

dispatchEvent

public void dispatchEvent(ConnectionLifecycleEvent event)
Dispatches a ConnectionLifecycleEvent to any registered listeners

Specified by:
dispatchEvent in interface EventDispatcher<ConnectionLifecycleEvent,ConnectionLifecycleListener>

removeEventListener

public void removeEventListener(ConnectionLifecycleListener listener)
unregisters a listener for ConnectionLifeCycleEvents

Specified by:
removeEventListener in interface EventDispatcher<ConnectionLifecycleEvent,ConnectionLifecycleListener>

countConnectionsWithNMessages

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

Specified by:
countConnectionsWithNMessages in interface ConnectionManager

getActiveConnectionMessages

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

Specified by:
getActiveConnectionMessages in interface ConnectionManager

canSendConnectBack

public boolean canSendConnectBack(Message.Network network)
Specified by:
canSendConnectBack in interface ConnectionManager
Returns:
true if a connect back request can be sent on the provided network

connectBackSent

public void connectBackSent(Message.Network network)
Description copied from interface: ConnectionManager
notification that a connect back request has been sent on the given network

Specified by:
connectBackSent in interface ConnectionManager

handleEvent

public void handleEvent(GnutellaConnectionEvent event)
Description copied from interface: EventListener
Notification that an event has occurred and should be handled.

Specified by:
handleEvent in interface EventListener<GnutellaConnectionEvent>

LimeWire Consolidated API

Copyright © 2009. All Rights Reserved.