girl 0.90.0 → 0.91.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: 2e1916068595360e4ab83189c93759e2c6ed05979d4a4128ff83f95390e91dce
4
- data.tar.gz: 9f39d67731002186f66f04e4bb463834980a243fc0d6322b5e35f749fa356f95
3
+ metadata.gz: 2314c2bce1ab734d24fa40a8709c61af56cb35558652a4d25ba958c71b3a3bf3
4
+ data.tar.gz: 964ca3642b80f790b444d55db3869109fbb1c746953d2b7777d87f8eb0e17ad0
5
5
  SHA512:
6
- metadata.gz: 18e61543e05ae79c31ee76a8504cfcfef1271aa1419430ae667b46c8291dcc790630aa1123bc662ce817117a26b68ac343f5c7679134a3205548f32ba28cfb31
7
- data.tar.gz: 797fa163ab50c3ace753ac833381bdeb040876c12de7d2b5570dbe0f3a799a91b18fa220ca5ea4ecbc8cfad69aabbd1dd245ad1bcd404b92423020890f5d38d1
6
+ metadata.gz: db5de1552c3841bf2f34c47c58e0f2c9789a6ed4101e3733654b1da9c557fccd97af0fb2f5c83212c3aa06ffc34630d7ab9e7798a0ebc41c6e41d32c0d742977
7
+ data.tar.gz: 3ea63129204abcadec92f7d77c7fa7222f700a819a9602c0a03e93134fbb86d3716a24dfbe387bb3e4e2b400fcb80af4c3cd92693ecec07b047c95d402a92ac2
@@ -1,6 +1,6 @@
1
1
  module Girl
2
2
  READ_SIZE = 1024 * 1024 # 一次读多少
3
- WBUFF_LIMIT = 100 * 1024 * 1024 # 写前上限,超过上限暂停读src/dst
3
+ WBUFF_LIMIT = 100 * 1024 * 1024 # 写前上限,超过上限暂停读
4
4
  RESUME_BELOW = WBUFF_LIMIT / 2 # 降到多少以下恢复读
5
5
  SEND_HELLO_COUNT = 10 # hello最多发几次
6
6
  EXPIRE_AFTER = 300 # 多久没有新流量,过期
@@ -124,8 +124,28 @@ module Girl
124
124
  return if src.closed?
125
125
  src_info = @src_infos[ src ]
126
126
  src_info[ :wbuff ] << data
127
- add_write( src )
128
127
  src_info[ :last_recv_at ] = Time.new
128
+ add_write( src )
129
+
130
+ if src_info[ :wbuff ].bytesize >= WBUFF_LIMIT then
131
+ dst = src_info[ :dst ]
132
+
133
+ if dst then
134
+ dst_info = @dst_infos[ dst ]
135
+ puts "p#{ Process.pid } #{ Time.new } pause dst #{ dst_info[ :domain ] }"
136
+ dst_info[ :paused ] = true
137
+ @reads.delete( dst )
138
+ else
139
+ stream = src_info[ :stream ]
140
+
141
+ if stream then
142
+ stream_info = @stream_infos[ stream ]
143
+ puts "p#{ Process.pid } #{ Time.new } pause stream #{ stream_info[ :domain ] }"
144
+ stream_info[ :paused ] = true
145
+ @reads.delete( stream )
146
+ end
147
+ end
148
+ end
129
149
  end
130
150
 
131
151
  ##
@@ -414,6 +434,30 @@ module Girl
414
434
  end
415
435
  end
416
436
 
437
+ @dst_infos.select{ | _, dst_info | dst_info[ :paused ] }.each do | dst, dst_info |
438
+ src = dst_info[ :src ]
439
+ src_info = @src_infos[ src ]
440
+
441
+ if src_info[ :wbuff ].size < RESUME_BELOW then
442
+ puts "p#{ Process.pid } #{ Time.new } src.wbuff below #{ RESUME_BELOW }, resume dst #{ dst_info[ :domain ] }"
443
+ dst_info[ :paused ] = false
444
+ add_read( dst )
445
+ trigger = true
446
+ end
447
+ end
448
+
449
+ @stream_infos.select{ | _, stream_info | stream_info[ :paused ] }.each do | stream, stream_info |
450
+ src = stream_info[ :src ]
451
+ src_info = @src_infos[ src ]
452
+
453
+ if src_info[ :wbuff ].size < RESUME_BELOW then
454
+ puts "p#{ Process.pid } #{ Time.new } src.wbuff below #{ RESUME_BELOW }, resume stream #{ stream_info[ :domain ] }"
455
+ stream_info[ :paused ] = false
456
+ add_read( stream )
457
+ trigger = true
458
+ end
459
+ end
460
+
417
461
  next_tick if trigger
418
462
  end
419
463
  end
@@ -469,7 +513,7 @@ module Girl
469
513
  rescue IO::WaitWritable
470
514
  # connect nonblock 必抛 wait writable
471
515
  rescue Exception => e
472
- puts "p#{ Process.pid } #{ Time.new } dst connect destination #{ e.class }, close src"
516
+ puts "p#{ Process.pid } #{ Time.new } dst connect destination #{ domain } #{ src_info[ :destination_port ] } #{ ip_info.ip_address } #{ e.class }, close src"
473
517
  set_src_closing( src )
474
518
  return
475
519
  end
@@ -479,8 +523,9 @@ module Girl
479
523
  dst_info = {
480
524
  local_port: local_port, # 本地端口
481
525
  src: src, # 对应src
482
- domain: domain, # 域名
526
+ domain: domain, # 目的地
483
527
  wbuff: '', # 写前,从src读到的流量
528
+ paused: false, # 是否已暂停读
484
529
  closing: false, # 准备关闭
485
530
  closing_read: false, # 准备关闭读
486
531
  closing_write: false # 准备关闭写
@@ -540,9 +585,12 @@ module Girl
540
585
  data << @custom.encode( src_info[ :rbuff ] )
541
586
  end
542
587
 
588
+ domain = src_info[ :destination_domain ]
543
589
  @stream_infos[ stream ] = {
544
- src: src, # 对应src
545
- wbuff: data # 写前,写往远端streamd
590
+ src: src, # 对应src
591
+ domain: domain, # 目的地
592
+ wbuff: data, # 写前,写往远端streamd
593
+ paused: false # 是否已暂停读
546
594
  }
547
595
 
548
596
  src_info[ :dst_id ] = dst_id
@@ -842,7 +890,7 @@ module Girl
842
890
  created_at: Time.new, # 创建时间
843
891
  last_recv_at: nil, # 上一次收到新流量(由dst收到,或者由stream收到)的时间
844
892
  last_sent_at: nil, # 上一次发出流量(由dst发出,或者由stream发出)的时间
845
- paused: false, # 是否已暂停
893
+ paused: false, # 是否已暂停读
846
894
  closing: false, # 准备关闭
847
895
  closing_read: false, # 准备关闭读
848
896
  closing_write: false # 准备关闭写
@@ -863,10 +911,10 @@ module Girl
863
911
  end
864
912
 
865
913
  from_addr = addrinfo.to_sockaddr
866
- @tun_info[ :last_recv_at ] = Time.new
867
914
  pack_id = data[ 0, 8 ].unpack( 'Q>' ).first
868
915
  return if pack_id != 0
869
916
 
917
+ @tun_info[ :last_recv_at ] = Time.new
870
918
  ctl_num = data[ 8 ].unpack( 'C' ).first
871
919
 
872
920
  case ctl_num
@@ -1065,7 +1113,7 @@ module Girl
1065
1113
  add_write( stream )
1066
1114
 
1067
1115
  if stream_info[ :wbuff ].bytesize >= WBUFF_LIMIT then
1068
- puts "p#{ Process.pid } #{ Time.new } pause tunnel src #{ src_info[ :id ] } #{ src_info[ :destination_domain ] }"
1116
+ puts "p#{ Process.pid } #{ Time.new } pause tunnel src #{ src_info[ :destination_domain ] }"
1069
1117
  src_info[ :paused ] = true
1070
1118
  @reads.delete( src )
1071
1119
  end
@@ -1094,7 +1142,7 @@ module Girl
1094
1142
  add_write( dst )
1095
1143
 
1096
1144
  if dst_info[ :wbuff ].bytesize >= WBUFF_LIMIT then
1097
- puts "p#{ Process.pid } #{ Time.new } pause direct src #{ src_info[ :id ] } #{ src_info[ :destination_domain ] }"
1145
+ puts "p#{ Process.pid } #{ Time.new } pause direct src #{ src_info[ :destination_domain ] }"
1098
1146
  src_info[ :paused ] = true
1099
1147
  @reads.delete( src )
1100
1148
  end
@@ -265,7 +265,7 @@ module Girl
265
265
  dst.connect_nonblock( destination_addr )
266
266
  rescue IO::WaitWritable
267
267
  rescue Exception => e
268
- puts "p#{ Process.pid } #{ Time.new } connect destination #{ e.class }"
268
+ puts "p#{ Process.pid } #{ Time.new } connect destination #{ domain_port } #{ e.class }"
269
269
  return false
270
270
  end
271
271
 
@@ -274,7 +274,7 @@ module Girl
274
274
  @dst_infos[ dst ] = {
275
275
  id: dst_id, # id
276
276
  tund: tund, # 对应tund
277
- domain_port: domain_port, # 域名和端口
277
+ domain_port: domain_port, # 目的地和端口
278
278
  rbuff: '', # 对应的streamd没准备好,暂存读到的流量
279
279
  streamd: nil, # 对应的streamd
280
280
  wbuff: '', # 从streamd读到的流量
@@ -282,7 +282,7 @@ module Girl
282
282
  created_at: Time.new, # 创建时间
283
283
  last_recv_at: nil, # 上一次收到新流量(由streamd收到)的时间
284
284
  last_sent_at: nil, # 上一次发出流量(由streamd发出)的时间
285
- paused: false, # 是否已暂停
285
+ paused: false, # 是否已暂停读
286
286
  closing: false, # 准备关闭
287
287
  closing_read: false, # 准备关闭读
288
288
  closing_write: false # 准备关闭写
@@ -379,6 +379,18 @@ module Girl
379
379
  end
380
380
  end
381
381
 
382
+ @streamd_infos.select{ | _, streamd_info | streamd_info[ :paused ] }.each do | streamd, streamd_info |
383
+ dst = streamd_info[ :dst ]
384
+ dst_info = @dst_infos[ dst ]
385
+
386
+ if dst_info[ :wbuff ].size < RESUME_BELOW then
387
+ puts "p#{ Process.pid } #{ Time.new } resume streamd #{ streamd_info[ :domain_port ] }"
388
+ streamd_info[ :paused ] = false
389
+ add_read( streamd )
390
+ trigger = true
391
+ end
392
+ end
393
+
382
394
  next_tick if trigger
383
395
  end
384
396
  end
@@ -616,10 +628,10 @@ module Girl
616
628
  return
617
629
  end
618
630
 
619
- tund_info[ :last_recv_at ] = Time.new
620
631
  pack_id = data[ 0, 8 ].unpack( 'Q>' ).first
621
632
  return if pack_id != 0
622
633
 
634
+ tund_info[ :last_recv_at ] = Time.new
623
635
  ctl_num = data[ 8 ].unpack( 'C' ).first
624
636
 
625
637
  case ctl_num
@@ -667,9 +679,11 @@ module Girl
667
679
  tund = tcpd_info[ :tund ]
668
680
 
669
681
  @streamd_infos[ streamd ] = {
670
- tund: tund, # 对应tund
671
- dst: nil, # 对应dst
672
- wbuff: '' # 写前,写往近端stream
682
+ tund: tund, # 对应tund
683
+ dst: nil, # 对应dst
684
+ domain_port: nil, # dst的目的地和端口
685
+ wbuff: '', # 写前,写往近端stream
686
+ paused: false # 是否已暂停读
673
687
  }
674
688
 
675
689
  add_read( streamd, :streamd )
@@ -704,7 +718,7 @@ module Girl
704
718
  add_write( streamd )
705
719
 
706
720
  if streamd_info[ :wbuff ].bytesize >= WBUFF_LIMIT then
707
- puts "p#{ Process.pid } #{ Time.new } pause dst #{ dst_info[ :id ] } #{ dst_info[ :domain_port ] }"
721
+ puts "p#{ Process.pid } #{ Time.new } pause dst #{ dst_info[ :domain_port ] }"
708
722
  dst_info[ :paused ] = true
709
723
  @reads.delete( dst )
710
724
  end
@@ -759,6 +773,7 @@ module Girl
759
773
  # puts "debug1 set streamd.dst #{ dst_id }"
760
774
  streamd_info[ :dst ] = dst
761
775
  dst_info = @dst_infos[ dst ]
776
+ streamd_info[ :domain_port ] = dst_info[ :domain_port ]
762
777
 
763
778
  unless dst_info[ :rbuff ].empty? then
764
779
  # puts "debug1 encode and move dst.rbuff to streamd.wbuff"
@@ -778,6 +793,12 @@ module Girl
778
793
  dst_info[ :wbuff ] << data
779
794
  dst_info[ :last_recv_at ] = Time.new
780
795
  add_write( dst )
796
+
797
+ if dst_info[ :wbuff ].bytesize >= WBUFF_LIMIT then
798
+ puts "p#{ Process.pid } #{ Time.new } pause streamd #{ streamd_info[ :domain_port ] }"
799
+ streamd_info[ :paused ] = true
800
+ @reads.delete( streamd )
801
+ end
781
802
  end
782
803
  end
783
804
 
@@ -1,3 +1,3 @@
1
1
  module Girl
2
- VERSION = '0.90.0'.freeze
2
+ VERSION = '0.91.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: girl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.90.0
4
+ version: 0.91.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - takafan