Class: PDTP::Server::FileService::Protocol
- Inherits:
-
Client::Connection
- Object
- EventMachine::Connection
- LengthPrefixProtocol
- Protocol
- Client::Connection
- PDTP::Server::FileService::Protocol
- Defined in:
- lib/pdtp/server/file_service_protocol.rb
Overview
Implements the file service for the pdtp protocol
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#file_service ⇒ Object
readonly
Returns the value of attribute file_service.
-
#lock ⇒ Object
readonly
Returns the value of attribute lock.
-
#transfers ⇒ Object
readonly
Returns the value of attribute transfers.
Attributes inherited from Client::Connection
Instance Method Summary collapse
-
#connection_completed ⇒ Object
Called after a connection to the server has been established.
-
#initialize(*args) ⇒ Protocol
constructor
A new instance of Protocol.
Methods inherited from Client::Connection
#finished, #print_stats, #receive_message, #unbind
Methods inherited from Protocol
#connection_open?, define_message_params, #error_close_connection, #get_peer_info, #hash_to_range, obj_matches_type?, #post_init, print_info, #range_to_hash, #receive_packet, #remote_peer_id, #send_message, #to_s, #unbind, validate_message
Methods inherited from LengthPrefixProtocol
#prefix_size=, #receive_data, #receive_packet, #send_packet
Constructor Details
#initialize(*args) ⇒ Protocol
Returns a new instance of Protocol.
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/pdtp/server/file_service_protocol.rb', line 39 def initialize *args @transfers = [] @client = self @connection = self @client_id = Digest::MD5.hexdigest "#{Time.now.to_f}#{$$}" @listen_addr = '0.0.0.0' @listen_port = 60860 @vhost = @listen_addr super end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
37 38 39 |
# File 'lib/pdtp/server/file_service_protocol.rb', line 37 def client @client end |
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
37 38 39 |
# File 'lib/pdtp/server/file_service_protocol.rb', line 37 def client_id @client_id end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
37 38 39 |
# File 'lib/pdtp/server/file_service_protocol.rb', line 37 def connection @connection end |
#file_service ⇒ Object (readonly)
Returns the value of attribute file_service.
37 38 39 |
# File 'lib/pdtp/server/file_service_protocol.rb', line 37 def file_service @file_service end |
#lock ⇒ Object (readonly)
Returns the value of attribute lock.
37 38 39 |
# File 'lib/pdtp/server/file_service_protocol.rb', line 37 def lock @lock end |
#transfers ⇒ Object (readonly)
Returns the value of attribute transfers.
37 38 39 |
# File 'lib/pdtp/server/file_service_protocol.rb', line 37 def transfers @transfers end |
Instance Method Details
#connection_completed ⇒ Object
Called after a connection to the server has been established
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/pdtp/server/file_service_protocol.rb', line 52 def connection_completed begin @http_server.register "/", Client::HttpHandler.new(self) # Register our client_id and listen_port :register, :listen_port => @listen_port, :client_id => @client_id @file_service = PDTP::Server::FileService.new @file_service.root = @base_path # Provide all the files in the root directory files = find_files @base_path files.each { |file| :provide, :url => "http://#{@vhost}/#{file}" } rescue Exception => e puts "Exception in connection_completed: #{e}" puts e.backtrace.join("\n") exit end end |