girl 0.89.0 → 0.90.0

This diff has not been reviewed by any users.
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a1e3e17f5d9ca7e92f7c61d52732b78e80b93fcaf9c39c19cb0d4ebc0bb353c
4
- data.tar.gz: 981a168ddcda54ccbddc39acb0dec0af00b018f1fba64ffd04444f584d306671
3
+ metadata.gz: 2e1916068595360e4ab83189c93759e2c6ed05979d4a4128ff83f95390e91dce
4
+ data.tar.gz: 9f39d67731002186f66f04e4bb463834980a243fc0d6322b5e35f749fa356f95
5
5
  SHA512:
6
- metadata.gz: '08f46bb81ff9d4ad4767aad8528e7c7c899f9c305db62f1dcb5079f3ebea28aed0ffc49946ac2b3503303c8dd807e9b27204c0042d3aca73f3c06e42881d294b'
7
- data.tar.gz: 533abffc741dcb060bfc80bf6ac9cdae98a3be4f38d70a7a2e3a0cd3df5eef2b617a961b66d965a306e5adab3d9464fbd3cec7ecd6bddf1b34cbe9cc8acd03c8
6
+ metadata.gz: 18e61543e05ae79c31ee76a8504cfcfef1271aa1419430ae667b46c8291dcc790630aa1123bc662ce817117a26b68ac343f5c7679134a3205548f32ba28cfb31
7
+ data.tar.gz: 797fa163ab50c3ace753ac833381bdeb040876c12de7d2b5570dbe0f3a799a91b18fa220ca5ea4ecbc8cfad69aabbd1dd245ad1bcd404b92423020890f5d38d1
@@ -22,24 +22,19 @@ Q>: 0 ctlmsg -> C: 1 tund port -> n: tund port -> n: tcpd port
22
22
 
23
23
  tun-tund:
24
24
 
25
- Q>: 0 ctlmsg -> C: 2 heartbeat not use
26
- 3 a new source -> Q>: src id -> encoded destination address
27
- 4 paired -> Q>: src id -> n: dst id
28
- 5 dest status not use
29
- 6 source status not use
30
- 7 miss not use
31
- 8 fin1 not use
32
- 9 confirm fin1 not use
33
- 10 fin2 not use
34
- 11 confirm fin2 not use
25
+ Q>: 0 ctlmsg -> C: 2 heartbeat [not use]
26
+ 3 a new source -> Q>: src id -> encoded destination address
27
+ 4 paired -> Q>: src id -> n: dst id
28
+ 5 dest status [not use]
29
+ 6 source status [not use]
30
+ 7 miss [not use]
31
+ 8 fin1 [not use]
32
+ 9 confirm fin1 [not use]
33
+ 10 fin2 [not use]
34
+ 11 confirm fin2 [not use]
35
35
  12 tund fin
36
36
  13 tun fin
37
37
  14 tun ip changed
38
- 15 single miss not use
39
- 16 range miss not use
40
- 17 continue not use
41
- 18 is resend ready not use
42
- 19 resend ready not use
43
38
  =end
44
39
 
45
40
  module Girl
@@ -84,14 +79,14 @@ module Girl
84
79
 
85
80
  if direct_path then
86
81
  raise "not found direct file #{ direct_path }" unless File.exist?( direct_path )
87
- directs = ( RESERVED_ROUTE.split( "\n" ) + IO.binread( direct_path ).split( "\n" ) ).map { | line | IPAddr.new( line.strip ) }
82
+ directs = ( RESERVED_ROUTE.split( "\n" ) + IO.binread( direct_path ).split( "\n" ) ).map{ | line | IPAddr.new( line.strip ) }
88
83
  end
89
84
 
90
85
  remotes = []
91
86
 
92
87
  if remote_path then
93
88
  raise "not found remote file #{ remote_path }" unless File.exist?( remote_path )
94
- remotes = IO.binread( remote_path ).split( "\n" ).map { | line | line.strip }
89
+ remotes = IO.binread( remote_path ).split( "\n" ).map{ | line | line.strip }
95
90
  end
96
91
 
97
92
  unless im then
@@ -7,7 +7,6 @@ module Girl
7
7
  def initialize( proxy_port, proxyd_host, proxyd_port, directs, remotes, im )
8
8
  @proxyd_host = proxyd_host
9
9
  @proxyd_addr = Socket.sockaddr_in( proxyd_port, proxyd_host )
10
- @proxyd_ip = Addrinfo.new( @proxyd_addr ).ip_address
11
10
  @directs = directs
12
11
  @remotes = remotes
13
12
  @custom = Girl::ProxyCustom.new( im )
@@ -588,22 +587,16 @@ module Girl
588
587
  tun.bind( Socket.sockaddr_in( 0, '0.0.0.0' ) )
589
588
  port = tun.local_address.ip_port
590
589
  tun_info = {
591
- port: port, # 端口
592
- pending_sources: [], # 还没配上tund,暂存的src
593
- ctlmsgs: [], # [ ctlmsg, to_addr ]
594
- resend_newers: {}, # 尾巴流量重传队列 src_id => newer_pack_ids
595
- resend_singles: {}, # 单个重传队列 src_id => single_miss_pack_ids
596
- resend_ranges: {}, # 区间重传队列 src_id => range_miss_pack_ids
597
- event_srcs: [], # rbuff不为空,或者准备关闭的src
598
- tund_addr: nil, # tund地址
599
- tcpd_addr: nil, # tcpd地址
600
- srcs: {}, # src_id => src
601
- created_at: Time.new, # 创建时间
602
- last_recv_at: nil, # 上一次收到流量的时间
603
- last_sent_at: nil, # 上一次发出流量的时间
604
- sender_addrs: nil, # 远端发送者地址
605
- last_ping_senders_at: nil, # 上一次ping发送者的时间
606
- closing: false # 是否准备关闭
590
+ port: port, # 端口
591
+ pending_sources: [], # 还没配上tund,暂存的src
592
+ ctlmsgs: [], # [ ctlmsg, to_addr ]
593
+ tund_addr: nil, # tund地址
594
+ tcpd_addr: nil, # tcpd地址
595
+ srcs: {}, # src_id => src
596
+ created_at: Time.new, # 创建时间
597
+ last_recv_at: nil, # 上一次收到流量的时间
598
+ last_sent_at: nil, # 上一次发出流量的时间
599
+ closing: false # 是否准备关闭
607
600
  }
608
601
 
609
602
  @tun = tun
@@ -701,27 +694,6 @@ module Girl
701
694
  add_read( src )
702
695
  end
703
696
 
704
- ##
705
- # send data
706
- #
707
- def send_data( data, to_addr = nil )
708
- unless to_addr then
709
- to_addr = @tun_info[ :tund_addr ]
710
- end
711
-
712
- begin
713
- written = @tun.sendmsg_nonblock( data, 0, to_addr )
714
- rescue IO::WaitWritable, Errno::EINTR
715
- print '.'
716
- return :wait
717
- rescue Errno::EHOSTUNREACH, Errno::ENETUNREACH, Errno::ENETDOWN => e
718
- puts "#{ Time.new } sendmsg #{ e.class }, close tun"
719
- return :fatal
720
- end
721
-
722
- written
723
- end
724
-
725
697
  ##
726
698
  # set dst closing
727
699
  #
@@ -856,24 +828,24 @@ module Girl
856
828
  # puts "debug1 accept a src #{ addrinfo.inspect } #{ src_id }"
857
829
 
858
830
  @src_infos[ src ] = {
859
- id: src_id, # id
860
- proxy_proto: :uncheck, # :uncheck / :http / :socks5
861
- proxy_type: :uncheck, # :uncheck / :checking / :direct / :tunnel / :negotiation
862
- destination_domain: nil, # 目的地域名
863
- destination_port: nil, # 目的地端口
864
- is_connect: true, # 代理协议是http的场合,是否是CONNECT
865
- rbuff: '', # 读到的流量
866
- stream: nil, # :tunnel的场合,对应的stream
867
- wbuff: '', # 从dst/stream读到的流量
868
- dst: nil, # :direct的场合,对应的dst
869
- dst_id: nil, # 远端dst id
870
- created_at: Time.new, # 创建时间
871
- last_recv_at: nil, # 上一次收到新流量(由dst收到,或者由stream收到)的时间
872
- last_sent_at: nil, # 上一次发出流量(由dst发出,或者由stream发出)的时间
873
- paused: false, # 是否已暂停
874
- closing: false, # 准备关闭
875
- closing_read: false, # 准备关闭读
876
- closing_write: false # 准备关闭写
831
+ id: src_id, # id
832
+ proxy_proto: :uncheck, # :uncheck / :http / :socks5
833
+ proxy_type: :uncheck, # :uncheck / :checking / :direct / :tunnel / :negotiation
834
+ destination_domain: nil, # 目的地域名
835
+ destination_port: nil, # 目的地端口
836
+ is_connect: true, # 代理协议是http的场合,是否是CONNECT
837
+ rbuff: '', # 读到的流量
838
+ dst: nil, # :direct的场合,对应的dst
839
+ stream: nil, # :tunnel的场合,对应的stream
840
+ dst_id: nil, # 远端dst id
841
+ wbuff: '', # dst/stream读到的流量
842
+ created_at: Time.new, # 创建时间
843
+ last_recv_at: nil, # 上一次收到新流量(由dst收到,或者由stream收到)的时间
844
+ last_sent_at: nil, # 上一次发出流量(由dst发出,或者由stream发出)的时间
845
+ paused: false, # 是否已暂停
846
+ closing: false, # 准备关闭
847
+ closing_read: false, # 准备关闭读
848
+ closing_write: false # 准备关闭写
877
849
  }
878
850
 
879
851
  add_read( src, :src )
@@ -1200,15 +1172,17 @@ module Girl
1200
1172
  # 发ctlmsg
1201
1173
  while @tun_info[ :ctlmsgs ].any? do
1202
1174
  data, to_addr = @tun_info[ :ctlmsgs ].first
1203
- sent = send_data( data, to_addr )
1204
1175
 
1205
- if sent == :fatal then
1206
- close_tun( tun )
1207
- return
1208
- elsif sent == :wait then
1209
- # puts "debug1 #{ Time.new } wait send ctlmsg left #{ @tun_info[ :ctlmsgs ].size }"
1176
+ begin
1177
+ @tun.sendmsg_nonblock( data, 0, to_addr )
1178
+ rescue IO::WaitWritable, Errno::EINTR
1179
+ puts "p#{ Process.pid } #{ Time.new } wait send ctlmsg, left #{ @tun_info[ :ctlmsgs ].size }"
1210
1180
  @tun_info[ :last_sent_at ] = now
1211
1181
  return
1182
+ rescue Errno::EHOSTUNREACH, Errno::ENETUNREACH, Errno::ENETDOWN => e
1183
+ puts "p#{ Process.pid } #{ Time.new } sendmsg #{ e.class }, close tun"
1184
+ close_tun( tun )
1185
+ return
1212
1186
  end
1213
1187
 
1214
1188
  @tun_info[ :ctlmsgs ].shift
@@ -1326,12 +1300,17 @@ module Girl
1326
1300
  rescue Exception => e
1327
1301
  # puts "debug1 write dst #{ e.class }"
1328
1302
  close_write_dst( dst )
1329
- close_read_src( src ) if src
1303
+ close_read_src( src )
1330
1304
  return
1331
1305
  end
1332
1306
 
1333
1307
  data = data[ written..-1 ]
1334
1308
  dst_info[ :wbuff ] = data
1309
+
1310
+ unless src.closed? then
1311
+ src_info = @src_infos[ src ]
1312
+ src_info[ :last_sent_at ] = Time.new
1313
+ end
1335
1314
  end
1336
1315
 
1337
1316
  ##
@@ -100,15 +100,6 @@ module Girl
100
100
  add_write( @proxyd )
101
101
  end
102
102
 
103
- ##
104
- # add ctlmsg resend ready
105
- #
106
- def add_ctlmsg_resend_ready( tund )
107
- tund_info = @tund_infos[ tund ]
108
- data = [ 0, RESEND_READY ].pack( 'Q>C' )
109
- add_ctlmsg( tund, data )
110
- end
111
-
112
103
  ##
113
104
  # add ctlmsg
114
105
  #
@@ -473,9 +464,9 @@ module Girl
473
464
  begin
474
465
  written = sock.sendmsg_nonblock( data, 0, to_addr )
475
466
  rescue IO::WaitWritable, Errno::EINTR
476
- print '.'
477
467
  return :wait
478
468
  rescue Errno::EHOSTUNREACH, Errno::ENETUNREACH, Errno::ENETDOWN => e
469
+ puts "p#{ Process.pid } #{ Time.new } sendmsg #{ e.class }"
479
470
  return :fatal
480
471
  end
481
472
 
@@ -577,20 +568,20 @@ module Girl
577
568
  add_read( tcpd, :tcpd )
578
569
 
579
570
  tund_info = {
580
- port: tund_port, # 端口
581
- tcpd: tcpd, # 对应的tcpd
582
- tcpd_port: tcpd_port, # tcpd端口
583
- ctlmsgs: [], # [ ctlmsg, to_addr ]
584
- tun_addr: from_addr, # tun地址
585
- dsts: {}, # dst_id => dst
586
- dst_ids: {}, # src_id => dst_id
587
- created_at: Time.new, # 创建时间
588
- last_recv_at: nil, # 上一次收到流量的时间
589
- last_sent_at: nil, # 上一次发出流量的时间
590
- closing: false, # 准备关闭
591
- closing_read: false, # 准备关闭读
592
- closing_write: false, # 准备关闭写
593
- changed_tun_addr: nil # 记录到和tun addr不符的来源地址
571
+ port: tund_port, # 端口
572
+ tcpd: tcpd, # 对应的tcpd
573
+ tcpd_port: tcpd_port, # tcpd端口
574
+ ctlmsgs: [], # [ ctlmsg, to_addr ]
575
+ tun_addr: from_addr, # tun地址
576
+ dsts: {}, # dst_id => dst
577
+ dst_ids: {}, # src_id => dst_id
578
+ created_at: Time.new, # 创建时间
579
+ last_recv_at: nil, # 上一次收到流量的时间
580
+ last_sent_at: nil, # 上一次发出流量的时间
581
+ closing: false, # 准备关闭
582
+ closing_read: false, # 准备关闭读
583
+ closing_write: false, # 准备关闭写
584
+ changed_tun_addr: nil # 记录到和tun addr不符的来源地址
594
585
  }
595
586
 
596
587
  @tunneling_tunds[ from_addr ] = tund
@@ -722,7 +713,7 @@ module Girl
722
713
  dst_info[ :rbuff ] << data
723
714
 
724
715
  if dst_info[ :rbuff ].bytesize >= WBUFF_LIMIT then
725
- # puts "debug1 dst.rbuff full #{ dst_info[ :rbuff ].bytesize }"
716
+ # puts "debug1 dst.rbuff full"
726
717
  set_dst_closing( dst )
727
718
  end
728
719
  end
@@ -800,6 +791,7 @@ module Girl
800
791
  sent = send_data( proxyd, data, to_addr )
801
792
 
802
793
  if sent == :wait then
794
+ puts "p#{ Process.pid } #{ Time.new } wait proxyd send ctlmsg, left #{ @proxyd_info[ :ctlmsgs ].size }"
803
795
  return
804
796
  else
805
797
  @proxyd_info[ :ctlmsgs ].shift
@@ -837,7 +829,7 @@ module Girl
837
829
  close_tund( tund )
838
830
  return
839
831
  elsif sent == :wait then
840
- # puts "debug1 #{ Time.new } wait send ctlmsg left #{ tund_info[ :ctlmsgs ].size }"
832
+ puts "p#{ Process.pid } #{ Time.new } wait tund #{ tund_info[ :port ] } send ctlmsg, left #{ tund_info[ :ctlmsgs ].size }"
841
833
  tund_info[ :last_sent_at ] = now
842
834
  return
843
835
  end
@@ -1,3 +1,3 @@
1
1
  module Girl
2
- VERSION = '0.89.0'.freeze
2
+ VERSION = '0.90.0'.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.89.0
4
+ version: 0.90.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - takafan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-10 00:00:00.000000000 Z
11
+ date: 2020-10-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: escape evil.
14
14
  email: