Class: PDTP::Server::Transfer

Inherits:
Object
  • Object
show all
Defined in:
lib/pdtp/server/transfer.rb

Overview

stores information for the server about a specific transfer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#acceptorObject (readonly)

Returns the value of attribute acceptor.



28
29
30
# File 'lib/pdtp/server/transfer.rb', line 28

def acceptor
  @acceptor
end

#byte_rangeObject (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

#chunkidObject (readonly)

Returns the value of attribute chunkid.



27
28
29
# File 'lib/pdtp/server/transfer.rb', line 27

def chunkid
  @chunkid
end

#connectorObject (readonly)

Returns the value of attribute connector.



28
29
30
# File 'lib/pdtp/server/transfer.rb', line 28

def connector
  @connector
end

#creation_timeObject

Returns the value of attribute creation_time.



30
31
32
# File 'lib/pdtp/server/transfer.rb', line 30

def creation_time
  @creation_time
end

#giverObject (readonly)

Returns the value of attribute giver.



27
28
29
# File 'lib/pdtp/server/transfer.rb', line 27

def giver
  @giver
end

#takerObject (readonly)

Returns the value of attribute taker.



27
28
29
# File 'lib/pdtp/server/transfer.rb', line 27

def taker
  @taker
end

#transfer_idObject

Returns the value of attribute transfer_id.



29
30
31
# File 'lib/pdtp/server/transfer.rb', line 29

def transfer_id
  @transfer_id
end

#urlObject (readonly)

Returns the value of attribute url.



27
28
29
# File 'lib/pdtp/server/transfer.rb', line 27

def url
  @url
end

#verification_askedObject

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_strObject



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

#failureObject

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_idObject

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

#successObject

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_sObject



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