Class: PDTP::Client::Transfer::Base
- Inherits:
-
Object
- Object
- PDTP::Client::Transfer::Base
- Defined in:
- lib/pdtp/client/transfer.rb
Overview
The base information and methods needed by client transfers
Instance Attribute Summary collapse
-
#byte_range ⇒ Object
readonly
Returns the value of attribute byte_range.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#file_service ⇒ Object
readonly
Returns the value of attribute file_service.
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#peer ⇒ Object
readonly
Returns the value of attribute peer.
-
#peer_id ⇒ Object
readonly
Returns the value of attribute peer_id.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#matches_message?(message) ⇒ Boolean
Returns true if a server message matches this transfer.
-
#parse_http_range(string) ⇒ Object
Takes an HTTP range and returns a ruby Range object.
- #send_ask_verify_message ⇒ Object
-
#send_completed_message(hash) ⇒ Object
Notify the server of transfer completion.
Instance Attribute Details
#byte_range ⇒ Object (readonly)
Returns the value of attribute byte_range.
44 45 46 |
# File 'lib/pdtp/client/transfer.rb', line 44 def byte_range @byte_range end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
45 46 47 |
# File 'lib/pdtp/client/transfer.rb', line 45 def connection @connection end |
#file_service ⇒ Object (readonly)
Returns the value of attribute file_service.
45 46 47 |
# File 'lib/pdtp/client/transfer.rb', line 45 def file_service @file_service end |
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
45 46 47 |
# File 'lib/pdtp/client/transfer.rb', line 45 def hash @hash end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
45 46 47 |
# File 'lib/pdtp/client/transfer.rb', line 45 def method @method end |
#peer ⇒ Object (readonly)
Returns the value of attribute peer.
44 45 46 |
# File 'lib/pdtp/client/transfer.rb', line 44 def peer @peer end |
#peer_id ⇒ Object (readonly)
Returns the value of attribute peer_id.
44 45 46 |
# File 'lib/pdtp/client/transfer.rb', line 44 def peer_id @peer_id end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
44 45 46 |
# File 'lib/pdtp/client/transfer.rb', line 44 def url @url end |
Instance Method Details
#matches_message?(message) ⇒ Boolean
Returns true if a server message matches this transfer
48 49 50 51 52 53 |
# File 'lib/pdtp/client/transfer.rb', line 48 def () @peer == ["peer"] and @url == ["url"] and @byte_range == ["range"] and @peer_id == ["peer_id"] end |
#parse_http_range(string) ⇒ Object
Takes an HTTP range and returns a ruby Range object
56 57 58 59 |
# File 'lib/pdtp/client/transfer.rb', line 56 def parse_http_range(string) raise RuntimeError, "Can't parse range string: #{string}" unless string =~ /bytes=([0-9]+)-([0-9]+)/ (($1).to_i)..(($2).to_i) end |
#send_ask_verify_message ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/pdtp/client/transfer.rb', line 73 def @connection.(:ask_verify, :url => @url, :peer => @peer, :range => @byte_range, :peer_id => @peer_id ) end |
#send_completed_message(hash) ⇒ Object
Notify the server of transfer completion. Hash field is used to denote success or failure
63 64 65 66 67 68 69 70 71 |
# File 'lib/pdtp/client/transfer.rb', line 63 def (hash) @connection.(:completed, :url => @url, :peer => @peer, :range => @byte_range, :peer_id => @peer_id, :hash => hash ) end |