LimeWire Consolidated API

com.limegroup.gnutella.connection
Interface Connection

All Superinterfaces:
Address, Connectable, IpPort
All Known Subinterfaces:
RoutedConnection
All Known Implementing Classes:
AbstractConnection, GnutellaConnection

public interface Connection
extends IpPort, Connectable

Defines an interface by which two parties can communicate using the Gnutella protocol over a Socket. Any capabilities or bandwidth statistics about the connection are retrievable using the getConnectionCapabilities() or getConnectionBandwidthStatistics() methods.

Connection exposes no methods for reading or 'starting', as it is possible for two implementations to use very different methods for processing incoming connections. For example, a blocking implementation would allow the caller to process messages on a case-by-case basis, reading one at a time. An asynchronous implementation (such as implementations of RoutedConnection) would have a start method that would funnel received messages to a third party.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.limewire.io.IpPort
IpPort.IpComparator, IpPort.IpPortComparator
 
Nested classes/interfaces inherited from interface org.limewire.io.Address
Address.EventType
 
Field Summary
 
Fields inherited from interface org.limewire.io.Connectable
COMPARATOR, EMPTY_LIST, EMPTY_SET
 
Fields inherited from interface org.limewire.io.IpPort
IP_COMPARATOR
 
Method Summary
 boolean allowNewPings()
          Returns whether or not we should allow new pings on this connection.
 boolean allowNewPongs()
          Returns whether or not we should allow new pongs on this connection.
 void close()
          Closes the Connection's socket and thus the connection itself.
 String getAddress()
          Returns the IP address of the remote host as a string.
 ConnectionBandwidthStatistics getConnectionBandwidthStatistics()
           
 ConnectionCapabilities getConnectionCapabilities()
           
 long getConnectionTime()
          Returns the time this connection was established, in milliseconds since January 1, 1970.
 InetAddress getInetAddress()
          Returns the address of the foreign host this is connected to.
 InetSocketAddress getInetSocketAddress()
          Returns the InetSocketAddress of the foreign host this is connected to.
 int getListeningPort()
          Gets the port that this connection is listening on.
 String getLocalePref()
          access the locale pref.
 int getPort()
          Accessor for the port number this connection is listening on.
 String getPropertyWritten(String name)
          Returns the value of the given outgoing (written) connection property, or null if no such property.
 Socket getSocket()
          Accessor for the Socket for this connection.
 void handleSimppVM(SimppVM simppVM)
          Sends the SimppVM down the connection
 void handleVendorMessage(VendorMessage vm)
          Call this method when you want to handle us to handle a VM.
 boolean isOpen()
           
 boolean isOutgoing()
          Used to determine whether the connection is incoming or outgoing.
 boolean isReadDeflated()
          Returns true if the incoming stream is deflated.
 boolean isStable()
          Checks whether this connection is considered a stable connection, meaning it has been up for enough time to be considered stable.
 boolean isStable(long millis)
          Checks whether this connection is considered a stable connection, by comparing the time it was established with the millis argument.
 boolean isTLSCapable()
          Returns true if no capabilites VM is received and the connection is TLS encoded, or if a capabilites VM is received and it advertises support for TLS.
 boolean isTLSEncoded()
          Returns true if the connection is currently over TLS.
 boolean isWriteDeflated()
          Returns true if the outgoing stream is deflated.
 void send(Message m)
          Sends a message.
 void sendPostInitializeMessages()
          Call this method when the Connection has been initialized and accepted as 'long-lived'.
 void sendUpdatedCapabilities()
          Call this method if you want to send your neighbours a message with your updated capabilities.
 void setListeningPort(int port)
          Sets the port where the connected node listens at, not the one got from socket
 
Methods inherited from interface org.limewire.io.Address
equals, getAddressDescription, hashCode
 

Method Detail

getConnectionCapabilities

ConnectionCapabilities getConnectionCapabilities()

getConnectionBandwidthStatistics

ConnectionBandwidthStatistics getConnectionBandwidthStatistics()

handleVendorMessage

void handleVendorMessage(VendorMessage vm)
Call this method when you want to handle us to handle a VM. We may....


sendPostInitializeMessages

void sendPostInitializeMessages()
Call this method when the Connection has been initialized and accepted as 'long-lived'.


sendUpdatedCapabilities

void sendUpdatedCapabilities()
Call this method if you want to send your neighbours a message with your updated capabilities.


setListeningPort

void setListeningPort(int port)
Sets the port where the connected node listens at, not the one got from socket


getConnectionTime

long getConnectionTime()
Returns the time this connection was established, in milliseconds since January 1, 1970.

Returns:
the time this connection was established

isOutgoing

boolean isOutgoing()
Used to determine whether the connection is incoming or outgoing.


send

void send(Message m)
          throws IOException
Sends a message. The message may be buffered, so call flush() to guarantee that the message is sent synchronously. This method is NOT thread-safe. Behavior is undefined if two threads are in a send call at the same time for a given connection.

Throws:
IOException

getAddress

String getAddress()
Returns the IP address of the remote host as a string.

Specified by:
getAddress in interface IpPort
Returns:
the IP address of the remote host as a string

getPort

int getPort()
Accessor for the port number this connection is listening on. Note that this is NOT the port of the socket itself. For incoming connections, the getPort method of the java.net.Socket class returns the ephemeral port that the host connected with. This port, however, is the port the remote host is listening on for new connections, which we set using Gnutella connection headers in the case of incoming connections. For outgoing connections, this is the port we used to connect to them -- their listening port.

Specified by:
getPort in interface IpPort
Returns:
the listening port for the remote host

getListeningPort

int getListeningPort()
Gets the port that this connection is listening on. If this is an outgoing connection, it will return the port to which the socket connected. Otherwise, if it is an incoming connection, it will return the port that the remote side had in the Listen-IP header. If there was no port describe, it will return -1.


getInetSocketAddress

InetSocketAddress getInetSocketAddress()
                                       throws IllegalStateException
Returns the InetSocketAddress of the foreign host this is connected to. This is a combination of the getInetAddress() & getPort() methods, it is not the remote socket address (as the listening port may have been updated by connection headers).

Specified by:
getInetSocketAddress in interface IpPort
Returns:
the InetSocketAddress of this host.
Throws:
IllegalStateException - if this is not initialized

getInetAddress

InetAddress getInetAddress()
                           throws IllegalStateException
Returns the address of the foreign host this is connected to.

Specified by:
getInetAddress in interface IpPort
Returns:
the InetAddress for this host
Throws:
IllegalStateException - this is not initialized

getSocket

Socket getSocket()
                 throws IllegalStateException
Accessor for the Socket for this connection.

Returns:
the Socket for this connection
Throws:
IllegalStateException - if this connection is not yet initialized

isStable

boolean isStable()
Checks whether this connection is considered a stable connection, meaning it has been up for enough time to be considered stable.

Returns:
true if the connection is considered stable, otherwise false

isStable

boolean isStable(long millis)
Checks whether this connection is considered a stable connection, by comparing the time it was established with the millis argument.

Returns:
true if the connection is considered stable, otherwise false

getPropertyWritten

String getPropertyWritten(String name)
Returns the value of the given outgoing (written) connection property, or null if no such property. For example, getProperty("X-Supernode") tells whether I am a supernode or a leaf node. If I wrote a property multiple time during connection, returns the latest.


isOpen

boolean isOpen()
Returns:
true until close() is called on this Connection

close

void close()
Closes the Connection's socket and thus the connection itself.


isWriteDeflated

boolean isWriteDeflated()
Returns true if the outgoing stream is deflated.

Returns:
true if the outgoing stream is deflated.

isReadDeflated

boolean isReadDeflated()
Returns true if the incoming stream is deflated.

Returns:
true if the incoming stream is deflated.

isTLSCapable

boolean isTLSCapable()
Returns true if no capabilites VM is received and the connection is TLS encoded, or if a capabilites VM is received and it advertises support for TLS. Otherwise, returns false.

Specified by:
isTLSCapable in interface Connectable

isTLSEncoded

boolean isTLSEncoded()
Returns true if the connection is currently over TLS.


allowNewPings

boolean allowNewPings()
Returns whether or not we should allow new pings on this connection. If we have recently received a ping, we will likely not allow the second ping to go through to avoid flooding the network with ping traffic.

Returns:
true if new pings are allowed along this connection, otherwise false

allowNewPongs

boolean allowNewPongs()
Returns whether or not we should allow new pongs on this connection. If we have recently received a pong, we will likely not allow the second pong to go through to avoid flooding the network with pong traffic. In practice, this is only used to limit pongs sent to leaves.

Returns:
true if new pongs are allowed along this connection, otherwise false

handleSimppVM

void handleSimppVM(SimppVM simppVM)
                   throws IOException
Sends the SimppVM down the connection

Throws:
IOException

getLocalePref

String getLocalePref()
access the locale pref. of the connected servent


LimeWire Consolidated API

Copyright © 2009. All Rights Reserved.