seda.sandStorm.lib.Gnutella
Class GnutellaConnection

java.lang.Object
  extended by seda.sandStorm.core.SimpleSink
      extended by seda.sandStorm.lib.Gnutella.GnutellaConnection
All Implemented Interfaces:
ProfilableIF, QueueElementIF, SinkIF, GnutellaConst

public class GnutellaConnection
extends SimpleSink
implements QueueElementIF, GnutellaConst

A GnutellaConnection represents a virtual connection to the Gnutella network. It may implement a single point-to-point connection between two peers, or a one-to-many connection to multiple peers.


Field Summary
private  java.net.InetAddress addr
           
private  boolean closed
           
private  ATcpConnection conn
           
private static boolean DEBUG
           
private  GnutellaPacketReader gpr
           
private  GnutellaServer gs
           
private  int port
           
 
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
GnutellaConnection(GnutellaServer gs, ATcpConnection conn)
           
 
Method Summary
 void close(SinkIF compQ)
           
 void enqueue_abort(java.lang.Object key)
          Not supported; throws an IllegalArgumentException.
 void enqueue_commit(java.lang.Object key)
          Not supported; throws an IllegalArgumentException.
 boolean enqueue_lossy(QueueElementIF element)
          Calls enqueue() and returns false if SinkException occurs.
 void enqueue_many(QueueElementIF[] elements)
          Simply calls enqueue() on each item in the array.
 java.lang.Object enqueue_prepare(QueueElementIF[] enqueueMe)
          Not supported; throws an IllegalArgumentException.
 void enqueue(QueueElementIF element)
          Must be implemented by subclasses.
 void flush(SinkIF compQ)
           
 java.net.InetAddress getAddress()
          Return the InetAddress of the peer.
(package private)  ATcpConnection getConnection()
           
 int getPort()
          Return the port of the peer.
(package private)  GnutellaPacketReader getReader()
           
 void sendPing()
          Send a ping to this connection.
 void sendPing(int ttl)
          Send a ping to this connection with the given TTL.
 int size()
          Returns 0.
 java.lang.String toString()
           
 
Methods inherited from class seda.sandStorm.core.SimpleSink
getEnqueuePredicate, profileSize, setEnqueuePredicate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG
See Also:
Constant Field Values

gs

private GnutellaServer gs

gpr

private GnutellaPacketReader gpr

conn

private ATcpConnection conn

addr

private java.net.InetAddress addr

port

private int port

closed

private boolean closed
Constructor Detail

GnutellaConnection

GnutellaConnection(GnutellaServer gs,
                   ATcpConnection conn)
Method Detail

getAddress

public java.net.InetAddress getAddress()
Return the InetAddress of the peer. Returns null if this is a 'virtual' connection.


getPort

public int getPort()
Return the port of the peer. Returns -1 if this is a 'virtual' connection.


sendPing

public void sendPing()
Send a ping to this connection.


sendPing

public void sendPing(int ttl)
Send a ping to this connection with the given TTL.


getConnection

ATcpConnection getConnection()

getReader

GnutellaPacketReader getReader()

enqueue

public void enqueue(QueueElementIF element)
             throws SinkException
Description copied from class: SimpleSink
Must be implemented by subclasses.

Specified by:
enqueue in interface SinkIF
Specified by:
enqueue in class SimpleSink
Parameters:
element - The QueueElementIF to enqueue
Throws:
SinkFullException - Indicates that the sink is temporarily full.
SinkClosedException - Indicates that the sink is no longer being serviced.
SinkException

enqueue_lossy

public boolean enqueue_lossy(QueueElementIF element)
Description copied from class: SimpleSink
Calls enqueue() and returns false if SinkException occurs.

Specified by:
enqueue_lossy in interface SinkIF
Overrides:
enqueue_lossy in class SimpleSink
Parameters:
element - The QueueElementIF to enqueue
Returns:
true if the element was enqueued, false otherwise.

enqueue_many

public void enqueue_many(QueueElementIF[] elements)
                  throws SinkException
Description copied from class: SimpleSink
Simply calls enqueue() on each item in the array. Note that this behavior breaks the property that enqueue_many() should be an "all or nothing" operation, since enqueue() might reject some items but not others. Don't use SimpleSink if this is going to be a problem.

Specified by:
enqueue_many in interface SinkIF
Overrides:
enqueue_many in class SimpleSink
Parameters:
elements - The element array to enqueue
Throws:
SinkFullException - Indicates that the sink is temporarily full.
SinkClosedException - Indicates that the sink is no longer being serviced.
SinkException

size

public int size()
Description copied from class: SimpleSink
Returns 0.

Specified by:
size in interface SinkIF
Overrides:
size in class SimpleSink

close

public void close(SinkIF compQ)
           throws SinkClosedException
Throws:
SinkClosedException

flush

public void flush(SinkIF compQ)
           throws SinkClosedException
Throws:
SinkClosedException

enqueue_prepare

public java.lang.Object enqueue_prepare(QueueElementIF[] enqueueMe)
                                 throws SinkException
Description copied from class: SimpleSink
Not supported; throws an IllegalArgumentException.

Specified by:
enqueue_prepare in interface SinkIF
Overrides:
enqueue_prepare in class SimpleSink
Parameters:
enqueueMe - The element array to provisionally enqueue
Returns:
A "transaction key" that may be used to commit or abort the provisional enqueue
Throws:
SinkFullException - Indicates that the sink is temporarily full and that the requested elements could not be provisionally enqueued.
SinkClosedException - Indicates that the sink is no longer being serviced.
SinkException
See Also:
enqueue_commit, enqueue_abort

enqueue_commit

public void enqueue_commit(java.lang.Object key)
Description copied from class: SimpleSink
Not supported; throws an IllegalArgumentException.

Specified by:
enqueue_commit in interface SinkIF
Overrides:
enqueue_commit in class SimpleSink

enqueue_abort

public void enqueue_abort(java.lang.Object key)
Description copied from class: SimpleSink
Not supported; throws an IllegalArgumentException.

Specified by:
enqueue_abort in interface SinkIF
Overrides:
enqueue_abort in class SimpleSink

toString

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