girl 9.1.2 → 9.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/girl/proxyd.rb CHANGED
@@ -11,63 +11,63 @@ require 'socket'
11
11
  module Girl
12
12
  class Proxyd
13
13
 
14
- def initialize( config_path = nil )
15
- if config_path then
16
- raise "not found config file #{ config_path }" unless File.exist?( config_path )
17
- conf = JSON.parse( IO.binread( config_path ), symbolize_names: true )
18
- puts "load #{ config_path } #{ conf.inspect }"
19
- proxyd_port = conf[ :proxyd_port ]
20
- memd_port = conf[ :memd_port ]
21
- nameserver = conf[ :nameserver ]
22
- reset_traff_day = conf[ :reset_traff_day ]
23
- ims = conf[ :ims ]
24
- p2d_host = conf[ :p2d_host ]
25
- p2d_port = conf[ :p2d_port ]
26
- head_len = conf[ :head_len ] # 头长度
27
- h_a_new_source = conf[ :h_a_new_source ] # A
28
- h_a_new_p2 = conf[ :h_a_new_p2 ] # B
29
- h_dst_close = conf[ :h_dst_close ] # D
30
- h_heartbeat = conf[ :h_heartbeat ] # H
31
- h_p1_close = conf[ :h_p1_close ] # I
32
- h_p2_close = conf[ :h_p2_close ] # J
33
- h_p2_traffic = conf[ :h_p2_traffic ] # K
34
- h_p1_overflow = conf[ :h_p1_overflow ] # L
35
- h_p1_underhalf = conf[ :h_p1_underhalf ] # M
36
- h_p2_overflow = conf[ :h_p2_overflow ] # N
37
- h_p2_underhalf = conf[ :h_p2_underhalf ] # O
38
- h_query = conf[ :h_query ] # Q
39
- h_response = conf[ :h_response ] # R
40
- h_src_close = conf[ :h_src_close ] # S
41
- h_traffic = conf[ :h_traffic ] # T
42
- h_src_overflow = conf[ :h_src_overflow ] # U
43
- h_src_underhalf = conf[ :h_src_underhalf ] # V
44
- h_dst_overflow = conf[ :h_dst_overflow ] # W
45
- h_dst_underhalf = conf[ :h_dst_underhalf ] # X
46
- expire_connecting = conf[ :expire_connecting ] # 连接多久没有建成关闭(秒)
47
- expire_long_after = conf[ :expire_long_after ] # 长连接多久没有新流量关闭(秒)
48
- expire_proxy_after = conf[ :expire_proxy_after ] # proxy多久没有收到流量重建(秒)
49
- expire_resolv_cache = conf[ :expire_resolv_cache ] # dns查询结果缓存多久(秒)
50
- expire_short_after = conf[ :expire_short_after ] # 短连接创建多久后关闭(秒)
51
- is_debug = conf[ :is_debug ]
14
+ def initialize(config_path = nil)
15
+ if config_path
16
+ raise "not found config file #{config_path}" unless File.exist?(config_path)
17
+ conf = JSON.parse(IO.binread(config_path), symbolize_names: true)
18
+ puts "load #{config_path} #{conf.inspect}"
19
+ proxyd_port = conf[:proxyd_port]
20
+ memd_port = conf[:memd_port]
21
+ nameserver = conf[:nameserver]
22
+ reset_traff_day = conf[:reset_traff_day]
23
+ ims = conf[:ims]
24
+ p2d_host = conf[:p2d_host]
25
+ p2d_port = conf[:p2d_port]
26
+ head_len = conf[:head_len] # 头长度
27
+ h_a_new_source = conf[:h_a_new_source] # A
28
+ h_a_new_p2 = conf[:h_a_new_p2] # B
29
+ h_dst_close = conf[:h_dst_close] # D
30
+ h_heartbeat = conf[:h_heartbeat] # H
31
+ h_p1_close = conf[:h_p1_close] # I
32
+ h_p2_close = conf[:h_p2_close] # J
33
+ h_p2_traffic = conf[:h_p2_traffic] # K
34
+ h_p1_overflow = conf[:h_p1_overflow] # L
35
+ h_p1_underhalf = conf[:h_p1_underhalf] # M
36
+ h_p2_overflow = conf[:h_p2_overflow] # N
37
+ h_p2_underhalf = conf[:h_p2_underhalf] # O
38
+ h_query = conf[:h_query] # Q
39
+ h_response = conf[:h_response] # R
40
+ h_src_close = conf[:h_src_close] # S
41
+ h_traffic = conf[:h_traffic] # T
42
+ h_src_overflow = conf[:h_src_overflow] # U
43
+ h_src_underhalf = conf[:h_src_underhalf] # V
44
+ h_dst_overflow = conf[:h_dst_overflow] # W
45
+ h_dst_underhalf = conf[:h_dst_underhalf] # X
46
+ expire_connecting = conf[:expire_connecting] # 连接多久没有建成关闭(秒)
47
+ expire_long_after = conf[:expire_long_after] # 长连接多久没有新流量关闭(秒)
48
+ expire_proxy_after = conf[:expire_proxy_after] # proxy多久没有收到流量重建(秒)
49
+ expire_resolv_cache = conf[:expire_resolv_cache] # dns查询结果缓存多久(秒)
50
+ expire_short_after = conf[:expire_short_after] # 短连接创建多久后关闭(秒)
51
+ is_debug = conf[:is_debug]
52
52
  end
53
53
 
54
54
  proxyd_port = proxyd_port ? proxyd_port.to_i : 6060
55
55
  memd_port = memd_port ? memd_port.to_i : proxyd_port + 1
56
56
 
57
- if nameserver then
58
- nameservers = nameserver.split( ' ' )
57
+ if nameserver
58
+ nameservers = nameserver.split(' ')
59
59
  else
60
60
  nameservers = []
61
61
  resolv_path = '/etc/resolv.conf'
62
62
 
63
- if File.exist?( resolv_path ) then
64
- text = IO.read( '/etc/resolv.conf' )
63
+ if File.exist?(resolv_path)
64
+ text = IO.read('/etc/resolv.conf')
65
65
 
66
- text.split( "\n" ).each do | line |
67
- match_data = /^nameserver \d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}/.match( line )
66
+ text.split("\n").each do |line|
67
+ match_data = /^nameserver \d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}/.match(line)
68
68
 
69
- if match_data then
70
- nameservers << match_data[ 0 ].split(' ')[ 1 ].strip
69
+ if match_data
70
+ nameservers << match_data[0].split(' ')[1].strip
71
71
  break if nameservers.size >= 3
72
72
  end
73
73
  end
@@ -106,23 +106,20 @@ module Girl
106
106
  expire_short_after = expire_short_after ? expire_short_after.to_i : 5
107
107
  is_server_fastopen = false
108
108
 
109
- if RUBY_PLATFORM.include?( 'linux' ) then
110
- IO.popen( 'sysctl -n net.ipv4.tcp_fastopen' ) do | io |
109
+ if RUBY_PLATFORM.include?('linux')
110
+ IO.popen('sysctl -n net.ipv4.tcp_fastopen') do |io|
111
111
  output = io.read
112
112
  val = output.to_i % 4
113
-
114
- if [ 2, 3 ].include?( val ) then
115
- is_server_fastopen = true
116
- end
113
+ is_server_fastopen = true if [2, 3].include?(val)
117
114
  end
118
115
  end
119
116
 
120
- puts "girl proxyd #{ Girl::VERSION }"
121
- puts "#{ proxyd_port } #{ memd_port } #{ p2d_host } #{ p2d_port } #{ nameservers.inspect } #{ reset_traff_day } #{ is_server_fastopen }"
117
+ puts "girl proxyd #{Girl::VERSION}"
118
+ puts "#{proxyd_port} #{memd_port} #{p2d_host} #{p2d_port} #{nameservers.inspect} #{reset_traff_day} #{is_server_fastopen}"
122
119
 
123
- if %w[ darwin linux ].any?{ | plat | RUBY_PLATFORM.include?( plat ) } then
124
- Process.setrlimit( :NOFILE, RLIMIT )
125
- puts "NOFILE #{ Process.getrlimit( :NOFILE ).inspect }"
120
+ if %w[darwin linux].any?{|plat| RUBY_PLATFORM.include?(plat)}
121
+ Process.setrlimit(:NOFILE, RLIMIT)
122
+ puts "NOFILE #{Process.getrlimit(:NOFILE).inspect}"
126
123
  end
127
124
 
128
125
  worker = Girl::ProxydWorker.new(
@@ -161,7 +158,7 @@ module Girl
161
158
  is_debug,
162
159
  is_server_fastopen )
163
160
 
164
- Signal.trap( :TERM ) do
161
+ Signal.trap(:TERM) do
165
162
  puts 'exit'
166
163
  worker.quit!
167
164
  end