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

#encrypt, #get_table, #merge, #merge_sort

Methods included from Ext

binary_path

Constructor Details

#initialize(options) ⇒ Cli

Returns a new instance of Cli.



12
13
14
15
16
# File 'lib/shadowsocks/cli.rb', line 12

def initialize(options)
  @side   = options[:side]
  @config = options[:config]
  @table  = get_table(config.password)
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

#tableObject

Returns the value of attribute table.



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

def table
  @table
end

Instance Method Details

#runObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/shadowsocks/cli.rb', line 18

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