girl 9.1.4 → 9.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 336d5a273c06df15d5c88139e32066b3c9a574bcc97fcf9c1690cb7aeb8034e7
4
- data.tar.gz: 339782aa3b87b31535897ccf5c4201cbfa2b53487625de16bccef9123ae71fad
3
+ metadata.gz: a169cd643cb853f29ec9046ac36d027d6ee58dcd0dcda253b631f5a62cb710a6
4
+ data.tar.gz: 47dd11c75a7ab9138d5ac8cc1a724c32dd1b4277077f9399fd81ef80662138b6
5
5
  SHA512:
6
- metadata.gz: 8c478838350d1862edcfd99d629f4c88d09d892816f73f6505ec567ba481d2774ee05dfbd018055629b4b709c55e2a0cf2b1f7ee8025d09c1d05ac7d0be621f3
7
- data.tar.gz: 95202954f953df2d1de2d53d9c4cfb8d4ed73d393e7f9d5b2418c9391bdbefea4e0294dc3c54d277519db789be211528232496a47899fc5a208e0e72f1a23883
6
+ metadata.gz: 49c302c5096078a4dd2bcd91d6d8ec161e6d61153f043d47f8f9fb98a84fb8b6c7d0ce151f1fbd78406d7c6ecdecc0dc5814f4f7a9323ab3502d4c89973b1628
7
+ data.tar.gz: 34b61c00f9732ee0001435acd00d3006b5f3e995a2cc153476878dea745bc92e18e7e51eeb93de7c09bd82fdce37ba2323a3abbce87ad8e5f66750fa73c3dd67
data/lib/girl/head.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  module Girl
2
- BACKLOG = 512 # 听队列大小,满后掉SYN包
3
- RLIMIT = 1024 # sock数上限
4
- READ_SIZE = 4 * 1024 * 1024 # 一次读多少
5
- WBUFF_LIMIT = 10 * 1024 * 1024 # 写前上限,超过上限暂停读另一头
6
- CLOSE_ABOVE = 30 * 1024 * 1024 # 超过多少强制关闭
7
- HEARTBEAT_INTERVAL = 10 # 心跳间隔
8
- CHECK_TRAFF_INTERVAL = 3600 # 多久检查一次,今天是不是流量计数重置日
2
+ BACKLOG = 512 # 听队列大小,满后掉SYN包
3
+ RLIMIT = 1024 # sock数上限
4
+ READ_SIZE = 1 * 1024 * 1024 # 一次最多读多少
5
+ WBUFF_LIMIT = 10 * 1024 * 1024 # 写前上限,超过上限暂停读另一头
6
+ CLOSE_ABOVE = 100 * 1024 * 1024 # 超过多少强制关闭
7
+ HEARTBEAT_INTERVAL = 10 # 心跳间隔
8
+ CHECK_TRAFF_INTERVAL = 3600 # 多久检查一次,今天是不是流量计数重置日
9
9
  HTTP_OK = "HTTP/1.1 200 OK\r\n\r\n"
10
10
  RESERVED_ROUTE = <<EOF
11
11
  0.0.0.0/8
@@ -37,7 +37,6 @@ module Girl
37
37
  is_debug,
38
38
  is_client_fastopen,
39
39
  is_server_fastopen)
40
-
41
40
  @proxyd_host = proxyd_host
42
41
  @proxyd_addr = Socket.sockaddr_in(proxyd_port, proxyd_host)
43
42
  @bigd_addr = Socket.sockaddr_in(bigd_port, proxyd_host)
@@ -47,7 +46,7 @@ module Girl
47
46
  @remotes = remotes
48
47
  @local_ips = Socket.ip_address_list.select{|info| info.ipv4?}.map{|info| info.ip_address}
49
48
  @update_roles = [:dns, :dst, :mem, :p1, :src, :rsv] # 参与淘汰的角色
50
- @updates_limit = 1008 # 淘汰池上限,1015(mac) - info, infod, memd, proxy, redir, rsvd, tspd
49
+ @updates_limit = 1008 # 淘汰池上限,1015(mac) - [info infod memd proxy redir rsvd tspd]
51
50
  @eliminate_count = 0 # 淘汰次数
52
51
  @reads = [] # 读池
53
52
  @writes = [] # 写池
@@ -61,13 +60,12 @@ module Girl
61
60
  @dns_infos = {} # dns => {:domain :src}
62
61
  @rsv_infos = {} # rsv => {:addrinfo :domain :type}
63
62
  @near_infos = {} # near_id => {:addrinfo :created_at :domain :id :type}
64
- @resolv_caches = {} # domain => [ip, created_at]
63
+ @resolv_caches = {} # domain => [ip created_at]
65
64
  @is_direct_caches = {} # ip => true / false
66
- @response_caches = {} # domain => [response, created_at, ip, is_remote]
67
- @response6_caches = {} # domain => [response, created_at, ip, is_remote]
65
+ @response_caches = {} # domain => [response created_at ip is_remote]
66
+ @response6_caches = {} # domain => [response created_at ip is_remote]
68
67
  @p1_infos = {} # p1 => {:closing :connected :in :is_big :overflowing :p2_id :wbuff}
69
68
  @appd_addr = Socket.sockaddr_in(appd_port, appd_host)
70
-
71
69
  @head_len = head_len
72
70
  @h_a_new_source = h_a_new_source
73
71
  @h_a_new_p2 = h_a_new_p2
@@ -88,7 +86,6 @@ module Girl
88
86
  @is_debug = is_debug
89
87
  @is_client_fastopen = is_client_fastopen
90
88
  @is_server_fastopen = is_server_fastopen
91
-
92
89
  new_a_redir(redir_host, redir_port)
93
90
  new_a_infod(redir_port)
94
91
  new_a_memd(memd_port)
@@ -173,7 +170,7 @@ module Girl
173
170
  private
174
171
 
175
172
  def add_big_wbuff(data)
176
- return if @big.nil? || @big.closed? || data.nil? || data.empty?
173
+ return if @big.closed? || data.nil? || data.empty?
177
174
  big_info = @big_infos[@big]
178
175
  big_info[:wbuff] << data
179
176
  bytesize = big_info[:wbuff].bytesize
@@ -187,19 +184,10 @@ module Girl
187
184
  if !big_info[:overflowing] && (bytesize >= WBUFF_LIMIT)
188
185
  puts "big overflow"
189
186
  big_info[:overflowing] = true
190
-
191
- @src_infos.select{|_, info| info[:is_big]}.each do |src, info|
192
- puts "pause src #{info[:destination_domain]}"
193
- @reads.delete(src)
194
- end
195
-
196
- @p1_infos.select{|_, info| info[:is_big]}.each do |p1, info|
197
- puts "pause p1 #{info[:p2_id]}"
198
- @reads.delete(p1)
199
- end
200
187
  end
201
188
 
202
189
  add_write(@big)
190
+ big_info[:overflowing]
203
191
  end
204
192
 
205
193
  def add_dst_wbuff(dst, data)
@@ -1169,12 +1157,6 @@ module Girl
1169
1157
  end
1170
1158
 
1171
1159
  set_update(p1)
1172
-
1173
- if @proxy.closed?
1174
- close_p1(p1)
1175
- return
1176
- end
1177
-
1178
1160
  p1_info = @p1_infos[p1]
1179
1161
  p1_info[:in] += data.bytesize
1180
1162
  p2_id = p1_info[:p2_id]
@@ -1187,8 +1169,23 @@ module Girl
1187
1169
  data = pack_p2_traffic(p2_id, data)
1188
1170
 
1189
1171
  if p1_info[:is_big]
1190
- add_big_wbuff(data)
1172
+ if @big.closed?
1173
+ close_p1(p1)
1174
+ return
1175
+ end
1176
+
1177
+ overflowing = add_big_wbuff(data)
1178
+
1179
+ if overflowing
1180
+ puts "big overflowing pause p1 #{p2_id}"
1181
+ @reads.delete(p1)
1182
+ end
1191
1183
  else
1184
+ if @proxy.closed?
1185
+ close_p1(p1)
1186
+ return
1187
+ end
1188
+
1192
1189
  add_proxy_wbuff(data)
1193
1190
  end
1194
1191
  end
@@ -1497,19 +1494,34 @@ module Girl
1497
1494
  end
1498
1495
  when :remote
1499
1496
  src_info[:in] += data.bytesize
1497
+ src_id = src_info[:src_id]
1500
1498
  domain = src_info[:destination_domain]
1501
1499
 
1502
1500
  if !src_info[:is_big] && (src_info[:in] >= READ_SIZE)
1503
- puts "set src is big #{domain}"
1501
+ puts "set src is big #{src_id} #{domain}"
1504
1502
  src_info[:is_big] = true
1505
1503
  end
1506
1504
 
1507
- src_id = src_info[:src_id]
1508
1505
  data = pack_traffic(src_id, data)
1509
1506
 
1510
1507
  if src_info[:is_big]
1511
- add_big_wbuff(data)
1508
+ if @big.closed?
1509
+ close_src(src)
1510
+ return
1511
+ end
1512
+
1513
+ overflowing = add_big_wbuff(data)
1514
+
1515
+ if overflowing
1516
+ puts "big overflowing pause src #{src_id} #{domain}"
1517
+ @reads.delete(src)
1518
+ end
1512
1519
  else
1520
+ if @proxy.closed?
1521
+ close_src(src)
1522
+ return
1523
+ end
1524
+
1513
1525
  add_proxy_wbuff(data)
1514
1526
  end
1515
1527
  when :direct
@@ -1772,7 +1784,7 @@ module Girl
1772
1784
  big_info[:overflowing] = false
1773
1785
 
1774
1786
  @src_infos.select{|_, info| info[:is_big]}.each do |src, info|
1775
- puts "resume src #{info[:destination_domain]}"
1787
+ puts "resume src #{info[:src_id]} #{info[:destination_domain]}"
1776
1788
  add_read(src)
1777
1789
  end
1778
1790
 
@@ -1976,8 +1988,9 @@ module Girl
1976
1988
  src_info[:wbuff] = data
1977
1989
 
1978
1990
  if src_info[:wbuff].empty? && src_info[:overflowing]
1991
+ src_id = src_info[:src_id]
1979
1992
  domain = src_info[:destination_domain]
1980
- puts "src empty #{domain}"
1993
+ puts "src empty #{src_id} #{domain}"
1981
1994
  src_info[:overflowing] = false
1982
1995
 
1983
1996
  if src_info[:proxy_type] == :direct
@@ -29,11 +29,10 @@ module Girl
29
29
  expire_short_after,
30
30
  is_debug,
31
31
  is_server_fastopen)
32
-
33
32
  @nameserver_addrs = nameservers.map{|n| Socket.sockaddr_in(53, n)}
34
33
  @reset_traff_day = reset_traff_day
35
34
  @update_roles = [:big, :dns, :dst, :mem, :p2, :proxy, :rsv] # 参与淘汰的角色
36
- @updates_limit = 1011 - ims.size # 淘汰池上限,1015(mac) - info, infod, memd, proxyd, p2ds(=ims)
35
+ @updates_limit = 1010 - ims.size # 淘汰池上限,1015(mac) - [bigd info infod memd proxyd] - p2ds
37
36
  @eliminate_count = 0 # 淘汰次数
38
37
  @reads = [] # 读池
39
38
  @writes = [] # 写池
@@ -42,15 +41,14 @@ module Girl
42
41
  @proxy_infos = {} # proxy => {:addrinfo :im :rbuff :wbuff}
43
42
  @big_infos = {} # big => {:addrinfo :im :overflowing :rbuff :wbuff}
44
43
  @im_infos = {} # im => {:addrinfo :big :big_connect_at :in :out :p2d :p2d_host :p2d_port :proxy :proxy_connect_at}
45
- @src_infos = {} # src_id => {:created_at, :dst :im :rbuff}
44
+ @src_infos = {} # src_id => {:created_at :dst :im :rbuff}
46
45
  @mem_infos = {} # mem => {:wbuff}
47
46
  @dst_infos = {} # dst => {:closing :connected :domain :im :in :ip :is_big :overflowing :port :rbuffs :src_id :wbuff}
48
47
  @dns_infos = {} # dns => {:domain :im :port :src_id}
49
48
  @rsv_infos = {} # rsv => {:domain :im :near_id}
50
- @resolv_caches = {} # domain => [:ip :created_at]
49
+ @resolv_caches = {} # domain => [ip created_at]
51
50
  @p2d_infos = {} # p2d => {:im}
52
51
  @p2_infos = {} # p2 => {:addrinfo :closing :im :in :is_big :overflowing :p2_id :wbuff}
53
-
54
52
  @head_len = head_len
55
53
  @h_a_new_source = h_a_new_source
56
54
  @h_a_new_p2 = h_a_new_p2
@@ -69,7 +67,6 @@ module Girl
69
67
  @expire_short_after = expire_short_after
70
68
  @is_debug = is_debug
71
69
  @is_server_fastopen = is_server_fastopen
72
-
73
70
  init_im_infos(ims, p2d_host, p2d_port)
74
71
  new_a_proxyd(proxyd_port)
75
72
  new_a_bigd(bigd_port)
@@ -164,19 +161,10 @@ module Girl
164
161
  if !big_info[:overflowing] && (bytesize >= WBUFF_LIMIT)
165
162
  puts "big overflow #{im}"
166
163
  big_info[:overflowing] = true
167
-
168
- @dst_infos.select{|_, info| (info[:im] == im) && info[:is_big]}.each do |dst, info|
169
- puts "pause dst #{info[:domain]}"
170
- @reads.delete(dst)
171
- end
172
-
173
- @p2_infos.select{|_, info| (info[:im] == im) && info[:is_big]}.each do |p2, info|
174
- puts "pause p2 #{info[:p2_id]}"
175
- @reads.delete(p2)
176
- end
177
164
  end
178
165
 
179
166
  add_write(big)
167
+ big_info[:overflowing]
180
168
  end
181
169
 
182
170
  def add_dst_wbuff(dst, data)
@@ -450,10 +438,9 @@ module Girl
450
438
  im_info = @im_infos[im]
451
439
 
452
440
  if im_info
453
- proxy = im_info[:proxy]
454
441
  puts "add h_p2_close #{im} #{p2_id}"
455
442
  msg = "#{@h_p2_close}#{[p2_id].pack('Q>')}"
456
- add_proxy_wbuff(proxy, pack_a_chunk(msg))
443
+ add_proxy_wbuff(im_info[:proxy], pack_a_chunk(msg))
457
444
  end
458
445
  end
459
446
 
@@ -693,7 +680,7 @@ module Girl
693
680
  im: im,
694
681
  in: 0,
695
682
  ip: ip,
696
- is_big: false, # 收来的流量是否是大流量
683
+ is_big: false, # 是否收流量大户
697
684
  overflowing: false,
698
685
  port: port,
699
686
  rbuffs: [],
@@ -969,9 +956,11 @@ module Girl
969
956
  dst_info = @dst_infos[dst]
970
957
  dst_info[:in] += data.bytesize
971
958
  im = dst_info[:im]
959
+ src_id = dst_info[:src_id]
960
+ domain = dst_info[:domain]
972
961
 
973
962
  if !dst_info[:is_big] && (dst_info[:in] >= READ_SIZE)
974
- puts "set dst is big #{im} #{dst_info[:domain]}"
963
+ puts "set dst is big #{im} #{src_id} #{domain}"
975
964
  dst_info[:is_big] = true
976
965
  end
977
966
 
@@ -983,14 +972,30 @@ module Girl
983
972
  end
984
973
 
985
974
  im_info[:in] += data.bytesize
986
- src_id = dst_info[:src_id]
987
975
  data = pack_traffic(src_id, data)
988
976
 
989
977
  if dst_info[:is_big]
990
978
  big = im_info[:big]
991
- add_big_wbuff(big, data)
979
+
980
+ if big.nil? || big.closed?
981
+ close_dst(dst)
982
+ return
983
+ end
984
+
985
+ overflowing = add_big_wbuff(big, data)
986
+
987
+ if overflowing
988
+ puts "big overflowing pause dst #{src_id} #{domain}"
989
+ @reads.delete(dst)
990
+ end
992
991
  else
993
992
  proxy = im_info[:proxy]
993
+
994
+ if proxy.nil? || proxy.closed?
995
+ close_dst(dst)
996
+ return
997
+ end
998
+
994
999
  add_proxy_wbuff(proxy, data)
995
1000
  end
996
1001
  end
@@ -1127,9 +1132,26 @@ module Girl
1127
1132
 
1128
1133
  if p2_info[:is_big]
1129
1134
  big = im_info[:big]
1130
- add_big_wbuff(big, data)
1135
+
1136
+ if big.nil? || big.closed?
1137
+ close_p2(p2)
1138
+ return
1139
+ end
1140
+
1141
+ overflowing = add_big_wbuff(big, data)
1142
+
1143
+ if overflowing
1144
+ puts "big overflowing pause p2 #{p2_id}"
1145
+ @reads.delete(p2)
1146
+ end
1131
1147
  else
1132
1148
  proxy = im_info[:proxy]
1149
+
1150
+ if proxy.nil? || proxy.closed?
1151
+ close_p2(p2)
1152
+ return
1153
+ end
1154
+
1133
1155
  add_proxy_wbuff(proxy, data)
1134
1156
  end
1135
1157
  end
@@ -1152,7 +1174,7 @@ module Girl
1152
1174
  closing: false,
1153
1175
  im: im,
1154
1176
  in: 0,
1155
- is_big: false, # 收来的流量是否是大流量
1177
+ is_big: false, # 是否收流量大户
1156
1178
  overflowing: false,
1157
1179
  p2_id: p2_id,
1158
1180
  wbuff: ''
@@ -1160,10 +1182,9 @@ module Girl
1160
1182
  add_read(p2, :p2)
1161
1183
  im_info = @im_infos[im]
1162
1184
  return unless im_info
1163
- proxy = im_info[:proxy]
1164
1185
  puts "add h_a_new_p2 #{im} #{p2_id}"
1165
1186
  msg = "#{@h_a_new_p2}#{[p2_id].pack('Q>')}"
1166
- add_proxy_wbuff(proxy, pack_a_chunk(msg))
1187
+ add_proxy_wbuff(im_info[:proxy], pack_a_chunk(msg))
1167
1188
  end
1168
1189
 
1169
1190
  def read_rsv(rsv)
@@ -1184,6 +1205,12 @@ module Girl
1184
1205
 
1185
1206
  if im_info
1186
1207
  proxy = im_info[:proxy]
1208
+
1209
+ if proxy.nil? || proxy.closed?
1210
+ close_rsv(rsv)
1211
+ return
1212
+ end
1213
+
1187
1214
  near_id = rsv_info[:near_id]
1188
1215
  puts "add h_response #{im} #{near_id} #{rsv_info[:domain]} #{data.bytesize}" if @is_debug
1189
1216
  msg = "#{@h_response}#{[near_id].pack('Q>')}#{data}"
@@ -1454,7 +1481,7 @@ module Girl
1454
1481
  big_info[:overflowing] = false
1455
1482
 
1456
1483
  @dst_infos.select{|_, info| (info[:im] == im) && info[:is_big]}.each do |dst, info|
1457
- puts "resume dst #{info[:domain]}"
1484
+ puts "resume dst #{info[:src_id]} #{info[:domain]}"
1458
1485
  add_read(dst)
1459
1486
  end
1460
1487
 
@@ -1507,10 +1534,11 @@ module Girl
1507
1534
 
1508
1535
  data = data[written..-1]
1509
1536
  dst_info[:wbuff] = data
1537
+ src_id = dst_info[:src_id]
1510
1538
  domain = dst_info[:domain]
1511
1539
 
1512
1540
  if dst_info[:wbuff].empty? && dst_info[:overflowing]
1513
- puts "dst empty #{im} #{domain}"
1541
+ puts "dst empty #{im} #{src_id} #{domain}"
1514
1542
  dst_info[:overflowing] = false
1515
1543
 
1516
1544
  if big
data/lib/girl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Girl
2
- VERSION = '9.1.4'.freeze
2
+ VERSION = '9.1.5'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: girl
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.1.4
4
+ version: 9.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - takafan