LimeWire Consolidated API

com.limegroup.gnutella
Class ExtendedEndpoint

java.lang.Object
  extended by com.limegroup.gnutella.Endpoint
      extended by com.limegroup.gnutella.ExtendedEndpoint
All Implemented Interfaces:
Serializable, Cloneable, Address, Connectable, IpPort

public class ExtendedEndpoint
extends Endpoint

An endpoint with additional history information used to prioritize HostCatcher's permanent list:

ExtendedEndpoint has methods to read and write information to a single line of text, e.g.:
    "18.239.0.144:6347,3043,1039939393,529333939;3343434;23433,3934223"
 
This "poor man's serialization" is used to help HostCatcher implement the reading and writing of gnutella.net files.

ExtendedEndpoint does not override the compareTo method because it creates confusion between compareTo and equals. For comparing by priority, users should use the return value of priorityComparator()

See Also:
Serialized Form

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
static String EOL
          We've always used "\n" for the record separator in our gnutella.net files, even on systems that normally use "\r\n" for end-of-line.
 
Fields inherited from interface org.limewire.io.Connectable
COMPARATOR, EMPTY_LIST, EMPTY_SET
 
Fields inherited from interface org.limewire.io.IpPort
IP_COMPARATOR
 
Constructor Summary
ExtendedEndpoint(InetAddress addr, int port)
           
ExtendedEndpoint(InetSocketAddress socketAddress)
          Creates an endpoint from a inet socket address.
ExtendedEndpoint(String host, int port)
          Creates a new ExtendedEndpoint without extended uptime information.
ExtendedEndpoint(String host, int port, int dailyUptime)
          Creates a new ExtendedEndpoint with uptime data read from a ping reply.
ExtendedEndpoint(String host, int port, int dailyUptime, long timeRecorded, boolean strict)
          Creates a new ExtendedEndpoint using data read from a file.
ExtendedEndpoint(String host, int port, String locale)
          creates a new ExtendedEndpoint with the specified locale
 
Method Summary
 void decrementUDPHostCacheFailure()
          Decrements the failures for this UDP Host Cache.
 String getClientLocale()
          accessor for the locale of this endpoint
 Iterator<Long> getConnectionFailures()
          Returns the last few times we successfully connected to this.
 Iterator<Long> getConnectionSuccesses()
          Returns the last few times we successfully connected to this.
 int getDailyUptime()
          Returns the average daily uptime (in seconds per day) reported in this' pong.
 DHTManager.DHTMode getDHTMode()
           
 int getDHTVersion()
           
 long getTimeRecorded()
          Returns the system time (in milliseconds) when this was created.
 int getUDPHostCacheFailures()
          Determines how many failures this UDP host cache had.
 boolean isTLSCapable()
          A getter for supporting TLS.
 boolean isUDPHostCache()
          Determines if this is an ExtendedEndpoint for a UDP Host Cache.
protected  long now()
          Returns the current system time in milliseconds.
static Comparator<ExtendedEndpoint> priorityComparator()
          Returns a Comparator that compares ExtendedEndpoint's by priority, where ExtendedEndpoint's with higher priority are more likely to be available.
static ExtendedEndpoint read(String line)
          Parses a new ExtendedEndpoint.
 void recordConnectionFailure()
          Records that we just failed to connect to this.
 void recordConnectionSuccess()
          Records that we just successfully connected to this.
 void recordUDPHostCacheFailure()
          Records a UDP Host Cache failure.
 void recordUDPHostCacheSuccess()
          Records a UDP Host Cache success.
 void setClientLocale(String l)
          set the locale
 void setDHTMode(DHTManager.DHTMode mode)
           
 void setDHTVersion(int dhtVersion)
           
 void setTLSCapable(boolean capable)
          A setter for supporting TLS.
 ExtendedEndpoint setUDPHostCache(boolean cache)
          Sets if this a UDP host cache endpoint.
 boolean supportsDHT()
           
 void write(Writer out)
          Writes this' state to a single line of out.
 
Methods inherited from class com.limegroup.gnutella.Endpoint
clone, equals, getAddress, getAddressDescription, getFiles, getHostBytes, getInetAddress, getInetSocketAddress, getKbytes, getPort, hashCode, isSameSubnet, normalizeFilesAndSize, setFiles, setHostname, setKbytes, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EOL

public static final String EOL
We've always used "\n" for the record separator in our gnutella.net files, even on systems that normally use "\r\n" for end-of-line. This has the nice advantage of making gnutella.net files portable across platforms.

See Also:
Constant Field Values
Constructor Detail

ExtendedEndpoint

public ExtendedEndpoint(String host,
                        int port,
                        int dailyUptime)
Creates a new ExtendedEndpoint with uptime data read from a ping reply. The creation time is set to the current system time. It is assumed that that we have not yet attempted a connection to this.


ExtendedEndpoint

public ExtendedEndpoint(String host,
                        int port)
Creates a new ExtendedEndpoint without extended uptime information. (The default will be used.) The creation time is set to the current system time. It is assumed that we have not yet attempted a connection to this.


ExtendedEndpoint

public ExtendedEndpoint(InetAddress addr,
                        int port)

ExtendedEndpoint

public ExtendedEndpoint(InetSocketAddress socketAddress)
Creates an endpoint from a inet socket address.


ExtendedEndpoint

public ExtendedEndpoint(String host,
                        int port,
                        int dailyUptime,
                        long timeRecorded,
                        boolean strict)
Creates a new ExtendedEndpoint using data read from a file. It is assumed that we have not yet attempted a connection to this.


ExtendedEndpoint

public ExtendedEndpoint(String host,
                        int port,
                        String locale)
creates a new ExtendedEndpoint with the specified locale

Method Detail

getTimeRecorded

public long getTimeRecorded()
Returns the system time (in milliseconds) when this was created.


getDailyUptime

public int getDailyUptime()
Returns the average daily uptime (in seconds per day) reported in this' pong.


setTLSCapable

public void setTLSCapable(boolean capable)
A setter for supporting TLS.


isTLSCapable

public boolean isTLSCapable()
A getter for supporting TLS.

Specified by:
isTLSCapable in interface Connectable
Overrides:
isTLSCapable in class Endpoint

recordConnectionSuccess

public void recordConnectionSuccess()
Records that we just successfully connected to this.


recordConnectionFailure

public void recordConnectionFailure()
Records that we just failed to connect to this.


getConnectionSuccesses

public Iterator<Long> getConnectionSuccesses()
Returns the last few times we successfully connected to this.

Returns:
an Iterator of system times in milliseconds, each as a Long, in descending order.

getConnectionFailures

public Iterator<Long> getConnectionFailures()
Returns the last few times we successfully connected to this.

Returns:
an Iterator of system times in milliseconds, each as a Long, in descending order.

getClientLocale

public String getClientLocale()
accessor for the locale of this endpoint


setClientLocale

public void setClientLocale(String l)
set the locale


setDHTVersion

public void setDHTVersion(int dhtVersion)

supportsDHT

public boolean supportsDHT()

setDHTMode

public void setDHTMode(DHTManager.DHTMode mode)

getDHTMode

public DHTManager.DHTMode getDHTMode()

getDHTVersion

public int getDHTVersion()

isUDPHostCache

public boolean isUDPHostCache()
Determines if this is an ExtendedEndpoint for a UDP Host Cache.

Overrides:
isUDPHostCache in class Endpoint

recordUDPHostCacheFailure

public void recordUDPHostCacheFailure()
Records a UDP Host Cache failure.


decrementUDPHostCacheFailure

public void decrementUDPHostCacheFailure()
Decrements the failures for this UDP Host Cache. This is intended for use when the network has died and we really don't want to consider the host a failure.


recordUDPHostCacheSuccess

public void recordUDPHostCacheSuccess()
Records a UDP Host Cache success.


getUDPHostCacheFailures

public int getUDPHostCacheFailures()
Determines how many failures this UDP host cache had.


setUDPHostCache

public ExtendedEndpoint setUDPHostCache(boolean cache)
Sets if this a UDP host cache endpoint.


now

protected long now()
Returns the current system time in milliseconds. Exists solely as a hook for testing.


write

public void write(Writer out)
           throws IOException
Writes this' state to a single line of out. Does not flush out.

Throws:
IOException - some problem writing to out
See Also:
read

read

public static ExtendedEndpoint read(String line)
                             throws ParseException
Parses a new ExtendedEndpoint. Strictly validates all data. For example, addresses MUST be in dotted quad format.

Parameters:
line - a single line read from the stream
Returns:
the endpoint constructed from the line
Throws:
IOException - problem reading from in, e.g., EOF reached prematurely
ParseException - data not in proper format. Does NOT necessarily set the offset of the exception properly.
See Also:
write

priorityComparator

public static Comparator<ExtendedEndpoint> priorityComparator()
Returns a Comparator that compares ExtendedEndpoint's by priority, where ExtendedEndpoint's with higher priority are more likely to be available. Currently this is implemented as follows, though the heuristic may change in the future:


LimeWire Consolidated API

Copyright © 2009. All Rights Reserved.