girl 0.57.0 → 0.60.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of girl might be problematic. Click here for more details.

@@ -3,7 +3,7 @@ require 'girl/version'
3
3
  require 'socket'
4
4
 
5
5
  ##
6
- # Girl::Resolv - dns查询得到正确的ip。近端。
6
+ # Girl::Resolv - dns查询得到正确的ip,近端。
7
7
  #
8
8
  # usage
9
9
  # =====
@@ -3,7 +3,7 @@ require 'girl/version'
3
3
  require 'socket'
4
4
 
5
5
  ##
6
- # Girl::Resolvd - dns查询得到正确的ip。远端。
6
+ # Girl::Resolvd - dns查询得到正确的ip,远端。
7
7
  #
8
8
  module Girl
9
9
  class Resolvd
@@ -4,7 +4,7 @@ require 'girl/version'
4
4
  require 'socket'
5
5
 
6
6
  ##
7
- # Girl::Tun - tcp流量正常的到达目的地。近端。
7
+ # Girl::Tun - tcp透明转发,近端。
8
8
  #
9
9
  # usage
10
10
  # =====
@@ -39,18 +39,6 @@ require 'socket'
39
39
  # 12 tund fin
40
40
  # 13 tun fin
41
41
  #
42
- # 两套关闭
43
- # ========
44
- #
45
- # 1-1. source.close -> ext.is_dest_closed ? no -> send fin1 loop
46
- # 1-2. recv got_fin1 -> break loop
47
- # 1-3. recv fin2 -> send got_fin2 -> del ext
48
- #
49
- # 2-1. recv fin1 -> send got_fin1 -> ext.is_dest_closed = true
50
- # 2-2. all sent && ext.biggest_dest_pack_id == ext.continue_dest_pack_id -> add closing source
51
- # 2-3. source.close -> ext.is_dest_closed ? yes -> del ext -> loop send fin2
52
- # 2-4. recv got_fin2 -> break loop
53
- #
54
42
  module Girl
55
43
  class Tun
56
44
  ##
@@ -96,6 +84,15 @@ module Girl
96
84
  rs, ws = IO.select( @reads, @writes )
97
85
 
98
86
  @mutex.synchronize do
87
+ ws.each do | sock |
88
+ case @roles[ sock ]
89
+ when :source
90
+ write_source( sock )
91
+ when :tun
92
+ write_tun( sock )
93
+ end
94
+ end
95
+
99
96
  rs.each do | sock |
100
97
  case @roles[ sock ]
101
98
  when :ctlr
@@ -108,15 +105,6 @@ module Girl
108
105
  read_tun( sock )
109
106
  end
110
107
  end
111
-
112
- ws.each do | sock |
113
- case @roles[ sock ]
114
- when :source
115
- write_source( sock )
116
- when :tun
117
- write_tun( sock )
118
- end
119
- end
120
108
  end
121
109
  end
122
110
  rescue Interrupt => e
@@ -707,13 +695,13 @@ module Girl
707
695
 
708
696
  def check_expire( tun )
709
697
  Thread.new do
710
- sleep HEARTBEAT_INTERVAL
698
+ sleep 3
711
699
 
712
- unless tun.closed?
713
- tun_info = @infos[ tun ]
700
+ @mutex.synchronize do
701
+ unless tun.closed?
702
+ tun_info = @infos[ tun ]
714
703
 
715
- unless tun_info[ :tund_addr ]
716
- @mutex.synchronize do
704
+ unless tun_info[ :tund_addr ]
717
705
  tun_id = @socks[ tun ]
718
706
  @ctlw.write( [ CTL_CLOSE, tun_id ].pack( 'CQ>' ) )
719
707
  end
@@ -739,26 +727,23 @@ module Girl
739
727
  def loop_check_expire( tun )
740
728
  Thread.new do
741
729
  loop do
742
- sleep 60
730
+ sleep CHECK_EXPIRE_INTERVAL
731
+
743
732
  break if tun.closed?
744
733
 
745
- now = Time.new
746
- tun_info = @infos[ tun ]
734
+ @mutex.synchronize do
735
+ now = Time.new
736
+ tun_info = @infos[ tun ]
747
737
 
748
- if now - tun_info[ :last_traffic_at ] > EXPIRE_AFTER
749
- @mutex.synchronize do
738
+ if now - tun_info[ :last_traffic_at ] > EXPIRE_AFTER
750
739
  tun_id = @socks[ tun ]
751
740
  # puts "debug ctlw close tun #{ tun_id } #{ Time.new } p#{ Process.pid }"
752
741
  @ctlw.write( [ CTL_CLOSE, tun_id ].pack( 'CQ>' ) )
753
742
  end
754
743
 
755
- break
756
- end
757
-
758
- exts = tun_info[ :source_exts ].select{ | _, ext | now - ext[ :created_at ] > 5 }
744
+ exts = tun_info[ :source_exts ].select{ | _, ext | now - ext[ :created_at ] > 5 }
759
745
 
760
- if exts.any?
761
- @mutex.synchronize do
746
+ if exts.any?
762
747
  exts.each do | source_id, ext |
763
748
  if ext[ :last_recv_at ].nil? || ( now - ext[ :last_recv_at ] > EXPIRE_AFTER )
764
749
  # puts "debug ctlw close source #{ source_id } #{ Time.new } p#{ Process.pid }"
@@ -781,10 +766,10 @@ module Girl
781
766
  break
782
767
  end
783
768
 
784
- tun_info = @infos[ tun ]
769
+ @mutex.synchronize do
770
+ tun_info = @infos[ tun ]
785
771
 
786
- if tun_info[ :source_exts ].any?
787
- @mutex.synchronize do
772
+ if tun_info[ :source_exts ].any?
788
773
  now = Time.new
789
774
 
790
775
  tun_info[ :source_exts ].each do | source_id, ext |
@@ -801,10 +786,8 @@ module Girl
801
786
  end
802
787
  end
803
788
  end
804
- end
805
789
 
806
- if tun_info[ :paused ] && ( tun_info[ :source_exts ].map{ | _, ext | ext[ :wmems ].size }.sum < RESUME_BELOW )
807
- @mutex.synchronize do
790
+ if tun_info[ :paused ] && ( tun_info[ :source_exts ].map{ | _, ext | ext[ :wmems ].size }.sum < RESUME_BELOW )
808
791
  tun_id = @socks[ tun ]
809
792
  puts "ctlw resume #{ tun_id } #{ Time.new } p#{ Process.pid }"
810
793
  @ctlw.write( [ CTL_RESUME, tun_id ].pack( 'CQ>' ) )
@@ -817,7 +800,7 @@ module Girl
817
800
 
818
801
  def loop_send_a_new_source( source, original_dst )
819
802
  Thread.new do
820
- 100.times do
803
+ 30.times do
821
804
  break if source.closed?
822
805
 
823
806
  source_info = @infos[ source ]
@@ -834,12 +817,12 @@ module Girl
834
817
  # puts "debug break a new source loop #{ Time.new } p#{ Process.pid }"
835
818
  break
836
819
  end
820
+ end
837
821
 
838
- @mutex.synchronize do
839
- ctlmsg = "#{ [ 0, A_NEW_SOURCE, source_id ].pack( 'Q>CQ>' ) }#{ original_dst }"
840
- # puts "debug send a new source #{ Time.new } p#{ Process.pid }"
841
- send_pack( tun, ctlmsg, tun_info[ :tund_addr ] )
842
- end
822
+ @mutex.synchronize do
823
+ ctlmsg = "#{ [ 0, A_NEW_SOURCE, source_id ].pack( 'Q>CQ>' ) }#{ original_dst }"
824
+ # puts "debug send a new source #{ Time.new } p#{ Process.pid }"
825
+ send_pack( tun, ctlmsg, tun_info[ :tund_addr ] )
843
826
  end
844
827
 
845
828
  sleep 1
@@ -849,7 +832,7 @@ module Girl
849
832
 
850
833
  def loop_send_fin1( tun, source_id )
851
834
  Thread.new do
852
- 100.times do
835
+ 30.times do
853
836
  break if tun.closed?
854
837
 
855
838
  tun_info = @infos[ tun ]
@@ -878,7 +861,7 @@ module Girl
878
861
 
879
862
  def loop_send_fin2( tun, source_id )
880
863
  Thread.new do
881
- 100.times do
864
+ 30.times do
882
865
  break if tun.closed?
883
866
 
884
867
  tun_info = @infos[ tun ]
@@ -4,19 +4,7 @@ require 'girl/version'
4
4
  require 'socket'
5
5
 
6
6
  ##
7
- # Girl::Tund - tcp流量正常的到达目的地。远端。
8
- #
9
- # 两套关闭
10
- # ========
11
- #
12
- # 1-1. dest.close -> ext.is_source_closed ? no -> send fin1 loop
13
- # 1-2. recv got_fin1 -> break loop
14
- # 1-3. recv fin2 -> send got_fin2 -> del ext
15
- #
16
- # 2-1. recv fin1 -> send got_fin1 -> ext.is_source_closed = true
17
- # 2-2. all sent && ext.biggest_source_pack_id == ext.continue_source_pack_id -> add closing dest
18
- # 2-3. dest.close -> ext.is_source_closed ? yes -> del ext -> loop send fin2
19
- # 2-4. recv got_fin2 -> break loop
7
+ # Girl::Tund - tcp透明转发,远端。
20
8
  #
21
9
  module Girl
22
10
  class Tund
@@ -54,6 +42,15 @@ module Girl
54
42
  rs, ws = IO.select( @reads, @writes )
55
43
 
56
44
  @mutex.synchronize do
45
+ ws.each do | sock |
46
+ case @roles[ sock ]
47
+ when :dest
48
+ write_dest( sock )
49
+ when :tund
50
+ write_tund( sock )
51
+ end
52
+ end
53
+
57
54
  rs.each do | sock |
58
55
  case @roles[ sock ]
59
56
  when :ctlr
@@ -66,15 +63,6 @@ module Girl
66
63
  read_tund( sock )
67
64
  end
68
65
  end
69
-
70
- ws.each do | sock |
71
- case @roles[ sock ]
72
- when :dest
73
- write_dest( sock )
74
- when :tund
75
- write_tund( sock )
76
- end
77
- end
78
66
  end
79
67
  end
80
68
  rescue Interrupt => e
@@ -660,13 +648,13 @@ module Girl
660
648
 
661
649
  def check_expire( tund )
662
650
  Thread.new do
663
- sleep HEARTBEAT_INTERVAL
651
+ sleep 3
664
652
 
665
- unless tund.closed?
666
- tund_info = @infos[ tund ]
653
+ @mutex.synchronize do
654
+ unless tund.closed?
655
+ tund_info = @infos[ tund ]
667
656
 
668
- unless tund_info[ :tun_addr ]
669
- @mutex.synchronize do
657
+ unless tund_info[ :tun_addr ]
670
658
  tund_id = @socks[ tund ]
671
659
  @ctlw.write( [ CTL_CLOSE, tund_id ].pack( 'CQ>' ) )
672
660
  end
@@ -678,25 +666,22 @@ module Girl
678
666
  def loop_check_expire( tund )
679
667
  Thread.new do
680
668
  loop do
681
- sleep 60
669
+ sleep CHECK_EXPIRE_INTERVAL
670
+
682
671
  break if tund.closed?
683
672
 
684
- now = Time.new
685
- tund_info = @infos[ tund ]
673
+ @mutex.synchronize do
674
+ now = Time.new
675
+ tund_info = @infos[ tund ]
686
676
 
687
- if now - tund_info[ :last_traffic_at ] > EXPIRE_AFTER
688
- @mutex.synchronize do
677
+ if now - tund_info[ :last_traffic_at ] > EXPIRE_AFTER
689
678
  tund_id = @socks[ tund ]
690
679
  @ctlw.write( [ CTL_CLOSE, tund_id ].pack( 'CQ>' ) )
691
680
  end
692
681
 
693
- break
694
- end
695
-
696
- exts = tund_info[ :dest_exts ].select{ | _, ext | now - ext[ :created_at ] > 5 }
682
+ exts = tund_info[ :dest_exts ].select{ | _, ext | now - ext[ :created_at ] > 5 }
697
683
 
698
- if exts.any?
699
- @mutex.synchronize do
684
+ if exts.any?
700
685
  exts.each do | dest_id, ext |
701
686
  if ext[ :last_recv_at ].nil? || ( now - ext[ :last_recv_at ] > EXPIRE_AFTER )
702
687
  # puts "debug ctlw close dest #{ dest_id } #{ Time.new } p#{ Process.pid }"
@@ -719,10 +704,10 @@ module Girl
719
704
  break
720
705
  end
721
706
 
722
- tund_info = @infos[ tund ]
707
+ @mutex.synchronize do
708
+ tund_info = @infos[ tund ]
723
709
 
724
- if tund_info[ :dest_exts ].any?
725
- @mutex.synchronize do
710
+ if tund_info[ :dest_exts ].any?
726
711
  now = Time.new
727
712
 
728
713
  tund_info[ :dest_exts ].each do | dest_id, ext |
@@ -739,10 +724,8 @@ module Girl
739
724
  end
740
725
  end
741
726
  end
742
- end
743
727
 
744
- if tund_info[ :paused ] && ( tund_info[ :dest_exts ].map{ | _, ext | ext[ :wmems ].size }.sum < RESUME_BELOW )
745
- @mutex.synchronize do
728
+ if tund_info[ :paused ] && ( tund_info[ :dest_exts ].map{ | _, ext | ext[ :wmems ].size }.sum < RESUME_BELOW )
746
729
  tund_id = @socks[ tund ]
747
730
  puts "ctlw resume #{ tund_id } #{ Time.new } p#{ Process.pid }"
748
731
  @ctlw.write( [ CTL_RESUME, tund_id ].pack( 'CQ>' ) )
@@ -755,7 +738,7 @@ module Girl
755
738
 
756
739
  def loop_send_fin1( tund, dest_id )
757
740
  Thread.new do
758
- 100.times do
741
+ 30.times do
759
742
  break if tund.closed?
760
743
 
761
744
  tund_info = @infos[ tund ]
@@ -784,7 +767,7 @@ module Girl
784
767
 
785
768
  def loop_send_fin2( tund, dest_id )
786
769
  Thread.new do
787
- 100.times do
770
+ 30.times do
788
771
  break if tund.closed?
789
772
 
790
773
  tund_info = @infos[ tund ]
@@ -2,7 +2,7 @@ require 'girl/version'
2
2
  require 'socket'
3
3
 
4
4
  ##
5
- # Girl::Udp - 转发udp。近端。
5
+ # Girl::Udp - udp透明转发,近端。
6
6
  #
7
7
  # usage
8
8
  # ======
@@ -2,7 +2,7 @@ require 'girl/version'
2
2
  require 'socket'
3
3
 
4
4
  ##
5
- # Girl::Udpd - 转发udp。远端。
5
+ # Girl::Udpd - udp透明转发,远端。
6
6
  #
7
7
  module Girl
8
8
  class Udpd
@@ -1,3 +1,3 @@
1
1
  module Girl
2
- VERSION = '0.57.0'.freeze
2
+ VERSION = '0.60.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: girl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.57.0
4
+ version: 0.60.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - takafan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-11 00:00:00.000000000 Z
11
+ date: 2020-05-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: while internet is evil, here's a girl.
14
14
  email:
@@ -19,8 +19,15 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - girl.gemspec
21
21
  - lib/girl.rb
22
+ - lib/girl/custom.rb
22
23
  - lib/girl/head.rb
23
24
  - lib/girl/hex.rb
25
+ - lib/girl/proxy.rb
26
+ - lib/girl/proxy_custom.rb
27
+ - lib/girl/proxy_worker.rb
28
+ - lib/girl/proxyd.rb
29
+ - lib/girl/proxyd_custom.rb
30
+ - lib/girl/proxyd_worker.rb
24
31
  - lib/girl/resolv.rb
25
32
  - lib/girl/resolvd.rb
26
33
  - lib/girl/tun.rb