|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.limegroup.gnutella.MessageRouter
One of the three classes that make up the core of the backend. This class' job is to direct the routing of messages and to count those message as they pass through. To do so, it aggregates a ConnectionManager that maintains a list of connections.
Field Summary | |
protected byte[] |
_clientGUID
The GUID we attach to QueryReplies to allow PushRequests in responses. |
protected static ConnectionManager |
_manager
Handle to the ConnectionManager to access our TCP connections. |
protected QueryUnicaster |
UNICASTER
Constant handle to the QueryUnicaster since it is called upon very frequently. |
Constructor Summary | |
protected |
MessageRouter()
Creates a MessageRouter. |
Method Summary | |
void |
broadcastPingRequest(PingRequest ping)
Broadcasts the ping request to all initialized connections, setting up the proper reply routing. |
protected boolean |
bufferResponsesForLaterDelivery(QueryRequest query,
Response[] resps)
Stores (for a limited time) the resps for later out-of-band delivery - interacts with handleLimeACKMessage |
protected abstract java.util.List |
createQueryReply(byte[] guid,
byte ttl,
long speed,
Response[] res,
byte[] clientGUID,
boolean busy,
boolean uploaded,
boolean measuredSpeed,
boolean isFromMcast)
Abstract method for creating query hits. |
void |
forwardQueryRequestToLeaves(QueryRequest query,
ReplyHandler handler)
Forwards the query request to any leaf connections. |
java.lang.String |
getPingRouteTableDump()
|
java.lang.String |
getPushRouteTableDump()
|
QueryRouteTable |
getQueryRouteTable()
Accessor for the most recently calculated QueryRouteTable for this node. |
java.lang.String |
getQueryRouteTableDump()
|
protected void |
handleLimeACKMessage(LimeACKVendorMessage ack,
java.net.DatagramPacket datagram)
Handles a ACK message - looks up the QueryReply and sends it out of band. |
void |
handleMessage(Message msg,
ManagedConnection receivingConnection)
The handler for all message types. |
void |
handleMulticastMessage(Message msg,
java.net.DatagramPacket datagram)
The handler for Multicast messages. |
protected void |
handlePingReply(PingReply reply,
ReplyHandler handler)
The default handler for PingRequests received in ManagedConnection.loopForMessages(). |
protected void |
handlePushProxyRequest(PushProxyRequest ppReq,
ManagedConnection source)
1) confirm that the connection is Ultrapeer to Leaf, then send your listening port in a PushProxyAcknowledgement. |
protected void |
handlePushRequest(PushRequest request,
ReplyHandler handler)
The default handler for PushRequests received in ManagedConnection.loopForMessages(). |
void |
handleQueryReply(QueryReply queryReply,
ReplyHandler handler)
The default handler for QueryReplies received in ManagedConnection.loopForMessages(). |
protected void |
handleQueryRequest(QueryRequest request,
ReplyHandler handler,
ResultCounter counter,
boolean locallyEvaluate)
The default handler for QueryRequests received in ManagedConnection.loopForMessages(). |
protected void |
handleQueryStatus(QueryStatusResponse resp,
ManagedConnection leaf)
This method should be invoked when this node receives a QueryStatusResponse message from the wire. |
protected void |
handleTCPConnectBackRequest(TCPConnectBackVendorMessage tcp,
Connection source)
Basically, just get the correct parameters, create a Socket, and send a "/n/n". |
protected void |
handleUDPConnectBackRequest(UDPConnectBackVendorMessage udp,
Connection source)
Basically, just get the correct parameters, create a temporary DatagramSocket, and send a Ping. |
void |
handleUDPMessage(Message msg,
java.net.DatagramPacket datagram)
The handler for all message types. |
protected void |
handleUDPPingReply(PingReply reply,
ReplyHandler handler,
java.net.InetAddress address,
int port)
|
protected void |
handleUDPPingRequest(PingRequest pingRequest,
ReplyHandler handler,
java.net.DatagramPacket datagram)
The default handler for PingRequests received in ManagedConnection.loopForMessages(). |
protected boolean |
hasValidQueryKey(java.net.InetAddress ip,
int port,
QueryRequest qr)
Returns true if the Query has a valid QueryKey. |
void |
initialize()
Links the MessageRouter up with the other back end pieces |
protected void |
multicastQueryRequest(QueryRequest query)
Send the query to the multicast group. |
void |
originateQuery(QueryRequest query,
ManagedConnection mc)
Originates a new query request to the ManagedConnection. |
void |
removeConnection(ReplyHandler rh)
A callback for ConnectionManager to clear a ReplyHandler from the routing tables when the connection is closed. |
protected abstract void |
respondToPingRequest(PingRequest request,
ReplyHandler handler)
Respond to the ping request. |
protected abstract boolean |
respondToQueryRequest(QueryRequest queryRequest,
byte[] clientGUID)
Respond to the query request. |
protected abstract void |
respondToUDPPingRequest(PingRequest request,
java.net.DatagramPacket datagram,
ReplyHandler handler)
Responds to a ping received over UDP -- implementations handle this differently from pings received over TCP, as it is assumed that the requester only wants pongs from other nodes that also support UDP messaging. |
java.util.Iterator |
responsesToQueryReplies(Response[] responses,
QueryRequest queryRequest)
Converts the passed responses to QueryReplies. |
protected void |
sendAcknowledgement(java.net.DatagramPacket datagram,
byte[] guid)
Sends an ack back to the GUESS client node. |
void |
sendDynamicQuery(QueryRequest query)
Generates a new dynamic query. |
protected void |
sendMulticastPushRequest(PushRequest push)
Sends a push request to the multicast network. |
protected void |
sendPingReply(PingReply pong,
ReplyHandler handler)
Uses the ping route table to send a PingReply to the appropriate connection. |
void |
sendPingRequest(PingRequest request,
ManagedConnection connection)
Sends the ping request to the designated connection, setting up the proper reply routing. |
void |
sendPushRequest(PushRequest push)
Uses the push route table to send a push request to the appropriate connection. |
protected void |
sendQueryKeyPong(PingRequest pr,
java.net.DatagramPacket datagram)
Generates a QueryKey for the source (described by datagram) and sends the QueryKey to it via a QueryKey pong.... |
protected void |
sendQueryReply(QueryReply queryReply)
Uses the query route table to send a QueryReply to the appropriate connection. |
void |
sendQueryRequest(QueryRequest request,
ManagedConnection connection)
Sends the query request to the designated connection, setting up the proper reply routing. |
void |
sendQueryRequest(QueryRequest request,
ManagedConnection sendConnection,
ReplyHandler handler)
Sends the passed query request, received on handler, to the passed sendConnection, only if the handler and the sendConnection are authenticated to a common domain To only send it the route table has a hit, use sendRoutedQueryToHost. |
protected void |
unicastQueryRequest(QueryRequest query,
ReplyHandler conn)
Adds the QueryRequest to the unicaster module. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static ConnectionManager _manager
protected byte[] _clientGUID
protected final QueryUnicaster UNICASTER
Constructor Detail |
protected MessageRouter()
Method Detail |
public void initialize()
public java.lang.String getPingRouteTableDump()
public java.lang.String getQueryRouteTableDump()
public java.lang.String getPushRouteTableDump()
public void removeConnection(ReplyHandler rh)
public void handleMessage(Message msg, ManagedConnection receivingConnection)
receivingConnection
- the ManagedConnection over which
the message was receivedpublic void handleUDPMessage(Message msg, java.net.DatagramPacket datagram)
msg
- the Message receiveddatagram
- the DatagramPacket containing the IP and
port of the client nodepublic void handleMulticastMessage(Message msg, java.net.DatagramPacket datagram)
msg
- the Message recieved.datagram
- the DatagramPacket containing the IP and
port of the client node.protected boolean hasValidQueryKey(java.net.InetAddress ip, int port, QueryRequest qr)
protected void sendAcknowledgement(java.net.DatagramPacket datagram, byte[] guid)
protected void handleUDPPingRequest(PingRequest pingRequest, ReplyHandler handler, java.net.DatagramPacket datagram)
protected void sendQueryKeyPong(PingRequest pr, java.net.DatagramPacket datagram)
protected void handleUDPPingReply(PingReply reply, ReplyHandler handler, java.net.InetAddress address, int port)
protected void handleQueryRequest(QueryRequest request, ReplyHandler handler, ResultCounter counter, boolean locallyEvaluate)
locallyEvaluate
- false if you don't want to send the query to
leaves and yourself, true otherwise....protected void handleLimeACKMessage(LimeACKVendorMessage ack, java.net.DatagramPacket datagram)
protected boolean bufferResponsesForLaterDelivery(QueryRequest query, Response[] resps)
protected void handleUDPConnectBackRequest(UDPConnectBackVendorMessage udp, Connection source)
protected void handleTCPConnectBackRequest(TCPConnectBackVendorMessage tcp, Connection source)
protected void handlePushProxyRequest(PushProxyRequest ppReq, ManagedConnection source)
protected void handleQueryStatus(QueryStatusResponse resp, ManagedConnection leaf)
public void sendPingRequest(PingRequest request, ManagedConnection connection)
public void sendQueryRequest(QueryRequest request, ManagedConnection connection)
public void broadcastPingRequest(PingRequest ping)
public void sendDynamicQuery(QueryRequest query)
query
- the QueryRequest instance that generates
queries for this dynamic query
NullPointerException
- if the QueryHandler
argument is nullpublic final void forwardQueryRequestToLeaves(QueryRequest query, ReplyHandler handler)
handler
- the ReplyHandler that responds to the
request appropriatelyprotected void unicastQueryRequest(QueryRequest query, ReplyHandler conn)
protected void multicastQueryRequest(QueryRequest query)
public void sendQueryRequest(QueryRequest request, ManagedConnection sendConnection, ReplyHandler handler)
sendConnection
- The connection on which to send out the queryhandler
- The connection on which we originally
received the querypublic void originateQuery(QueryRequest query, ManagedConnection mc)
mc
- The ManagedConnection to send the query alongprotected abstract void respondToPingRequest(PingRequest request, ReplyHandler handler)
protected abstract void respondToUDPPingRequest(PingRequest request, java.net.DatagramPacket datagram, ReplyHandler handler)
request
- the PingRequest to servicedatagram
- the DatagramPacket containing the pinghandler
- the ReplyHandler instance from which the
ping was received and to which pongs should be sentprotected abstract boolean respondToQueryRequest(QueryRequest queryRequest, byte[] clientGUID)
protected void handlePingReply(PingReply reply, ReplyHandler handler)
In all cases, the ping reply is recorded into the host catcher.
Override as desired, but you probably want to call super.handlePingReply if you do.
public void handleQueryReply(QueryReply queryReply, ReplyHandler handler)
Override as desired, but you probably want to call super.handleQueryReply if you do. This is public for testing purposes.
protected void handlePushRequest(PushRequest request, ReplyHandler handler)
protected void sendPingReply(PingReply pong, ReplyHandler handler)
protected void sendQueryReply(QueryReply queryReply) throws java.io.IOException
java.io.IOException
- if no appropriate route exists.public void sendPushRequest(PushRequest push) throws java.io.IOException
java.io.IOException
- if no appropriate route exists.protected void sendMulticastPushRequest(PushRequest push)
public java.util.Iterator responsesToQueryReplies(Response[] responses, QueryRequest queryRequest)
NOTE: This method doesnt have any side effect, and does not modify the state of this object
responses
- The responses to be convertedqueryRequest
- The query request corresponding to which we are
generating query replies.
protected abstract java.util.List createQueryReply(byte[] guid, byte ttl, long speed, Response[] res, byte[] clientGUID, boolean busy, boolean uploaded, boolean measuredSpeed, boolean isFromMcast)
public QueryRouteTable getQueryRouteTable()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |