Module: Fargo::Protocol::Peer
- Includes:
- DC, PeerDownload, PeerUpload, Utils
- Defined in:
- lib/fargo/protocol/peer.rb
Constant Summary
Constants included from PeerUpload
Fargo::Protocol::PeerUpload::CHUNKSIZE
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Attributes included from PeerDownload
Instance Method Summary collapse
- #connection_type ⇒ Object
- #post_init ⇒ Object
- #publish_args ⇒ Object
- #receive_message(type, message) ⇒ Object
- #send_lock ⇒ Object
- #supports ⇒ Object
Methods included from PeerUpload
Methods included from PeerDownload
#begin_download!, #parse_data?, #receive_data_chunk, #unbind
Methods included from DC
#parse_data?, #receive_data, #receive_data_chunk, #send_message, #unbind
Methods included from Fargo::Parser
#parse_command_message, #parse_message
Methods included from Utils
#encode_char, #generate_key, #generate_lock
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
12 13 14 |
# File 'lib/fargo/protocol/peer.rb', line 12 def client @client end |
Instance Method Details
#connection_type ⇒ Object
14 15 16 |
# File 'lib/fargo/protocol/peer.rb', line 14 def connection_type :peer end |
#post_init ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/fargo/protocol/peer.rb', line 18 def post_init super set_comm_inactivity_timeout 20 @lock, @pk = generate_lock @handshake_step = 0 end |
#publish_args ⇒ Object
100 101 102 |
# File 'lib/fargo/protocol/peer.rb', line 100 def publish_args {:nick => @other_nick} end |
#receive_message(type, message) ⇒ Object
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 |
# File 'lib/fargo/protocol/peer.rb', line 37 def type, case type when :mynick if @handshake_step == 0 @handshake_step = 1 @other_nick = [:nick] client.channel << [:download_opened, publish_args.merge(:connection => self)] @download = @client.lock_next_download! @other_nick, self @direction = @download.nil? ? 'Upload' : 'Download' else error 'Premature disconnect when mynick received' end when :lock if @handshake_step == 1 @remote_lock = [:lock] @handshake_step = 2 send_lock unless @lock_sent 'Supports', supports 'Direction', "#{@direction} #{@my_num = rand(10000)}" 'Key', generate_key(@remote_lock) else error 'Premature disconnect when lock received' end when :supports if @handshake_step == 2 @client_extensions = [:extensions] @handshake_step = 3 else error 'Premature disconnect when supports received' end when :direction if @handshake_step == 3 @client_num = [:number] @handshake_step = 4 else error 'Premature disconnect when direction received' end when :key if @handshake_step == 4 && generate_key(@lock) == [:key] @handshake_step = 5 begin_download! if @direction == 'Download' else error 'Premature disconnect when key received' end # This wasn't handled by us, proxy it on up to the client else super end end |
#send_lock ⇒ Object
27 28 29 30 31 |
# File 'lib/fargo/protocol/peer.rb', line 27 def send_lock @lock_sent = true 'MyNick', @client.config.nick 'Lock', "#{@lock} Pk=#{@pk}" end |
#supports ⇒ Object
33 34 35 |
# File 'lib/fargo/protocol/peer.rb', line 33 def supports 'MiniSlots XmlBZList ADCGet TTHF ZLIG GetZBlock' end |