Class: Shadowsocks::Cli

Inherits:
Object
  • Object
show all
Includes:
Table
Defined in:
lib/shadowsocks/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Table

#get_table, #merge, #merge_sort, #translate

Methods included from Ext

binary_path

Constructor Details

#initialize(options) ⇒ Cli

Returns a new instance of Cli.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/shadowsocks/cli.rb', line 12

def initialize(options)
  @side        = options[:side]
  @config      = options[:config]
  @ip_detector = Shadowsocks::IPDetector.new if @config.chnroutes

  @method_options = {
    method:   config.method,
    password: config.password
  }

  if @config.method == 'table'
    table = get_table(config.password)
    @method_options.merge!(
      encrypt_table: table[:encrypt],
      decrypt_table: table[:decrypt]
    )
  end
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



10
11
12
# File 'lib/shadowsocks/cli.rb', line 10

def args
  @args
end

#configObject

Returns the value of attribute config.



10
11
12
# File 'lib/shadowsocks/cli.rb', line 10

def config
  @config
end

#sideObject

Returns the value of attribute side.



10
11
12
# File 'lib/shadowsocks/cli.rb', line 10

def side
  @side
end

Instance Method Details

#runObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/shadowsocks/cli.rb', line 31

def run
  case side
  when :local
    EventMachine::run {
      Signal.trap("INT")  { EventMachine.stop }
      Signal.trap("TERM") { EventMachine.stop }

      puts "*** Local side is up, port:#{config.local_port}"
      puts "*** Hit Ctrl+c to stop"
      EventMachine::start_server "0.0.0.0", config.local_port, Shadowsocks::Local::LocalListener, &method(:initialize_connection)
    }
  when :server
    EventMachine::run {
      Signal.trap("INT")  { EventMachine.stop }
      Signal.trap("TERM") { EventMachine.stop }

      puts "*** Server side is up, port:#{config.server_port}"
      puts "*** Hit Ctrl+c to stop"

      EventMachine::start_server "0.0.0.0", config.server_port, Shadowsocks::Server::ServerListener, &method(:initialize_connection)
    }
  end
end