com.kenmccrary.jtella
Class GNUTellaConnection

java.lang.Object
  |
  +--com.kenmccrary.jtella.GNUTellaConnection

public class GNUTellaConnection
extends java.lang.Object

The GNUTellaConnection represents a connection to the GNUTella network. The connection consists of one or more socket connections to servant nodes on the network.

The following is an example initiating a GNUTellaConnection.

     GNUTellaConnection c = new GNUTellaConnection("gnutellahosts.com", 6346);
     c.start();
 


Constructor Summary
GNUTellaConnection()
          Constructs an empty connection, the application must add a host cache or servant to generate activity
GNUTellaConnection(ConnectionData connData)
          Construct the connection specifying connection data.
GNUTellaConnection(ConnectionData connData, java.lang.String host, int port)
          Construct the connection, providing ConnectionData to initialize the connection and the address of a host cache servant
GNUTellaConnection(java.lang.String host, int port)
          Construct the connection using default connection data and the supplied information regarding the host cache on the network
 
Method Summary
 void addConnection(java.lang.String ipAddress, int port)
          Attempts an outgoing connection on the specified host
 void addHostCacheServant(java.lang.String ipAddress, int port)
          Informs the system of a host cache servant on the network
 FileServerSession createFileServerSession(MessageReceiver receiver)
          Creates a file serving session.
 SearchSession createSearchSession(java.lang.String query, int maxResults, int minSpeed, MessageReceiver receiver)
          Creates a session to conduct network searches
 ConnectionData getConnectionData()
          Get the ConnectionData settings
 java.util.LinkedList getConnectionList()
          Gets the current list of connections to GNUTella
 HostCache getHostCache()
          Get the current HostCache.
 SearchMonitorSession getSearchMonitorSession(MessageReceiver searchReceiver)
          Get a search monitor session to monitor query requests flowing through this network connection.
 short[] getServantIdentifier()
          Get the servant identifier the GnutellaConnection is using.
 boolean isOnline()
          Query if we are online with the network, with at least one active node connection
 void removeHostCacheServant(java.lang.String ipAddress, int port)
          Removes host cache servant information
 void start()
          Starts the connection
 void stop()
          Stop the connection, after execution the GNUTellaConnection is unusable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GNUTellaConnection

public GNUTellaConnection()
                   throws java.net.UnknownHostException,
                          java.io.IOException
Constructs an empty connection, the application must add a host cache or servant to generate activity

GNUTellaConnection

public GNUTellaConnection(java.lang.String host,
                          int port)
                   throws java.net.UnknownHostException,
                          java.io.IOException
Construct the connection using default connection data and the supplied information regarding the host cache on the network
Parameters:
host - can be a machine name or IP address
port - port to use

GNUTellaConnection

public GNUTellaConnection(ConnectionData connData)
                   throws java.net.UnknownHostException,
                          java.io.IOException
Construct the connection specifying connection data. The connection will not have access to a host cache unless specified later.
Parameters:
connData - connection data

GNUTellaConnection

public GNUTellaConnection(ConnectionData connData,
                          java.lang.String host,
                          int port)
                   throws java.net.UnknownHostException,
                          java.io.IOException
Construct the connection, providing ConnectionData to initialize the connection and the address of a host cache servant
Parameters:
host - can be a machine name or IP address
port - port to use
Method Detail

start

public void start()
Starts the connection

stop

public void stop()
Stop the connection, after execution the GNUTellaConnection is unusable. A new connection must be created if needed. If a temporary disconnect from NodeConnections is desired, the connection count requests can be set to 0

getHostCache

public HostCache getHostCache()
Get the current HostCache. Using the HostCache an application can query the known hosts, and add and remove hosts
Returns:
host cache

isOnline

public boolean isOnline()
Query if we are online with the network, with at least one active node connection
Returns:
true if online, false otherwise

getConnectionData

public ConnectionData getConnectionData()
Get the ConnectionData settings
Returns:
connection data

createSearchSession

public SearchSession createSearchSession(java.lang.String query,
                                         int maxResults,
                                         int minSpeed,
                                         MessageReceiver receiver)
Creates a session to conduct network searches
Parameters:
query - search query
maxResults - maximum result set size
minSpeed - minimum speed for responding servants
receiver - receiver for search responses
Returns:
session

getSearchMonitorSession

public SearchMonitorSession getSearchMonitorSession(MessageReceiver searchReceiver)
Get a search monitor session to monitor query requests flowing through this network connection.
Parameters:
searchReceiver - message receiver

createFileServerSession

public FileServerSession createFileServerSession(MessageReceiver receiver)
Creates a file serving session. FileServerSession can respond with a query hit
Parameters:
receiver - message receiver

getConnectionList

public java.util.LinkedList getConnectionList()
Gets the current list of connections to GNUTella
Returns:
list of connections

addConnection

public void addConnection(java.lang.String ipAddress,
                          int port)
Attempts an outgoing connection on the specified host
Parameters:
ipAddress - host IP
port - port number

addHostCacheServant

public void addHostCacheServant(java.lang.String ipAddress,
                                int port)
Informs the system of a host cache servant on the network
Parameters:
ipAddress - host IP
port - port number

removeHostCacheServant

public void removeHostCacheServant(java.lang.String ipAddress,
                                   int port)
Removes host cache servant information
Parameters:
ipAddress - host IP
port - port number

getServantIdentifier

public short[] getServantIdentifier()
Get the servant identifier the GnutellaConnection is using. The servant identifier is used in connection with Push message processing
Returns:
servant identifier