Class SimpleGnutellaServer

java.lang.Object
  extended by SimpleGnutellaServer
All Implemented Interfaces:
EventHandlerIF

public class SimpleGnutellaServer
extends java.lang.Object
implements EventHandlerIF

This is a simple Gnutella server implemented using the Sandstorm Gnutella library. It correctly implements packet routing. It does not respond to queries or host any shared files itself; it simply routes packets to other hosts on the network.


Nested Class Summary
(package private)  class SimpleGnutellaServer.timerEvent
          Small internal class to represent a timer event.
 
Field Summary
private static boolean ACCEPT_CONNECTIONS
           
private static int CATCHER_CONNECTIONS
           
private static int CLEAN_TIMER_FREQUENCY
           
private static boolean DEBUG
           
private static boolean DO_CATCHER
           
private static boolean DO_CLEANER
           
private  GnutellaServer gs
           
private  ManagerIF mgr
           
private static int MIN_CONNECTIONS
           
private  java.lang.String myName
           
private  SinkIF mySink
           
private  int num_connections
           
private static int NUM_FILES
           
private static int NUM_KB
           
private  java.util.Hashtable packetTable
           
private static boolean ROUTE_PACKETS
           
private static boolean SEND_PONGS
           
private static java.lang.String SERVER_HOSTNAME
           
private  ssTimer timer
           
private static boolean VERBOSE
           
 
Constructor Summary
SimpleGnutellaServer()
           
 
Method Summary
 void destroy()
          Called when an event handler is destroyed.
private  void doCatcher()
           
private  void doClean(SimpleGnutellaServer.timerEvent ev)
           
private  void doTimer(SimpleGnutellaServer.timerEvent ev)
           
private  void forwardPacket(GnutellaPacket pkt)
           
private  void forwardPacketToAll(GnutellaPacket pkt)
           
 void handleEvent(QueueElementIF item)
          The main event handling code.
 void handleEvents(QueueElementIF[] items)
          Handle the events corresponding to the given QueueElementIF array.
 void init(ConfigDataIF config)
          Called when an event handler is initialized.
private  boolean rememberPacket(GnutellaPacket pkt)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG
See Also:
Constant Field Values

VERBOSE

private static final boolean VERBOSE
See Also:
Constant Field Values

DO_CLEANER

private static boolean DO_CLEANER

ACCEPT_CONNECTIONS

private static boolean ACCEPT_CONNECTIONS

SEND_PONGS

private static boolean SEND_PONGS

ROUTE_PACKETS

private static boolean ROUTE_PACKETS

CLEAN_TIMER_FREQUENCY

private static final int CLEAN_TIMER_FREQUENCY
See Also:
Constant Field Values

SERVER_HOSTNAME

private static java.lang.String SERVER_HOSTNAME

DO_CATCHER

private static boolean DO_CATCHER

CATCHER_CONNECTIONS

private static int CATCHER_CONNECTIONS

MIN_CONNECTIONS

private static final int MIN_CONNECTIONS
See Also:
Constant Field Values

NUM_FILES

private static final int NUM_FILES
See Also:
Constant Field Values

NUM_KB

private static final int NUM_KB
See Also:
Constant Field Values

mgr

private ManagerIF mgr

myName

private java.lang.String myName

mySink

private SinkIF mySink

timer

private ssTimer timer

gs

private GnutellaServer gs

packetTable

private java.util.Hashtable packetTable

num_connections

private int num_connections
Constructor Detail

SimpleGnutellaServer

public SimpleGnutellaServer()
Method Detail

init

public void init(ConfigDataIF config)
          throws java.lang.Exception
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
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

doCatcher

private void doCatcher()

forwardPacketToAll

private void forwardPacketToAll(GnutellaPacket pkt)

forwardPacket

private void forwardPacket(GnutellaPacket pkt)

rememberPacket

private boolean rememberPacket(GnutellaPacket pkt)

handleEvent

public void handleEvent(QueueElementIF item)
The main event handling code.

Specified by:
handleEvent in interface EventHandlerIF

handleEvents

public void handleEvents(QueueElementIF[] items)
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

doClean

private void doClean(SimpleGnutellaServer.timerEvent ev)

doTimer

private void doTimer(SimpleGnutellaServer.timerEvent ev)