Class: Fargo::Connection::Upload

Inherits:
Base
  • Object
show all
Includes:
Parser, Utils
Defined in:
lib/fargo/connection/upload.rb

Instance Attribute Summary

Attributes inherited from Base

#socket

Attributes included from Publisher

#subscribers

Instance Method Summary collapse

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?, #disconnect, #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 Method Details

#file_lengthObject



80
81
# File 'lib/fargo/connection/upload.rb', line 80

def file_length
end

#post_listenObject



9
10
11
12
13
# File 'lib/fargo/connection/upload.rb', line 9

def post_listen
  @lock, @pk = generate_lock
  write "$MyNick #{self[:nick]}|$Lock #{@lock} Pk=#{@pk}"
  @handshake_step = 0
end

#receive(data) ⇒ Object



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
# File 'lib/fargo/connection/upload.rb', line 19

def receive data
  message = parse_message data
  publish message[:type], message
  case message[:type]
    when :mynick
      if @handshake_step == 0
        @remote_nick = message[:nick]
        @handshake_step = 1
      else
        disconnect
      end
    when :lock
      if @handshake_step == 1
        @remote_lock = message[:lock]
        @handshake_step = 2
      else
        disconnect
      end
    when :supports
      if @handshake_step == 2
        @remote_extensions = message[:extensions]
        @handshake_step = 3
      else
        disconnect
      end
    when :direction
      if @handshake_step == 3 && message[:direction] == 'download'
        @handshake_step = 4
        @client_num = message[:number]
      else
        disconnect
      end
    when :key
      if @handshake_step == 4 && generate_key(@lock) == message[:key]
        write supports
        write "$Direction Download #{@my_num = rand 10000}"
        write "$Key #{generate_key @remote_lock}"
        @handshake_step = 5
      else
        disconnect
      end
    when :get
      if @handshake_step == 5
        @filepath = message[:path]
        @offset = message[:offset]
        write "$FileLength #{file_length}"
        @handshake_step = 5
      else
        disconnect
      end
    when :send
      write_chunk if @handshake_step == 5
  
    else
      # Fargo.logger.warn "Ignoring `#{data}'\n"
  end
end

#supportsObject



15
16
17
# File 'lib/fargo/connection/upload.rb', line 15

def supports
  "$Supports BZList TTHL TTHF" # ???
end

#write_chunkObject



77
78
# File 'lib/fargo/connection/upload.rb', line 77

def write_chunk
end