Class: PDTP::Server::ChunkInfo
- Inherits:
-
Object
- Object
- PDTP::Server::ChunkInfo
- Defined in:
- lib/pdtp/server/chunk_info.rb
Overview
Stores information about the chunks requested or provided by a client FIXME this entire class is in need of a rewrite
Defined Under Namespace
Classes: FileStats
Instance Method Summary collapse
-
#get_file_stats ⇒ Object
Returns an array of FileStats objects for debug output.
-
#high_priority_chunk ⇒ Object
returns a high priority requested chunk.
-
#initialize ⇒ ChunkInfo
constructor
A new instance of ChunkInfo.
- #provided?(filename, chunk) ⇒ Boolean
- #requested?(filename, chunk) ⇒ Boolean
-
#set(state, filename, range) ⇒ Object
Set the state for a given chunk range.
Constructor Details
#initialize ⇒ ChunkInfo
Returns a new instance of ChunkInfo.
30 31 32 |
# File 'lib/pdtp/server/chunk_info.rb', line 30 def initialize @files = {} end |
Instance Method Details
#get_file_stats ⇒ Object
Returns an array of FileStats objects for debug output
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/pdtp/server/chunk_info.rb', line 62 def get_file_stats @files.map do |name, chunkmap| fs = FileStats.new fs.file_chunks = chunkmap.last.end + 1 fs.url = name chunkmap.each do |range, state| length = range.end - range.begin + 1 case state when :requested then fs.chunks_requested += length when :provided then fs.chunks_provided += length when :transferring then fs.chunks_transferring += length end end fs end end |
#high_priority_chunk ⇒ Object
returns a high priority requested chunk
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/pdtp/server/chunk_info.rb', line 49 def high_priority_chunk #right now return any chunk @files.each do |name, chunkmap| range, _ = chunkmap.find { |_, state| state == :requested } next unless range return name, range.begin end nil end |
#provided?(filename, chunk) ⇒ Boolean
40 41 42 |
# File 'lib/pdtp/server/chunk_info.rb', line 40 def provided?(filename, chunk) get(filename, chunk) == :provided end |
#requested?(filename, chunk) ⇒ Boolean
44 45 46 |
# File 'lib/pdtp/server/chunk_info.rb', line 44 def requested?(filename,chunk) get(filename, chunk) == :requested end |