File: socksify.rb

package info (click to toggle)
ruby-em-socksify 0.3.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 168 kB
  • sloc: ruby: 256; sh: 20; makefile: 3
file content (46 lines) | stat: -rw-r--r-- 958 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
module EventMachine

  module Socksify
    def socksify(host, port, username = nil, password = nil, version = 5, &blk)
      @socks_target_host = host
      @socks_target_port = port
      @socks_username = username
      @socks_password = password
      @socks_version = version
      @socks_data = ''

      socks_hook
      socks_send_handshake

      @socks_deferrable = DefaultDeferrable.new
      @socks_deferrable.callback(&blk) if blk
      @socks_deferrable
    end

    def socks_hook
      if @socks_version == 5
        extend SOCKS5
      else
        raise ArgumentError, 'SOCKS version unsupported'
      end

      class << self
        alias receive_data socks_receive_data
      end
    end

    def socks_unhook(ip = nil)
      class << self
        remove_method :receive_data
      end

      @socks_deferrable.succeed(ip)
    end

    def socks_receive_data(data)
      @socks_data << data
      socks_parse_response
    end
  end

end