com.limegroup.gnutella
Class Endpoint

java.lang.Object
  extended bycom.limegroup.gnutella.Endpoint
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable, java.io.Serializable
Direct Known Subclasses:
EndpointData, ExtendedEndpoint

public class Endpoint
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable, java.lang.Comparable

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

See Also:
Serialized Form

Field Summary
 boolean processed
          Needed for Network Discovery.
 
Constructor Summary
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(java.lang.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(java.lang.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(java.lang.String hostname, int port)
           
Endpoint(java.lang.String hostname, int port, long files, long kbytes)
           
 
Method Summary
protected  java.lang.Object clone()
           
 int compareTo(java.lang.Object o)
          The comparison function (It uses the connectivity as the measure for comparison ie if a.connectivity > b.connectivity then a.compareTo(b) > 0
 boolean equals(java.lang.Object o)
          Endpoints are equal if their hostnames and ports are.
 int getConnectivity()
          returns the connectivity of the node
 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
 java.lang.String getHostname()
           
 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()
           
 int getWeight()
          Gets the weight of this endpoint
 int hashCode()
           
 boolean isPrivateAddress()
           
 boolean isSameSubnet(Endpoint other)
           
 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 setConnectivity(int connectivity)
          Sets the connectivity of the node
 void setFiles(long files)
          Sets the number of files the host has
 void setHostname(java.lang.String hostname)
           
 void setKbytes(long kbytes)
          Sets the size of all files the host has, in kilobytes,
 void setWeight(int weight)
          Sets the weight of the node
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

processed

public transient boolean processed
Needed for Network Discovery. Records information regarding wthether the neighbours of this node has been identified or not

Constructor Detail

Endpoint

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


Endpoint

public Endpoint(java.lang.String hostAndPort,
                boolean requireNumeric)
         throws java.lang.IllegalArgumentException
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     
 
No DNS lookups are ever involved, so this constructor won't block.

See Also:
(String))

Endpoint

public Endpoint(java.lang.String hostname,
                int port)

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(java.lang.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

setConnectivity

public void setConnectivity(int connectivity)
Sets the connectivity of the node

Parameters:
connectivity - the connectivity to be set

setWeight

public void setWeight(int weight)
Sets the weight of the node

Parameters:
weight - the weight to be set

getWeight

public int getWeight()
Gets the weight of this endpoint

Returns:
The weight of the endpoint

getConnectivity

public int getConnectivity()
returns the connectivity of the node

Returns:
The connectivity of the node

compareTo

public int compareTo(java.lang.Object o)
The comparison function (It uses the connectivity as the measure for comparison ie if a.connectivity > b.connectivity then a.compareTo(b) > 0

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - the other object to be compared to

toString

public java.lang.String toString()

getHostname

public java.lang.String getHostname()

setHostname

public void setHostname(java.lang.String hostname)

getPort

public int getPort()

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(java.lang.Object o)
Endpoints are equal if their hostnames and ports are. The number and size of files does not matter.


hashCode

public int hashCode()

clone

protected java.lang.Object clone()

getHostBytes

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

Throws:
java.net.UnknownHostException

isPrivateAddress

public boolean isPrivateAddress()

isSameSubnet

public boolean isSameSubnet(Endpoint other)