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
-
#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.
- #to_s ⇒ Object
Constructor Details
#initialize(taker, giver, url, chunkid, byte_range, connector_receives = true) ⇒ Transfer
Returns a new instance of Transfer.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/pdtp/server/transfer.rb', line 21 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.
16 17 18 |
# File 'lib/pdtp/server/transfer.rb', line 16 def acceptor @acceptor end |
#byte_range ⇒ Object (readonly)
Returns the value of attribute byte_range.
16 17 18 |
# File 'lib/pdtp/server/transfer.rb', line 16 def byte_range @byte_range end |
#chunkid ⇒ Object (readonly)
Returns the value of attribute chunkid.
15 16 17 |
# File 'lib/pdtp/server/transfer.rb', line 15 def chunkid @chunkid end |
#connector ⇒ Object (readonly)
Returns the value of attribute connector.
16 17 18 |
# File 'lib/pdtp/server/transfer.rb', line 16 def connector @connector end |
#creation_time ⇒ Object
Returns the value of attribute creation_time.
18 19 20 |
# File 'lib/pdtp/server/transfer.rb', line 18 def creation_time @creation_time end |
#giver ⇒ Object (readonly)
Returns the value of attribute giver.
15 16 17 |
# File 'lib/pdtp/server/transfer.rb', line 15 def giver @giver end |
#taker ⇒ Object (readonly)
Returns the value of attribute taker.
15 16 17 |
# File 'lib/pdtp/server/transfer.rb', line 15 def taker @taker end |
#transfer_id ⇒ Object
Returns the value of attribute transfer_id.
17 18 19 |
# File 'lib/pdtp/server/transfer.rb', line 17 def transfer_id @transfer_id end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
15 16 17 |
# File 'lib/pdtp/server/transfer.rb', line 15 def url @url end |
#verification_asked ⇒ Object
Returns the value of attribute verification_asked.
19 20 21 |
# File 'lib/pdtp/server/transfer.rb', line 19 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
45 46 47 48 49 |
# File 'lib/pdtp/server/transfer.rb', line 45 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
55 56 57 58 59 |
# File 'lib/pdtp/server/transfer.rb', line 55 def debug_str str = '' str << "to_s=#{to_s}" str << " taker_id=#{@taker.user_data.client_id} giver_id=#{@giver.user_data.client_id}" end |
#recompute_transfer_id ⇒ Object
calculates the transfer id for this transfer based on the local data
38 39 40 41 42 |
# File 'lib/pdtp/server/transfer.rb', line 38 def recompute_transfer_id id1=connector.user_data.client_id id2=acceptor.user_data.client_id @transfer_id=Transfer::gen_transfer_id(id1,id2,@url,@byte_range) end |
#to_s ⇒ Object
51 52 53 |
# File 'lib/pdtp/server/transfer.rb', line 51 def to_s "taker=#{@taker}, giver=#{@giver}, connector=#{@connector}, acceptor=#{@acceptor}, url=#{@url}, chunk_id=#{@chunkid} range=#{@byte_range}" end |