girl 4.5.0 → 4.6.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: 2631d53d8c27dfb593364dc65b8d84cfbcad3e27f231c906f1b5ae6ceeea44fd
4
- data.tar.gz: 6bef34c3cf545b9851038dcd630f62afd5117402ac4955ecadf6bdda3f633e68
3
+ metadata.gz: 8d3b294765df9759f671cd5916a4315aa5872a85e42ea9739d8e2bd409f55f49
4
+ data.tar.gz: 8405a9e93e8c038e757c3a191c40c3801ff34e9ce593be0b0187ee728cb70fa7
5
5
  SHA512:
6
- metadata.gz: 221343c8278bea0f825adee69c7bc392005c637a787e6561004607ce5529105e9ecb5cdfd88d9b6523caff23b05cd0dcf4085d523e873f44c80e37a6360b3947
7
- data.tar.gz: c1efea95b6fb2d91111abd3d97d36b557a40b6261361209abf39f9a645452afdadf85014ae338229a2b8333efb32c773456c169cc9fc9c015614b9decf8f7cd4
6
+ metadata.gz: 8b09b4c9b12257b9fc8672eace67cd89bfac89b5032ffb6ccf2a6810342a3c09e45ba0b6658b86cafd7d671fdeaf0235de794a3f0b356c2835a3c5248de9743b
7
+ data.tar.gz: 5e16e91e812c7c53d3fbb47e4c16fc90f7f922a011d4983b6ee955306fd88496b7965e0f02c7ab78b9db80e25a4468c483dffab634d009d1f459d1a16c589a8f
data/lib/girl/head.rb CHANGED
@@ -5,7 +5,7 @@ module Girl
5
5
  CHUNK_SIZE = 65535 # 按块加解密,块尺寸上限,不超过65535
6
6
  EXPIRE_NEW = 5 # 多久没有建立通道,过期
7
7
  EXPIRE_CONNECTING = 2 # 连接中,多久没连上过期
8
- EXPIRE_AFTER = 300 # 多久没有新流量,过期
8
+ EXPIRE_AFTER = 86400 # 多久没有新流量,过期
9
9
  EXPIRE_CTL = 86400 # 多久没有ctlmsg来,过期
10
10
  RESET_TRAFF_DAY = 1 # 流量计数重置日,0为不重置
11
11
  CHECK_TRAFF_INTERVAL = 86400 # 检查今天是否是流量计数重置日间隔
@@ -507,8 +507,8 @@ module Girl
507
507
  if @ctl && !@ctl.closed? then
508
508
  last_recv_at = @ctl_info[ :last_recv_at ] || @ctl_info[ :created_at ]
509
509
 
510
- if now - last_recv_at >= EXPIRE_AFTER then
511
- puts "p#{ Process.pid } #{ Time.new } expire ctl"
510
+ if now - last_recv_at >= EXPIRE_CTL then
511
+ puts "p#{ Process.pid } #{ Time.new } expire ctl #{ EXPIRE_CTL }"
512
512
  @ctl_info[ :closing ] = true
513
513
  next_tick
514
514
  end
@@ -563,7 +563,7 @@ module Girl
563
563
  if !dst.closed? then
564
564
  dst_info = @dst_infos[ dst ]
565
565
 
566
- if dst_info[ :wbuff ].size < RESUME_BELOW then
566
+ if dst_info[ :wbuff ].bytesize < RESUME_BELOW then
567
567
  puts "p#{ Process.pid } #{ Time.new } resume direct src #{ src_info[ :destination_domain ] }"
568
568
  add_resume_src( src )
569
569
  end
@@ -574,7 +574,7 @@ module Girl
574
574
  if atun && !atun.closed? then
575
575
  atun_info = @atun_infos[ atun ]
576
576
 
577
- if atun_info[ :wbuff ].size < RESUME_BELOW then
577
+ if atun_info[ :wbuff ].bytesize < RESUME_BELOW then
578
578
  puts "p#{ Process.pid } #{ Time.new } resume tunnel src #{ src_info[ :destination_domain ] }"
579
579
  add_resume_src( src )
580
580
  end
@@ -589,7 +589,7 @@ module Girl
589
589
  if src && !src.closed? then
590
590
  src_info = @src_infos[ src ]
591
591
 
592
- if src_info[ :wbuff ].size < RESUME_BELOW then
592
+ if src_info[ :wbuff ].bytesize < RESUME_BELOW then
593
593
  puts "p#{ Process.pid } #{ Time.new } resume dst #{ dst_info[ :domain ] }"
594
594
  add_resume_dst( dst )
595
595
  end
@@ -603,7 +603,7 @@ module Girl
603
603
  if src && !src.closed? then
604
604
  src_info = @src_infos[ src ]
605
605
 
606
- if src_info[ :wbuff ].size < RESUME_BELOW then
606
+ if src_info[ :wbuff ].bytesize < RESUME_BELOW then
607
607
  puts "p#{ Process.pid } #{ Time.new } resume btun #{ btun_info[ :domain ] }"
608
608
  add_resume_btun( btun )
609
609
  end
@@ -647,13 +647,14 @@ module Girl
647
647
  domain = src_info[ :destination_domain ]
648
648
  destination_addr = Socket.sockaddr_in( src_info[ :destination_port ], ip_info.ip_address )
649
649
  dst = Socket.new( ip_info.ipv4? ? Socket::AF_INET : Socket::AF_INET6, Socket::SOCK_STREAM, 0 )
650
+ dst.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1 )
650
651
 
651
652
  begin
652
653
  dst.connect_nonblock( destination_addr )
653
654
  rescue IO::WaitWritable
654
655
  # connect nonblock 必抛 wait writable
655
656
  rescue Exception => e
656
- puts "p#{ Process.pid } #{ Time.new } dst connect destination #{ domain } #{ src_info[ :destination_port ] } #{ ip_info.ip_address } #{ e.class }, close src"
657
+ puts "p#{ Process.pid } #{ Time.new } dst connect destination #{ domain } #{ src_info[ :destination_port ] } #{ ip_info.ip_address } #{ e.class }"
657
658
  dst.close
658
659
  add_closing_src( src )
659
660
  return
@@ -721,6 +722,7 @@ module Girl
721
722
  #
722
723
  def new_a_redir( redir_port )
723
724
  redir = Socket.new( Socket::AF_INET, Socket::SOCK_STREAM, 0 )
725
+ redir.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1 )
724
726
  redir.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEADDR, 1 )
725
727
 
726
728
  if RUBY_PLATFORM.include?( 'linux' ) then
@@ -747,23 +749,25 @@ module Girl
747
749
 
748
750
  # puts "debug new atun and btun"
749
751
  atun = Socket.new( Socket::AF_INET, Socket::SOCK_STREAM, 0 )
752
+ atun.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1 )
750
753
 
751
754
  begin
752
755
  atun.connect_nonblock( @ctl_info[ :atund_addr ] )
753
756
  rescue IO::WaitWritable
754
757
  rescue Exception => e
755
- puts "p#{ Process.pid } #{ Time.new } connect atund #{ e.class }, close atun"
758
+ puts "p#{ Process.pid } #{ Time.new } connect atund #{ e.class }"
756
759
  atun.close
757
760
  return
758
761
  end
759
762
 
760
763
  btun = Socket.new( Socket::AF_INET, Socket::SOCK_STREAM, 0 )
764
+ btun.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1 )
761
765
 
762
766
  begin
763
767
  btun.connect_nonblock( @ctl_info[ :btund_addr ] )
764
768
  rescue IO::WaitWritable
765
769
  rescue Exception => e
766
- puts "p#{ Process.pid } #{ Time.new } connect btund #{ e.class }, close btun"
770
+ puts "p#{ Process.pid } #{ Time.new } connect btund #{ e.class }"
767
771
  btun.close
768
772
  return
769
773
  end
@@ -1047,7 +1051,7 @@ module Girl
1047
1051
 
1048
1052
  case ctl_num
1049
1053
  when TUND_PORT then
1050
- return if @ctl_info[ :atund_addr ] || data.size != 5
1054
+ return if @ctl_info[ :atund_addr ] || data.bytesize != 5
1051
1055
  atund_port, btund_port = data[ 1, 4 ].unpack( 'nn' )
1052
1056
  puts "p#{ Process.pid } #{ Time.new } got tund port #{ atund_port } #{ btund_port }"
1053
1057
  @ctl_info[ :resends ].delete( [ HELLO ].pack( 'C' ) )
@@ -1061,14 +1065,14 @@ module Girl
1061
1065
  @pending_srcs.clear
1062
1066
  end
1063
1067
  when PAIRED then
1064
- return if data.size != 11
1068
+ return if data.bytesize != 11
1065
1069
  src_id, dst_id = data[ 1, 10 ].unpack( 'Q>n' )
1066
1070
  # puts "debug got paired #{ src_id } #{ dst_id }"
1067
1071
  @ctl_info[ :resends ].delete( [ A_NEW_SOURCE, src_id ].pack( 'CQ>' ) )
1068
1072
  @ctl_info[ :last_recv_at ] = Time.new
1069
1073
  new_tuns( src_id, dst_id )
1070
1074
  when UNKNOWN_CTL_ADDR then
1071
- puts "p#{ Process.pid } #{ Time.new } got unknown ctl addr, close ctl"
1075
+ puts "p#{ Process.pid } #{ Time.new } got unknown ctl addr"
1072
1076
  close_ctl( ctl )
1073
1077
  end
1074
1078
  end
@@ -306,6 +306,7 @@ module Girl
306
306
  #
307
307
  def deal_with_destination_addr( ctl_addr, src_id, destination_addr, domain_port )
308
308
  dst = Socket.new( Addrinfo.new( destination_addr ).ipv4? ? Socket::AF_INET : Socket::AF_INET6, Socket::SOCK_STREAM, 0 )
309
+ dst.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1 )
309
310
 
310
311
  begin
311
312
  dst.connect_nonblock( destination_addr )
@@ -444,7 +445,7 @@ module Girl
444
445
  if btun && !btun.closed? then
445
446
  btun_info = @btun_infos[ btun ]
446
447
 
447
- if btun_info[ :wbuff ].size < RESUME_BELOW then
448
+ if btun_info[ :wbuff ].bytesize < RESUME_BELOW then
448
449
  puts "p#{ Process.pid } #{ Time.new } resume dst #{ dst_info[ :domain_port ] }"
449
450
  add_resume_dst( dst )
450
451
  end
@@ -458,7 +459,7 @@ module Girl
458
459
  if dst && !dst.closed? then
459
460
  dst_info = @dst_infos[ dst ]
460
461
 
461
- if dst_info[ :wbuff ].size < RESUME_BELOW then
462
+ if dst_info[ :wbuff ].bytesize < RESUME_BELOW then
462
463
  puts "p#{ Process.pid } #{ Time.new } resume atun #{ atun_info[ :domain_port ] }"
463
464
  add_resume_atun( atun )
464
465
  end
@@ -515,6 +516,7 @@ module Girl
515
516
  #
516
517
  def new_a_tund
517
518
  tund = Socket.new( Socket::AF_INET, Socket::SOCK_STREAM, 0 )
519
+ tund.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1 )
518
520
  tund.bind( Socket.sockaddr_in( 0, '0.0.0.0' ) )
519
521
  tund.listen( 127 )
520
522
  tund
@@ -663,7 +665,7 @@ module Girl
663
665
  if ctl_info then
664
666
  atund_port, btund_port = ctl_info[ :atund_port ], ctl_info[ :btund_port ]
665
667
  else
666
- return if data.size <= 1
668
+ return if data.bytesize <= 1
667
669
  im = data[ 1..-1 ]
668
670
  result = @custom.check( im, addrinfo )
669
671
 
@@ -717,7 +719,7 @@ module Girl
717
719
  return
718
720
  end
719
721
 
720
- return if data.size <= 9
722
+ return if data.bytesize <= 9
721
723
  src_id = data[ 1, 8 ].unpack( 'Q>' ).first
722
724
  dst_id = ctl_info[ :dst_ids ][ src_id ]
723
725
 
@@ -520,8 +520,8 @@ module Girl
520
520
  if @ctl && !@ctl.closed? then
521
521
  last_recv_at = @ctl_info[ :last_recv_at ] || @ctl_info[ :created_at ]
522
522
 
523
- if now - last_recv_at >= EXPIRE_AFTER then
524
- puts "p#{ Process.pid } #{ Time.new } expire ctl"
523
+ if now - last_recv_at >= EXPIRE_CTL then
524
+ puts "p#{ Process.pid } #{ Time.new } expire ctl #{ EXPIRE_CTL }"
525
525
  @ctl_info[ :closing ] = true
526
526
  next_tick
527
527
  end
@@ -583,7 +583,7 @@ module Girl
583
583
  if !dst.closed? then
584
584
  dst_info = @dst_infos[ dst ]
585
585
 
586
- if dst_info[ :wbuff ].size < RESUME_BELOW then
586
+ if dst_info[ :wbuff ].bytesize < RESUME_BELOW then
587
587
  puts "p#{ Process.pid } #{ Time.new } resume direct src #{ src_info[ :destination_domain ] }"
588
588
  add_resume_src( src )
589
589
  end
@@ -594,7 +594,7 @@ module Girl
594
594
  if atun && !atun.closed? then
595
595
  atun_info = @atun_infos[ atun ]
596
596
 
597
- if atun_info[ :wbuff ].size < RESUME_BELOW then
597
+ if atun_info[ :wbuff ].bytesize < RESUME_BELOW then
598
598
  puts "p#{ Process.pid } #{ Time.new } resume tunnel src #{ src_info[ :destination_domain ] }"
599
599
  add_resume_src( src )
600
600
  end
@@ -609,7 +609,7 @@ module Girl
609
609
  if src && !src.closed? then
610
610
  src_info = @src_infos[ src ]
611
611
 
612
- if src_info[ :wbuff ].size < RESUME_BELOW then
612
+ if src_info[ :wbuff ].bytesize < RESUME_BELOW then
613
613
  puts "p#{ Process.pid } #{ Time.new } resume dst #{ dst_info[ :domain ] }"
614
614
  add_resume_dst( dst )
615
615
  end
@@ -623,7 +623,7 @@ module Girl
623
623
  if src && !src.closed? then
624
624
  src_info = @src_infos[ src ]
625
625
 
626
- if src_info[ :wbuff ].size < RESUME_BELOW then
626
+ if src_info[ :wbuff ].bytesize < RESUME_BELOW then
627
627
  puts "p#{ Process.pid } #{ Time.new } resume btun #{ btun_info[ :domain ] }"
628
628
  add_resume_btun( btun )
629
629
  end
@@ -667,14 +667,14 @@ module Girl
667
667
  domain = src_info[ :destination_domain ]
668
668
  destination_addr = Socket.sockaddr_in( src_info[ :destination_port ], ip_info.ip_address )
669
669
  dst = Socket.new( ip_info.ipv4? ? Socket::AF_INET : Socket::AF_INET6, Socket::SOCK_STREAM, 0 )
670
- dst.setsockopt( Socket::SOL_TCP, Socket::TCP_NODELAY, 1 )
670
+ dst.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1 )
671
671
 
672
672
  begin
673
673
  dst.connect_nonblock( destination_addr )
674
674
  rescue IO::WaitWritable
675
675
  # connect nonblock 必抛 wait writable
676
676
  rescue Exception => e
677
- puts "p#{ Process.pid } #{ Time.new } dst connect destination #{ domain } #{ src_info[ :destination_port ] } #{ ip_info.ip_address } #{ e.class }, close src"
677
+ puts "p#{ Process.pid } #{ Time.new } dst connect destination #{ domain } #{ src_info[ :destination_port ] } #{ ip_info.ip_address } #{ e.class }"
678
678
  dst.close
679
679
  add_closing_src( src )
680
680
  return
@@ -735,6 +735,7 @@ module Girl
735
735
  #
736
736
  def new_a_redir( redir_port )
737
737
  redir = Socket.new( Socket::AF_INET, Socket::SOCK_STREAM, 0 )
738
+ redir.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1 )
738
739
  redir.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEADDR, 1 )
739
740
  redir.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEPORT, 1 )
740
741
  redir.bind( Socket.sockaddr_in( redir_port, '0.0.0.0' ) )
@@ -773,7 +774,7 @@ module Girl
773
774
  to_addr = @nameserver_addr
774
775
  end
775
776
 
776
- puts "p#{ Process.pid } #{ Time.new } new a rsv to #{ Addrinfo.new( to_addr ).inspect }"
777
+ # puts "debug new a rsv to #{ Addrinfo.new( to_addr ).inspect }"
777
778
 
778
779
  @rsv_infos[ rsv ] = {
779
780
  src_addr: src_addr,
@@ -795,23 +796,25 @@ module Girl
795
796
 
796
797
  # puts "debug new atun and btun"
797
798
  atun = Socket.new( Socket::AF_INET, Socket::SOCK_STREAM, 0 )
799
+ atun.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1 )
798
800
 
799
801
  begin
800
802
  atun.connect_nonblock( @ctl_info[ :atund_addr ] )
801
803
  rescue IO::WaitWritable
802
804
  rescue Exception => e
803
- puts "p#{ Process.pid } #{ Time.new } connect atund #{ e.class }, close atun"
805
+ puts "p#{ Process.pid } #{ Time.new } connect atund #{ e.class }"
804
806
  atun.close
805
807
  return
806
808
  end
807
809
 
808
810
  btun = Socket.new( Socket::AF_INET, Socket::SOCK_STREAM, 0 )
811
+ btun.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1 )
809
812
 
810
813
  begin
811
814
  btun.connect_nonblock( @ctl_info[ :btund_addr ] )
812
815
  rescue IO::WaitWritable
813
816
  rescue Exception => e
814
- puts "p#{ Process.pid } #{ Time.new } connect btund #{ e.class }, close btun"
817
+ puts "p#{ Process.pid } #{ Time.new } connect btund #{ e.class }"
815
818
  btun.close
816
819
  return
817
820
  end
@@ -1095,7 +1098,7 @@ module Girl
1095
1098
 
1096
1099
  case ctl_num
1097
1100
  when TUND_PORT then
1098
- return if @ctl_info[ :atund_addr ] || data.size != 5
1101
+ return if @ctl_info[ :atund_addr ] || data.bytesize != 5
1099
1102
  atund_port, btund_port = data[ 1, 4 ].unpack( 'nn' )
1100
1103
  puts "p#{ Process.pid } #{ Time.new } got tund port #{ atund_port } #{ btund_port }"
1101
1104
  @ctl_info[ :resends ].delete( [ HELLO ].pack( 'C' ) )
@@ -1109,14 +1112,14 @@ module Girl
1109
1112
  @pending_srcs.clear
1110
1113
  end
1111
1114
  when PAIRED then
1112
- return if data.size != 11
1115
+ return if data.bytesize != 11
1113
1116
  src_id, dst_id = data[ 1, 10 ].unpack( 'Q>n' )
1114
1117
  # puts "debug got paired #{ src_id } #{ dst_id }"
1115
1118
  @ctl_info[ :resends ].delete( [ A_NEW_SOURCE, src_id ].pack( 'CQ>' ) )
1116
1119
  @ctl_info[ :last_recv_at ] = Time.new
1117
1120
  new_tuns( src_id, dst_id )
1118
1121
  when UNKNOWN_CTL_ADDR then
1119
- puts "p#{ Process.pid } #{ Time.new } got unknown ctl addr, close ctl"
1122
+ puts "p#{ Process.pid } #{ Time.new } got unknown ctl addr"
1120
1123
  close_ctl( ctl )
1121
1124
  end
1122
1125
  end
@@ -244,7 +244,7 @@ module Girl
244
244
  redir.close
245
245
  @roles.delete( redir )
246
246
  @reads.delete( redir )
247
- @src_infos.each { | src, _ | close_src( src ) }
247
+ @src_infos.keys.each { | src | close_src( src ) }
248
248
  end
249
249
 
250
250
  ##
@@ -340,9 +340,21 @@ module Girl
340
340
  @src_infos.each do | src, src_info |
341
341
  last_recv_at = src_info[ :last_recv_at ] || src_info[ :created_at ]
342
342
  last_sent_at = src_info[ :last_sent_at ] || src_info[ :created_at ]
343
- expire_after = src_info[ :dst ] ? EXPIRE_AFTER : EXPIRE_NEW
344
343
 
345
- if ( now - last_recv_at >= expire_after ) && ( now - last_sent_at >= expire_after ) then
344
+ if src_info[ :dst ] then
345
+ if src_info[ :dst_connected ] then
346
+ expire_after = EXPIRE_AFTER
347
+ is_expire = ( now - last_recv_at >= expire_after ) && ( now - last_sent_at >= expire_after )
348
+ else
349
+ expire_after = EXPIRE_CONNECTING
350
+ is_expire = ( now - src_info[ :dst_created_at ] >= expire_after )
351
+ end
352
+ else
353
+ expire_after = EXPIRE_NEW
354
+ is_expire = ( now - last_recv_at >= expire_after ) && ( now - last_sent_at >= expire_after )
355
+ end
356
+
357
+ if is_expire then
346
358
  puts "p#{ Process.pid } #{ Time.new } expire src #{ expire_after } #{ src_info[ :id ] } #{ src_info[ :destination_domain ] }"
347
359
  add_closing_src( src )
348
360
 
@@ -370,7 +382,7 @@ module Girl
370
382
  if dst && !dst.closed? then
371
383
  dst_info = @dst_infos[ dst ]
372
384
 
373
- if dst_info[ :wbuff ].size < RESUME_BELOW then
385
+ if dst_info[ :wbuff ].bytesize < RESUME_BELOW then
374
386
  puts "p#{ Process.pid } #{ Time.new } resume direct src #{ src_info[ :destination_domain ] }"
375
387
  add_resume_src( src )
376
388
  end
@@ -384,7 +396,7 @@ module Girl
384
396
  if src && !src.closed? then
385
397
  src_info = @src_infos[ src ]
386
398
 
387
- if src_info[ :wbuff ].size < RESUME_BELOW then
399
+ if src_info[ :wbuff ].bytesize < RESUME_BELOW then
388
400
  puts "p#{ Process.pid } #{ Time.new } resume dst #{ dst_info[ :domain ] }"
389
401
  add_resume_dst( dst )
390
402
  end
@@ -403,13 +415,14 @@ module Girl
403
415
  domain = src_info[ :destination_domain ]
404
416
  destination_addr = Socket.sockaddr_in( src_info[ :destination_port ], ip_info.ip_address )
405
417
  dst = Socket.new( ip_info.ipv4? ? Socket::AF_INET : Socket::AF_INET6, Socket::SOCK_STREAM, 0 )
418
+ dst.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1 )
406
419
 
407
420
  begin
408
421
  dst.connect_nonblock( destination_addr )
409
422
  rescue IO::WaitWritable
410
423
  # connect nonblock 必抛 wait writable
411
424
  rescue Exception => e
412
- puts "p#{ Process.pid } #{ Time.new } dst connect destination #{ domain } #{ src_info[ :destination_port ] } #{ ip_info.ip_address } #{ e.class }, close src"
425
+ puts "p#{ Process.pid } #{ Time.new } dst connect destination #{ domain } #{ src_info[ :destination_port ] } #{ ip_info.ip_address } #{ e.class }"
413
426
  dst.close
414
427
  add_closing_src( src )
415
428
  return
@@ -424,10 +437,12 @@ module Girl
424
437
  }
425
438
 
426
439
  @dst_infos[ dst ] = dst_info
427
- add_read( dst, :dst )
428
440
  src_info[ :proxy_type ] = :direct
429
441
  src_info[ :dst ] = dst
442
+ src_info[ :dst_created_at ] = Time.new
430
443
  add_socks5_conn_reply( src )
444
+ add_read( dst, :dst )
445
+ add_write( dst )
431
446
  end
432
447
 
433
448
  ##
@@ -435,6 +450,7 @@ module Girl
435
450
  #
436
451
  def new_a_redir
437
452
  pre = Socket.new( Socket::AF_INET, Socket::SOCK_STREAM, 0 )
453
+ pre.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1 )
438
454
  pre.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEADDR, 1 )
439
455
  pre.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEPORT, 1 )
440
456
  pre.bind( Socket.sockaddr_in( @redir_port, '0.0.0.0' ) )
@@ -599,6 +615,8 @@ module Girl
599
615
  is_connect: true, # 代理协议是http的场合,是否是CONNECT
600
616
  rbuff: '', # 读到的流量
601
617
  dst: nil, # 对应的dst
618
+ dst_created_at: nil, # 对应的dst的创建时间
619
+ dst_connected: false, # 对应的dst是否已连接
602
620
  wbuff: '', # 从dst读到的流量
603
621
  created_at: Time.new, # 创建时间
604
622
  last_recv_at: nil, # 上一次收到新流量(由dst收到)的时间
@@ -812,6 +830,12 @@ module Girl
812
830
 
813
831
  dst_info = @dst_infos[ dst ]
814
832
  src = dst_info[ :src ]
833
+ src_info = @src_infos[ src ]
834
+
835
+ unless src.closed? then
836
+ src_info[ :dst_connected ] = true
837
+ end
838
+
815
839
  data = dst_info[ :wbuff ]
816
840
 
817
841
  # 写前为空,处理关闭写
@@ -842,7 +866,6 @@ module Girl
842
866
  dst_info[ :wbuff ] = data
843
867
 
844
868
  unless src.closed? then
845
- src_info = @src_infos[ src ]
846
869
  src_info[ :last_sent_at ] = Time.new
847
870
  end
848
871
  end
data/lib/girl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Girl
2
- VERSION = '4.5.0'.freeze
2
+ VERSION = '4.6.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.5.0
4
+ version: 4.6.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-15 00:00:00.000000000 Z
11
+ date: 2021-04-20 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.1.4
58
+ rubygems_version: 3.2.3
59
59
  signing_key:
60
60
  specification_version: 4
61
61
  summary: 妹子