girl 9.1.8 → 9.2.0

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: a2c6dd87559c942761c2b8c9ffc27801755af55ea4348d215e244a22eb322e73
4
- data.tar.gz: 9d9600b04852239dc01e39ea078eb75353dc8734032ea96c00e56e14f84dfc85
3
+ metadata.gz: d155f995eb24eb7cc229250e742c6774227409957f11174c083d5ffbc0786327
4
+ data.tar.gz: d9209954dea7a1a83e1afcb5caeb2c11df7f6a979da98148b9c89d20ab362558
5
5
  SHA512:
6
- metadata.gz: 54c9c01fef8adbb375aeba548473b117c1867cb515db9cd9672a959e3822589a122f27807b0523adf206b61b826f61df7c85e693cdbab757917b9fd56540826e
7
- data.tar.gz: 3ff6355c411f60822c5c6d2a281b164c4d8a623af2de0f0003a84e5e215dada347b7637c7c1bd6867a2dd3f6011f692d0ae609d3a2070a429f5d61d661c92c59
6
+ metadata.gz: f173264881db0d06eaa9ed74b067344ce26b26e942c46e283ce9a7018f22f05948e3a34d54041a1bb2f263ff41046671f4873352c81e546adc1fefe15d372f20
7
+ data.tar.gz: 99b35c8abceafb34f19660f9721a737928ba9d652e171d5ebe7c309a032d9649e6dee86c80a2c63a5730e01ac05469a369fba202e2d8b718b13a5daa22feec47
data/girl.gemspec CHANGED
@@ -27,4 +27,5 @@ lib/girl/version.rb
27
27
  ]
28
28
 
29
29
  spec.require_paths = ['lib']
30
+ spec.required_ruby_version = '>= 1.6.7'
30
31
  end
data/lib/girl/proxy.rb CHANGED
@@ -51,7 +51,7 @@ module Girl
51
51
  h_p1_switch_to_big = conf[:h_p1_switch_to_big] # X
52
52
  expire_connecting = conf[:expire_connecting] # 连接多久没有建成关闭(秒)
53
53
  expire_long_after = conf[:expire_long_after] # 长连接多久没有新流量关闭(秒)
54
- expire_proxy_after = conf[:expire_proxy_after] # proxy多久没有收到流量重建(秒)
54
+ expire_proxy_after = conf[:expire_proxy_after] # proxy多久没有收到流量关闭(秒)
55
55
  expire_resolv_cache = conf[:expire_resolv_cache] # dns查询结果缓存多久(秒)
56
56
  expire_short_after = conf[:expire_short_after] # 短连接创建多久后关闭(秒)
57
57
  is_debug = conf[:is_debug]
@@ -582,7 +582,6 @@ module Girl
582
582
  return if data.bytesize < 9
583
583
  p2_id = data[1, 8].unpack('Q>').first
584
584
  data = data[9..-1]
585
- # puts "big got h_p2_traffic #{p2_id} #{data.bytesize}" if @is_debug
586
585
  p1, p1_info = @p1_infos.find{|_, info| info[:p2_id] == p2_id}
587
586
 
588
587
  if p1_info
@@ -596,7 +595,6 @@ module Girl
596
595
  return if data.bytesize < 9
597
596
  src_id = data[1, 8].unpack('Q>').first
598
597
  data = data[9..-1]
599
- # puts "big got h_traffic #{src_id} #{data.bytesize}" if @is_debug
600
598
  src, src_info = @src_infos.find{|_, info| info[:src_id] == src_id}
601
599
 
602
600
  if src_info
@@ -1163,9 +1161,10 @@ module Girl
1163
1161
  when 'heartbeat'
1164
1162
  new_a_proxy if @proxy.closed?
1165
1163
  new_a_big if @big.closed?
1164
+ now = Time.new
1166
1165
  proxy_info = @proxy_infos[@proxy]
1167
1166
 
1168
- if Time.new.to_i - proxy_info[:recv_at].to_i >= @expire_proxy_after
1167
+ if now.to_i - proxy_info[:recv_at].to_i >= @expire_proxy_after
1169
1168
  puts "renew proxy"
1170
1169
  close_proxy(@proxy)
1171
1170
  new_a_proxy
@@ -1175,7 +1174,7 @@ module Girl
1175
1174
 
1176
1175
  big_info = @big_infos[@big]
1177
1176
 
1178
- if Time.new.to_i - big_info[:recv_at].to_i >= @expire_proxy_after
1177
+ if now.to_i - big_info[:recv_at].to_i >= @expire_proxy_after
1179
1178
  puts "renew big"
1180
1179
  close_big(@big)
1181
1180
  new_a_big
data/lib/girl/proxyd.rb CHANGED
@@ -42,6 +42,7 @@ module Girl
42
42
  h_p1_switch_to_big = conf[:h_p1_switch_to_big] # X
43
43
  expire_connecting = conf[:expire_connecting] # 连接多久没有建成关闭(秒)
44
44
  expire_long_after = conf[:expire_long_after] # 长连接多久没有新流量关闭(秒)
45
+ expire_proxy_after = conf[:expire_proxy_after] # proxy多久没有收到流量关闭(秒)
45
46
  expire_resolv_cache = conf[:expire_resolv_cache] # dns查询结果缓存多久(秒)
46
47
  expire_short_after = conf[:expire_short_after] # 短连接创建多久后关闭(秒)
47
48
  is_debug = conf[:is_debug]
@@ -94,6 +95,7 @@ module Girl
94
95
  h_p1_switch_to_big = h_p1_switch_to_big ? h_p1_switch_to_big.to_s : 'X'
95
96
  expire_connecting = expire_connecting ? expire_connecting.to_i : 5
96
97
  expire_long_after = expire_long_after ? expire_long_after.to_i : 3600
98
+ expire_proxy_after = expire_proxy_after ? expire_proxy_after.to_i : 60
97
99
  expire_resolv_cache = expire_resolv_cache ? expire_resolv_cache.to_i : 600
98
100
  expire_short_after = expire_short_after ? expire_short_after.to_i : 5
99
101
  is_server_fastopen = false
@@ -141,6 +143,7 @@ module Girl
141
143
  h_p1_switch_to_big,
142
144
  expire_connecting,
143
145
  expire_long_after,
146
+ expire_proxy_after,
144
147
  expire_resolv_cache,
145
148
  expire_short_after,
146
149
  is_debug,
@@ -29,6 +29,7 @@ module Girl
29
29
  h_p1_switch_to_big,
30
30
  expire_connecting,
31
31
  expire_long_after,
32
+ expire_proxy_after,
32
33
  expire_resolv_cache,
33
34
  expire_short_after,
34
35
  is_debug,
@@ -42,8 +43,8 @@ module Girl
42
43
  @writes = [] # 写池
43
44
  @roles = {} # sock => :big / :bigd / :dns / :dst / :infod / :mem / :memd / :p2 / :p2d / :proxy / :proxyd / :rsv
44
45
  @updates = {} # sock => updated_at
45
- @proxy_infos = {} # proxy => {:addrinfo :im :rbuff :wbuff}
46
- @big_infos = {} # big => {:addrinfo :im :overflowing :rbuff :wbuff}
46
+ @proxy_infos = {} # proxy => {:addrinfo :im :rbuff :recv_at :wbuff}
47
+ @big_infos = {} # big => {:addrinfo :im :overflowing :rbuff :recv_at :wbuff}
47
48
  @im_infos = {} # im => {:addrinfo :big :big_connect_at :in :out :p2d :p2d_host :p2d_port :proxy :proxy_connect_at}
48
49
  @src_infos = {} # src_id => {:created_at :dst :im :rbuff}
49
50
  @mem_infos = {} # mem => {:wbuff}
@@ -71,6 +72,7 @@ module Girl
71
72
  @h_p1_switch_to_big = h_p1_switch_to_big
72
73
  @expire_connecting = expire_connecting
73
74
  @expire_long_after = expire_long_after
75
+ @expire_proxy_after = expire_proxy_after
74
76
  @expire_resolv_cache = expire_resolv_cache
75
77
  @expire_short_after = expire_short_after
76
78
  @is_debug = is_debug
@@ -349,8 +351,8 @@ module Girl
349
351
  def check_expire_bigs
350
352
  now = Time.new
351
353
 
352
- @big_infos.select{|big, _| now.to_i - @updates[big].to_i >= @expire_long_after}.each do |big, info|
353
- puts "expire big #{info[:im]}"
354
+ @big_infos.select{|big, info| now.to_i - info[:recv_at].to_i >= @expire_proxy_after}.each do |big, info|
355
+ puts "expire big #{info[:im]} #{info[:addrinfo].ip_unpack.inspect}"
354
356
  close_big(big)
355
357
  end
356
358
  end
@@ -394,8 +396,8 @@ module Girl
394
396
  def check_expire_proxies
395
397
  now = Time.new
396
398
 
397
- @proxy_infos.select{|proxy, _| now.to_i - @updates[proxy].to_i >= @expire_long_after}.each do |proxy, info|
398
- puts "expire proxy #{info[:im]}"
399
+ @proxy_infos.select{|proxy, info| now.to_i - info[:recv_at].to_i >= @expire_proxy_after}.each do |proxy, info|
400
+ puts "expire proxy #{info[:im]} #{info[:addrinfo].ip_unpack.inspect}"
399
401
  close_proxy(proxy)
400
402
  end
401
403
  end
@@ -540,6 +542,8 @@ module Girl
540
542
  big_info = @big_infos[big]
541
543
  im = big_info[:im]
542
544
  return unless im
545
+ now = Time.new
546
+ big_info[:recv_at] = now
543
547
  h = data[0]
544
548
 
545
549
  case h
@@ -547,7 +551,6 @@ module Girl
547
551
  return if data.bytesize < 9
548
552
  p2_id = data[1, 8].unpack('Q>').first
549
553
  data = data[9..-1]
550
- # puts "big got h_p2_traffic #{im} #{p2_id} #{data.bytesize}" if @is_debug
551
554
  p2, p2_info = @p2_infos.find{|_, info| (info[:im] == im) && (info[:p2_id] == p2_id)}
552
555
 
553
556
  if p2_info
@@ -561,7 +564,6 @@ module Girl
561
564
  return if data.bytesize < 9
562
565
  src_id = data[1, 8].unpack('Q>').first
563
566
  data = data[9..-1]
564
- # puts "big got h_traffic #{im} #{src_id} #{data.bytesize}" if @is_debug
565
567
  src_info = @src_infos[src_id]
566
568
 
567
569
  if src_info
@@ -587,6 +589,8 @@ module Girl
587
589
  proxy_info = @proxy_infos[proxy]
588
590
  im = proxy_info[:im]
589
591
  return unless im
592
+ now = Time.new
593
+ proxy_info[:recv_at] = now
590
594
  h = data[0]
591
595
 
592
596
  case h
@@ -597,7 +601,7 @@ module Girl
597
601
  domain_port = data[9..-1]
598
602
  puts "got h_a_new_source #{im} #{src_id} #{domain_port.inspect}" if @is_debug
599
603
  @src_infos[src_id] = {
600
- created_at: Time.new,
604
+ created_at: now,
601
605
  dst: nil,
602
606
  im: im,
603
607
  rbuff: ''
@@ -1025,15 +1029,14 @@ module Girl
1025
1029
 
1026
1030
  puts "accept a big #{addrinfo.ip_unpack.inspect}"
1027
1031
 
1028
- big_info = {
1032
+ @big_infos[big] = {
1029
1033
  addrinfo: addrinfo,
1030
1034
  im: nil,
1031
1035
  overflowing: false,
1032
1036
  rbuff: '',
1037
+ recv_at: Time.new,
1033
1038
  wbuff: ''
1034
1039
  }
1035
-
1036
- @big_infos[big] = big_info
1037
1040
  add_read(big, :big)
1038
1041
  end
1039
1042
 
@@ -1447,6 +1450,7 @@ module Girl
1447
1450
  addrinfo: addrinfo,
1448
1451
  im: nil,
1449
1452
  rbuff: '',
1453
+ recv_at: Time.new,
1450
1454
  wbuff: ''
1451
1455
  }
1452
1456
  add_read(proxy, :proxy)
@@ -1581,15 +1585,6 @@ module Girl
1581
1585
  return
1582
1586
  end
1583
1587
 
1584
- im = big_info[:im]
1585
- im_info = @im_infos[im]
1586
-
1587
- if im_info.nil? || im_info[:proxy].nil?
1588
- puts "proxy not found close big"
1589
- close_big(big)
1590
- return
1591
- end
1592
-
1593
1588
  data = big_info[:wbuff]
1594
1589
 
1595
1590
  if data.empty?
@@ -1607,12 +1602,18 @@ module Girl
1607
1602
  end
1608
1603
 
1609
1604
  set_update(big)
1610
- im_info[:out] += written
1605
+ im = big_info[:im]
1606
+
1607
+ if im
1608
+ im_info = @im_infos[im]
1609
+ im_info[:out] += written if im_info
1610
+ end
1611
+
1611
1612
  data = data[written..-1]
1612
1613
  big_info[:wbuff] = data
1613
1614
 
1614
1615
  if big_info[:wbuff].empty? && big_info[:overflowing]
1615
- puts "big empty #{big_info[:im]}"
1616
+ puts "big empty #{im}"
1616
1617
  big_info[:overflowing] = false
1617
1618
 
1618
1619
  @dst_infos.select{|_, info| (info[:im] == im) && info[:is_big]}.each do |dst, info|
@@ -1636,6 +1637,15 @@ module Girl
1636
1637
  return
1637
1638
  end
1638
1639
 
1640
+ im = dst_info[:im]
1641
+ im_info = @im_infos[im]
1642
+
1643
+ unless im_info
1644
+ puts "im info not found close dst"
1645
+ close_dst(dst)
1646
+ return
1647
+ end
1648
+
1639
1649
  dst_info[:connected] = true
1640
1650
  data = dst_info[:wbuff]
1641
1651
 
@@ -1659,14 +1669,7 @@ module Girl
1659
1669
  end
1660
1670
 
1661
1671
  set_update(dst)
1662
- im = dst_info[:im]
1663
- im_info = @im_infos[im]
1664
-
1665
- if im_info
1666
- im_info[:out] += written
1667
- big = im_info[:big]
1668
- end
1669
-
1672
+ im_info[:out] += written
1670
1673
  data = data[written..-1]
1671
1674
  dst_info[:wbuff] = data
1672
1675
  src_id = dst_info[:src_id]
@@ -1675,6 +1678,7 @@ module Girl
1675
1678
  if dst_info[:overflowing] && dst_info[:wbuff].empty? && dst_info[:wpend].empty?
1676
1679
  puts "dst empty #{im} #{src_id} #{domain}"
1677
1680
  dst_info[:overflowing] = false
1681
+ big = im_info[:big]
1678
1682
 
1679
1683
  if big
1680
1684
  puts "resume big"
@@ -1723,6 +1727,15 @@ module Girl
1723
1727
  return
1724
1728
  end
1725
1729
 
1730
+ im = p2_info[:im]
1731
+ im_info = @im_infos[im]
1732
+
1733
+ unless im_info
1734
+ puts "im info not found close p2"
1735
+ close_p2(p2)
1736
+ return
1737
+ end
1738
+
1726
1739
  data = p2_info[:wbuff]
1727
1740
 
1728
1741
  if data.empty?
@@ -1745,9 +1758,6 @@ module Girl
1745
1758
  end
1746
1759
 
1747
1760
  set_update(p2)
1748
- im = p2_info[:im]
1749
- im_info = @im_infos[im]
1750
- big = im_info[:big] if im_info
1751
1761
  data = data[written..-1]
1752
1762
  p2_info[:wbuff] = data
1753
1763
  p2_id = p2_info[:p2_id]
@@ -1755,6 +1765,7 @@ module Girl
1755
1765
  if p2_info[:overflowing] && p2_info[:wbuff].empty? && p2_info[:wpend].empty?
1756
1766
  puts "p2 empty #{im} #{p2_id}"
1757
1767
  p2_info[:overflowing] = false
1768
+ big = im_info[:big]
1758
1769
 
1759
1770
  if big
1760
1771
  puts "resume big"
@@ -1790,8 +1801,12 @@ module Girl
1790
1801
 
1791
1802
  set_update(proxy)
1792
1803
  im = proxy_info[:im]
1793
- im_info = @im_infos[im]
1794
- im_info[:out] += written if im_info
1804
+
1805
+ if im
1806
+ im_info = @im_infos[im]
1807
+ im_info[:out] += written if im_info
1808
+ end
1809
+
1795
1810
  data = data[written..-1]
1796
1811
  proxy_info[:wbuff] = data
1797
1812
  end
data/lib/girl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Girl
2
- VERSION = '9.1.8'.freeze
2
+ VERSION = '9.2.0'.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.8
4
+ version: 9.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - takafan
@@ -36,7 +36,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '0'
39
+ version: 1.6.7
40
40
  required_rubygems_version: !ruby/object:Gem::Requirement
41
41
  requirements:
42
42
  - - ">="