ucr.core
Class Connection

java.lang.Object
  extended byucr.core.Connection
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
NodeConnection

public abstract class Connection
extends java.lang.Object
implements java.lang.Runnable

Represents a connection to an application communicating with the GNUTella protocol


Field Summary
static int CONNECTION_INCOMING
          Connection created by another servant
static int CONNECTION_OUTGOING
          Connection created be JTella servant
protected  ConnectionData connectionData
           
private  java.lang.Thread connectionThread
           
private static java.lang.String CRLF
           
protected  double DROP_RATE
           
private  GUID[] GUIDs
           
private  int[] HITs
           
protected  java.lang.String host
           
(package private)  int idx
           
protected  int inputCount
           
protected  java.io.DataInputStream inputStream
           
protected  java.io.BufferedReader inputStreamBuffer
           
private  java.util.List messageBacklog
           
protected  java.io.DataOutputStream outputStream
           
protected  int port
           
protected  Router router
           
private static java.lang.String SERVER_HELLO
           
private static java.lang.String SERVER_READY
           
private static java.lang.String SERVER_REJECT
           
protected  boolean shutdownFlag
           
(package private)  int SIZE
           
protected  java.net.Socket socket
           
protected  int status
           
static int STATUS_CONNECTING
          Connection is attempting to connected to GNUTella
static int STATUS_FAILED
          Connection is not operating normally
static int STATUS_OK
          Connection is operating normally
static int STATUS_STOPPED
          Connection has been stopped
protected  int type
           
 
Constructor Summary
(package private) Connection(Router router, java.net.Socket socket, ConnectionData connectionData)
          Construct the connection with an existing socket
(package private) Connection(Router router, java.lang.String host, int port, ConnectionData connectionData)
          Construct the Connection using host/port information
 
Method Summary
 void add_query(GUID guid)
           
 void dumpTable()
           
 java.lang.String getConnectedServant()
          Get the connected host
(package private)  java.lang.String getHost()
          Retrieve the host this connection links to
 Host getHostConnectedServant()
          Get the connected host
 int getStatus()
          Get the current status of the connection
 int getType()
          Get the type of connection, incoming or outgoing
 void incr_arrive(GUID guid, int results)
           
private  void initSocket()
          Constructor helper
 int queryhits_arrived()
           
(package private)  void send(Message m)
          Sends a Message through this connection
(package private)  void sendAndReceive(Message m, MessageReceiver receiver)
          Sends a message down the connection and sends any response to MessageReceiver
 void shutdown()
          Stops the connection and cleans up
(package private)  boolean startIncomingConnection(boolean accept)
          Starts an incomming connection to a node on the network, does initial handshake
(package private)  boolean startOutgoingConnection(java.lang.String _MYPORT)
          Starts an outgoing connection to a node on the network, does initial handshaking Initially we will send the other peer our PORT in order to let him know on which port are we accepting connenctions since MYIP+MYPORT provides a unique address for some host
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.lang.Runnable
run
 

Field Detail

STATUS_CONNECTING

public static final int STATUS_CONNECTING
Connection is attempting to connected to GNUTella

See Also:
Constant Field Values

STATUS_OK

public static final int STATUS_OK
Connection is operating normally

See Also:
Constant Field Values

STATUS_FAILED

public static final int STATUS_FAILED
Connection is not operating normally

See Also:
Constant Field Values

STATUS_STOPPED

public static final int STATUS_STOPPED
Connection has been stopped

See Also:
Constant Field Values

CONNECTION_INCOMING

public static final int CONNECTION_INCOMING
Connection created by another servant

See Also:
Constant Field Values

CONNECTION_OUTGOING

public static final int CONNECTION_OUTGOING
Connection created be JTella servant

See Also:
Constant Field Values

CRLF

private static java.lang.String CRLF

SERVER_HELLO

private static java.lang.String SERVER_HELLO

SERVER_READY

private static java.lang.String SERVER_READY

SERVER_REJECT

private static java.lang.String SERVER_REJECT

messageBacklog

private java.util.List messageBacklog

connectionThread

private java.lang.Thread connectionThread

shutdownFlag

protected boolean shutdownFlag

socket

protected java.net.Socket socket

inputStream

protected java.io.DataInputStream inputStream

outputStream

protected java.io.DataOutputStream outputStream

inputStreamBuffer

protected java.io.BufferedReader inputStreamBuffer

router

protected Router router

connectionData

protected ConnectionData connectionData

host

protected java.lang.String host

port

protected int port

status

protected int status

type

protected int type

inputCount

protected int inputCount

DROP_RATE

protected double DROP_RATE

SIZE

int SIZE

GUIDs

private GUID[] GUIDs

HITs

private int[] HITs

idx

int idx
Constructor Detail

Connection

Connection(Router router,
           java.lang.String host,
           int port,
           ConnectionData connectionData)
     throws java.net.UnknownHostException,
            java.io.IOException
Construct the Connection using host/port information

Parameters:
router - message router
host - can be a machine name or IP address
port - port to use

Connection

Connection(Router router,
           java.net.Socket socket,
           ConnectionData connectionData)
     throws java.io.IOException
Construct the connection with an existing socket

Parameters:
router - message router
socket - socket connection to another servant
Method Detail

add_query

public void add_query(GUID guid)

incr_arrive

public void incr_arrive(GUID guid,
                        int results)

queryhits_arrived

public int queryhits_arrived()

dumpTable

public void dumpTable()

initSocket

private void initSocket()
                 throws java.io.IOException
Constructor helper

Throws:
java.io.IOException

getHost

java.lang.String getHost()
Retrieve the host this connection links to


shutdown

public void shutdown()
Stops the connection and cleans up


startOutgoingConnection

boolean startOutgoingConnection(java.lang.String _MYPORT)
Starts an outgoing connection to a node on the network, does initial handshaking Initially we will send the other peer our PORT in order to let him know on which port are we accepting connenctions since MYIP+MYPORT provides a unique address for some host

Returns:
true for a good start, false for failure

startIncomingConnection

boolean startIncomingConnection(boolean accept)
Starts an incomming connection to a node on the network, does initial handshake

Parameters:
accept - is true to accept connection, false to reject
Returns:
true for a good start, false otherwise

sendAndReceive

void sendAndReceive(Message m,
                    MessageReceiver receiver)
              throws java.io.IOException
Sends a message down the connection and sends any response to MessageReceiver

Throws:
java.io.IOException

send

void send(Message m)
    throws java.io.IOException
Sends a Message through this connection

Parameters:
m - message
Throws:
java.io.IOException

getConnectedServant

public java.lang.String getConnectedServant()
Get the connected host

Returns:
host name

getHostConnectedServant

public Host getHostConnectedServant()
Get the connected host

Returns:
host name

getStatus

public int getStatus()
Get the current status of the connection

Returns:
status

getType

public int getType()
Get the type of connection, incoming or outgoing

Returns:
connection type