More information: http://www.cs.berkeley.edu/~mdw/proj/seda/

seda.sandStorm.lib.Gnutella
Class GnutellaServer

java.lang.Object
  |
  +--seda.sandStorm.lib.Gnutella.GnutellaServer
All Implemented Interfaces:
EventHandlerIF, GnutellaConst

public class GnutellaServer
extends java.lang.Object
implements EventHandlerIF, GnutellaConst

A GnutellaServer is a SandStorm stage which allows outgoing connections to be established to the Gnutella network, and accepts incoming connections. The server has a client sink associated with it, onto which GnutellaConnection and GnutellaPacket events are pushed. When a connection is closed, a SinkClosedEvent is pushed, with the sink pointer set to the GnutellaConnection that closed. If a an outgoing connection fails, a GnutellaConnectFailedevent is pushed.

Author:
Matt Welsh (mdw at cs dot berkeley dot edu)
See Also:

Inner Class Summary
(package private)  class GnutellaServer.connectionState
          Internal class used to monitor state of connections during handshake phase
 
Fields inherited from interface seda.sandStorm.lib.Gnutella.GnutellaConst
DEFAULT_DOWNLOAD_PORT, DEFAULT_GNUTELLA_PORT, DEFAULT_HOPS, DEFAULT_PING_INTERVAL, DEFAULT_SPEED, DEFAULT_TTL, GNUTELLA_CONNECT, GNUTELLA_FN_PING, GNUTELLA_FN_PONG, GNUTELLA_FN_PUSH, GNUTELLA_FN_QUERY, GNUTELLA_FN_QUERYHITS, GNUTELLA_OK, MAX_PAYLOAD_SIZE, PACKET_HEADER_SIZE, WRITE_CLOG_THRESHOLD
 
Constructor Summary
GnutellaServer(ManagerIF mgr, SinkIF clientSink)
          Create a Gnutella server listening for incoming connections on the default port of 6346.
GnutellaServer(ManagerIF mgr, SinkIF clientSink, int listenPort)
          Create a Gnutella server listening for incoming connections on the given listenPort.
 
Method Summary
(package private) static void ()
           
(package private)  void cleanupConnection(ATcpConnection tcpconn, GnutellaConnection gc)
           
(package private)  void closeConnection(ATcpConnection tcpconn, SinkIF compQ)
           
 void destroy()
          Called when an event handler is destroyed.
(package private)  SinkIF getSink()
           
 void handleEvent(QueueElementIF qel)
          Handle the event corresponding to the given QueueElementIF.
 void handleEvents(QueueElementIF[] qelarr)
          Handle the events corresponding to the given QueueElementIF array.
 void init(ConfigDataIF config)
          Called when an event handler is initialized.
 void openConnection(java.net.InetAddress address, int port)
          Open a connection to the given address and port.
 void openConnection(java.lang.String hostname, int port)
          Open a connection to the given hostname and port.
 void registerSink(SinkIF sink)
          Register a sink to receive incoming packets on this connection.
 void sendToAllButOne(GnutellaPacket pkt, GnutellaConnection exclude)
          Send a packet to all nodes but the given node.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GnutellaServer

public GnutellaServer(ManagerIF mgr,
                      SinkIF clientSink)
               throws java.lang.Exception
Create a Gnutella server listening for incoming connections on the default port of 6346.

GnutellaServer

public GnutellaServer(ManagerIF mgr,
                      SinkIF clientSink,
                      int listenPort)
               throws java.lang.Exception
Create a Gnutella server listening for incoming connections on the given listenPort. If listenPort == 0, no incoming connections will be accepted. (Outgoing connections can still be established using openConnection.)
Method Detail

static void ()

init

public void init(ConfigDataIF config)
          throws java.io.IOException
Description copied from interface: EventHandlerIF
Called when an event handler is initialized. This method should perform any initialization operations as required by the application.
Specified by:
init in interface EventHandlerIF
Following copied from interface: seda.sandStorm.api.EventHandlerIF
Parameters:
config - The set of configuration parameters for the stage.
Throws:
java.lang.Exception - The EventHandler can indicate an error to the runtime during initialization by throwing an Exception.

destroy

public void destroy()
Description copied from interface: EventHandlerIF
Called when an event handler is destroyed. This method should perform any cleanup or shutdown operations as required by the application before the event handler is removed from the system.
Specified by:
destroy in interface EventHandlerIF
Following copied from interface: seda.sandStorm.api.EventHandlerIF
Throws:
java.lang.Exception - The EventHandler can indicate an error to the runtime during shutdown by throwing an Exception.

openConnection

public void openConnection(java.lang.String hostname,
                           int port)
                    throws java.net.UnknownHostException
Open a connection to the given hostname and port. When the connection is established, a GnutellaConnection will be pushed to this server's client sink.

openConnection

public void openConnection(java.net.InetAddress address,
                           int port)
Open a connection to the given address and port. When the connection is established, a GnutellaConnection will be pushed to this server's client sink.

handleEvent

public void handleEvent(QueueElementIF qel)
Description copied from interface: EventHandlerIF
Handle the event corresponding to the given QueueElementIF. This method is invoked by the system when a single event is pending for the event handler.
Specified by:
handleEvent in interface EventHandlerIF
Following copied from interface: seda.sandStorm.api.EventHandlerIF
Throws:
EventHandlerException - The application may throw an exception to indicate an error condition during event processing.

handleEvents

public void handleEvents(QueueElementIF[] qelarr)
Description copied from interface: EventHandlerIF
Handle the events corresponding to the given QueueElementIF array. This method is invoked when multiple events are pending for the event handler. The application may reorder, filter, or drop these events if it wishes to do so.
Specified by:
handleEvents in interface EventHandlerIF
Following copied from interface: seda.sandStorm.api.EventHandlerIF
Throws:
EventHandlerException - The application may throw an exception to indicate an error condition during event processing.

closeConnection

void closeConnection(ATcpConnection tcpconn,
                     SinkIF compQ)

cleanupConnection

void cleanupConnection(ATcpConnection tcpconn,
                       GnutellaConnection gc)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

registerSink

public void registerSink(SinkIF sink)
Register a sink to receive incoming packets on this connection.

getSink

SinkIF getSink()

sendToAllButOne

public void sendToAllButOne(GnutellaPacket pkt,
                            GnutellaConnection exclude)
Send a packet to all nodes but the given node. Useful for packet routing.

More information: http://www.cs.berkeley.edu/~mdw/proj/seda/