com.limegroup.gnutella.downloader
Class MagnetDownloader

java.lang.Object
  extended bycom.limegroup.gnutella.downloader.ManagedDownloader
      extended bycom.limegroup.gnutella.downloader.MagnetDownloader
All Implemented Interfaces:
BandwidthTracker, Downloader, java.io.Serializable

public class MagnetDownloader
extends ManagedDownloader
implements java.io.Serializable

A ManagedDownloader for MAGNET URIs. Unlike a ManagedDownloader, a MagnetDownloader need not have an initial RemoteFileDesc. Instead it can be started with various combinations of the following:

Names in parentheses are those given by the MAGNET specification at http://magnet-uri.sourceforge.net/magnet-draft-overview.txt

Implementation note: this uses ManagedDownloader to try the initial download location. Unfortunately ManagedDownloader requires RemoteFileDesc's. We can fake up most of the RFD fields, but size presents problems. ManagedDownloader depends on size for swarming purposes. It is possible to redesign the swarming algorithm to work around the lack of size, but this is complex, especially with regard to HTTP/1.1 swarming. For this reason, we simply make a HEAD request to get the content length before starting the download.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.limegroup.gnutella.downloader.ManagedDownloader
UNKNOWN_FILENAME
 
Fields inherited from interface com.limegroup.gnutella.Downloader
ABORTED, COMPLETE, CONNECTING, CORRUPT_FILE, COULDNT_MOVE_TO_LIBRARY, DOWNLOADING, GAVE_UP, HASHING, QUEUED, REMOTE_QUEUED, SAVING, WAITING_FOR_CONNECTIONS, WAITING_FOR_RESULTS, WAITING_FOR_RETRY, WAITING_FOR_USER
 
Constructor Summary
MagnetDownloader(DownloadManager manager, FileManager filemanager, IncompleteFileManager ifm, ActivityCallback callback, URN urn, java.lang.String textQuery, java.lang.String filename, java.lang.String[] defaultURLs)
          Creates a new MAGNET downloader.
 
Method Summary
protected  boolean allowAddition(RemoteFileDesc other)
          Overrides ManagedDownloader to allow any files with the right hash/keywords, even if this doesn't currently have any download locations.
 java.lang.String getFileName()
          Overrides ManagedDownloader to display a reasonable file name even when no locations have been found.
protected  QueryRequest newRequery(int numRequeries)
          Overrides ManagedDownloader to use the query words and hash (if any) specified by the MAGNET URI.
protected  void tryAllDownloads(boolean deserialized)
          Overrides ManagedDownloader to ensure that the default location is tried.
 
Methods inherited from class com.limegroup.gnutella.downloader.ManagedDownloader
acceptDownload, addDownload, addDownloadForced, conflicts, conflicts, discardCorruptDownload, finish, getAddress, getAmountRead, getAverageBandwidth, getBrowseEnabledHost, getBusyHostCount, getChatEnabledHost, getContentLength, getDownloadFragment, getFailedState, getHosts, getMeasuredBandwidth, getNumberOfAlternateLocations, getNumDownloaders, getPossibleHostCount, getQueryCount, getQueuedHostCount, getQueuePosition, getRemainingStateTime, getRetriesWaiting, getState, getVendor, hasBrowseEnabledHost, hasChatEnabledHost, hasRFD, initialize, initializeIncompleteFile, measureBandwidth, pauseForRequery, resume, shouldInitAltLocs, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MagnetDownloader

public MagnetDownloader(DownloadManager manager,
                        FileManager filemanager,
                        IncompleteFileManager ifm,
                        ActivityCallback callback,
                        URN urn,
                        java.lang.String textQuery,
                        java.lang.String filename,
                        java.lang.String[] defaultURLs)
Creates a new MAGNET downloader. Immediately tries to download from defaultURLs, if specified. If that fails, or if defaultURLs does not provide alternate locations, issues a requery with textQuery and urn, as provided. (Note that at least one must be non-null.) If filename is specified, it will be used as the name of the complete file; otherwise it will be taken from any search results or guessed from defaultURLs.

Parameters:
manager - controls download queuing; passed to superclass
filemanager - shares saved files; passed to superclass
ifm - maintains blocks stored on disk; passed to superclass
callback - notifies GUI of updates; passed to superclass
urn - the hash of the file (exact topic), or null if unknown
textQuery - requery keywords (keyword topic), or null if unknown
filename - the final file name, or null if unknown
defaultURLs - the initial locations to try (exact source), or null if unknown
Method Detail

tryAllDownloads

protected void tryAllDownloads(boolean deserialized)
Overrides ManagedDownloader to ensure that the default location is tried.

Overrides:
tryAllDownloads in class ManagedDownloader

newRequery

protected QueryRequest newRequery(int numRequeries)
                           throws CantResumeException
Overrides ManagedDownloader to use the query words and hash (if any) specified by the MAGNET URI.

Overrides:
newRequery in class ManagedDownloader
Parameters:
numRequeries - the number of requeries that have already happened
Returns:
a new QueryRequest for making the requery
Throws:
CantResumeException - if this doesn't know what to search for

allowAddition

protected boolean allowAddition(RemoteFileDesc other)
Overrides ManagedDownloader to allow any files with the right hash/keywords, even if this doesn't currently have any download locations.

Overrides:
allowAddition in class ManagedDownloader

getFileName

public java.lang.String getFileName()
Overrides ManagedDownloader to display a reasonable file name even when no locations have been found.

Specified by:
getFileName in interface Downloader
Overrides:
getFileName in class ManagedDownloader