com.limegroup.gnutella
Class RemoteFileDesc

java.lang.Object
  extended bycom.limegroup.gnutella.RemoteFileDesc
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
URLRemoteFileDesc

public class RemoteFileDesc
extends java.lang.Object
implements java.io.Serializable

A reference to a single file on a remote machine. In this respect RemoteFileDesc is similar to a URL, but it contains Gnutella- specific data as well, such as the server's 16-byte GUID.

This class is serialized to disk as part of the downloads.dat file. Hence you must be very careful before making any changes. Deleting or changing the types of fields is DISALLOWED. Adding field a F is acceptable as long as the readObject() method of this initializes F to a reasonable value when reading from older files where the fields are not present. This is exactly what we do with _urns and _browseHostEnabled. On the other hand, older version of LimeWire will simply discard any extra fields F if reading from a newer serialized file.

See Also:
Serialized Form

Constructor Summary
RemoteFileDesc(RemoteFileDesc rfd, Endpoint ep)
          Constructs a new RemoteFileDesc exactly like the other one, but with a different remote host.
RemoteFileDesc(java.lang.String host, int port, long index, java.lang.String filename, int size, byte[] clientGUID, int speed, boolean chat, int quality, boolean browseHost, LimeXMLDocument xmlDoc, java.util.Set urns, boolean replyToMulticast, boolean firewalled, java.lang.String vendor, long timestamp, java.util.Set proxies)
          Constructs a new RemoteFileDesc with metadata.
 
Method Summary
 boolean browseHostEnabled()
           
 boolean chatEnabled()
           
 boolean equals(java.lang.Object o)
          Overrides Object.equals to return instance equality based on the equality of all RemoteFileDesc fields.
 java.util.List getAvailableRanges()
          Accessor for the available ranges.
 byte[] getClientGUID()
          Accessor for the client guid for this file, which can be null.
 int getFailedCount()
          Returns the current failed count.
 java.lang.String getFileName()
          Accessor for the file name for this file, which can be null.
 java.lang.String getHost()
          Accessor for the host ip with this file.
 long getIndex()
          Accessor for the index this file, which can be null.
 int getPort()
          Accessor for the port of the host with this file.
 java.util.Set getPushProxies()
          Accessor for the Set of PushProxyInterfaces for this file -- can be empty, but is guaranteed to be non-null.
 int getQuality()
          Returns the "quality" of the remote file in terms of firewalled status, whether or not the remote host has open slots, etc.
 URN getSHA1Urn()
          Accessor for the SHA1 URN for this RemoteFileDesc.
 int getSize()
          Accessor for the size in bytes of this file.
 int getSpeed()
          Accessor for the speed of the host with this file, which can be null.
 java.net.URL getUrl()
          Returns an URL instance for this RemoteFileDesc.
 java.util.Set getUrns()
          Accessor for the Set of URNs for this RemoteFileDesc.
 java.lang.String getVendor()
           
 LimeXMLDocument getXMLDoc()
          Returns the LimeXMLDocument for this RemoteFileDesc, which can be null.
 void incrementFailedCount()
          Increments the failed count by one.
 boolean isAltLocCapable()
           
 boolean isFromAlternateLocation()
          Determines whether or not this RemoteFileDesc was created from an alternate location.
 boolean isHTTP11()
          Accessor for HTTP11.
 boolean isPartialSource()
          Returns true if this is a partial source
 boolean isPrivate()
          Determines whether or not this host reported a private address.
 boolean isReplyToMulticast()
          Determines whether or not this RFD was a reply to a multicast query.
 void resetFailedCount()
          Resets the failed count back to zero.
 void setAvailableRanges(java.util.List availableRanges)
          Mutator for the available ranges.
 void setHTTP11(boolean http11)
          Mutator for HTTP11.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RemoteFileDesc

public RemoteFileDesc(RemoteFileDesc rfd,
                      Endpoint ep)
Constructs a new RemoteFileDesc exactly like the other one, but with a different remote host. It is okay to use the same internal structures for URNs because the Set is immutable.


RemoteFileDesc

public RemoteFileDesc(java.lang.String host,
                      int port,
                      long index,
                      java.lang.String filename,
                      int size,
                      byte[] clientGUID,
                      int speed,
                      boolean chat,
                      int quality,
                      boolean browseHost,
                      LimeXMLDocument xmlDoc,
                      java.util.Set urns,
                      boolean replyToMulticast,
                      boolean firewalled,
                      java.lang.String vendor,
                      long timestamp,
                      java.util.Set proxies)
Constructs a new RemoteFileDesc with metadata.

Parameters:
host - the host's ip
port - the host's port
index - the index of the file that the client sent
filename - the name of the file
clientGUID - the unique identifier of the client
speed - the speed of the connection
chat - true if the location is chattable
quality - the quality of the connection, where 0 is the worst and 3 is the best. (This is the same system as in the GUI but on a 0 to N-1 scale.)
browseHost - specifies whether or not the remote host supports browse host
xmlDoc - the LimeXMLDocument for the response
urns - the Set of URNs for the file
replyToMulticast - true if its from a reply to a multicast query
Throws:
IllegalArgumentException - if any of the arguments are not valid
NullPointerException - if the host argument is null or if the file name is null
Method Detail

isHTTP11

public boolean isHTTP11()
Accessor for HTTP11.

Returns:
Whether or not we think this host supports HTTP11.

setHTTP11

public void setHTTP11(boolean http11)
Mutator for HTTP11. Should be set after connecting.


isPartialSource

public boolean isPartialSource()
Returns true if this is a partial source


getAvailableRanges

public java.util.List getAvailableRanges()
Accessor for the available ranges.


setAvailableRanges

public void setAvailableRanges(java.util.List availableRanges)
Mutator for the available ranges.


getFailedCount

public int getFailedCount()
Returns the current failed count.


incrementFailedCount

public void incrementFailedCount()
Increments the failed count by one.


resetFailedCount

public void resetFailedCount()
Resets the failed count back to zero.


isFromAlternateLocation

public boolean isFromAlternateLocation()
Determines whether or not this RemoteFileDesc was created from an alternate location.


getHost

public final java.lang.String getHost()
Accessor for the host ip with this file.

Returns:
the host ip with this file

getPort

public final int getPort()
Accessor for the port of the host with this file.

Returns:
the file name for the port of the host

getIndex

public final long getIndex()
Accessor for the index this file, which can be null.

Returns:
the file name for this file, which can be null

getSize

public final int getSize()
Accessor for the size in bytes of this file.

Returns:
the size in bytes of this file

getFileName

public final java.lang.String getFileName()
Accessor for the file name for this file, which can be null.

Returns:
the file name for this file, which can be null

getClientGUID

public final byte[] getClientGUID()
Accessor for the client guid for this file, which can be null.

Returns:
the client guid for this file, which can be null

getSpeed

public final int getSpeed()
Accessor for the speed of the host with this file, which can be null.

Returns:
the speed of the host with this file, which can be null

getVendor

public final java.lang.String getVendor()

chatEnabled

public final boolean chatEnabled()

browseHostEnabled

public final boolean browseHostEnabled()

getQuality

public final int getQuality()
Returns the "quality" of the remote file in terms of firewalled status, whether or not the remote host has open slots, etc.

Returns:
the current "quality" of the remote file in terms of the determined likelihood of the request succeeding

getXMLDoc

public final LimeXMLDocument getXMLDoc()
Returns the LimeXMLDocument for this RemoteFileDesc, which can be null.

Returns:
the LimeXMLDocument for this RemoteFileDesc, which can be null.

getUrns

public final java.util.Set getUrns()
Accessor for the Set of URNs for this RemoteFileDesc.

Returns:
the Set of URNs for this RemoteFileDesc

getSHA1Urn

public final URN getSHA1Urn()
Accessor for the SHA1 URN for this RemoteFileDesc.

Returns:
the SHA1 URN for this RemoteFileDesc, or null if there is none

getUrl

public java.net.URL getUrl()
Returns an URL instance for this RemoteFileDesc.

Returns:
an URL instance for this RemoteFileDesc

isReplyToMulticast

public final boolean isReplyToMulticast()
Determines whether or not this RFD was a reply to a multicast query.

Returns:
true if this RFD was in reply to a multicast query, otherwise false

isPrivate

public final boolean isPrivate()
Determines whether or not this host reported a private address.

Returns:
true if the address for this host is private, otherwise false. If the address is unknown, returns true TODO:: use InetAddress in this class for the host so that we don't have to go through the process of creating one each time we check it it's a private address

getPushProxies

public final java.util.Set getPushProxies()
Accessor for the Set of PushProxyInterfaces for this file -- can be empty, but is guaranteed to be non-null.

Returns:
the Set of proxy hosts that will accept push requests for this host -- can be empty

isAltLocCapable

public final boolean isAltLocCapable()
Returns:
true if I am not (firewalled, multicast host, have private IP) and i do have a valid port & address.

equals

public boolean equals(java.lang.Object o)
Overrides Object.equals to return instance equality based on the equality of all RemoteFileDesc fields.

Returns:
true if all of fields of this RemoteFileDesc instance are equal to all of the fields of the specified object, and false if this is not the case, or if the specified object is not a RemoteFileDesc. Dynamic values such as _http11, _proxies and _availableSources are not checked here, as they can change and still be considered the same "remote file".

toString

public java.lang.String toString()