girl 4.4.0 → 4.5.0

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.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d7b905d2180abe835d892f44038fdf2f96b6710ad942fa2d762a2484430ea48f
4
- data.tar.gz: d0a95baf185ce66219c7ce783c975d5bdd4bd9e00273ae77842f70697301ac40
3
+ metadata.gz: 2631d53d8c27dfb593364dc65b8d84cfbcad3e27f231c906f1b5ae6ceeea44fd
4
+ data.tar.gz: 6bef34c3cf545b9851038dcd630f62afd5117402ac4955ecadf6bdda3f633e68
5
5
  SHA512:
6
- metadata.gz: 6659b516924a9a43be0b7cf9c3d85ae8bda57e22d131089ae295f24ca7247d628e7d8fc795e6625cadac81a785b6390ae1ec3e170a42d5c3403e023879ff11ea
7
- data.tar.gz: 6800db65291e870d6a87c3b22328a9415210c73b8535d5077609f0a957901a05f6832e621321ad9b5f2e78c609c640f1fe18ad8321e44ee195a4af7da2b62239
6
+ metadata.gz: 221343c8278bea0f825adee69c7bc392005c637a787e6561004607ce5529105e9ecb5cdfd88d9b6523caff23b05cd0dcf4085d523e873f44c80e37a6360b3947
7
+ data.tar.gz: c1efea95b6fb2d91111abd3d97d36b557a40b6261361209abf39f9a645452afdadf85014ae338229a2b8333efb32c773456c169cc9fc9c015614b9decf8f7cd4
data/lib/girl/head.rb CHANGED
@@ -1,13 +1,15 @@
1
1
  module Girl
2
- READ_SIZE = 1024 * 1024 # atun, btun一次读多少
2
+ READ_SIZE = 1024 * 1024 # 一次读多少
3
3
  WBUFF_LIMIT = 50 * 1024 * 1024 # 写前上限,超过上限暂停读
4
4
  RESUME_BELOW = WBUFF_LIMIT / 2 # 降到多少以下恢复读
5
+ CHUNK_SIZE = 65535 # 按块加解密,块尺寸上限,不超过65535
5
6
  EXPIRE_NEW = 5 # 多久没有建立通道,过期
7
+ EXPIRE_CONNECTING = 2 # 连接中,多久没连上过期
6
8
  EXPIRE_AFTER = 300 # 多久没有新流量,过期
7
9
  EXPIRE_CTL = 86400 # 多久没有ctlmsg来,过期
8
10
  RESET_TRAFF_DAY = 1 # 流量计数重置日,0为不重置
9
11
  CHECK_TRAFF_INTERVAL = 86400 # 检查今天是否是流量计数重置日间隔
10
- CHECK_EXPIRE_INTERVAL = 5 # 检查过期间隔
12
+ CHECK_EXPIRE_INTERVAL = 1 # 检查过期间隔
11
13
  CHECK_RESUME_INTERVAL = 1 # 检查恢复读间隔
12
14
  RESOLV_CACHE_EXPIRE = 300 # dns查询结果缓存多久过期
13
15
  RESEND_LIMIT = 5 # ctlmsg重传次数
@@ -52,7 +54,9 @@ EOF
52
54
  READ_SIZE
53
55
  WBUFF_LIMIT
54
56
  RESUME_BELOW
57
+ CHUNK_SIZE
55
58
  EXPIRE_NEW
59
+ EXPIRE_CONNECTING
56
60
  EXPIRE_AFTER
57
61
  EXPIRE_CTL
58
62
  RESET_TRAFF_DAY
@@ -517,9 +517,24 @@ module Girl
517
517
  @src_infos.each do | src, src_info |
518
518
  last_recv_at = src_info[ :last_recv_at ] || src_info[ :created_at ]
519
519
  last_sent_at = src_info[ :last_sent_at ] || src_info[ :created_at ]
520
- expire_after = ( src_info[ :dst ] || src_info[ :atun ] ) ? EXPIRE_AFTER : EXPIRE_NEW
521
520
 
522
- if ( now - last_recv_at >= expire_after ) && ( now - last_sent_at >= expire_after ) then
521
+ if src_info[ :dst ] then
522
+ if src_info[ :dst_connected ] then
523
+ expire_after = EXPIRE_AFTER
524
+ is_expire = ( now - last_recv_at >= expire_after ) && ( now - last_sent_at >= expire_after )
525
+ else
526
+ expire_after = EXPIRE_CONNECTING
527
+ is_expire = ( now - src_info[ :dst_created_at ] >= expire_after )
528
+ end
529
+ elsif src_info[ :atun ] then
530
+ expire_after = EXPIRE_AFTER
531
+ is_expire = ( now - last_recv_at >= expire_after ) && ( now - last_sent_at >= expire_after )
532
+ else
533
+ expire_after = EXPIRE_NEW
534
+ is_expire = ( now - last_recv_at >= expire_after ) && ( now - last_sent_at >= expire_after )
535
+ end
536
+
537
+ if is_expire then
523
538
  puts "p#{ Process.pid } #{ Time.new } expire src #{ expire_after } #{ src_info[ :id ] } #{ src_info[ :destination_domain ] }"
524
539
  add_closing_src( src )
525
540
 
@@ -653,9 +668,9 @@ module Girl
653
668
  }
654
669
 
655
670
  @dst_infos[ dst ] = dst_info
656
- add_read( dst, :dst )
657
671
  src_info[ :proxy_type ] = :direct
658
672
  src_info[ :dst ] = dst
673
+ src_info[ :dst_created_at ] = Time.new
659
674
 
660
675
  if src_info[ :proxy_proto ] == :http then
661
676
  if src_info[ :is_connect ] then
@@ -664,11 +679,13 @@ module Girl
664
679
  elsif src_info[ :rbuff ] then
665
680
  # puts "debug move src.rbuff to dst.wbuff"
666
681
  dst_info[ :wbuff ] << src_info[ :rbuff ]
667
- add_write( dst )
668
682
  end
669
683
  elsif src_info[ :proxy_proto ] == :socks5 then
670
684
  add_socks5_conn_reply( src )
671
685
  end
686
+
687
+ add_read( dst, :dst )
688
+ add_write( dst )
672
689
  end
673
690
 
674
691
  ##
@@ -755,7 +772,7 @@ module Girl
755
772
  atun_wbuff = [ dst_id ].pack( 'n' )
756
773
 
757
774
  until src_info[ :rbuff ].empty? do
758
- data = src_info[ :rbuff ][ 0, 65535 ]
775
+ data = src_info[ :rbuff ][ 0, CHUNK_SIZE ]
759
776
  data_size = data.bytesize
760
777
  # puts "debug move src.rbuff #{ data_size } to atun.wbuff"
761
778
  atun_wbuff << pack_a_chunk( data )
@@ -929,7 +946,7 @@ module Girl
929
946
  # read dotr
930
947
  #
931
948
  def read_dotr( dotr )
932
- dotr.read_nonblock( 65535 )
949
+ dotr.read_nonblock( READ_SIZE )
933
950
 
934
951
  if @ctl_info && @ctl_info[ :closing ] then
935
952
  send_ctlmsg( [ CTL_FIN ].pack( 'C' ) )
@@ -993,6 +1010,8 @@ module Girl
993
1010
  is_connect: true, # 代理协议是http的场合,是否是CONNECT
994
1011
  rbuff: '', # 读到的流量
995
1012
  dst: nil, # :direct的场合,对应的dst
1013
+ dst_created_at: nil, # :direct的场合,对应的dst的创建时间
1014
+ dst_connected: false, # :direct的场合,对应的dst是否已连接
996
1015
  ctl: nil, # :tunnel的场合,对应的ctl
997
1016
  atun: nil, # :tunnel的场合,对应的atun
998
1017
  btun: nil, # :tunnel的场合,对应的btun
@@ -1066,7 +1085,7 @@ module Girl
1066
1085
  src_info = @src_infos[ src ]
1067
1086
 
1068
1087
  begin
1069
- data = src.read_nonblock( 65535 )
1088
+ data = src.read_nonblock( CHUNK_SIZE )
1070
1089
  rescue IO::WaitReadable
1071
1090
  print 'r'
1072
1091
  return
@@ -1248,7 +1267,7 @@ module Girl
1248
1267
  src = dst_info[ :src ]
1249
1268
 
1250
1269
  begin
1251
- data = dst.read_nonblock( 65535 )
1270
+ data = dst.read_nonblock( CHUNK_SIZE )
1252
1271
  rescue IO::WaitReadable
1253
1272
  print 'r'
1254
1273
  return
@@ -1413,6 +1432,12 @@ module Girl
1413
1432
 
1414
1433
  dst_info = @dst_infos[ dst ]
1415
1434
  src = dst_info[ :src ]
1435
+ src_info = @src_infos[ src ]
1436
+
1437
+ unless src.closed? then
1438
+ src_info[ :dst_connected ] = true
1439
+ end
1440
+
1416
1441
  data = dst_info[ :wbuff ]
1417
1442
 
1418
1443
  # 写前为空,处理关闭写
@@ -1443,7 +1468,6 @@ module Girl
1443
1468
  dst_info[ :wbuff ] = data
1444
1469
 
1445
1470
  unless src.closed? then
1446
- src_info = @src_infos[ src ]
1447
1471
  src_info[ :last_sent_at ] = Time.new
1448
1472
  end
1449
1473
  end
@@ -324,6 +324,7 @@ module Girl
324
324
  ctl_addr: ctl_addr, # 对应ctl
325
325
  im: ctl_info[ :im ], # 标识
326
326
  domain_port: domain_port, # 目的地和端口
327
+ connected: false, # 是否已连接
327
328
  rbuff: '', # 对应的tun没准备好,暂存读到的流量
328
329
  atun: nil, # 对应的atun
329
330
  btun: nil, # 对应的btun
@@ -336,6 +337,7 @@ module Girl
336
337
  }
337
338
 
338
339
  add_read( dst, :dst )
340
+ add_write( dst )
339
341
 
340
342
  ctl_info[ :dst_ids ][ src_id ] = dst_id
341
343
  ctl_info[ :dsts ][ dst_id ] = dst
@@ -404,11 +406,17 @@ module Girl
404
406
  end
405
407
 
406
408
  @dst_infos.each do | dst, dst_info |
407
- last_recv_at = dst_info[ :last_recv_at ] || dst_info[ :created_at ]
408
- last_sent_at = dst_info[ :last_sent_at ] || dst_info[ :created_at ]
409
- expire_after = dst_info[ :btun ] ? EXPIRE_AFTER : EXPIRE_NEW
409
+ if dst_info[ :connected ] then
410
+ last_recv_at = dst_info[ :last_recv_at ] || dst_info[ :created_at ]
411
+ last_sent_at = dst_info[ :last_sent_at ] || dst_info[ :created_at ]
412
+ expire_after = EXPIRE_AFTER
413
+ is_expire = ( now - last_recv_at >= expire_after ) && ( now - last_sent_at >= expire_after )
414
+ else
415
+ expire_after = EXPIRE_CONNECTING
416
+ is_expire = ( now - dst_info[ :created_at ] >= expire_after )
417
+ end
410
418
 
411
- if ( now - last_recv_at >= expire_after ) && ( now - last_sent_at >= expire_after ) then
419
+ if is_expire then
412
420
  puts "p#{ Process.pid } #{ Time.new } expire dst #{ expire_after } #{ dst_info[ :domain_port ] }"
413
421
 
414
422
  unless @closing_dsts.include?( dst ) then
@@ -609,7 +617,7 @@ module Girl
609
617
  # read dotr
610
618
  #
611
619
  def read_dotr( dotr )
612
- dotr.read_nonblock( 65535 )
620
+ dotr.read_nonblock( READ_SIZE )
613
621
 
614
622
  if @deleting_ctl_infos.any? then
615
623
  @deleting_ctl_infos.each { | ctl_addr | del_ctl_info( ctl_addr ) }
@@ -772,7 +780,7 @@ module Girl
772
780
  btun = dst_info[ :btun ]
773
781
 
774
782
  begin
775
- data = dst.read_nonblock( 65535 )
783
+ data = dst.read_nonblock( CHUNK_SIZE )
776
784
  rescue IO::WaitReadable
777
785
  print 'r'
778
786
  return
@@ -1044,7 +1052,7 @@ module Girl
1044
1052
  data2 = ''
1045
1053
 
1046
1054
  until dst_info[ :rbuff ].empty? do
1047
- _data = dst_info[ :rbuff ][ 0, 65535 ]
1055
+ _data = dst_info[ :rbuff ][ 0, CHUNK_SIZE ]
1048
1056
  data_size = _data.bytesize
1049
1057
  # puts "debug move dst.rbuff to btun.wbuff"
1050
1058
  data2 << pack_a_chunk( _data )
@@ -1067,6 +1075,7 @@ module Girl
1067
1075
  end
1068
1076
 
1069
1077
  dst_info = @dst_infos[ dst ]
1078
+ dst_info[ :connected ] = true
1070
1079
  atun = dst_info[ :atun ]
1071
1080
  data = dst_info[ :wbuff ]
1072
1081
 
@@ -537,9 +537,24 @@ module Girl
537
537
  @src_infos.each do | src, src_info |
538
538
  last_recv_at = src_info[ :last_recv_at ] || src_info[ :created_at ]
539
539
  last_sent_at = src_info[ :last_sent_at ] || src_info[ :created_at ]
540
- expire_after = ( src_info[ :dst ] || src_info[ :tun ] ) ? EXPIRE_AFTER : EXPIRE_NEW
541
540
 
542
- if ( now - last_recv_at >= expire_after ) && ( now - last_sent_at >= expire_after ) then
541
+ if src_info[ :dst ] then
542
+ if src_info[ :dst_connected ] then
543
+ expire_after = EXPIRE_AFTER
544
+ is_expire = ( now - last_recv_at >= expire_after ) && ( now - last_sent_at >= expire_after )
545
+ else
546
+ expire_after = EXPIRE_CONNECTING
547
+ is_expire = ( now - src_info[ :dst_created_at ] >= expire_after )
548
+ end
549
+ elsif src_info[ :atun ] then
550
+ expire_after = EXPIRE_AFTER
551
+ is_expire = ( now - last_recv_at >= expire_after ) && ( now - last_sent_at >= expire_after )
552
+ else
553
+ expire_after = EXPIRE_NEW
554
+ is_expire = ( now - last_recv_at >= expire_after ) && ( now - last_sent_at >= expire_after )
555
+ end
556
+
557
+ if is_expire then
543
558
  puts "p#{ Process.pid } #{ Time.new } expire src #{ expire_after } #{ src_info[ :id ] } #{ src_info[ :destination_domain ] }"
544
559
  add_closing_src( src )
545
560
 
@@ -674,15 +689,17 @@ module Girl
674
689
  }
675
690
 
676
691
  @dst_infos[ dst ] = dst_info
677
- add_read( dst, :dst )
678
692
  src_info[ :proxy_type ] = :direct
679
693
  src_info[ :dst ] = dst
694
+ src_info[ :dst_created_at ] = Time.new
680
695
 
681
696
  if src_info[ :rbuff ] then
682
697
  # puts "debug move src.rbuff to dst.wbuff"
683
698
  dst_info[ :wbuff ] << src_info[ :rbuff ]
684
- add_write( dst )
685
699
  end
700
+
701
+ add_read( dst, :dst )
702
+ add_write( dst )
686
703
  end
687
704
 
688
705
  ##
@@ -803,7 +820,7 @@ module Girl
803
820
  atun_wbuff = [ dst_id ].pack( 'n' )
804
821
 
805
822
  until src_info[ :rbuff ].empty? do
806
- data = src_info[ :rbuff ][ 0, 65535 ]
823
+ data = src_info[ :rbuff ][ 0, CHUNK_SIZE ]
807
824
  data_size = data.bytesize
808
825
  # puts "debug move src.rbuff #{ data_size } to atun.wbuff"
809
826
  atun_wbuff << pack_a_chunk( data )
@@ -934,7 +951,7 @@ module Girl
934
951
  # read dotr
935
952
  #
936
953
  def read_dotr( dotr )
937
- dotr.read_nonblock( 65535 )
954
+ dotr.read_nonblock( READ_SIZE )
938
955
 
939
956
  if @ctl_info && @ctl_info[ :closing ] then
940
957
  send_ctlmsg( [ CTL_FIN ].pack( 'C' ) )
@@ -1039,6 +1056,8 @@ module Girl
1039
1056
  destination_port: dest_port, # 目的地端口
1040
1057
  rbuff: '', # 读到的流量
1041
1058
  dst: nil, # :direct的场合,对应的dst
1059
+ dst_created_at: nil, # :direct的场合,对应的dst的创建时间
1060
+ dst_connected: false, # :direct的场合,对应的dst是否已连接
1042
1061
  ctl: nil, # :tunnel的场合,对应的ctl
1043
1062
  atun: nil, # :tunnel的场合,对应的atun
1044
1063
  btun: nil, # :tunnel的场合,对应的btun
@@ -1114,7 +1133,7 @@ module Girl
1114
1133
  src_info = @src_infos[ src ]
1115
1134
 
1116
1135
  begin
1117
- data = src.read_nonblock( 65535 )
1136
+ data = src.read_nonblock( CHUNK_SIZE )
1118
1137
  rescue IO::WaitReadable
1119
1138
  print 'r'
1120
1139
  return
@@ -1176,7 +1195,7 @@ module Girl
1176
1195
  src = dst_info[ :src ]
1177
1196
 
1178
1197
  begin
1179
- data = dst.read_nonblock( 65535 )
1198
+ data = dst.read_nonblock( CHUNK_SIZE )
1180
1199
  rescue IO::WaitReadable
1181
1200
  print 'r'
1182
1201
  return
@@ -1341,6 +1360,12 @@ module Girl
1341
1360
 
1342
1361
  dst_info = @dst_infos[ dst ]
1343
1362
  src = dst_info[ :src ]
1363
+ src_info = @src_infos[ src ]
1364
+
1365
+ unless src.closed? then
1366
+ src_info[ :dst_connected ] = true
1367
+ end
1368
+
1344
1369
  data = dst_info[ :wbuff ]
1345
1370
 
1346
1371
  # 写前为空,处理关闭写
@@ -1371,7 +1396,6 @@ module Girl
1371
1396
  dst_info[ :wbuff ] = data
1372
1397
 
1373
1398
  unless src.closed? then
1374
- src_info = @src_infos[ src ]
1375
1399
  src_info[ :last_sent_at ] = Time.new
1376
1400
  end
1377
1401
  end
@@ -162,7 +162,7 @@ module Girl
162
162
  # read dotr
163
163
  #
164
164
  def read_dotr( dotr )
165
- dotr.read_nonblock( 65535 )
165
+ dotr.read_nonblock( READ_SIZE )
166
166
 
167
167
  if @closing_dsts.any? then
168
168
  @closing_dsts.each { | dst | close_dst( dst ) }
@@ -534,7 +534,7 @@ module Girl
534
534
  # read dotr
535
535
  #
536
536
  def read_dotr( dotr )
537
- dotr.read_nonblock( 65535 )
537
+ dotr.read_nonblock( READ_SIZE )
538
538
 
539
539
  if @closing_srcs.any? then
540
540
  @closing_srcs.each { | src | close_src( src ) }
@@ -623,7 +623,7 @@ module Girl
623
623
  src_info = @src_infos[ src ]
624
624
 
625
625
  begin
626
- data = src.read_nonblock( 65535 )
626
+ data = src.read_nonblock( READ_SIZE )
627
627
  rescue IO::WaitReadable
628
628
  return
629
629
  rescue Errno::EINTR => e
@@ -741,7 +741,7 @@ module Girl
741
741
  src = dst_info[ :src ]
742
742
 
743
743
  begin
744
- data = dst.read_nonblock( 65535 )
744
+ data = dst.read_nonblock( READ_SIZE )
745
745
  rescue IO::WaitReadable, Errno::EINTR
746
746
  print 'r'
747
747
  return
data/lib/girl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Girl
2
- VERSION = '4.4.0'.freeze
2
+ VERSION = '4.5.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: 4.4.0
4
+ version: 4.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - takafan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-14 00:00:00.000000000 Z
11
+ date: 2021-04-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: escape evil.
14
14
  email:
@@ -55,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
55
  - !ruby/object:Gem::Version
56
56
  version: '0'
57
57
  requirements: []
58
- rubygems_version: 3.2.15
58
+ rubygems_version: 3.1.4
59
59
  signing_key:
60
60
  specification_version: 4
61
61
  summary: 妹子