Class: PDTP::Server::Transfer
- Inherits:
-
Object
- Object
- PDTP::Server::Transfer
- Defined in:
- lib/pdtp/server/transfer.rb
Overview
stores information for the server about a specific transfer
Instance Attribute Summary collapse
-
#acceptor ⇒ Object
readonly
Returns the value of attribute acceptor.
-
#byte_range ⇒ Object
readonly
Returns the value of attribute byte_range.
-
#chunkid ⇒ Object
readonly
Returns the value of attribute chunkid.
-
#connector ⇒ Object
readonly
Returns the value of attribute connector.
-
#creation_time ⇒ Object
Returns the value of attribute creation_time.
-
#giver ⇒ Object
readonly
Returns the value of attribute giver.
-
#taker ⇒ Object
readonly
Returns the value of attribute taker.
-
#transfer_id ⇒ Object
Returns the value of attribute transfer_id.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#verification_asked ⇒ Object
Returns the value of attribute verification_asked.
Class Method Summary collapse
-
.gen_transfer_id(id1, id2, url, byte_range) ⇒ Object
Generates a transfer id based on 2 client ids, a url, and a byte range.
Instance Method Summary collapse
- #debug_str ⇒ Object
-
#failure ⇒ Object
Update internal data upon a failed transfer.
-
#initialize(taker, giver, url, chunkid, byte_range, connector_receives = true) ⇒ Transfer
constructor
A new instance of Transfer.
-
#recompute_transfer_id ⇒ Object
Calculates the transfer id for this transfer based on the local data.
-
#success ⇒ Object
Update internal data upon a successful transfer.
- #to_s ⇒ Object
Constructor Details
#initialize(taker, giver, url, chunkid, byte_range, connector_receives = true) ⇒ Transfer
Returns a new instance of Transfer.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/pdtp/server/transfer.rb', line 40 def initialize(taker, giver, url, chunkid, byte_range, connector_receives = true) @taker, @giver, @url, @chunkid, @byte_range = taker, giver, url, chunkid, byte_range @verification_asked = false @creation_time = Time.now if connector_receives @connector = @taker @acceptor = @giver else @connector = @giver @acceptor = @taker end recompute_transfer_id end |
Instance Attribute Details
#acceptor ⇒ Object (readonly)
Returns the value of attribute acceptor.
28 29 30 |
# File 'lib/pdtp/server/transfer.rb', line 28 def acceptor @acceptor end |
#byte_range ⇒ Object (readonly)
Returns the value of attribute byte_range.
28 29 30 |
# File 'lib/pdtp/server/transfer.rb', line 28 def byte_range @byte_range end |
#chunkid ⇒ Object (readonly)
Returns the value of attribute chunkid.
27 28 29 |
# File 'lib/pdtp/server/transfer.rb', line 27 def chunkid @chunkid end |
#connector ⇒ Object (readonly)
Returns the value of attribute connector.
28 29 30 |
# File 'lib/pdtp/server/transfer.rb', line 28 def connector @connector end |
#creation_time ⇒ Object
Returns the value of attribute creation_time.
30 31 32 |
# File 'lib/pdtp/server/transfer.rb', line 30 def creation_time @creation_time end |
#giver ⇒ Object (readonly)
Returns the value of attribute giver.
27 28 29 |
# File 'lib/pdtp/server/transfer.rb', line 27 def giver @giver end |
#taker ⇒ Object (readonly)
Returns the value of attribute taker.
27 28 29 |
# File 'lib/pdtp/server/transfer.rb', line 27 def taker @taker end |
#transfer_id ⇒ Object
Returns the value of attribute transfer_id.
29 30 31 |
# File 'lib/pdtp/server/transfer.rb', line 29 def transfer_id @transfer_id end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
27 28 29 |
# File 'lib/pdtp/server/transfer.rb', line 27 def url @url end |
#verification_asked ⇒ Object
Returns the value of attribute verification_asked.
31 32 33 |
# File 'lib/pdtp/server/transfer.rb', line 31 def verification_asked @verification_asked end |
Class Method Details
.gen_transfer_id(id1, id2, url, byte_range) ⇒ Object
Generates a transfer id based on 2 client ids, a url, and a byte range
34 35 36 37 38 |
# File 'lib/pdtp/server/transfer.rb', line 34 def self.gen_transfer_id(id1,id2,url,byte_range) a = id1 < id2 ? id1 : id2 b = id1 < id2 ? id2 : id1 "#{a}$#{b}$#{url}$#{byte_range}" end |
Instance Method Details
#debug_str ⇒ Object
79 80 81 82 83 |
# File 'lib/pdtp/server/transfer.rb', line 79 def debug_str str = '' str << "to_s=#{to_s}" str << " taker_id=#{@taker.client_id} giver_id=#{@giver.client_id}" end |
#failure ⇒ Object
Update internal data upon a failed transfer
71 72 73 |
# File 'lib/pdtp/server/transfer.rb', line 71 def failure taker.failure self end |
#recompute_transfer_id ⇒ Object
Calculates the transfer id for this transfer based on the local data
58 59 60 61 62 |
# File 'lib/pdtp/server/transfer.rb', line 58 def recompute_transfer_id id1 = connector.client_id id2 = acceptor.client_id @transfer_id = Transfer::gen_transfer_id id1, id2, @url, @byte_range end |
#success ⇒ Object
Update internal data upon a successful transfer
65 66 67 68 |
# File 'lib/pdtp/server/transfer.rb', line 65 def success giver.success self taker.success self end |
#to_s ⇒ Object
75 76 77 |
# File 'lib/pdtp/server/transfer.rb', line 75 def to_s "taker=#{@taker}, giver=#{@giver}, connector=#{@connector}, acceptor=#{@acceptor}, url=#{@url}, chunk_id=#{@chunkid} range=#{@byte_range}" end |