Class: PDTP::ClientInfo
- Inherits:
-
Object
- Object
- PDTP::ClientInfo
- Defined in:
- lib/pdtp/server/client_info.rb
Overview
stores information about a single connected client
Instance Attribute Summary collapse
-
#chunk_info ⇒ Object
Returns the value of attribute chunk_info.
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#listen_port ⇒ Object
Returns the value of attribute listen_port.
-
#transfers ⇒ Object
Returns the value of attribute transfers.
-
#trust ⇒ Object
Returns the value of attribute trust.
Instance Method Summary collapse
-
#get_stalled_transfers ⇒ Object
returns a list of all the stalled transfers this client is a part of.
-
#initialize ⇒ ClientInfo
constructor
A new instance of ClientInfo.
-
#wants_download? ⇒ Boolean
(also: #wants_upload?)
returns true if this client wants the server to spawn a transfer for it.
Constructor Details
#initialize ⇒ ClientInfo
Returns a new instance of ClientInfo.
20 21 22 23 24 25 |
# File 'lib/pdtp/server/client_info.rb', line 20 def initialize @chunk_info=ChunkInfo.new @listen_port=6000 #default @trust=Trust.new @transfers=Hash.new end |
Instance Attribute Details
#chunk_info ⇒ Object
Returns the value of attribute chunk_info.
16 17 18 |
# File 'lib/pdtp/server/client_info.rb', line 16 def chunk_info @chunk_info end |
#client_id ⇒ Object
Returns the value of attribute client_id.
17 18 19 |
# File 'lib/pdtp/server/client_info.rb', line 17 def client_id @client_id end |
#listen_port ⇒ Object
Returns the value of attribute listen_port.
17 18 19 |
# File 'lib/pdtp/server/client_info.rb', line 17 def listen_port @listen_port end |
#transfers ⇒ Object
Returns the value of attribute transfers.
18 19 20 |
# File 'lib/pdtp/server/client_info.rb', line 18 def transfers @transfers end |
#trust ⇒ Object
Returns the value of attribute trust.
16 17 18 |
# File 'lib/pdtp/server/client_info.rb', line 16 def trust @trust end |
Instance Method Details
#get_stalled_transfers ⇒ Object
returns a list of all the stalled transfers this client is a part of
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/pdtp/server/client_info.rb', line 44 def get_stalled_transfers stalled=[] timeout=20.0 now=Time.now @transfers.each do |key,t| #only delete if we are the acceptor to prevent race conditions next if t.acceptor.user_data != self if now-t.creation_time > timeout and not t.verification_asked stalled << t end end stalled end |
#wants_download? ⇒ Boolean Also known as: wants_upload?
returns true if this client wants the server to spawn a transfer for it
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/pdtp/server/client_info.rb', line 28 def wants_download? transfer_state_allowed=5 total_allowed=10 transferring=0 @transfers.each do |key, t| transferring=transferring+1 if t.verification_asked return false if transferring >= transfer_state_allowed end @transfers.size < total_allowed end |