girl 9.1.1 → 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.
- checksums.yaml +4 -4
- data/lib/girl/dns.rb +52 -55
- data/lib/girl/head.rb +2 -2
- data/lib/girl/proxy.rb +73 -74
- data/lib/girl/proxy_worker.rb +975 -985
- data/lib/girl/proxyd.rb +55 -58
- data/lib/girl/proxyd_worker.rb +633 -636
- data/lib/girl/version.rb +1 -1
- metadata +3 -6
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(
|
|
15
|
-
if config_path
|
|
16
|
-
raise "not found config file #{
|
|
17
|
-
conf = JSON.parse(
|
|
18
|
-
puts "load #{
|
|
19
|
-
proxyd_port = conf[
|
|
20
|
-
memd_port = conf[
|
|
21
|
-
nameserver = conf[
|
|
22
|
-
reset_traff_day = conf[
|
|
23
|
-
ims = conf[
|
|
24
|
-
p2d_host = conf[
|
|
25
|
-
p2d_port = conf[
|
|
26
|
-
head_len = conf[
|
|
27
|
-
h_a_new_source = conf[
|
|
28
|
-
h_a_new_p2 = conf[
|
|
29
|
-
h_dst_close = conf[
|
|
30
|
-
h_heartbeat = conf[
|
|
31
|
-
h_p1_close = conf[
|
|
32
|
-
h_p2_close = conf[
|
|
33
|
-
h_p2_traffic = conf[
|
|
34
|
-
h_p1_overflow = conf[
|
|
35
|
-
h_p1_underhalf = conf[
|
|
36
|
-
h_p2_overflow = conf[
|
|
37
|
-
h_p2_underhalf = conf[
|
|
38
|
-
h_query = conf[
|
|
39
|
-
h_response = conf[
|
|
40
|
-
h_src_close = conf[
|
|
41
|
-
h_traffic = conf[
|
|
42
|
-
h_src_overflow = conf[
|
|
43
|
-
h_src_underhalf = conf[
|
|
44
|
-
h_dst_overflow = conf[
|
|
45
|
-
h_dst_underhalf = conf[
|
|
46
|
-
expire_connecting = conf[
|
|
47
|
-
expire_long_after = conf[
|
|
48
|
-
expire_proxy_after = conf[
|
|
49
|
-
expire_resolv_cache = conf[
|
|
50
|
-
expire_short_after = conf[
|
|
51
|
-
is_debug = conf[
|
|
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
|
|
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?(
|
|
64
|
-
text = IO.read(
|
|
63
|
+
if File.exist?(resolv_path)
|
|
64
|
+
text = IO.read('/etc/resolv.conf')
|
|
65
65
|
|
|
66
|
-
text.split(
|
|
67
|
-
match_data = /^nameserver \d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}/.match(
|
|
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
|
|
70
|
-
nameservers << match_data[
|
|
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?(
|
|
110
|
-
IO.popen(
|
|
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 #{
|
|
121
|
-
puts "#{
|
|
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[
|
|
124
|
-
Process.setrlimit(
|
|
125
|
-
puts "NOFILE #{
|
|
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(
|
|
161
|
+
Signal.trap(:TERM) do
|
|
165
162
|
puts 'exit'
|
|
166
163
|
worker.quit!
|
|
167
164
|
end
|