LimeWire Consolidated API

com.limegroup.gnutella
Class MessageRouterImpl

java.lang.Object
  extended by com.limegroup.gnutella.MessageRouterImpl
All Implemented Interfaces:
MessageRouter, Service
Direct Known Subclasses:
StandardMessageRouter

public abstract class MessageRouterImpl
extends Object
implements 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.


Nested Class Summary
 class MessageRouterImpl.MulticastPingReplyHandler
           
 class MessageRouterImpl.MulticastPingRequestHandler
           
 class MessageRouterImpl.MulticastQueryReplyHandler
           
 class MessageRouterImpl.MulticastQueryRequestHandler
           
 class MessageRouterImpl.UDPQueryReplyHandler
          This class handles UDP query replies and forwards them to the OOBHandler if they are not replies to multicast or unicast queries.
 class MessageRouterImpl.VendorMessageHandler
           
 
Field Summary
protected  byte[] _clientGUID
          The GUID we attach to QueryReplies to allow PushRequests in responses.
protected  com.google.inject.Provider<ActivityCallback> activityCallback
           
protected  ScheduledExecutorService backgroundExecutor
           
protected  ConnectionManager connectionManager
           
protected  ConnectionServices connectionServices
           
protected  ContentManager contentManager
           
protected  DHTManager dhtManager
           
protected  DownloadManager downloadManager
           
protected  FileManager fileManager
           
protected  ReplyHandler forMeReplyHandler
           
protected  HeadPongFactory headPongFactory
           
protected  HostCatcher hostCatcher
           
protected  com.google.inject.Provider<LimeACKHandler> limeAckHandler
           
protected  com.google.inject.Provider<MessageDispatcher> messageDispatcher
           
protected  GuidMap multicastGuidMap
           
protected  MulticastService multicastService
           
protected  NetworkManager networkManager
           
protected  OnDemandUnicaster onDemandUnicaster
           
protected  PingReplyFactory pingReplyFactory
           
protected  com.google.inject.Provider<PongCacher> pongCacher
           
protected  QRPUpdater qrpUpdater
           
protected  QueryDispatcher queryDispatcher
           
protected  QueryHandlerFactory queryHandlerFactory
           
protected  QueryReplyFactory queryReplyFactory
           
protected  QueryRequestFactory queryRequestFactory
           
protected  QueryUnicaster queryUnicaster
           
protected  SearchResultHandler searchResultHandler
           
protected  com.google.inject.Provider<SimppManager> simppManager
           
protected  SocketsManager socketsManager
           
protected  StaticMessages staticMessages
           
protected  UDPReplyHandlerCache udpReplyHandlerCache
           
protected  UDPService udpService
           
protected  com.google.inject.Provider<UpdateHandler> updateHandler
           
protected  UploadManager uploadManager
           
 
Fields inherited from interface com.limegroup.gnutella.MessageRouter
CLEAR_TIME
 
Constructor Summary
protected MessageRouterImpl(NetworkManager networkManager, QueryRequestFactory queryRequestFactory, QueryHandlerFactory queryHandlerFactory, OnDemandUnicaster onDemandUnicaster, HeadPongFactory headPongFactory, PingReplyFactory pingReplyFactory, ConnectionManager connectionManager, ReplyHandler forMeReplyHandler, QueryUnicaster queryUnicaster, FileManager fileManager, ContentManager contentManager, DHTManager dhtManager, UploadManager uploadManager, DownloadManager downloadManager, UDPService udpService, SearchResultHandler searchResultHandler, SocketsManager socketsManager, HostCatcher hostCatcher, QueryReplyFactory queryReplyFactory, StaticMessages staticMessages, com.google.inject.Provider<MessageDispatcher> messageDispatcher, MulticastService multicastService, QueryDispatcher queryDispatcher, com.google.inject.Provider<ActivityCallback> activityCallback, ConnectionServices connectionServices, ApplicationServices applicationServices, ScheduledExecutorService backgroundExecutor, com.google.inject.Provider<PongCacher> pongCacher, com.google.inject.Provider<SimppManager> simppManager, com.google.inject.Provider<UpdateHandler> updateHandler, GuidMapManager guidMapManager, UDPReplyHandlerCache udpReplyHandlerCache, com.google.inject.Provider<InspectionRequestHandler> inspectionRequestHandlerFactory, com.google.inject.Provider<UDPCrawlerPingHandler> udpCrawlerPingHandlerFactory, PingRequestFactory pingRequestFactory, MessageHandlerBinder messageHandlerBinder, com.google.inject.Provider<OOBHandler> oobHandlerFactory, com.google.inject.Provider<MACCalculatorRepositoryManager> MACCalculatorRepositoryManager, com.google.inject.Provider<LimeACKHandler> limeACKHandler, OutgoingQueryReplyFactory outgoingQueryReplyFactory, QRPUpdater qrpUpdater, URNFilter urnFilter)
          Creates a MessageRouter.
 
Method Summary
 boolean addBypassedSource(QueryReply reply, ReplyHandler handler)
          Adds the sender of the reply message to an internal cache under the guid of the message if the sender can receive unsolicited UDP.
 boolean addBypassedSource(ReplyNumberVendorMessage reply, ReplyHandler handler)
          Adds the sender of the reply message to an internal cache under the guid of the message if the sender can receive unsolicited UDP.
 void addMessageHandler(Class<? extends Message> clazz, MessageHandler handler)
          Adds the new handler as a handler in addition to other handlers.
 void addMulticastMessageHandler(Class<? extends Message> clazz, MessageHandler handler)
          Adds the new handler as a handler in addition to other handlers for multicast messages.
 void addUDPMessageHandler(Class<? extends Message> clazz, MessageHandler handler)
          Adds the new handler as a handler in addition to other handlers for UDP messages.
 void broadcastPingRequest(PingRequest ping)
          Broadcasts the ping request to all initialized connections, setting up the proper reply routing.
 void downloadFinished(GUID guid)
          Call this to inform us that a download is finished or whatever.
 void forwardInspectionRequestToLeaves(InspectionRequest ir)
          Forwards an inspection request to leaf connections that support it.
 void forwardQueryRequestToLeaves(QueryRequest query, ReplyHandler handler)
          Forwards the query request to any leaf connections.
 MessageHandler getMessageHandler(Class<? extends Message> clazz)
          Returns a MessageHandler for the specified Message Class or null if no such MessageHandler exists.
 MessageHandler getMulticastMessageHandler(Class<? extends Message> clazz)
          Returns a MessageHandler for the specified Message Class or null if no such MessageHandler exists.
 int getNumOOBToRequest(ReplyNumberVendorMessage reply)
          Returns the number of results to request from source of reply.
 long getOOBExpireTime()
          Time after which an OOB session should be expired.
 String getPingRouteTableDump()
           
 ReplyHandler getPushHandler(byte[] guid)
          Returns the appropriate handler from the _pushRouteTable.
 String getPushRouteTableDump()
           
 Set<GUESSEndpoint> getQueryLocs(GUID guid)
           
 QueryRouteTable getQueryRouteTable()
          Accessor for the most recently calculated QueryRouteTable for this node.
 String getQueryRouteTableDump()
           
 String getServiceName()
           
 MessageHandler getUDPMessageHandler(Class<? extends Message> clazz)
          Returns a MessageHandler for the specified Message Class or null if no such MessageHandler exists.
 void handleMessage(Message msg, ReplyHandler receivingConnection)
          The handler for all message types.
 void handleMulticastMessage(Message msg, InetSocketAddress addr)
          The handler for Multicast messages.
protected  void handlePingReply(PingReply reply, ReplyHandler handler)
          The default handler for PingRequests.
protected  void handlePushProxyRequest(PushProxyRequest ppReq, RoutedConnection source)
          1) confirm that the connection is Ultrapeer to Leaf, then send your listening port in a PushProxyAcknowledgement.
 void handleQueryReply(QueryReply queryReply, ReplyHandler handler)
          The default handler for QueryReplies.
 void handleQueryRequest(QueryRequest request, ReplyHandler handler, ResultCounter counter, boolean locallyEvaluate)
          The default handler for QueryRequests.
protected  void handleQueryStatus(QueryStatusResponse resp, RoutedConnection leaf)
          This method should be invoked when this node receives a QueryStatusResponse message from the wire.
protected  void handleTCPConnectBackRedirect(TCPConnectBackRedirect tcp, Connection source)
          Basically, just get the correct parameters, create a Socket, and send a "/n/n".
protected  void handleTCPConnectBackRequest(TCPConnectBackVendorMessage tcp, Connection source)
          Forwards the request to neighboring Ultrapeers as a TCPConnectBackRedirect message.
protected  void handleUDPConnectBackRedirect(UDPConnectBackRedirect udp, Connection source)
          Sends a ping to the person requesting the connectback request.
protected  void handleUDPConnectBackRequest(UDPConnectBackVendorMessage udp, Connection source)
          Forwards the UDPConnectBack to neighboring peers as a UDPConnectBackRedirect request.
 void handleUDPMessage(Message msg, InetSocketAddress addr)
          The handler for all message types.
protected  void handleUDPPingReply(PingReply reply, ReplyHandler handler, InetAddress address, int port)
           
protected  void handleUDPPingRequest(PingRequest pingRequest, ReplyHandler handler, InetSocketAddress addr)
          Responds to a UDP ping or query key request.
protected  boolean hasValidQueryKey(InetAddress ip, int port, QueryRequest qr)
          Returns true if the Query has a valid AddressSecurityToken.
 void initialize()
           
 boolean isHostUnicastQueried(GUID guid, IpPort host)
          Determines if we've sent a unicast OOB query to the given host using the given query GUID.
 boolean isQueryAlive(GUID guid)
           
protected  void multicastQueryRequest(QueryRequest query)
          Send the query to the multicast group.
protected  void originateMulticastQuery(QueryRequest query)
          Originates a multicast query from this host.
 void originateQueryGUID(byte[] guid)
          Routes a query GUID to yourself.
 void queryKilled(GUID guid)
          Call this to inform us that a query has been killed by a user or whatever.
 void registerMessageListener(byte[] guid, MessageListener ml)
          Adds the specified MessageListener for messages with this GUID.
protected abstract  void respondToPingRequest(PingRequest request, ReplyHandler handler)
          Respond to the ping request.
protected abstract  boolean respondToQueryRequest(QueryRequest queryRequest, byte[] clientGUID, ReplyHandler handler)
          Respond to the query request.
protected abstract  void respondToUDPPingRequest(PingRequest request, InetSocketAddress addr, 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.
 Iterable<QueryReply> responsesToQueryReplies(Response[] responses, QueryRequest queryRequest)
          Converts the passed responses to QueryReplies.
 Iterable<QueryReply> responsesToQueryReplies(Response[] responses, QueryRequest queryRequest, int REPLY_LIMIT, SecurityToken securityToken)
          Converts the passed responses to QueryReplies.
protected  void sendAcknowledgement(InetSocketAddress addr, byte[] guid)
          Sends an ack back to the GUESS client node.
 void sendDynamicQuery(QueryRequest query)
          Generates a new dynamic query.
 boolean sendInitialQuery(QueryRequest query, RoutedConnection mc)
          Used to send the first request to a specific ultrapeer when dynamic querying.
 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, RoutedConnection 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, InetSocketAddress addr)
          Generates an AddressSecurityToken for the source (described by addr) and sends it in an AddressSecurityToken pong
protected  void sendQueryReply(QueryReply queryReply)
          Uses the query route table to send a QueryReply to the appropriate connection.
 void sendQueryRequest(QueryRequest request, RoutedConnection connection)
          Sends the query request to the designated connection, setting up the proper reply routing.
 void setMessageHandler(Class<? extends Message> clazz, MessageHandler handler)
          Installs a MessageHandler for "regular" Messages.
 void setMulticastMessageHandler(Class<? extends Message> clazz, MessageHandler handler)
          Installs a MessageHandler for Multicast Messages.
 void setUDPMessageHandler(Class<? extends Message> clazz, MessageHandler handler)
          Installs a MessageHandler for UDP Messages.
 void start()
           
 void stop()
           
protected  void unicastQueryRequest(QueryRequest query, ReplyHandler conn)
          Adds the QueryRequest to the unicaster module.
 void unregisterMessageListener(byte[] guid, MessageListener ml)
          Unregisters this MessageListener from listening to the GUID.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_clientGUID

protected byte[] _clientGUID
The GUID we attach to QueryReplies to allow PushRequests in responses.


networkManager

protected final NetworkManager networkManager

queryRequestFactory

protected final QueryRequestFactory queryRequestFactory

queryHandlerFactory

protected final QueryHandlerFactory queryHandlerFactory

onDemandUnicaster

protected final OnDemandUnicaster onDemandUnicaster

headPongFactory

protected final HeadPongFactory headPongFactory

pingReplyFactory

protected final PingReplyFactory pingReplyFactory

connectionManager

protected final ConnectionManager connectionManager

forMeReplyHandler

protected final ReplyHandler forMeReplyHandler

queryUnicaster

protected final QueryUnicaster queryUnicaster

fileManager

protected final FileManager fileManager

contentManager

protected final ContentManager contentManager

dhtManager

protected final DHTManager dhtManager

uploadManager

protected final UploadManager uploadManager

downloadManager

protected final DownloadManager downloadManager

udpService

protected final UDPService udpService

searchResultHandler

protected final SearchResultHandler searchResultHandler

socketsManager

protected final SocketsManager socketsManager

hostCatcher

protected final HostCatcher hostCatcher

queryReplyFactory

protected final QueryReplyFactory queryReplyFactory

staticMessages

protected final StaticMessages staticMessages

messageDispatcher

protected final com.google.inject.Provider<MessageDispatcher> messageDispatcher

multicastService

protected final MulticastService multicastService

queryDispatcher

protected final QueryDispatcher queryDispatcher

activityCallback

protected final com.google.inject.Provider<ActivityCallback> activityCallback

connectionServices

protected final ConnectionServices connectionServices

backgroundExecutor

protected final ScheduledExecutorService backgroundExecutor

pongCacher

protected final com.google.inject.Provider<PongCacher> pongCacher

simppManager

protected final com.google.inject.Provider<SimppManager> simppManager

updateHandler

protected final com.google.inject.Provider<UpdateHandler> updateHandler

udpReplyHandlerCache

protected final UDPReplyHandlerCache udpReplyHandlerCache

multicastGuidMap

protected final GuidMap multicastGuidMap

limeAckHandler

protected final com.google.inject.Provider<LimeACKHandler> limeAckHandler

qrpUpdater

protected final QRPUpdater qrpUpdater
Constructor Detail

MessageRouterImpl

@Inject
protected MessageRouterImpl(NetworkManager networkManager,
                                   QueryRequestFactory queryRequestFactory,
                                   QueryHandlerFactory queryHandlerFactory,
                                   OnDemandUnicaster onDemandUnicaster,
                                   HeadPongFactory headPongFactory,
                                   PingReplyFactory pingReplyFactory,
                                   ConnectionManager connectionManager,
                                   ReplyHandler forMeReplyHandler,
                                   QueryUnicaster queryUnicaster,
                                   FileManager fileManager,
                                   ContentManager contentManager,
                                   DHTManager dhtManager,
                                   UploadManager uploadManager,
                                   DownloadManager downloadManager,
                                   UDPService udpService,
                                   SearchResultHandler searchResultHandler,
                                   SocketsManager socketsManager,
                                   HostCatcher hostCatcher,
                                   QueryReplyFactory queryReplyFactory,
                                   StaticMessages staticMessages,
                                   com.google.inject.Provider<MessageDispatcher> messageDispatcher,
                                   MulticastService multicastService,
                                   QueryDispatcher queryDispatcher,
                                   com.google.inject.Provider<ActivityCallback> activityCallback,
                                   ConnectionServices connectionServices,
                                   ApplicationServices applicationServices,
                                   ScheduledExecutorService backgroundExecutor,
                                   com.google.inject.Provider<PongCacher> pongCacher,
                                   com.google.inject.Provider<SimppManager> simppManager,
                                   com.google.inject.Provider<UpdateHandler> updateHandler,
                                   GuidMapManager guidMapManager,
                                   UDPReplyHandlerCache udpReplyHandlerCache,
                                   com.google.inject.Provider<InspectionRequestHandler> inspectionRequestHandlerFactory,
                                   com.google.inject.Provider<UDPCrawlerPingHandler> udpCrawlerPingHandlerFactory,
                                   PingRequestFactory pingRequestFactory,
                                   MessageHandlerBinder messageHandlerBinder,
                                   com.google.inject.Provider<OOBHandler> oobHandlerFactory,
                                   com.google.inject.Provider<MACCalculatorRepositoryManager> MACCalculatorRepositoryManager,
                                   com.google.inject.Provider<LimeACKHandler> limeACKHandler,
                                   OutgoingQueryReplyFactory outgoingQueryReplyFactory,
                                   QRPUpdater qrpUpdater,
                                   URNFilter urnFilter)
Creates a MessageRouter. Must call initialize before using.

Method Detail

setMessageHandler

public void setMessageHandler(Class<? extends Message> clazz,
                              MessageHandler handler)
Description copied from interface: MessageRouter
Installs a MessageHandler for "regular" Messages.

Specified by:
setMessageHandler in interface MessageRouter
Parameters:
clazz - The Class of the Message
handler - The Handler of the Message

addMessageHandler

public void addMessageHandler(Class<? extends Message> clazz,
                              MessageHandler handler)
Description copied from interface: MessageRouter
Adds the new handler as a handler in addition to other handlers.

Specified by:
addMessageHandler in interface MessageRouter
Parameters:
clazz - The Class of the Message
handler - The Handler of the Message

getMessageHandler

public MessageHandler getMessageHandler(Class<? extends Message> clazz)
Description copied from interface: MessageRouter
Returns a MessageHandler for the specified Message Class or null if no such MessageHandler exists.

Specified by:
getMessageHandler in interface MessageRouter

setUDPMessageHandler

public void setUDPMessageHandler(Class<? extends Message> clazz,
                                 MessageHandler handler)
Description copied from interface: MessageRouter
Installs a MessageHandler for UDP Messages.

Specified by:
setUDPMessageHandler in interface MessageRouter
Parameters:
clazz - The Class of the Message
handler - The Handler of the Message

addUDPMessageHandler

public void addUDPMessageHandler(Class<? extends Message> clazz,
                                 MessageHandler handler)
Description copied from interface: MessageRouter
Adds the new handler as a handler in addition to other handlers for UDP messages.

Specified by:
addUDPMessageHandler in interface MessageRouter
Parameters:
clazz - The Class of the Message
handler - The Handler of the Message

getUDPMessageHandler

public MessageHandler getUDPMessageHandler(Class<? extends Message> clazz)
Description copied from interface: MessageRouter
Returns a MessageHandler for the specified Message Class or null if no such MessageHandler exists.

Specified by:
getUDPMessageHandler in interface MessageRouter

setMulticastMessageHandler

public void setMulticastMessageHandler(Class<? extends Message> clazz,
                                       MessageHandler handler)
Description copied from interface: MessageRouter
Installs a MessageHandler for Multicast Messages.

Specified by:
setMulticastMessageHandler in interface MessageRouter
Parameters:
clazz - The Class of the Message
handler - The Handler of the Message

addMulticastMessageHandler

public void addMulticastMessageHandler(Class<? extends Message> clazz,
                                       MessageHandler handler)
Description copied from interface: MessageRouter
Adds the new handler as a handler in addition to other handlers for multicast messages.

Specified by:
addMulticastMessageHandler in interface MessageRouter
Parameters:
clazz - The Class of the Message
handler - The Handler of the Message

getMulticastMessageHandler

public MessageHandler getMulticastMessageHandler(Class<? extends Message> clazz)
Description copied from interface: MessageRouter
Returns a MessageHandler for the specified Message Class or null if no such MessageHandler exists.

Specified by:
getMulticastMessageHandler in interface MessageRouter

initialize

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

getServiceName

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

start

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

stop

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

originateQueryGUID

public void originateQueryGUID(byte[] guid)
Description copied from interface: MessageRouter
Routes a query GUID to yourself.

Specified by:
originateQueryGUID in interface MessageRouter

queryKilled

public void queryKilled(GUID guid)
                 throws IllegalArgumentException
Description copied from interface: MessageRouter
Call this to inform us that a query has been killed by a user or whatever. Useful for purging unneeded info.
Callers of this should make sure that they have purged the guid from their tables.

Specified by:
queryKilled in interface MessageRouter
Throws:
IllegalArgumentException - if the guid is null

downloadFinished

public void downloadFinished(GUID guid)
                      throws IllegalArgumentException
Description copied from interface: MessageRouter
Call this to inform us that a download is finished or whatever. Useful for purging unneeded info.
If the caller is a Downloader, please be sure to clear yourself from the active and waiting lists in DownloadManager.

Specified by:
downloadFinished in interface MessageRouter
Throws:
IllegalArgumentException - if the guid is null

getQueryLocs

public Set<GUESSEndpoint> getQueryLocs(GUID guid)
Specified by:
getQueryLocs in interface MessageRouter
Parameters:
guid - the guid of the query you want endpoints for.

getPingRouteTableDump

public String getPingRouteTableDump()
Specified by:
getPingRouteTableDump in interface MessageRouter

getQueryRouteTableDump

public String getQueryRouteTableDump()
Specified by:
getQueryRouteTableDump in interface MessageRouter

getPushRouteTableDump

public String getPushRouteTableDump()
Specified by:
getPushRouteTableDump in interface MessageRouter

handleMessage

public void handleMessage(Message msg,
                          ReplyHandler receivingConnection)
Description copied from interface: MessageRouter
The handler for all message types. Processes a message based on the message type.

Specified by:
handleMessage in interface MessageRouter
receivingConnection - the ReplyHandler over which the message was received

handleUDPMessage

public void handleUDPMessage(Message msg,
                             InetSocketAddress addr)
Description copied from interface: MessageRouter
The handler for all message types. Processes a message based on the message type.

Specified by:
handleUDPMessage in interface MessageRouter
Parameters:
msg - the Message received
addr - the InetSocketAddress containing the IP and port of the client node

handleMulticastMessage

public void handleMulticastMessage(Message msg,
                                   InetSocketAddress addr)
Description copied from interface: MessageRouter
The handler for Multicast messages. Processes a message based on the message type.

Specified by:
handleMulticastMessage in interface MessageRouter
Parameters:
msg - the Message recieved.
addr - the InetSocketAddress containing the IP and port of the client node.

hasValidQueryKey

protected boolean hasValidQueryKey(InetAddress ip,
                                   int port,
                                   QueryRequest qr)
Returns true if the Query has a valid AddressSecurityToken. false if it isn't present or valid.


sendAcknowledgement

protected void sendAcknowledgement(InetSocketAddress addr,
                                   byte[] guid)
Sends an ack back to the GUESS client node.


handleUDPPingRequest

protected void handleUDPPingRequest(PingRequest pingRequest,
                                    ReplyHandler handler,
                                    InetSocketAddress addr)
Responds to a UDP ping or query key request.


sendQueryKeyPong

protected void sendQueryKeyPong(PingRequest pr,
                                InetSocketAddress addr)
Generates an AddressSecurityToken for the source (described by addr) and sends it in an AddressSecurityToken pong


handleUDPPingReply

protected void handleUDPPingReply(PingReply reply,
                                  ReplyHandler handler,
                                  InetAddress address,
                                  int port)

handleQueryRequest

public void handleQueryRequest(QueryRequest request,
                               ReplyHandler handler,
                               ResultCounter counter,
                               boolean locallyEvaluate)
The default handler for QueryRequests. This implementation updates stats, does the broadcast, and generates a response. You can customize behavior in three ways: 1. Override. You can assume that duplicate messages (messages with the same GUID that arrived via different paths) have already been filtered. If you want stats updated, you'll have to call super.handleQueryRequest. 2. Override broadcastQueryRequest. This allows you to use the default handling framework and just customize request routing. 3. Implement respondToQueryRequest. This allows you to use the default handling framework and just customize responses.

Parameters:
locallyEvaluate - false if you don't want to send the query to leaves and yourself, true otherwise....

addBypassedSource

public boolean addBypassedSource(ReplyNumberVendorMessage reply,
                                 ReplyHandler handler)
Adds the sender of the reply message to an internal cache under the guid of the message if the sender can receive unsolicited UDP.

Specified by:
addBypassedSource in interface MessageRouter
Returns:
true if successfully added to the bypassed results cache
See Also:
#getQueryLocs(GUID)} for retrieval

addBypassedSource

public boolean addBypassedSource(QueryReply reply,
                                 ReplyHandler handler)
Adds the sender of the reply message to an internal cache under the guid of the message if the sender can receive unsolicited UDP.

Specified by:
addBypassedSource in interface MessageRouter
See Also:
#getQueryLocs(GUID)} for retrieval

getNumOOBToRequest

public int getNumOOBToRequest(ReplyNumberVendorMessage reply)
Description copied from interface: MessageRouter
Returns the number of results to request from source of reply.

Specified by:
getNumOOBToRequest in interface MessageRouter
Returns:
-1 if no results are desired

isQueryAlive

public boolean isQueryAlive(GUID guid)
Specified by:
isQueryAlive in interface MessageRouter
Returns:
true if there is still a route for this reply

isHostUnicastQueried

public boolean isHostUnicastQueried(GUID guid,
                                    IpPort host)
Description copied from interface: MessageRouter
Determines if we've sent a unicast OOB query to the given host using the given query GUID.

Specified by:
isHostUnicastQueried in interface MessageRouter

handleUDPConnectBackRequest

protected void handleUDPConnectBackRequest(UDPConnectBackVendorMessage udp,
                                           Connection source)
Forwards the UDPConnectBack to neighboring peers as a UDPConnectBackRedirect request.


handleUDPConnectBackRedirect

protected void handleUDPConnectBackRedirect(UDPConnectBackRedirect udp,
                                            Connection source)
Sends a ping to the person requesting the connectback request.


handleTCPConnectBackRequest

protected void handleTCPConnectBackRequest(TCPConnectBackVendorMessage tcp,
                                           Connection source)
Forwards the request to neighboring Ultrapeers as a TCPConnectBackRedirect message.


handleTCPConnectBackRedirect

protected void handleTCPConnectBackRedirect(TCPConnectBackRedirect tcp,
                                            Connection source)
Basically, just get the correct parameters, create a Socket, and send a "/n/n".


handlePushProxyRequest

protected void handlePushProxyRequest(PushProxyRequest ppReq,
                                      RoutedConnection source)
1) confirm that the connection is Ultrapeer to Leaf, then send your listening port in a PushProxyAcknowledgement. 2) Also cache the client's client GUID.


handleQueryStatus

protected void handleQueryStatus(QueryStatusResponse resp,
                                 RoutedConnection leaf)
This method should be invoked when this node receives a QueryStatusResponse message from the wire. If this node is an Ultrapeer, we should update the Dynamic Querier about the status of the leaf's query.


sendPingRequest

public void sendPingRequest(PingRequest request,
                            RoutedConnection connection)
Description copied from interface: MessageRouter
Sends the ping request to the designated connection, setting up the proper reply routing.

Specified by:
sendPingRequest in interface MessageRouter

sendQueryRequest

public void sendQueryRequest(QueryRequest request,
                             RoutedConnection connection)
Description copied from interface: MessageRouter
Sends the query request to the designated connection, setting up the proper reply routing.

Specified by:
sendQueryRequest in interface MessageRouter

broadcastPingRequest

public void broadcastPingRequest(PingRequest ping)
Description copied from interface: MessageRouter
Broadcasts the ping request to all initialized connections, setting up the proper reply routing.

Specified by:
broadcastPingRequest in interface MessageRouter

sendDynamicQuery

public void sendDynamicQuery(QueryRequest query)
Description copied from interface: MessageRouter
Generates a new dynamic query. This method is used to send a new dynamic query from this host (the user initiated this query directly, so it's replies are intended for this node).

Specified by:
sendDynamicQuery in interface MessageRouter
Parameters:
query - the QueryRequest instance that generates queries for this dynamic query

originateMulticastQuery

protected void originateMulticastQuery(QueryRequest query)
Originates a multicast query from this host. This will alter the GUID of the query and store it in a mapping of new -> old GUID. When replies come in, if they have the new GUID, they are reset to be the old one and the multicast flag is allowed.

Parameters:
query -

forwardQueryRequestToLeaves

public final void forwardQueryRequestToLeaves(QueryRequest query,
                                              ReplyHandler handler)
Description copied from interface: MessageRouter
Forwards the query request to any leaf connections.

Specified by:
forwardQueryRequestToLeaves in interface MessageRouter
handler - the ReplyHandler that responds to the request appropriately

unicastQueryRequest

protected void unicastQueryRequest(QueryRequest query,
                                   ReplyHandler conn)
Adds the QueryRequest to the unicaster module. Not much work done here, see QueryUnicaster for more details.


multicastQueryRequest

protected void multicastQueryRequest(QueryRequest query)
Send the query to the multicast group.


sendInitialQuery

public boolean sendInitialQuery(QueryRequest query,
                                RoutedConnection mc)
Description copied from interface: MessageRouter
Used to send the first request to a specific ultrapeer when dynamic querying.

Specified by:
sendInitialQuery in interface MessageRouter
mc - The RoutedConnection to send the query along
Returns:
false if the query was not sent, true if so

respondToPingRequest

protected abstract void respondToPingRequest(PingRequest request,
                                             ReplyHandler handler)
Respond to the ping request. Implementations typically will either do nothing (if they don't think a response is appropriate) or call sendPingReply(PingReply). This method is called from the default handlePingRequest.


respondToUDPPingRequest

protected abstract void respondToUDPPingRequest(PingRequest request,
                                                InetSocketAddress addr,
                                                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.

Parameters:
request - the PingRequest to service
addr - the InetSocketAddress containing the ping
handler - the ReplyHandler instance from which the ping was received and to which pongs should be sent

respondToQueryRequest

protected abstract boolean respondToQueryRequest(QueryRequest queryRequest,
                                                 byte[] clientGUID,
                                                 ReplyHandler handler)
Respond to the query request. Implementations typically will either do nothing (if they don't think a response is appropriate) or call sendQueryReply(QueryReply). This method is called from the default handleQueryRequest.


handlePingReply

protected void handlePingReply(PingReply reply,
                               ReplyHandler handler)
The default handler for PingRequests. This implementation uses the ping route table to route a ping reply. If an appropriate route doesn't exist, records the error statistics. On sucessful routing, the PingReply count is incremented.

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.


handleQueryReply

public void handleQueryReply(QueryReply queryReply,
                             ReplyHandler handler)
Description copied from interface: MessageRouter
The default handler for QueryReplies. This implementation uses the query route table to route a query reply. If an appropriate route doesn't exist, records the error statistics. On sucessful routing, the QueryReply count is incremented.

Override as desired, but you probably want to call super.handleQueryReply if you do. This is public for testing purposes.

Specified by:
handleQueryReply in interface MessageRouter

getPushHandler

public ReplyHandler getPushHandler(byte[] guid)
Returns the appropriate handler from the _pushRouteTable. This enforces that requests for my clientGUID will return FOR_ME_REPLY_HANDLER, even if it's not in the table. Will also iterate through leaves if they are not in the table.

Specified by:
getPushHandler in interface MessageRouter
Parameters:
guid - the client guid
Returns:
null if no reply handler is registered for the guid

sendPingReply

protected void sendPingReply(PingReply pong,
                             ReplyHandler handler)
Uses the ping route table to send a PingReply to the appropriate connection. Since this is used for PingReplies orginating here, no stats are updated.


sendQueryReply

protected void sendQueryReply(QueryReply queryReply)
                       throws IOException
Uses the query route table to send a QueryReply to the appropriate connection. Since this is used for QueryReplies orginating here, no stats are updated.

Throws:
IOException - if no appropriate route exists.

sendPushRequest

public void sendPushRequest(PushRequest push)
                     throws IOException
Description copied from interface: MessageRouter
Uses the push route table to send a push request to the appropriate connection. Since this is used for PushRequests orginating here, no stats are updated.

Specified by:
sendPushRequest in interface MessageRouter
Throws:
IOException - if no appropriate route exists.

sendMulticastPushRequest

public void sendMulticastPushRequest(PushRequest push)
Description copied from interface: MessageRouter
Sends a push request to the multicast network. No lookups are performed in the push route table, because the message will always be broadcast to everyone.

Specified by:
sendMulticastPushRequest in interface MessageRouter

responsesToQueryReplies

public Iterable<QueryReply> responsesToQueryReplies(Response[] responses,
                                                    QueryRequest queryRequest)
Description copied from interface: MessageRouter
Converts the passed responses to QueryReplies. Each QueryReply can accomodate atmost 255 responses. Not all the responses may get included in QueryReplies in case the query request came from a far away host.

NOTE: This method doesnt have any side effect, and does not modify the state of this object

Specified by:
responsesToQueryReplies in interface MessageRouter
Parameters:
responses - The responses to be converted
queryRequest - The query request corresponding to which we are generating query replies.
Returns:
Iterable of QueryReply

responsesToQueryReplies

public Iterable<QueryReply> responsesToQueryReplies(Response[] responses,
                                                    QueryRequest queryRequest,
                                                    int REPLY_LIMIT,
                                                    SecurityToken securityToken)
Converts the passed responses to QueryReplies. Each QueryReply can accomodate atmost 255 responses. Not all the responses may get included in QueryReplies in case the query request came from a far away host.

NOTE: This method doesnt have any side effect, and does not modify the state of this object

Specified by:
responsesToQueryReplies in interface MessageRouter
Parameters:
responses - The responses to be converted
queryRequest - The query request corresponding to which we are generating query replies.
REPLY_LIMIT - the maximum number of responses to have in each reply.
security - token might be null
Returns:
Iterable of QueryReply

getQueryRouteTable

public QueryRouteTable getQueryRouteTable()
Description copied from interface: MessageRouter
Accessor for the most recently calculated QueryRouteTable for this node. If this node is an Ultrapeer, the table will include all data for leaf nodes in addition to data for this node's files.

Specified by:
getQueryRouteTable in interface MessageRouter
Returns:
the QueryRouteTable for this node

registerMessageListener

public void registerMessageListener(byte[] guid,
                                    MessageListener ml)
Description copied from interface: MessageRouter
Adds the specified MessageListener for messages with this GUID. You must manually unregister the listener. This works by replacing the necessary maps & lists, so that notifying doesn't have to hold any locks.

Specified by:
registerMessageListener in interface MessageRouter

unregisterMessageListener

public void unregisterMessageListener(byte[] guid,
                                      MessageListener ml)
Description copied from interface: MessageRouter
Unregisters this MessageListener from listening to the GUID. This works by replacing the necessary maps & lists so that notifying doesn't have to hold any locks.

Specified by:
unregisterMessageListener in interface MessageRouter

forwardInspectionRequestToLeaves

public void forwardInspectionRequestToLeaves(InspectionRequest ir)
Description copied from interface: MessageRouter
Forwards an inspection request to leaf connections that support it.

Specified by:
forwardInspectionRequestToLeaves in interface MessageRouter

getOOBExpireTime

public long getOOBExpireTime()
Description copied from interface: MessageRouter
Time after which an OOB session should be expired.

Specified by:
getOOBExpireTime in interface MessageRouter
Returns:

LimeWire Consolidated API

Copyright © 2009. All Rights Reserved.