LimeWire Consolidated API

com.limegroup.gnutella
Class Endpoint

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

public class Endpoint
extends Object
implements Cloneable, Connectable, IpPort, Serializable

Immutable IP/port pair. Also contains an optional number and size of files, mainly for legacy reasons.

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
 
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
protected Endpoint()
           
  Endpoint(byte[] hostBytes, int port)
          Creates a new Endpoint instance
  Endpoint(byte[] hostBytes, int port, long files, long kbytes)
          Creates a new Endpoint instance
  Endpoint(Endpoint ep)
          Constructs a new endpoint from pre-existing endpoint by copying the fields
  Endpoint(InetAddress addr, int port)
           
  Endpoint(String hostAndPort)
          Returns a new Endpoint from a Gnutella-style host/port pair: If hostAndPort is of the format "host:port", where port is a number, returns new Endpoint(host, port).
  Endpoint(String hostAndPort, boolean requireNumeric)
          Same as new Endpoint(hostAndPort) but with additional restrictions on hostAndPart; if requireNumeric==true and the host part of hostAndPort is not as a numeric dotted-quad IP address, throws IllegalArgumentException.
  Endpoint(String hostAndPort, boolean requireNumeric, boolean strict)
          Constructs a new endpoint.
  Endpoint(String hostname, int port)
           
  Endpoint(String hostname, int port, boolean strict)
          Constructs a new endpoint using the specific hostname & port.
  Endpoint(String hostname, int port, long files, long kbytes)
           
 
Method Summary
protected  Object clone()
           
 boolean equals(Object o)
          Endpoints are equal if their hostnames and ports are.
 String getAddress()
          Assessor for the address string.
 String getAddressDescription()
           
 long getFiles()
          Returns the number of files the host has, or -1 if I don't know
 byte[] getHostBytes()
          This method returns the IP of the end point as an array of bytes
 InetAddress getInetAddress()
          Accessor for the InetAddress instance for this host.
 InetSocketAddress getInetSocketAddress()
          Accessor for the InetSocketAddress that can describe the IP & Port.
 long getKbytes()
          Returns the size of all files the host has, in kilobytes, or -1 if I don't know, it also makes sure that the kbytes/files ratio is not ridiculous, in which case it normalizes the values
 int getPort()
          Assessor for the port this host is listening on.
 int hashCode()
           
 boolean isSameSubnet(Endpoint other)
           
 boolean isTLSCapable()
          Determines if this endpoint supports TLS.
 boolean isUDPHostCache()
          Determines if this is a UDP host cache.
 void normalizeFilesAndSize()
          If the number of files or the kbytes exceed certain limit, it considers them as false data, and initializes the number of files as well as kbytes to zero in that case
 void setFiles(long files)
          Sets the number of files the host has
 void setHostname(String hostname)
           
 void setKbytes(long kbytes)
          Sets the size of all files the host has, in kilobytes,
 String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Endpoint

protected Endpoint()

Endpoint

public Endpoint(String hostAndPort)
         throws IllegalArgumentException
Returns a new Endpoint from a Gnutella-style host/port pair:

Throws:
IllegalArgumentException

Endpoint

public Endpoint(String hostAndPort,
                boolean requireNumeric)
Same as new Endpoint(hostAndPort) but with additional restrictions on hostAndPart; if requireNumeric==true and the host part of hostAndPort is not as a numeric dotted-quad IP address, throws IllegalArgumentException. Examples:
 new Endpoint("www.limewire.org:6346", false) ==> ok
 new Endpoint("not a url:6346", false) ==> ok
 new Endpoint("www.limewire.org:6346", true) ==> IllegalArgumentException
 new Endpoint("64.61.25.172:6346", true) ==> ok
 new Endpoint("64.61.25.172", true) ==> ok
 new Endpoint("127.0.0.1:ABC", false) ==> IllegalArgumentException     
 
If requireNumeric is true no DNS lookups are ever involved. If requireNumeric is false a DNS lookup MAY be performed if the hostname is not numeric.

See Also:
(String))

Endpoint

public Endpoint(String hostAndPort,
                boolean requireNumeric,
                boolean strict)
Constructs a new endpoint. If requireNumeric is true, or strict is false, no DNS lookups are ever involved. If requireNumeric is false or strict is true, a DNS lookup MAY be performed if the hostname is not numeric. To never block, make sure strict is false.


Endpoint

public Endpoint(String hostname,
                int port)

Endpoint

public Endpoint(InetAddress addr,
                int port)

Endpoint

public Endpoint(String hostname,
                int port,
                boolean strict)
Constructs a new endpoint using the specific hostname & port. If strict is true, this does a DNS lookup against the name, failing if the lookup couldn't complete.


Endpoint

public Endpoint(byte[] hostBytes,
                int port)
Creates a new Endpoint instance

Parameters:
hostBytes - IP address of the host (MSB first)
port - The port number for the host

Endpoint

public Endpoint(String hostname,
                int port,
                long files,
                long kbytes)
Parameters:
files - the number of files the host has
kbytes - the size of all of the files, in kilobytes

Endpoint

public Endpoint(byte[] hostBytes,
                int port,
                long files,
                long kbytes)
Creates a new Endpoint instance

Parameters:
hostBytes - IP address of the host (MSB first)
port - The port number for the host
files - the number of files the host has
kbytes - the size of all of the files, in kilobytes

Endpoint

public Endpoint(Endpoint ep)
Constructs a new endpoint from pre-existing endpoint by copying the fields

Parameters:
ep - The endpoint from whom to initialize the member fields of this new endpoint
Method Detail

toString

public String toString()
Overrides:
toString in class Object

getAddress

public String getAddress()
Description copied from interface: IpPort
Assessor for the address string.

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

getInetAddress

public InetAddress getInetAddress()
Accessor for the InetAddress instance for this host. Implements IpPort interface.

Specified by:
getInetAddress in interface IpPort
Returns:
the InetAddress for this host, or null if the InetAddress cannot be created

setHostname

public void setHostname(String hostname)

getPort

public int getPort()
Description copied from interface: IpPort
Assessor for the port this host is listening on.

Specified by:
getPort in interface IpPort
Returns:
the port this host is listening on

getInetSocketAddress

public InetSocketAddress getInetSocketAddress()
Description copied from interface: IpPort
Accessor for the InetSocketAddress that can describe the IP & Port.

Specified by:
getInetSocketAddress in interface IpPort
Returns:
the InetSocketAddress of this host.

getAddressDescription

public String getAddressDescription()
Specified by:
getAddressDescription in interface Address

getFiles

public long getFiles()
Returns the number of files the host has, or -1 if I don't know


setFiles

public void setFiles(long files)
Sets the number of files the host has


getKbytes

public long getKbytes()
Returns the size of all files the host has, in kilobytes, or -1 if I don't know, it also makes sure that the kbytes/files ratio is not ridiculous, in which case it normalizes the values


normalizeFilesAndSize

public void normalizeFilesAndSize()
If the number of files or the kbytes exceed certain limit, it considers them as false data, and initializes the number of files as well as kbytes to zero in that case


setKbytes

public void setKbytes(long kbytes)
Sets the size of all files the host has, in kilobytes,


equals

public boolean equals(Object o)
Endpoints are equal if their hostnames and ports are. The number and size of files does not matter.

Specified by:
equals in interface Address
Overrides:
equals in class Object

hashCode

public int hashCode()
Specified by:
hashCode in interface Address
Overrides:
hashCode in class Object

clone

protected Object clone()
Overrides:
clone in class Object

getHostBytes

public byte[] getHostBytes()
                    throws UnknownHostException
This method returns the IP of the end point as an array of bytes

Throws:
UnknownHostException

isSameSubnet

public boolean isSameSubnet(Endpoint other)

isUDPHostCache

public boolean isUDPHostCache()
Determines if this is a UDP host cache.


isTLSCapable

public boolean isTLSCapable()
Determines if this endpoint supports TLS.

Specified by:
isTLSCapable in interface Connectable

LimeWire Consolidated API

Copyright © 2009. All Rights Reserved.