@Override public File getFile() { if (_torrent.isComplete()) { return _torrent.getMetaInfo().getFileSystem().getCompleteFile(); } else { return _torrent.getMetaInfo().getFileSystem().getIncompleteFile(); } }
/** * Stop this download. Calls stop() on the ManagedTorrent, and then removes it from the * TorrentManager's list of them. */ public void stop() { // Tell the ManagedTorrent to stop if (!_torrent.hasStopped()) _torrent.stop(); // Remove it from the program's list RouterService.getTorrentManager().removeTorrent(_torrent, true); }
public boolean isInactive() { switch (_torrent.getState()) { case PAUSED: case STOPPED: return true; } return false; }
/** * Get the number of hosts we are remotely queued on. For BitTorrent, these are remote computers * we're connected to for this torrent, but that are choking us. * * @param The number of connections we have but are witholding data from us */ public int getQueuedHostCount() { // Loop through the ManagedTorrent object's list of BTConnection objects int qd = 0; for (Iterator iter = _torrent.getConnections().iterator(); iter.hasNext(); ) { BTConnection c = (BTConnection) iter.next(); // If this remote computer is choking us, count it if (c.isChoking()) qd++; } // Return the count return qd; }
/** * Get a list of the IP addresses of the remote computers we're connected to in order to get this * torrent. * * @return An Iterator you can move down a list of Endpoint objects */ public Iterator getHosts() { // Make an empty HashSet we'll fill with Endpoint objects and return Set ret = new HashSet(); // Loop for each BTConnection in the ManagedTorrent's list of them for (Iterator iter = _torrent.getConnections().iterator(); iter.hasNext(); ) { BTConnection btc = (BTConnection) iter.next(); // If we're not choking this connection right now, add it's IP address to our list if (!btc.isChoking()) ret.add(btc.getEndpoint()); } // Return the HashSet of Endpoint objects with the addresses return ret.iterator(); }
public void handleTorrentEvent(TorrentEvent evt) { if (evt.getTorrent() != _torrent) return; switch (evt.getType()) { case STARTED: torrentStarted(); break; case STOP_APPROVED: _torrent.stop(); break; case STOPPED: torrentStopped(); dispatcher.removeEventListener(this); break; // the below don't need any special handling... case COMPLETE: case STARTING: case STOP_REQUESTED: // handled in TorrentDHTManager case FIRST_CHUNK_VERIFIED: } }
public UploadStatus getState() { if (_torrent.getState() == TorrentState.STOPPED) { return UploadStatus.CANCELLED; } if (!_torrent.isActive()) { if (_torrent.isComplete() && _torrent.getRatio() > 1) { return UploadStatus.COMPLETE; } return UploadStatus.INTERRUPTED; } if (_torrent.isUploading()) return UploadStatus.UPLOADING; if (_torrent.isSuspended()) return UploadStatus.SUSPENDED; // neither uploading, nor suspended.. return UploadStatus.WAITING_REQUESTS; }
/** * Determine what state this BitTorrent download is in right now. * * <p>The possible states are: QUEUED CONNECTING DOWNLOADING WAITING_FOR_RETRY COMPLETE ABORTED * GAVE_UP COULDNT_MOVE_TO_LIBRARY WAITING_FOR_RESULTS CORRUPT_FILE * * @return The int code for the state */ public int getState() { // Ask the ManagedTorrent object return _torrent.getState(); }
/** * Get the start of the file that we can preview play for the user. BitTorrent downloads don't * happen from the start, so we can't do this. Returns null if the file isn't done yet, and the * whole file if it is. * * @return null if the torrent is still downloading. A Java File object with the path to the saved * file. */ public File getDownloadFragment() { // Return null until we have the entire torrent if (!_torrent.isComplete()) return null; return getFile(); }
public void measureBandwidth() { _torrent.measureBandwidth(); }
public float getMeasuredBandwidth() throws InsufficientDataException { if (!_torrent.isActive()) return 0.f; return _torrent.getMeasuredBandwidth(false); }
/** * Find out how many remote computers don't have any information that we need. Loops through our * connections for this torrent, counting those that are not interesting to us. * * @return The number of connections we have open, but aren't using */ public int getBusyHostCount() { // Have the ManagedTorrent count our connections that have no data we need return _torrent.getNumBusyPeers(); }
/** * Find out how many computers we're connected to in order to get this torrent. * * @return The number of connections we have for this torrent */ public int getNumberOfAlternateLocations() { // Count our connections return _torrent.getNumAltLocs(); }
/** Pause this download. Calls pause() on the ManagedTorrent. */ public void pause() { // Have the ManagedTorrent do it _torrent.pause(); }
public long getTotalAmountUploaded() { return _torrent.getTotalUploaded(); }
/** * Find out how many remote computers we have open connections to sharing this torrent through. * * @return The number of connections we have */ public int getNumHosts() { // Ask the ManagedTorrent that made us, and represents this torrent return _torrent.getNumConnections(); }
/** * Get the path of this BitTorrent download. While we're still getting the torrent, returns a path * like "C:\Documents and Settings\Kevin\Incomplete\File Name.ext". After it's done, returns a * path like "C:\Documents and Settings\Kevin\Shared\File Name.ext". * * @return A Java File object with the path */ public File getFile() { // Return the path in the "Saved" or "Incomplete" folder if (_torrent.isComplete()) return _info.getCompleteFile(); return _info.getBaseFile(); }
/** * Get the torrent's info hash as a text URN, like "urn:sha1:JAZSGOLT6UP4I5N5KGJRZPSF6RZCEJKQ". * The info hash is the SHA1 hash of the "info" section of the bencoded data of the .torrent file. * * @return A String like "urn:sha1:JAZSGOLT6UP4I5N5KGJRZPSF6RZCEJKQ" */ public URN getSHA1Urn() { // Get it from the BTMetaInfo object return _torrent.getMetaInfo().getURN(); }
/** * Determine if this BitTorrent download is finished yet. * * @return true if it's done, false if not */ public boolean isCompleted() { // Ask the ManagedTorrent object return _torrent.isComplete(); }
/** * Find out how many addresses we tried to connect to and we're unable to connect to while making * connections to get this torrent. * * @return The number of addresses we couldn't connect to */ public int getNumberOfInvalidAlternateLocations() { // Count the number of Endpoint objects the ManagedTorrent placed in its _badPeers list return _torrent.getNumBadPeers(); }
@Override public URN getUrn() { return _torrent.getMetaInfo().getURN(); }
/** * Determine if this BitTorrent download is paused. Asks the ManagedTorrent object. * * @return True if the download is paused */ public boolean isPaused() { // Ask the ManagedTorrent object return _torrent.isPaused(); }
@Override public int getNumUploadConnections() { return _torrent.getNumUploadPeers(); }
/** * Determine if this BitTorrent download is paused or stopped. * * @return True if the ManagedTorrent is paused or has stopped. False if it's going. */ public boolean isInactive() { // Return true if the ManagedTorrent is paused or stopped return _torrent.isPaused() || _torrent.hasStopped(); }
/** Resume downloading this torrent. Has the ManagedTorrent object do it. */ public boolean resume() { // Have the ManagedTorrent object do it return _torrent.resume(); }
/** * Find out how many more addresses we have of remote computers that have this torrent. * * @return The number of addressess we could connect to */ public int getPossibleHostCount() { // Get the number of addresses in the ManagedTorrent object's _peers list return _torrent.getNumPeers(); }