Class: PDTP::Server::ClientInfo
- Inherits:
-
Object
- Object
- PDTP::Server::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.
33 34 35 36 37 38 |
# File 'lib/pdtp/server/client_info.rb', line 33 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.
29 30 31 |
# File 'lib/pdtp/server/client_info.rb', line 29 def chunk_info @chunk_info end |
#client_id ⇒ Object
Returns the value of attribute client_id.
30 31 32 |
# File 'lib/pdtp/server/client_info.rb', line 30 def client_id @client_id end |
#listen_port ⇒ Object
Returns the value of attribute listen_port.
30 31 32 |
# File 'lib/pdtp/server/client_info.rb', line 30 def listen_port @listen_port end |
#transfers ⇒ Object
Returns the value of attribute transfers.
31 32 33 |
# File 'lib/pdtp/server/client_info.rb', line 31 def transfers @transfers end |
#trust ⇒ Object
Returns the value of attribute trust.
29 30 31 |
# File 'lib/pdtp/server/client_info.rb', line 29 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
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/pdtp/server/client_info.rb', line 57 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
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/pdtp/server/client_info.rb', line 41 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 |