|
LimeWire Consolidated API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.limegroup.gnutella.ConnectionManagerImpl
public class ConnectionManagerImpl
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 |
|---|
@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 |
|---|
public void start()
start in interface ConnectionManagerstart in interface Servicepublic String getServiceName()
getServiceName in interface Servicepublic void initialize()
initialize in interface Servicepublic void stop()
stop in interface Service
public void createConnectionAsynchronously(String hostname,
int portnum,
SocketsManager.ConnectType type)
createConnectionAsynchronously in interface ConnectionManager
public void acceptConnection(String word,
Socket socket)
ConnectionAcceptor
acceptConnection in interface ConnectionAcceptorword - first word that arrived on the wiresocket - the newly opened socket.public void acceptConnection(Socket socket)
acceptConnection in interface ConnectionManagerpublic void remove(RoutedConnection mc)
remove in interface ConnectionManagermc - the RoutedConnection instance to removepublic boolean isBlocking()
ConnectionAcceptorConnectionAcceptor.acceptConnection(String, Socket) needs to be
invoked in a separate thread.
isBlocking in interface ConnectionAcceptorpublic boolean isSupernode()
isSupernode in interface ConnectionManagerpublic boolean isSupernodeCapable()
isSupernodeCapable in interface ConnectionManagerpublic boolean isBehindProxy()
isBehindProxy in interface ConnectionManagerpublic boolean isActiveSupernode()
isActiveSupernode in interface ConnectionManagerpublic boolean isShieldedLeaf()
isShieldedLeaf in interface ConnectionManagerpublic boolean hasSupernodeClientConnection()
hasSupernodeClientConnection in interface ConnectionManagerpublic boolean hasFreeSlots()
hasFreeSlots in interface ConnectionManagerpublic boolean isConnectedTo(String hostName)
isConnectedTo in interface ConnectionManagerpublic boolean isConnectingTo(IpPort host)
isConnectingTo in interface ConnectionManagerpublic int getNumFetchingConnections()
ConnectionManager
getNumFetchingConnections in interface ConnectionManagerpublic int getNumConnections()
getNumConnections in interface ConnectionManagerpublic int getNumInitializedConnections()
getNumInitializedConnections in interface ConnectionManagerpublic int getNumInitializedClientConnections()
getNumInitializedClientConnections in interface ConnectionManagerpublic int getNumClientSupernodeConnections()
getNumClientSupernodeConnections in interface ConnectionManagerpublic int getNumUltrapeerConnections()
getNumUltrapeerConnections in interface ConnectionManagerpublic int getNumOldConnections()
getNumOldConnections in interface ConnectionManagerpublic int getNumFreeLeafSlots()
getNumFreeLeafSlots in interface ConnectionManagerpublic int getNumFreeLimeWireLeafSlots()
getNumFreeLimeWireLeafSlots in interface ConnectionManagerpublic int getNumFreeNonLeafSlots()
getNumFreeNonLeafSlots in interface ConnectionManagerpublic int getNumFreeLimeWireNonLeafSlots()
getNumFreeLimeWireNonLeafSlots in interface ConnectionManagerpublic boolean isLocaleMatched()
isLocaleMatched in interface ConnectionManagerpublic int getNumLimeWireLocalePrefSlots()
getNumLimeWireLocalePrefSlots in interface ConnectionManagerpublic boolean isFullyConnected()
isFullyConnected in interface ConnectionManagerpublic boolean isConnected()
isConnected in interface ConnectionManagerpublic boolean isConnecting()
isConnecting in interface ConnectionManagerpublic void measureBandwidth()
measureBandwidth in interface ConnectionManagerBandwidthTracker.measureBandwidth()public float getMeasuredUpstreamBandwidth()
getMeasuredUpstreamBandwidth in interface ConnectionManagerBandwidthTracker.measureBandwidth()public float getMeasuredDownstreamBandwidth()
getMeasuredDownstreamBandwidth in interface ConnectionManagerBandwidthTracker.measureBandwidth()public HandshakeStatus allowConnectionAsLeaf(HandshakeResponse hr)
allowConnectionAsLeaf in interface ConnectionManagerc - The connection we received, for which to
test if we have incoming slot.
public HandshakeStatus allowConnection(HandshakeResponse hr)
allowConnection in interface ConnectionManagerc - The connection we received, for which to
test if we have incoming slot.
public boolean allowAnyConnection()
allowAnyConnection in interface ConnectionManager
public HandshakeStatus allowConnection(HandshakeResponse hr,
boolean leaf)
allowConnection in interface ConnectionManageroutgoing - true if this is an outgoing connection; true if incomingultrapeerHeader - the value of the X-Ultrapeer header, or null
if it was not writtenuseragentHeader - the value of the User-Agent header, or null if
it was not written
public boolean supernodeNeeded()
supernodeNeeded in interface ConnectionManagerpublic List<RoutedConnection> getInitializedConnections()
getInitializedConnections in interface ConnectionManagerpublic List<RoutedConnection> getInitializedConnectionsMatchLocale(String loc)
getInitializedConnectionsMatchLocale in interface ConnectionManagerpublic List<RoutedConnection> getInitializedClientConnections()
getInitializedClientConnections in interface ConnectionManagerpublic List<RoutedConnection> getInitializedClientConnectionsMatchLocale(String loc)
getInitializedClientConnectionsMatchLocale in interface ConnectionManagerpublic List<RoutedConnection> getConnections()
getConnections in interface ConnectionManagerpublic Set<Connectable> getPushProxies()
getPushProxies in interface ConnectionManagerpublic boolean sendTCPConnectBackRequests()
sendTCPConnectBackRequests in interface ConnectionManagerpublic boolean sendUDPConnectBackRequests(GUID cbGuid)
sendUDPConnectBackRequests in interface ConnectionManagerpublic void updateQueryStatus(QueryStatusResponse stat)
updateQueryStatus in interface ConnectionManager - public Endpoint getConnectedGUESSUltrapeer()
getConnectedGUESSUltrapeer in interface ConnectionManagerpublic List<RoutedConnection> getConnectedGUESSUltrapeers()
getConnectedGUESSUltrapeers in interface ConnectionManagerpublic void connectionInitializingIncoming(RoutedConnection c)
connectionInitializingIncoming in interface ConnectionManagerpublic boolean connectionInitialized(RoutedConnection c)
connectionInitialized in interface ConnectionManagerpublic void sendUpdatedCapabilities()
sendUpdatedCapabilities in interface ConnectionManagerpublic void disconnect(boolean willTryToReconnect)
disconnect in interface ConnectionManagerwillTryToReconnect - Whether or not this is only a temporary disconnectionpublic long getCurrentAverageUptime()
getCurrentAverageUptime in interface ConnectionManagerpublic void connect()
connect in interface ConnectionManagerpublic boolean allowLeafDemotion()
allowLeafDemotion in interface ConnectionManagerpublic void tryToBecomeAnUltrapeer(int demotionLimit)
tryToBecomeAnUltrapeer in interface ConnectionManagerdemotionLimit - 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 Ultrapeerpublic int getPreferredConnectionCount()
getPreferredConnectionCount in interface ConnectionManagerpublic boolean isConnectionIdle()
isConnectionIdle in interface ConnectionManagerpublic void noInternetConnection()
noInternetConnection in interface ConnectionManagerpublic void addEventListener(ConnectionLifecycleListener listener)
addEventListener in interface EventDispatcher<ConnectionLifecycleEvent,ConnectionLifecycleListener>public void dispatchEvent(ConnectionLifecycleEvent event)
dispatchEvent in interface EventDispatcher<ConnectionLifecycleEvent,ConnectionLifecycleListener>public void removeEventListener(ConnectionLifecycleListener listener)
removeEventListener in interface EventDispatcher<ConnectionLifecycleEvent,ConnectionLifecycleListener>public int countConnectionsWithNMessages(int messageThreshold)
countConnectionsWithNMessages in interface ConnectionManagerpublic int getActiveConnectionMessages()
getActiveConnectionMessages in interface ConnectionManagerpublic boolean canSendConnectBack(Message.Network network)
canSendConnectBack in interface ConnectionManagerpublic void connectBackSent(Message.Network network)
ConnectionManager
connectBackSent in interface ConnectionManagerpublic void handleEvent(GnutellaConnectionEvent event)
EventListener
handleEvent in interface EventListener<GnutellaConnectionEvent>
|
LimeWire Consolidated API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||