Class: Fargo::Connection::Hub
- Defined in:
- lib/fargo/connection/hub.rb
Instance Attribute Summary collapse
-
#hubname ⇒ Object
readonly
Returns the value of attribute hubname.
Attributes inherited from Base
Attributes included from Publisher
Instance Method Summary collapse
- #disconnect ⇒ Object
-
#receive(data) ⇒ Object
See <www.teamfair.info/DC-Protocol.htm> for specifics on the DC protocol.
Methods included from Parser
#parse_command_message, #parse_message
Methods included from Utils
#encode_char, #generate_key, #generate_lock
Methods inherited from Base
#connect, #connected?, #initialize, #listen, #open_socket, #write
Methods included from Publisher
#publish, #subscribe, #subscribed_to?, #unsubscribe
Constructor Details
This class inherits a constructor from Fargo::Connection::Base
Instance Attribute Details
#hubname ⇒ Object (readonly)
Returns the value of attribute hubname.
8 9 10 |
# File 'lib/fargo/connection/hub.rb', line 8 def hubname @hubname end |
Instance Method Details
#disconnect ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'lib/fargo/connection/hub.rb', line 109 def disconnect if @client_connections @client_connections.each &:disconnect @client_connections.clear end super end |
#receive(data) ⇒ Object
See <www.teamfair.info/DC-Protocol.htm> for specifics on the DC protocol
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/fargo/connection/hub.rb', line 17 def receive data = data case [:type] when :lock @validated = false write "$Key #{generate_key [:lock]}" when :hubname @hubname = [:name] write "$ValidateNick #{@client.config.nick}" unless @validated when :getpass write "$MyPass #{@client.password}" when :badpass, :hubfull Fargo.logger.warn "Disconnecting because of: #{.inspect}" disconnect when :hello if [:who] == @client.config.nick Fargo.logger.info "Connected to DC Hub #{@hubname} (#{config.address}:#{config.port})" @validated = true write '$Version 1,0091' write '$GetNickList' write "$MyINFO $ALL #{@client.config.nick} " + "#{@client.description}$ $#{@client.config.speed || 'DSL'}" + "#{@status || 1.chr}$#{@client.config.email}" + "$#{@client.share_size}$" end when :connect_to_me if !@client.nicks.include?([:nick]) Fargo.logger.info "Invalid connect_to_me request from: #{[:nick]}" return end @client_connections ||= [] connection = Fargo::Connection::Download.new @client connection.config.address = [:address] connection.config.port = [:port] # we're going to initiate the download connection.config.first = true # proxy all messages from them back to the client and delete the # connection if necessary connection.subscribe { |*args| @client.publish *args @client_connections.delete connection unless connection.connected? } # establish the connection. This will also listen for data to be # read/written connection.connect # keep track of who we're downloading from @client_connections << connection when :search # Make sure we received a valid search request if [:searcher].nil? || !@client.nicks.include?([:searcher]) Fargo.logger.info "Invalid search request: #{.inspect}" return end # Let the client handle the results @results = @client.search_files # Send all the results to the peer. Take care of active/passive # connections @results.each { |r| if [:address] r.active_send @client.config.nick, [:ip], [:port] else write "$SR #{@client.config.nick} #{r}" end } when :revconnect # TODO: Don't send RevConnectToMe when we're passive and # receiving is passive if @client.config.passive write "$RevConnectToMe #{@client.config.nick} #{[:who]}" else write "$ConnectToMe #{@client.config.nick} #{@client.config.address}:#{@client.config.extport}" end # proxy this message on up the stack if we don't handle it else @client.publish [:type], end end |