|
LimeWire Consolidated API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.limegroup.gnutella.connection.AbstractConnection
com.limegroup.gnutella.connection.GnutellaConnection
public class GnutellaConnection
A Connection managed by a ConnectionManager. GnutellaConnection provides a sophisticated message buffering mechanism. When you call send(Message), the message is not actually delivered to the socket; instead it buffered in an application-level buffer. Periodically, messages are read from the buffer and written to the network. Furthermore, GnutellaConnection provides a simple form of flow control. If messages are queued faster than they can be written to the network, they are dropped in the following order: PingRequest, PingReply, QueryRequest, QueryReply, and PushRequest. See the implementation notes below for more details.
All GnutellaConnection have two underlying spam filters: a personal filter (controls what I see) and a route filter (also controls what I pass along to others). See SpamFilter for a description. You can change them with setPersonalFilter and setRouteFilter.
GnutellaConnection maintain a large number of statistics, such as the current bandwidth for upstream & downstream.
GnutellaConnection also takes care of various VendorMessage handling, in particular Hops Flow, UDP ConnectBack, and TCP ConnectBack. See handleVendorMessage().
This class implements ReplyHandler to route pongs and query replies that originated from it.
| Nested Class Summary | |
|---|---|
static class |
GnutellaConnection.EventType
|
| Nested classes/interfaces inherited from interface org.limewire.io.IpPort |
|---|
IpPort.IpComparator, IpPort.IpPortComparator |
| Field Summary |
|---|
| Fields inherited from class com.limegroup.gnutella.connection.AbstractConnection |
|---|
CONNECTION_CLOSED, myIp, socket |
| Fields inherited from interface org.limewire.io.Connectable |
|---|
COMPARATOR, EMPTY_LIST, EMPTY_SET |
| Fields inherited from interface org.limewire.io.IpPort |
|---|
IP_COMPARATOR |
| Constructor Summary | |
|---|---|
GnutellaConnection(Socket socket,
ConnectionManager connectionManager,
NetworkManager networkManager,
QueryRequestFactory queryRequestFactory,
HeadersFactory headersFactory,
HandshakeResponderFactory handshakeResponderFactory,
QueryReplyFactory queryReplyFactory,
MessageDispatcher messageDispatcher,
NetworkUpdateSanityChecker networkUpdateSanityChecker,
SearchResultHandler searchResultHandler,
CapabilitiesVMFactory capabilitiesVMFactory,
Acceptor acceptor,
MessagesSupportedVendorMessage supportedVendorMessage,
com.google.inject.Provider<SimppManager> simppManager,
com.google.inject.Provider<UpdateHandler> updateHandler,
com.google.inject.Provider<ConnectionServices> connectionServices,
GuidMapManager guidMapManager,
SpamFilterFactory spamFilterFactory,
MessageReaderFactory messageReaderFactory,
MessageFactory messageFactory,
ApplicationServices applicationServices,
SecureMessageVerifier secureMessageVerifier,
OutOfBandStatistics outOfBandStatistics,
NetworkInstanceUtils networkInstanceUtils)
Creates an incoming connection. |
|
GnutellaConnection(String host,
int port,
SocketsManager.ConnectType type,
ConnectionManager connectionManager,
NetworkManager networkManager,
QueryRequestFactory queryRequestFactory,
HeadersFactory headersFactory,
HandshakeResponderFactory handshakeResponderFactory,
QueryReplyFactory queryReplyFactory,
MessageDispatcher messageDispatcher,
NetworkUpdateSanityChecker networkUpdateSanityChecker,
SearchResultHandler searchResultHandler,
CapabilitiesVMFactory capabilitiesVMFactory,
SocketsManager socketsManager,
Acceptor acceptor,
MessagesSupportedVendorMessage supportedVendorMessage,
com.google.inject.Provider<SimppManager> simppManager,
com.google.inject.Provider<UpdateHandler> updateHandler,
com.google.inject.Provider<ConnectionServices> connectionServices,
GuidMapManager guidMapManager,
SpamFilterFactory spamFilterFactory,
MessageReaderFactory messageReaderFactory,
MessageFactory messageFactory,
ApplicationServices applicationServices,
SecureMessageVerifier secureMessageVerifier,
OutOfBandStatistics outOfBandStatistics,
NetworkInstanceUtils networkInstanceUtils)
Creates a new outgoing connection to the specified host on the specified port, using the specified kind of ConnectType. |
|
| Method Summary | |
|---|---|
void |
addListener(EventListener<GnutellaConnectionEvent> listener)
Adds the listener. |
protected void |
closeImpl()
This should be implemented by subclasses to close any resources they acquired during the lifetime of the connection. |
void |
countDroppedMessage()
A callback for the ConnectionManager to inform this connection that a message was dropped. |
byte[] |
getClientGUID()
Gets the clientGUID of this ReplyHandler. |
ConnectionMessageStatistics |
getConnectionMessageStatistics()
|
float |
getMeasuredDownstreamBandwidth()
Returns the downstream bandwidth between the last two calls to measureBandwidth. |
float |
getMeasuredUpstreamBandwidth()
Returns the upstream bandwidth between the last two calls to measureBandwidth. |
Message.Network |
getNetwork()
The network this message-receiver uses for creating messages. |
long |
getNextQRPForwardTime()
Returns the system time that we should next forward a query route table along this connection. |
int |
getNumMessagesReceived()
Returns the number of messages received on this connection |
int |
getNumMessagesSent()
Returns the number of messages sent on this connection |
long |
getNumQueriesReceived()
Returns the number of queries received over this connection. |
long |
getNumQueryReplies()
Returns the number of query replies received over this connection. |
long |
getNumReceivedMessagesDropped()
The number of messages received on this connection either filtered out or dropped because we didn't know how to route them. |
int |
getNumSentMessagesDropped()
Returns the number of messages I dropped while trying to send on this connection. |
Object |
getQRPLock()
|
int |
getQueryRouteTableEmptyUnits()
Accessor for the last QueryRouteTable's Empty Units. |
double |
getQueryRouteTablePercentFull()
Accessor for the last QueryRouteTable's percent full. |
QueryRouteTable |
getQueryRouteTableReceived()
Accessor for the QueryRouteTable received along this connection. |
QueryRouteTable |
getQueryRouteTableSent()
Accessor for the query route table associated with this. |
int |
getQueryRouteTableSize()
Accessor for the last QueryRouteTable's size. |
int |
getQueryRouteTableUnitsInUse()
Accessor for the last QueryRouteTable's Units In Use. |
ConnectionRoutingStatistics |
getRoutedConnectionStatistics()
|
byte |
getSoftMax()
The soft-max this message-receiver uses for creating messages. |
void |
handlePingReply(PingReply pingReply,
ReplyHandler receivingConnection)
Handle the PingReply, failing silently |
void |
handlePushRequest(PushRequest pushRequest,
ReplyHandler receivingConnection)
Handle the PushRequest, failing silently |
void |
handleQueryReply(QueryReply queryReply,
ReplyHandler receivingConnection)
Handle the QueryReply, failing silently |
void |
handleVendorMessage(VendorMessage vm)
Call this method when you want to handle us to handle a VM. |
protected boolean |
hitsQueryRouteTable(QueryRequest query)
Determines whether or not this query hits the QRT. |
void |
incrementNextQRPForwardTime(long curTime)
Increments the next time we should forward query route tables for this connection. |
void |
initialize(GnetConnectObserver observer)
Attempts to initialize the connection. |
protected void |
initialize(Properties requestHeaders,
HandshakeResponder responder,
int timeout,
GnetConnectObserver observer)
Initialize the connection by doing the handshake. |
Map<String,Object> |
inspect()
|
boolean |
isBusyLeaf()
Returns true iff this connection is a shielded leaf connection, and has signalled that it does not want to receive routed queries (no upload slots or some other reason). |
boolean |
isGoodLeaf()
Returns whether or not this handler is considered a "good" leaf connection. |
boolean |
isGoodUltrapeer()
Returns whether or not this handler is considered a "good" Ultrapeer connection. |
boolean |
isHighDegreeConnection()
Returns whether or not this connection is a high-degree connection, meaning that it maintains a high number of intra-Ultrapeer connections. |
boolean |
isKillable()
Returns whether or not this handler is killable by the handler watchdog. |
boolean |
isLeafConnection()
Returns whether or not this reply handler is a leaf -- whether or not the host on the other end of this connection is a leaf of this (necessarily) Ultrapeer. |
boolean |
isMyPushProxy()
Returns whether or not this connection is a push proxy for me |
boolean |
isPersonalSpam(Message m)
|
boolean |
isPushProxyFor()
Returns whether or not I'm a push proxy for this connection |
boolean |
isSupernodeClientConnection()
Returns whether or not this ReplyHandler sends replies from an Ultrapeer to a leaf. |
boolean |
isUltrapeerQueryRoutingConnection()
Returns whether or not this handler uses Ultrapeer query routing. |
void |
measureBandwidth()
Takes a snapshot of the upstream and downstream bandwidth since the last call to measureBandwidth. |
void |
messagingClosed()
Notification that the stream is closed. |
void |
originateQuery(QueryRequest query)
This is a specialized send method for queries that we originate, either from ourselves directly, or on behalf of one of our leaves when we're an Ultrapeer. |
void |
patchQueryRouteTable(PatchTableMessage ptm)
Patches the QueryRouteTable for this connection. |
void |
processReadMessage(Message m)
Notification that a message is available for processing. |
void |
processSentMessage(Message m)
|
boolean |
removeListener(EventListener<GnutellaConnectionEvent> listener)
Returns true if the listener was removed. |
void |
reply(Message m)
Just sends whatever message we ask it to. |
void |
resetQueryRouteTable(ResetTableMessage rtm)
Resets the query route table for this connection. |
void |
send(Message m)
Sends the message through this connection. |
void |
setBusy(boolean bSet)
Set's a leaf's busy timer to now, if bSet is true, else clears the flag |
void |
setLocalePreferencing(boolean b)
set preferencing for the responder (The preference of the Responder is used when creating the response (in Connection.java: conclude..)) |
void |
setPersonalFilter(SpamFilter filter)
|
void |
setPushProxyFor(boolean pushProxyFor)
Sets whether or not I'm a push proxy for this connection |
void |
setQueryRouteTableSent(QueryRouteTable qrt)
Mutator for the last query route table that was sent along this connection. |
void |
setRouteFilter(SpamFilter filter)
|
boolean |
shouldForwardQuery(QueryRequest query)
Determines whether or not the specified QueryRequest instance should be sent to the connection. |
void |
shutdown()
Releases any resources used by this component. |
void |
startMessaging()
Handles core Gnutella request/reply protocol. |
boolean |
supportsPongCaching()
Returns whether or not this node supports pong caching. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface com.limegroup.gnutella.connection.Connection |
|---|
allowNewPings, allowNewPongs, close, getAddress, getConnectionBandwidthStatistics, getConnectionCapabilities, getConnectionTime, getInetAddress, getInetSocketAddress, getListeningPort, getLocalePref, getPort, getPropertyWritten, getSocket, handleSimppVM, isOpen, isOutgoing, isReadDeflated, isStable, isStable, isTLSCapable, isTLSEncoded, isWriteDeflated, sendPostInitializeMessages, sendUpdatedCapabilities, setListeningPort |
| Methods inherited from interface org.limewire.io.Address |
|---|
equals, getAddressDescription, hashCode |
| Methods inherited from interface com.limegroup.gnutella.ReplyHandler |
|---|
allowNewPings, getLocalePref, handleSimppVM, isOpen, isOutgoing, isStable |
| Constructor Detail |
|---|
public GnutellaConnection(String host,
int port,
SocketsManager.ConnectType type,
ConnectionManager connectionManager,
NetworkManager networkManager,
QueryRequestFactory queryRequestFactory,
HeadersFactory headersFactory,
HandshakeResponderFactory handshakeResponderFactory,
QueryReplyFactory queryReplyFactory,
MessageDispatcher messageDispatcher,
NetworkUpdateSanityChecker networkUpdateSanityChecker,
SearchResultHandler searchResultHandler,
CapabilitiesVMFactory capabilitiesVMFactory,
SocketsManager socketsManager,
Acceptor acceptor,
MessagesSupportedVendorMessage supportedVendorMessage,
com.google.inject.Provider<SimppManager> simppManager,
com.google.inject.Provider<UpdateHandler> updateHandler,
com.google.inject.Provider<ConnectionServices> connectionServices,
GuidMapManager guidMapManager,
SpamFilterFactory spamFilterFactory,
MessageReaderFactory messageReaderFactory,
MessageFactory messageFactory,
ApplicationServices applicationServices,
SecureMessageVerifier secureMessageVerifier,
OutOfBandStatistics outOfBandStatistics,
NetworkInstanceUtils networkInstanceUtils)
host - the address of the host we're connecting toport - the port the host is listening ontype - the type of outgoing connection we want to make (TLS, PLAIN,
etc)
public GnutellaConnection(Socket socket,
ConnectionManager connectionManager,
NetworkManager networkManager,
QueryRequestFactory queryRequestFactory,
HeadersFactory headersFactory,
HandshakeResponderFactory handshakeResponderFactory,
QueryReplyFactory queryReplyFactory,
MessageDispatcher messageDispatcher,
NetworkUpdateSanityChecker networkUpdateSanityChecker,
SearchResultHandler searchResultHandler,
CapabilitiesVMFactory capabilitiesVMFactory,
Acceptor acceptor,
MessagesSupportedVendorMessage supportedVendorMessage,
com.google.inject.Provider<SimppManager> simppManager,
com.google.inject.Provider<UpdateHandler> updateHandler,
com.google.inject.Provider<ConnectionServices> connectionServices,
GuidMapManager guidMapManager,
SpamFilterFactory spamFilterFactory,
MessageReaderFactory messageReaderFactory,
MessageFactory messageFactory,
ApplicationServices applicationServices,
SecureMessageVerifier secureMessageVerifier,
OutOfBandStatistics outOfBandStatistics,
NetworkInstanceUtils networkInstanceUtils)
| Method Detail |
|---|
public void initialize(GnetConnectObserver observer)
throws IOException
RoutedConnection
initialize in interface RoutedConnectionIOException
protected void initialize(Properties requestHeaders,
HandshakeResponder responder,
int timeout,
GnetConnectObserver observer)
throws IOException
timeout - for outgoing connections, the timeout in milliseconds to
use in establishing the socket, or 0 for no timeout. If the
platform does not support native timeouts, it will be emulated
with threads.
IOException - we were unable to connect to the host
NoGnutellaOkException - one of the participants responded with
an error code other than 200 OK (possibly after several rounds
of 401's)
BadHandshakeException - some other problem establishing the
connection, e.g., the server responded with HTTP, closed the
the connection during handshaking, etc.public void resetQueryRouteTable(ResetTableMessage rtm)
RoutedConnection
resetQueryRouteTable in interface RoutedConnectionrtm - the ResetTableMessagepublic void patchQueryRouteTable(PatchTableMessage ptm)
RoutedConnection
patchQueryRouteTable in interface RoutedConnectionptm - the patch with the data to updatepublic void setBusy(boolean bSet)
bSet - Whether to SET or CLEAR the busy timer for this hostpublic boolean isBusyLeaf()
RoutedConnection
isBusyLeaf in interface RoutedConnectionpublic boolean shouldForwardQuery(QueryRequest query)
RoutedConnection
shouldForwardQuery in interface RoutedConnectionquery - the QueryRequest to check against the data
protected boolean hitsQueryRouteTable(QueryRequest query)
public QueryRouteTable getQueryRouteTableReceived()
ConnectionRoutingStatistics
getQueryRouteTableReceived in interface ConnectionRoutingStatisticspublic double getQueryRouteTablePercentFull()
ConnectionRoutingStatistics
getQueryRouteTablePercentFull in interface ConnectionRoutingStatisticspublic int getQueryRouteTableSize()
ConnectionRoutingStatistics
getQueryRouteTableSize in interface ConnectionRoutingStatisticspublic int getQueryRouteTableEmptyUnits()
ConnectionRoutingStatistics
getQueryRouteTableEmptyUnits in interface ConnectionRoutingStatisticspublic int getQueryRouteTableUnitsInUse()
ConnectionRoutingStatistics
getQueryRouteTableUnitsInUse in interface ConnectionRoutingStatisticspublic void send(Message m)
RoutedConnection
send in interface Connectionsend in interface RoutedConnectionpublic void originateQuery(QueryRequest query)
RoutedConnection
originateQuery in interface RoutedConnectionquery - the QueryRequest to sendpublic void shutdown()
Shutdownable
shutdown must never throw any exceptions.
shutdown in interface Shutdownableprotected void closeImpl()
AbstractConnection
closeImpl in class AbstractConnectionpublic void startMessaging()
startMessaging in interface RoutedConnectionIOException - passed on from the receive call; failures to forward
or route messages are silently swallowed, allowing the message
loop to continue.public void messagingClosed()
MessageReceiver
messagingClosed in interface MessageReceiverpublic void processReadMessage(Message m)
MessageReceiver
processReadMessage in interface MessageReceiverprocessReadMessage in class AbstractConnectionpublic void processSentMessage(Message m)
processSentMessage in interface SentMessageHandlerpublic long getNumQueryReplies()
ConnectionMessageStatistics
getNumQueryReplies in interface ConnectionMessageStatisticspublic long getNumQueriesReceived()
ConnectionMessageStatistics
getNumQueriesReceived in interface ConnectionMessageStatisticspublic Message.Network getNetwork()
MessageReceiver
getNetwork in interface MessageReceiverpublic byte getSoftMax()
MessageReceiver
getSoftMax in interface MessageReceivergetSoftMax in class AbstractConnectionpublic void countDroppedMessage()
ConnectionMessageStatistics
countDroppedMessage in interface ConnectionMessageStatisticscountDroppedMessage in interface ReplyHandlerpublic boolean isPersonalSpam(Message m)
isPersonalSpam in interface ReplyHandlerpublic void setRouteFilter(SpamFilter filter)
setRouteFilter in interface RoutedConnectionpublic void setPersonalFilter(SpamFilter filter)
setPersonalFilter in interface RoutedConnection
public void handlePingReply(PingReply pingReply,
ReplyHandler receivingConnection)
ReplyHandler
handlePingReply in interface ReplyHandler
public void handleQueryReply(QueryReply queryReply,
ReplyHandler receivingConnection)
ReplyHandler
handleQueryReply in interface ReplyHandlerpublic byte[] getClientGUID()
ReplyHandler
getClientGUID in interface ReplyHandler
public void handlePushRequest(PushRequest pushRequest,
ReplyHandler receivingConnection)
ReplyHandler
handlePushRequest in interface ReplyHandlerpublic void handleVendorMessage(VendorMessage vm)
AbstractConnection
handleVendorMessage in interface ConnectionhandleVendorMessage in class AbstractConnectionpublic void addListener(EventListener<GnutellaConnectionEvent> listener)
ListenerSupport
addListener in interface ListenerSupport<GnutellaConnectionEvent>public boolean removeListener(EventListener<GnutellaConnectionEvent> listener)
ListenerSupport
removeListener in interface ListenerSupport<GnutellaConnectionEvent>public int getNumMessagesSent()
ConnectionMessageStatistics
getNumMessagesSent in interface ConnectionMessageStatisticspublic int getNumMessagesReceived()
ConnectionMessageStatistics
getNumMessagesReceived in interface ConnectionMessageStatisticsgetNumMessagesReceived in interface ReplyHandlerpublic int getNumSentMessagesDropped()
ConnectionMessageStatistics
getNumSentMessagesDropped in interface ConnectionMessageStatisticspublic long getNumReceivedMessagesDropped()
ConnectionMessageStatistics
getNumReceivedMessagesDropped in interface ConnectionMessageStatisticspublic void measureBandwidth()
RoutedConnection
measureBandwidth in interface RoutedConnectionBandwidthTracker.measureBandwidth()public float getMeasuredUpstreamBandwidth()
RoutedConnection
getMeasuredUpstreamBandwidth in interface RoutedConnectionBandwidthTracker.measureBandwidth()public float getMeasuredDownstreamBandwidth()
RoutedConnection
getMeasuredDownstreamBandwidth in interface RoutedConnectionBandwidthTracker.measureBandwidth()public long getNextQRPForwardTime()
ConnectionRoutingStatistics
getNextQRPForwardTime in interface ConnectionRoutingStatisticspublic void incrementNextQRPForwardTime(long curTime)
ConnectionRoutingStatistics
incrementNextQRPForwardTime in interface ConnectionRoutingStatisticscurTime - the current time in milliseconds, used to calculate the
next update timepublic boolean isKillable()
ReplyHandler
isKillable in interface ReplyHandlerpublic QueryRouteTable getQueryRouteTableSent()
ConnectionRoutingStatistics
getQueryRouteTableSent in interface ConnectionRoutingStatisticspublic void setQueryRouteTableSent(QueryRouteTable qrt)
ConnectionRoutingStatistics
setQueryRouteTableSent in interface ConnectionRoutingStatisticsqrt - the last query route table that was sent along this connectionpublic boolean isMyPushProxy()
RoutedConnection
isMyPushProxy in interface RoutedConnectionpublic boolean isPushProxyFor()
RoutedConnection
isPushProxyFor in interface RoutedConnectionpublic void setPushProxyFor(boolean pushProxyFor)
RoutedConnection
setPushProxyFor in interface RoutedConnectionpublic Object getQRPLock()
getQRPLock in interface RoutedConnectionpublic void setLocalePreferencing(boolean b)
RoutedConnection
setLocalePreferencing in interface RoutedConnectionpublic void reply(Message m)
ReplyHandler
reply in interface ReplyHandlerpublic Map<String,Object> inspect()
inspect in interface Inspectablepublic ConnectionRoutingStatistics getRoutedConnectionStatistics()
getRoutedConnectionStatistics in interface RoutedConnectionpublic final boolean isGoodLeaf()
ReplyHandler
isGoodLeaf in interface ReplyHandlerpublic final boolean isGoodUltrapeer()
ReplyHandler
isGoodUltrapeer in interface ReplyHandlerpublic final boolean isHighDegreeConnection()
ReplyHandler
isHighDegreeConnection in interface ReplyHandlerpublic final boolean isLeafConnection()
ReplyHandler
isLeafConnection in interface ReplyHandlerpublic final boolean isSupernodeClientConnection()
ReplyHandler
isSupernodeClientConnection in interface ReplyHandlerpublic final boolean isUltrapeerQueryRoutingConnection()
ReplyHandler
isUltrapeerQueryRoutingConnection in interface ReplyHandlerpublic final boolean supportsPongCaching()
ReplyHandler
supportsPongCaching in interface ReplyHandlerpublic final ConnectionMessageStatistics getConnectionMessageStatistics()
getConnectionMessageStatistics in interface RoutedConnection
|
LimeWire Consolidated API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||