girl 4.6.0 → 4.7.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: 8d3b294765df9759f671cd5916a4315aa5872a85e42ea9739d8e2bd409f55f49
4
- data.tar.gz: 8405a9e93e8c038e757c3a191c40c3801ff34e9ce593be0b0187ee728cb70fa7
3
+ metadata.gz: e06e25ddc6594959cceb39bd5d4ad420941dfaeec6866a86d7817e974cf9bc2f
4
+ data.tar.gz: 6d8016cd3a42b0cf611bad16759e34f130f193bb9e68a88f5f8b80597bd62dc9
5
5
  SHA512:
6
- metadata.gz: 8b09b4c9b12257b9fc8672eace67cd89bfac89b5032ffb6ccf2a6810342a3c09e45ba0b6658b86cafd7d671fdeaf0235de794a3f0b356c2835a3c5248de9743b
7
- data.tar.gz: 5e16e91e812c7c53d3fbb47e4c16fc90f7f922a011d4983b6ee955306fd88496b7965e0f02c7ab78b9db80e25a4468c483dffab634d009d1f459d1a16c589a8f
6
+ metadata.gz: d1d49eddf9232d1af3cbf4d9426a257cdaf48003fe9a1b08fdca5b1caaba5497eda97b3092b49191c228868026d70843839ac711b1a70201832901062caeecf8
7
+ data.tar.gz: aa1f7dc236106913f5ea2c061fd5b54c7675da04e0db71fc2d200f1665213c8c33b5ed78a4959111453b19189562d0ba233cbf3cc71e32fb3575e7199050b77f
@@ -7,7 +7,6 @@ module Girl
7
7
  def initialize( redir_port, proxyd_host, proxyd_port, directs, remotes, im )
8
8
  @proxyd_host = proxyd_host
9
9
  @proxyd_port = proxyd_port
10
- @proxyd_addr = Socket.sockaddr_in( proxyd_port, proxyd_host )
11
10
  @directs = directs
12
11
  @remotes = remotes
13
12
  @custom = Girl::ProxyCustom.new( im )
@@ -431,8 +430,7 @@ module Girl
431
430
  return if src.closed?
432
431
  src_info = @src_infos[ src ]
433
432
 
434
- if ( ( @ip_address_list.any? { | addrinfo | addrinfo.ip_address == ip_info.ip_address } ) && ( src_info[ :destination_port ] == @redir_port ) ) \
435
- || ( ( ip_info.ip_address == @proxyd_host ) && ( src_info[ :destination_port ] == @proxyd_port ) ) then
433
+ if ( @ip_address_list.any? { | addrinfo | addrinfo.ip_address == ip_info.ip_address } ) && ( src_info[ :destination_port ] == @redir_port ) then
436
434
  puts "p#{ Process.pid } #{ Time.new } ignore #{ ip_info.ip_address }:#{ src_info[ :destination_port ] }"
437
435
  add_closing_src( src )
438
436
  return
@@ -509,8 +507,7 @@ module Girl
509
507
 
510
508
  if now - last_recv_at >= EXPIRE_CTL then
511
509
  puts "p#{ Process.pid } #{ Time.new } expire ctl #{ EXPIRE_CTL }"
512
- @ctl_info[ :closing ] = true
513
- next_tick
510
+ set_ctl_closing
514
511
  end
515
512
  end
516
513
 
@@ -630,6 +627,7 @@ module Girl
630
627
 
631
628
  if resend >= RESEND_LIMIT then
632
629
  @ctl_info[ :resends ].delete( key )
630
+ set_ctl_closing
633
631
  break
634
632
  end
635
633
 
@@ -702,7 +700,10 @@ module Girl
702
700
  @ctl = ctl
703
701
  add_read( ctl, :ctl )
704
702
 
703
+ ctld_port = @proxyd_port + 5.times.to_a.sample
704
+ ctld_addr = Socket.sockaddr_in( ctld_port, @proxyd_host )
705
705
  @ctl_info = {
706
+ ctld_addr: ctld_addr, # ctld地址
706
707
  resends: ConcurrentHash.new, # key => count
707
708
  atund_addr: nil, # atund地址,src->dst
708
709
  btund_addr: nil, # btund地址,dst->src
@@ -712,7 +713,7 @@ module Girl
712
713
  }
713
714
 
714
715
  hello = @custom.hello
715
- puts "p#{ Process.pid } #{ Time.new } hello i'm #{ hello.inspect }"
716
+ puts "p#{ Process.pid } #{ Time.new } hello i'm #{ hello.inspect } #{ ctld_port }"
716
717
  key = [ HELLO ].pack( 'C' )
717
718
  add_ctlmsg( key, hello )
718
719
  end
@@ -887,7 +888,7 @@ module Girl
887
888
  data = @custom.encode( data )
888
889
 
889
890
  begin
890
- @ctl.sendmsg( data, 0, @proxyd_addr )
891
+ @ctl.sendmsg( data, 0, @ctl_info[ :ctld_addr ] )
891
892
  @ctl_info[ :last_sent_at ] = Time.new
892
893
  rescue Exception => e
893
894
  puts "p#{ Process.pid } #{ Time.new } sendmsg #{ e.class }"
@@ -907,6 +908,15 @@ module Girl
907
908
  add_write( atun )
908
909
  end
909
910
 
911
+ ##
912
+ # set ctl closing
913
+ #
914
+ def set_ctl_closing
915
+ return if @ctl.closed?
916
+ @ctl_info[ :closing ] = true
917
+ next_tick
918
+ end
919
+
910
920
  ##
911
921
  # set dst closing write
912
922
  #
@@ -28,7 +28,7 @@ module Girl
28
28
  dotr, dotw = IO.pipe
29
29
  @dotw = dotw
30
30
  add_read( dotr, :dotr )
31
- new_a_ctld( proxyd_port )
31
+ new_ctlds( proxyd_port )
32
32
  new_a_infod( infod_port )
33
33
  end
34
34
 
@@ -345,7 +345,7 @@ module Girl
345
345
 
346
346
  data = [ PAIRED, src_id, dst_id ].pack( 'CQ>n' )
347
347
  # puts "debug add ctlmsg paired #{ src_id } #{ dst_id }"
348
- send_ctlmsg( data, ctl_addr )
348
+ send_ctlmsg( ctl_info[ :ctld ], data, ctl_addr )
349
349
  end
350
350
 
351
351
  ##
@@ -488,18 +488,6 @@ module Girl
488
488
  end
489
489
  end
490
490
 
491
- ##
492
- # new a ctld
493
- #
494
- def new_a_ctld( proxyd_port )
495
- ctld = Socket.new( Socket::AF_INET, Socket::SOCK_DGRAM, 0 )
496
- ctld.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEPORT, 1 )
497
- ctld.bind( Socket.sockaddr_in( proxyd_port, '0.0.0.0' ) )
498
- puts "p#{ Process.pid } #{ Time.new } ctld bind on #{ proxyd_port }"
499
- add_read( ctld, :ctld )
500
- @ctld = ctld
501
- end
502
-
503
491
  ##
504
492
  # new a infod
505
493
  #
@@ -522,6 +510,20 @@ module Girl
522
510
  tund
523
511
  end
524
512
 
513
+ ##
514
+ # new ctlds
515
+ #
516
+ def new_ctlds( proxyd_port )
517
+ 5.times do | i |
518
+ ctld_port = proxyd_port + i
519
+ ctld = Socket.new( Socket::AF_INET, Socket::SOCK_DGRAM, 0 )
520
+ ctld.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEPORT, 1 )
521
+ ctld.bind( Socket.sockaddr_in( ctld_port, '0.0.0.0' ) )
522
+ puts "p#{ Process.pid } #{ Time.new } ctld bind on #{ ctld_port }"
523
+ add_read( ctld, :ctld )
524
+ end
525
+ end
526
+
525
527
  ##
526
528
  # next tick
527
529
  #
@@ -581,11 +583,11 @@ module Girl
581
583
  ##
582
584
  # send ctlmsg
583
585
  #
584
- def send_ctlmsg( data, to_addr )
586
+ def send_ctlmsg( ctld, data, to_addr )
585
587
  data = @custom.encode( data )
586
588
 
587
589
  begin
588
- @ctld.sendmsg( data, 0, to_addr )
590
+ ctld.sendmsg( data, 0, to_addr )
589
591
  rescue Exception => e
590
592
  puts "p#{ Process.pid } #{ Time.new } sendmsg #{ e.class }"
591
593
  end
@@ -697,6 +699,7 @@ module Girl
697
699
  }
698
700
 
699
701
  @ctl_infos[ ctl_addr ] = {
702
+ ctld: ctld, # 对应的ctld
700
703
  addrinfo: addrinfo, # 地址
701
704
  im: im, # 标识
702
705
  atund: atund, # 对应atund,src->dst
@@ -712,10 +715,10 @@ module Girl
712
715
  end
713
716
 
714
717
  data2 = [ TUND_PORT, atund_port, btund_port ].pack( 'Cnn' )
715
- send_ctlmsg( data2, ctl_addr )
718
+ send_ctlmsg( ctld, data2, ctl_addr )
716
719
  when A_NEW_SOURCE then
717
720
  unless ctl_info then
718
- send_ctlmsg( [ UNKNOWN_CTL_ADDR ].pack( 'C' ), addrinfo )
721
+ send_ctlmsg( ctld, [ UNKNOWN_CTL_ADDR ].pack( 'C' ), addrinfo )
719
722
  return
720
723
  end
721
724
 
@@ -726,7 +729,7 @@ module Girl
726
729
  if dst_id then
727
730
  data2 = [ PAIRED, src_id, dst_id ].pack( 'CQ>n' )
728
731
  # puts "debug dst id exist, send ctlmsg paired #{ src_id } #{ dst_id }"
729
- send_ctlmsg( data2, ctl_addr )
732
+ send_ctlmsg( ctld, data2, ctl_addr )
730
733
  return
731
734
  end
732
735
 
data/lib/girl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Girl
2
- VERSION = '4.6.0'.freeze
2
+ VERSION = '4.7.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.6.0
4
+ version: 4.7.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-20 00:00:00.000000000 Z
11
+ date: 2021-04-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: escape evil.
14
14
  email: