|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.limegroup.gnutella.Connection
com.limegroup.gnutella.ManagedConnection
A Connection managed by a ConnectionManager. Includes a loopForMessages method that runs forever (or until an IOException occurs), receiving and replying to Gnutella messages. ManagedConnection is only instantiated through a ConnectionManager.
ManagedConnection 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, a thread reads messages from the buffer, writes them to the network, and flushes the socket buffers. This means that there is no need to manually call flush(). Furthermore, ManagedConnection 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 ManagedConnection's 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. These filters are configured by the properties in the SettingsManager, but you can change them with setPersonalFilter and setRouteFilter.
ManagedConnection maintain a large number of statistics, such as the current bandwidth for upstream & downstream. ManagedConnection doesn't quite fit the BandwidthTracker interface, unfortunately. On the query-routing3-branch and pong-caching CVS branches, these statistics have been bundled into a single object, reducing the complexity of ManagedConnection.
ManagedConnection 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.
Field Summary |
Fields inherited from class com.limegroup.gnutella.Connection |
_200_OK, _closed, _messagesSupported, CONNECT, CONNECTION_CLOSED, CRLF, GNUTELLA_06, GNUTELLA_06_200, GNUTELLA_OK_06, MAX_HANDSHAKE_ATTEMPTS, USER_INPUT_WAIT_TIME |
Constructor Summary | |
ManagedConnection(java.lang.String host,
int port)
Creates a new outgoing connection to the specified host on the specified port. |
Method Summary | |
void |
addReceived()
Increments the stat for the number of messages received. |
void |
addReceivedDropped()
Increments the number of received messages that have been dropped. |
void |
buildAndStartQueues()
Builds queues and starts the OutputRunner. |
void |
close()
Closes the Connection's socket and thus the connection itself. |
void |
countDroppedMessage()
A callback for the ConnectionManager to inform this connection that a message was dropped. |
void |
flush()
Does nothing. |
java.util.Set |
getDomains()
Returns the domain to which this connection is authenticated |
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. |
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 |
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. |
protected java.io.OutputStream |
getOutputStream()
Throttles the super's OutputStream. |
float |
getPercentReceivedDropped()
|
float |
getPercentSentDropped()
|
java.net.InetAddress |
getPushProxyAddress()
|
int |
getPushProxyPort()
|
java.lang.Object |
getQRPLock()
|
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. |
void |
handlePingReply(PingReply pingReply,
ReplyHandler receivingConnection)
This method is called when a reply is received for a PingRequest originating on this Connection. |
void |
handlePushRequest(PushRequest pushRequest,
ReplyHandler receivingConnection)
This method is called when a PushRequest is received for a QueryReply originating on this Connection. |
void |
handleQueryReply(QueryReply queryReply,
ReplyHandler receivingConnection)
This method is called when a reply is received for a QueryRequest originating on this Connection. |
protected void |
handleVendorMessage(VendorMessage vm)
Call this method when you want to handle us to handle a VM. |
boolean |
hitsQueryRouteTable(QueryRequest query)
Determines whether or not the specified QueryRequest instance has a hit in the query routing tables. |
void |
incrementNextQRPForwardTime(long curTime)
Increments the next time we should forward query route tables for this connection. |
void |
initialize()
Initializes this without timeout; exactly like initialize(0). |
boolean |
isKillable()
Returns true if this should not be policed by the ConnectionWatchdog, e.g., because this is a connection to a Clip2 reflector. |
boolean |
isPersonalSpam(Message m)
A callback for Message Handler implementations to check to see if a message is considered to be undesirable by the message's receiving connection. |
boolean |
isSpam(Message m)
Utility method for checking whether or not this message is considered spam. |
void |
measureBandwidth()
Takes a snapshot of the upstream and downstream bandwidth since the last call to measureBandwidth. |
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. |
Message |
receive()
Override of receive to do ConnectionManager stats and to properly shut down the connection on IOException |
Message |
receive(int timeout)
Override of receive to do MessageRouter stats and to properly shut down the connection on IOException |
void |
resetQueryRouteTable(ResetTableMessage rtm)
Resets the query route table for this connection. |
void |
send(Message m)
Sends a message. |
void |
setHorizonEnabled(boolean enable)
|
void |
setPersonalFilter(SpamFilter filter)
|
void |
setQueryRouteTableSent(QueryRouteTable qrt)
Mutator for the last query route table that was sent along this connection. |
void |
setRouteFilter(SpamFilter filter)
|
void |
updateHorizonStats(PingReply pingReply)
This method is called when a reply is received by this connection for a PingRequest that originated from LimeWire. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.limegroup.gnutella.ReplyHandler |
allowNewPings, getInetAddress, isGoodLeaf, isGoodUltrapeer, isHighDegreeConnection, isLeafConnection, isOpen, isOutgoing, isStable, isSupernodeClientConnection, isUltrapeerQueryRoutingConnection, supportsPongCaching |
Constructor Detail |
public ManagedConnection(java.lang.String host, int port)
host
- the address of the host we're connecting toport
- the port the host is listening onMethod Detail |
public void initialize() throws java.io.IOException, NoGnutellaOkException, BadHandshakeException
Connection
initialize
in class Connection
java.io.IOException
NoGnutellaOkException
BadHandshakeException
Connection.initialize(int)
public void resetQueryRouteTable(ResetTableMessage rtm)
rtm
- the ResetTableMessagepublic void patchQueryRouteTable(PatchTableMessage ptm)
ptm
- the patch with the data to updatepublic boolean hitsQueryRouteTable(QueryRequest query)
query
- the QueryRequest to check against
the tables
public QueryRouteTable getQueryRouteTableReceived()
public double getQueryRouteTablePercentFull()
protected java.io.OutputStream getOutputStream() throws java.io.IOException
getOutputStream
in class Connection
java.io.IOException
public Message receive() throws java.io.IOException, BadPacketException
receive
in class Connection
java.io.IOException
BadPacketException
public Message receive(int timeout) throws java.io.IOException, BadPacketException, java.io.InterruptedIOException
receive
in class Connection
java.io.IOException
BadPacketException
java.io.InterruptedIOException
public void send(Message m)
This method IS thread safe. Multiple threads can be in a send call at the same time for a given connection.
send
in class Connection
public void originateQuery(QueryRequest query)
query
- the QueryRequest to sendpublic void addReceivedDropped()
public void addReceived()
public void flush() throws java.io.IOException
flush
in class Connection
java.io.IOException
public void buildAndStartQueues()
public void close()
Connection
close
in class Connection
public boolean isSpam(Message m)
m
- the Message to check
public void countDroppedMessage()
countDroppedMessage
in interface ReplyHandler
public boolean isPersonalSpam(Message m)
isPersonalSpam
in interface ReplyHandler
public void setRouteFilter(SpamFilter filter)
public void setPersonalFilter(SpamFilter filter)
public java.util.Set getDomains()
getDomains
in interface ReplyHandler
public void handlePingReply(PingReply pingReply, ReplyHandler receivingConnection)
handlePingReply
in interface ReplyHandler
public void handleQueryReply(QueryReply queryReply, ReplyHandler receivingConnection)
handleQueryReply
in interface ReplyHandler
public void handlePushRequest(PushRequest pushRequest, ReplyHandler receivingConnection)
handlePushRequest
in interface ReplyHandler
protected void handleVendorMessage(VendorMessage vm)
Connection
handleVendorMessage
in class Connection
public int getNumMessagesSent()
public int getNumMessagesReceived()
getNumMessagesReceived
in interface ReplyHandler
public int getNumSentMessagesDropped()
public long getNumReceivedMessagesDropped()
public float getPercentReceivedDropped()
public float getPercentSentDropped()
public void measureBandwidth()
BandwidthTracker.measureBandwidth()
public float getMeasuredUpstreamBandwidth()
BandwidthTracker.measureBandwidth()
public float getMeasuredDownstreamBandwidth()
BandwidthTracker.measureBandwidth()
public void setHorizonEnabled(boolean enable)
public void updateHorizonStats(PingReply pingReply)
public long getNextQRPForwardTime()
public void incrementNextQRPForwardTime(long curTime)
curTime
- the current time in milliseconds, used to calculate
the next update timepublic boolean isKillable()
isKillable
in interface ReplyHandler
public QueryRouteTable getQueryRouteTableSent()
public void setQueryRouteTableSent(QueryRouteTable qrt)
qrt
- the last query route table that was sent along this
connectionpublic int getPushProxyPort()
getPushProxyPort
in interface PushProxyInterface
public java.net.InetAddress getPushProxyAddress()
getPushProxyAddress
in interface PushProxyInterface
getPushProxyPort()
public java.lang.Object getQRPLock()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |