class QuartzTorrent::TorrentDataDelegate
Data about torrents for use by the end user.
Attributes
Array
of currently raised alarms
Bitfield
representing which pieces of the torrent are completed.
Count of completed bytes of the torrent
Download rate in bytes/second
Download rate limit in bytes/second if a limit is set, nil otherwise
Download rate limit in bytes/second if a limit is set, nil otherwise
Torrent Metainfo.info
struct. This is nil if the torrent has no metadata and we haven’t downloaded it yet (i.e. a magnet link).
Infohash of the torrent. This is binary data.
How much of the metainfo info we have downloaded in bytes. This is only set when the state is :downloading_metainfo
Length of metainfo info in bytes. This is only set when the state is :downloading_metainfo
Whether or not the torrent is paused.
Array
of peers for the torrent. These include connected, disconnected, and handshaking peers
Whether or not the torrent is queued.
After we have completed downloading a torrent, we will continue to upload until we have uploaded ratio * torrent_size bytes. If nil, no limit on upload.
Recommended display name for this torrent.
State of the torrent. This may be one of :downloading_metainfo, :error, :checking_pieces, :running, :downloading_metainfo, or :deleted. The :deleted state indicates that the torrent that this TorrentDataDelegate
refers to is no longer being managed by the peer client.
Upload rate in bytes/second
Upload rate limit in bytes/second if a limit is set, nil otherwise
Public Class Methods
Create a new TorrentDataDelegate
. This is meant to only be called internally.
# File lib/quartz_torrent/peerclient.rb, line 130 def initialize(torrentData, peerClientHandler) fillFrom(torrentData) @torrentData = torrentData @peerClientHandler = peerClientHandler end
Public Instance Methods
Set the fields of this TorrentDataDelegate
from the passed torrentData. This is meant to only be called internally.
# File lib/quartz_torrent/peerclient.rb, line 190 def internalRefresh fillFrom(@torrentData) end
Update the data in this TorrentDataDelegate
from the torrentData object that it was created from. TODO: What if that torrentData is now gone?
# File lib/quartz_torrent/peerclient.rb, line 184 def refresh @peerClientHandler.updateDelegateTorrentData self end
Private Instance Methods
# File lib/quartz_torrent/peerclient.rb, line 246 def buildPeersList(torrentData) @peers = [] torrentData.peers.all.each do |peer| @peers.push peer.clone end end
# File lib/quartz_torrent/peerclient.rb, line 195 def fillFrom(torrentData) @infoHash = torrentData.infoHash @info = torrentData.info @bytesUploadedDataOnly = torrentData.bytesUploadedDataOnly @bytesDownloadedDataOnly = torrentData.bytesDownloadedDataOnly @bytesUploaded = torrentData.bytesUploaded @bytesDownloaded = torrentData.bytesDownloaded if torrentData.state == :checking_pieces # When checking pieces there is only one request pending with the piece manager. checkExistingRequestId = torrentData.pieceManagerRequestMetadata.keys.first progress = torrentData.pieceManager.progress checkExistingRequestId @completedBytes = progress ? progress * torrentData.info.dataLength / 100 : 0 else @completedBytes = torrentData.blockState.nil? ? 0 : torrentData.blockState.completedLength end # This should really be a copy: @completePieceBitfield = torrentData.blockState.nil? ? nil : torrentData.blockState.completePieceBitfield buildPeersList(torrentData) @downloadRate = @peers.reduce(0){ |memo, peer| memo + peer.uploadRate } @uploadRate = @peers.reduce(0){ |memo, peer| memo + peer.downloadRate } @downloadRateDataOnly = @peers.reduce(0){ |memo, peer| memo + peer.uploadRateDataOnly } @uploadRateDataOnly = @peers.reduce(0){ |memo, peer| memo + peer.downloadRateDataOnly } @state = torrentData.state @metainfoLength = nil @paused = torrentData.paused @queued = torrentData.queued @metainfoCompletedLength = nil if torrentData.metainfoPieceState && torrentData.state == :downloading_metainfo @metainfoLength = torrentData.metainfoPieceState.metainfoLength @metainfoCompletedLength = torrentData.metainfoPieceState.metainfoCompletedLength end if torrentData.info @recommendedName = torrentData.info.name else if torrentData.magnet @recommendedName = torrentData.magnet.displayName else @recommendedName = nil end end @downloadRateLimit = torrentData.downRateLimit.unitsPerSecond if torrentData.downRateLimit @uploadRateLimit = torrentData.upRateLimit.unitsPerSecond if torrentData.upRateLimit @ratio = torrentData.ratio @uploadDuration = torrentData.uploadDuration @alarms = torrentData.alarms.all end