Class: Fargo::Client
- Inherits:
-
Object
- Object
- Fargo::Client
- Includes:
- ActiveSupport::Callbacks, ActiveSupport::Configurable, Supports::Chat, Supports::Downloads, Supports::FileList, Supports::NickList, Supports::Persistence, Supports::Searches, Supports::Timeout, Supports::Uploads
- Defined in:
- lib/fargo/client.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#hub ⇒ Object
readonly
Returns the value of attribute hub.
Attributes included from Supports::Downloads
#current_downloads, #failed_downloads, #finished_downloads, #queued_downloads, #timed_out, #trying
Attributes included from Supports::NickList
Instance Method Summary collapse
- #connect ⇒ Object
- #connected? ⇒ Boolean
- #description ⇒ Object
- #disconnect ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
Methods included from Supports::FileList
Methods included from Supports::Timeout
Methods included from Supports::Persistence
#connect_with, #connected_with?, #connection_for, #disconnect_from, #nicks_connected_with
Methods included from Supports::Downloads
#clear_failed_downloads, #clear_finished_downloads, #download, #has_download_slot?, #lock_next_download!, #remove_download, #retry_download, #try_again
Methods included from Supports::Searches
#remove_search, #search, #search_files, #search_hub, #search_results, #searches
Methods included from Supports::NickList
#get_info, #get_ip, #info, #nick_has_slot?
Methods included from Supports::Uploads
Methods included from Supports::Chat
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/fargo/client.rb', line 40 def initialize run_callbacks :initialization do @channel = EventMachine::Channel.new @connection_timeouts = {} @channel.subscribe do |type, hash| Fargo.logger.debug "Channel received: #{type} - #{hash.inspect}" end end end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
38 39 40 |
# File 'lib/fargo/client.rb', line 38 def channel @channel end |
#hub ⇒ Object (readonly)
Returns the value of attribute hub.
38 39 40 |
# File 'lib/fargo/client.rb', line 38 def hub @hub end |
Instance Method Details
#connect ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/fargo/client.rb', line 51 def connect EventMachine.error_handler{ |e| Fargo.logger.debug "Error raised during event loop: #{e.}" Fargo.logger.debug e.backtrace.join("\n") } EventMachine.connect config.hub_address, config.hub_port, Fargo::Protocol::Hub do |conn| @hub = conn @hub.client = self end unless config.passive EventMachine.start_server '0.0.0.0', config.active_port, Fargo::Protocol::Download do |conn| conn.client = self end EventMachine.open_datagram_socket '0.0.0.0', config.search_port, Fargo::Protocol::DC do |conn| conn.client = self end end end |
#connected? ⇒ Boolean
76 77 78 |
# File 'lib/fargo/client.rb', line 76 def connected? EventMachine.reactor_running? end |
#description ⇒ Object
85 86 87 |
# File 'lib/fargo/client.rb', line 85 def description "<fargo V:#{Fargo::VERSION},M:#{config.passive ? 'P' : 'A'},H:1/0/0,S:#{open_slots},Dt:1.2.6/W>" end |
#disconnect ⇒ Object
80 81 82 83 |
# File 'lib/fargo/client.rb', line 80 def disconnect Fargo.logger.info 'Disconnecting from hub.' EventMachine.stop_event_loop end |