girl 0.97.0 → 0.98.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: 1488058f7502fb83ee815a38ba4b11276a2bd5732bfadf596f5f42fbbb6bae53
4
- data.tar.gz: 1ac6377572a1ff976f4626127e78f76e7c949683b035c2df7426acac70b3ac86
3
+ metadata.gz: a0201dd1519345fc7a831c89a0a8ab139d2fa96d66da2545fcfd1de9102bbe23
4
+ data.tar.gz: e529faf1d41f6d80074eed26519c0fef85a092058dc74a936e17c067ce3a6f1b
5
5
  SHA512:
6
- metadata.gz: 27bc728548949021b2f477ede35b85ff3888ba3371824d32458a390fe9040a10ac0fd11483f25426cda27b95784a2f71b3837fed6b264583ced0378ef6c1b2ee
7
- data.tar.gz: d07a0a982e4ecbaf4c798163027bbdd68c7cd3510280e5f904a079aa6796aa57f5b0c96067c86ee71630409e92eb923050b132974496bfdbfed71154e61e2a60
6
+ metadata.gz: eec9fbcfa84d537bf1c9a301f2974ac5d2b3b3a0b6a4614d071b39c329faf8800e168afa618851a083a3bfc1df0770bb8da7252457394b6f3a1b02778fdae293
7
+ data.tar.gz: 37dc3789f90c73e6116a15cce0b37b1532f6c2b250996e8db0b0b1ad21ffb8d9a7909b6d06218c20574026f3730b134a0383dc348cad12c5ff56fe5897df420a
@@ -13,6 +13,7 @@ module Girl
13
13
  @mutex = Mutex.new
14
14
  @reads = []
15
15
  @writes = []
16
+ @closing_srcs = []
16
17
  @roles = {} # sock => :dotr / :proxy / :src / :dst / :tun / :stream
17
18
  @src_infos = {} # src => {}
18
19
  @dst_infos = {} # dst => {}
@@ -120,7 +121,7 @@ module Girl
120
121
  # add src wbuff
121
122
  #
122
123
  def add_src_wbuff( src, data )
123
- return if src.closed?
124
+ return if src.closed? || @closing_srcs.include?( src )
124
125
  src_info = @src_infos[ src ]
125
126
  src_info[ :wbuff ] << data
126
127
  src_info[ :last_recv_at ] = Time.new
@@ -166,7 +167,7 @@ module Girl
166
167
  # add write
167
168
  #
168
169
  def add_write( sock )
169
- unless @writes.include?( sock ) then
170
+ if !sock.closed? && !@writes.include?( sock ) then
170
171
  @writes << sock
171
172
  end
172
173
  end
@@ -294,7 +295,6 @@ module Girl
294
295
  def close_tun( tun )
295
296
  # puts "debug1 close tun"
296
297
  close_sock( tun )
297
- @tun_info[ :srcs ].each{ | _, src | set_src_closing( src ) }
298
298
  end
299
299
 
300
300
  ##
@@ -314,7 +314,6 @@ module Girl
314
314
  src_info = @src_infos[ src ]
315
315
  end
316
316
 
317
- src_info[ :closed_write ] = true
318
317
  src_info
319
318
  end
320
319
 
@@ -335,7 +334,6 @@ module Girl
335
334
  dst_info = @dst_infos[ dst ]
336
335
  end
337
336
 
338
- dst_info[ :closed_write ] = true
339
337
  dst_info
340
338
  end
341
339
 
@@ -356,7 +354,6 @@ module Girl
356
354
  stream_info = @stream_infos[ stream ]
357
355
  end
358
356
 
359
- stream_info[ :closed_write ] = true
360
357
  stream_info
361
358
  end
362
359
 
@@ -402,7 +399,7 @@ module Girl
402
399
  trigger = false
403
400
  now = Time.new
404
401
 
405
- if @tun && !@tun.closed? then
402
+ if @tun && !@tun.closed? && !@tun_info[ :closing ] then
406
403
  last_recv_at = @tun_info[ :last_recv_at ] || @tun_info[ :created_at ]
407
404
 
408
405
  if @tun_info[ :srcs ].empty? && ( now - last_recv_at >= EXPIRE_AFTER ) then
@@ -512,7 +509,7 @@ module Girl
512
509
 
513
510
  Thread.new do
514
511
  SEND_HELLO_COUNT.times do | i |
515
- if @tun.nil? || @tun.closed? || src.closed? || src_info[ :stream ] then
512
+ if @tun.nil? || @tun.closed? || @tun_info[ :closing ] || src.closed? || src_info[ :stream ] then
516
513
  # puts "debug1 break loop send a new source #{ src_info[ :dst_port ] }"
517
514
  break
518
515
  end
@@ -554,13 +551,11 @@ module Girl
554
551
 
555
552
  # puts "debug1 a new dst #{ dst.local_address.inspect }"
556
553
  dst_info = {
557
- src: src, # 对应src
558
- domain: domain, # 目的地
559
- wbuff: '', # 写前,从src读到的流量
560
- paused: false, # 是否已暂停读
561
- closing: false, # 准备关闭
562
- closing_write: false, # 准备关闭写
563
- closed_write: false # 已关闭写
554
+ src: src, # 对应src
555
+ domain: domain, # 目的地
556
+ wbuff: '', # 写前,从src读到的流量
557
+ paused: false, # 是否已暂停读
558
+ closing_write: false # 准备关闭写
564
559
  }
565
560
 
566
561
  @dst_infos[ dst ] = dst_info
@@ -623,9 +618,7 @@ module Girl
623
618
  domain: domain, # 目的地
624
619
  wbuff: data, # 写前,写往远端streamd
625
620
  paused: false, # 是否已暂停读
626
- closing: false, # 准备关闭
627
- closing_write: false, # 准备关闭写
628
- closed_write: false # 已关闭写
621
+ closing_write: false # 准备关闭写
629
622
  }
630
623
 
631
624
  src_info[ :dst_id ] = dst_id
@@ -689,7 +682,7 @@ module Girl
689
682
 
690
683
  Thread.new do
691
684
  SEND_HELLO_COUNT.times do | i |
692
- if @tun.nil? || @tun.closed? || @tun_info[ :tund_addr ] then
685
+ if @tun.nil? || @tun.closed? || @tun_info[ :closing ] || @tun_info[ :tund_addr ] then
693
686
  # puts "debug1 break loop send hello"
694
687
  break
695
688
  end
@@ -776,22 +769,6 @@ module Girl
776
769
  add_read( src )
777
770
  end
778
771
 
779
- ##
780
- # set dst closing
781
- #
782
- def set_dst_closing( dst )
783
- return if dst.closed?
784
- dst_info = @dst_infos[ dst ]
785
-
786
- if dst_info[ :closed_write ] then
787
- close_dst( dst )
788
- else
789
- dst_info[ :closing ] = true
790
- @reads.delete( dst )
791
- add_write( dst )
792
- end
793
- end
794
-
795
772
  ##
796
773
  # set dst closing write
797
774
  #
@@ -799,7 +776,7 @@ module Girl
799
776
  return if dst.closed?
800
777
 
801
778
  dst_info = @dst_infos[ dst ]
802
- return if dst_info[ :closed_write ]
779
+ return if dst_info[ :closing_write ]
803
780
 
804
781
  dst_info[ :closing_write ] = true
805
782
  add_write( dst )
@@ -809,26 +786,21 @@ module Girl
809
786
  # set src is closing
810
787
  #
811
788
  def set_src_closing( src )
812
- return if src.closed?
813
- src_info = @src_infos[ src ]
814
-
815
- if src_info[ :closed_write ] then
816
- close_src( src )
817
- else
818
- src_info[ :closing ] = true
819
- @reads.delete( src )
820
- add_write( src )
821
- end
789
+ return if src.closed? || @closing_srcs.include?( src )
790
+ @reads.delete( src )
791
+ @writes.delete( src )
792
+ @closing_srcs << src
793
+ add_write( @tun ) if @tun
822
794
  end
823
795
 
824
796
  ##
825
797
  # set src closing write
826
798
  #
827
799
  def set_src_closing_write( src )
828
- return if src.closed?
800
+ return if src.closed? || @closing_srcs.include?( src )
829
801
 
830
802
  src_info = @src_infos[ src ]
831
- return if src_info[ :closed_write ]
803
+ return if src_info[ :closing_write ]
832
804
 
833
805
  src_info[ :closing_write ] = true
834
806
  add_write( src )
@@ -857,7 +829,7 @@ module Girl
857
829
  return if stream.closed?
858
830
 
859
831
  stream_info = @stream_infos[ stream ]
860
- return if stream_info[ :closed_write ]
832
+ return if stream_info[ :closing_write ]
861
833
 
862
834
  stream_info[ :closing_write ] = true
863
835
  add_write( stream )
@@ -867,10 +839,11 @@ module Girl
867
839
  # set tun is closing
868
840
  #
869
841
  def set_tun_closing
870
- return if @tun.closed?
842
+ return if @tun.closed? || @tun_info[ :closing ]
871
843
  @tun_info[ :closing ] = true
872
844
  @reads.delete( @tun )
873
845
  add_write( @tun )
846
+ @tun_info[ :srcs ].each{ | _, src | set_src_closing( src ) }
874
847
  end
875
848
 
876
849
  ##
@@ -929,9 +902,7 @@ module Girl
929
902
  last_recv_at: nil, # 上一次收到新流量(由dst收到,或者由stream收到)的时间
930
903
  last_sent_at: nil, # 上一次发出流量(由dst发出,或者由stream发出)的时间
931
904
  paused: false, # 是否已暂停读
932
- closing: false, # 准备关闭
933
- closing_write: false, # 准备关闭写
934
- closed_write: false # 已关闭写
905
+ closing_write: false # 准备关闭写
935
906
  }
936
907
 
937
908
  add_read( src, :src )
@@ -1258,6 +1229,11 @@ module Girl
1258
1229
  #
1259
1230
  def write_tun( tun )
1260
1231
  # 处理关闭
1232
+ if @closing_srcs.any? then
1233
+ @closing_srcs.each{ | src | close_src( src ) }
1234
+ @closing_srcs.clear
1235
+ end
1236
+
1261
1237
  if @tun_info[ :closing ] then
1262
1238
  close_tun( tun )
1263
1239
  return
@@ -1293,14 +1269,6 @@ module Girl
1293
1269
  return if src.closed?
1294
1270
  src_info = @src_infos[ src ]
1295
1271
  dst = src_info[ :dst ]
1296
-
1297
- # 处理关闭
1298
- if src_info[ :closing ] then
1299
- close_src( src )
1300
- return
1301
- end
1302
-
1303
- # 处理wbuff
1304
1272
  data = src_info[ :wbuff ]
1305
1273
 
1306
1274
  # 写前为空,处理关闭写
@@ -1346,13 +1314,6 @@ module Girl
1346
1314
  return if dst.closed?
1347
1315
  dst_info = @dst_infos[ dst ]
1348
1316
  src = dst_info[ :src ]
1349
-
1350
- # 处理关闭
1351
- if dst_info[ :closing ] then
1352
- close_dst( dst )
1353
- return
1354
- end
1355
-
1356
1317
  data = dst_info[ :wbuff ]
1357
1318
 
1358
1319
  # 写前为空,处理关闭写
@@ -1395,13 +1356,6 @@ module Girl
1395
1356
  return if stream.closed?
1396
1357
  stream_info = @stream_infos[ stream ]
1397
1358
  src = stream_info[ :src ]
1398
-
1399
- # 处理关闭
1400
- if stream_info[ :closing ] then
1401
- close_stream( stream )
1402
- return
1403
- end
1404
-
1405
1359
  data = stream_info[ :wbuff ]
1406
1360
 
1407
1361
  # 写前为空,处理关闭写
@@ -9,6 +9,8 @@ module Girl
9
9
  @mutex = Mutex.new
10
10
  @reads = []
11
11
  @writes = []
12
+ @closing_dsts = []
13
+ @closing_streamds = []
12
14
  @roles = {} # sock => :dotr / :proxyd / :infod / :dst / :tund / :tcpd / :streamd
13
15
  @tund_infos = {} # tund => {}
14
16
  @tcpd_infos = {} # tcpd => {}
@@ -131,7 +133,7 @@ module Girl
131
133
  # add streamd wbuff
132
134
  #
133
135
  def add_streamd_wbuff( streamd, data )
134
- return if streamd.closed?
136
+ return if streamd.closed? || @closing_streamds.include?( streamd )
135
137
  streamd_info = @streamd_infos[ streamd ]
136
138
  streamd_info[ :wbuff ] << data
137
139
  add_write( streamd )
@@ -152,7 +154,7 @@ module Girl
152
154
  # add write
153
155
  #
154
156
  def add_write( sock )
155
- unless @writes.include?( sock ) then
157
+ if !sock.closed? && !@writes.include?( sock ) then
156
158
  @writes << sock
157
159
  end
158
160
  end
@@ -248,7 +250,6 @@ module Girl
248
250
  tcpd = tund_info[ :tcpd ]
249
251
  close_sock( tcpd )
250
252
  @tcpd_infos.delete( tcpd )
251
- tund_info[ :dsts ].each{ | _, dst | set_dst_closing( dst ) }
252
253
  @tunneling_tunds.delete( tund_info[ :tun_addr ] )
253
254
  end
254
255
 
@@ -269,7 +270,6 @@ module Girl
269
270
  dst_info = @dst_infos[ dst ]
270
271
  end
271
272
 
272
- dst_info[ :closed_write ] = true
273
273
  dst_info
274
274
  end
275
275
 
@@ -290,7 +290,6 @@ module Girl
290
290
  streamd_info = @streamd_infos[ streamd ]
291
291
  end
292
292
 
293
- streamd_info[ :closed_write ] = true
294
293
  streamd_info
295
294
  end
296
295
 
@@ -325,9 +324,7 @@ module Girl
325
324
  last_recv_at: nil, # 上一次收到新流量(由streamd收到)的时间
326
325
  last_sent_at: nil, # 上一次发出流量(由streamd发出)的时间
327
326
  paused: false, # 是否已暂停读
328
- closing: false, # 准备关闭
329
- closing_write: false, # 准备关闭写
330
- closed_write: false # 已关闭写
327
+ closing_write: false # 准备关闭写
331
328
  }
332
329
 
333
330
  add_read( dst, :dst )
@@ -370,12 +367,14 @@ module Girl
370
367
  now = Time.new
371
368
 
372
369
  @tund_infos.each do | tund, tund_info |
373
- last_recv_at = tund_info[ :last_recv_at ] || tund_info[ :created_at ]
374
-
375
- if tund_info[ :dsts ].empty? && ( now - last_recv_at >= EXPIRE_AFTER ) then
376
- puts "p#{ Process.pid } #{ Time.new } expire tund #{ tund_info[ :port ] }"
377
- set_tund_closing( tund )
378
- trigger = true
370
+ unless tund_info[ :closing ] then
371
+ last_recv_at = tund_info[ :last_recv_at ] || tund_info[ :created_at ]
372
+
373
+ if tund_info[ :dsts ].empty? && ( now - last_recv_at >= EXPIRE_AFTER ) then
374
+ puts "p#{ Process.pid } #{ Time.new } expire tund #{ tund_info[ :port ] }"
375
+ set_tund_closing( tund )
376
+ trigger = true
377
+ end
379
378
  end
380
379
  end
381
380
 
@@ -562,26 +561,22 @@ module Girl
562
561
  # set dst closing
563
562
  #
564
563
  def set_dst_closing( dst )
565
- return if dst.closed?
564
+ return if dst.closed? || @closing_dsts.include?( dst )
565
+ @reads.delete( dst )
566
+ @writes.delete( dst )
567
+ @closing_dsts << dst
566
568
  dst_info = @dst_infos[ dst ]
567
-
568
- if dst_info[ :closed_write ] then
569
- close_dst( dst )
570
- else
571
- dst_info[ :closing ] = true
572
- @reads.delete( dst )
573
- add_write( dst )
574
- end
569
+ add_write( dst_info[ :tund ] )
575
570
  end
576
571
 
577
572
  ##
578
573
  # set dst closing write
579
574
  #
580
575
  def set_dst_closing_write( dst )
581
- return if dst.closed?
576
+ return if dst.closed? || @closing_dsts.include?( dst )
582
577
 
583
578
  dst_info = @dst_infos[ dst ]
584
- return if dst_info[ :closed_write ]
579
+ return if dst_info[ :closing_write ]
585
580
 
586
581
  dst_info[ :closing_write ] = true
587
582
  add_write( dst )
@@ -591,26 +586,22 @@ module Girl
591
586
  # set streamd closing
592
587
  #
593
588
  def set_streamd_closing( streamd )
594
- return if streamd.closed?
589
+ return if streamd.closed? || @closing_streamds.include?( streamd )
590
+ @reads.delete( streamd )
591
+ @writes.delete( streamd )
592
+ @closing_streamds << streamd
595
593
  streamd_info = @streamd_infos[ streamd ]
596
-
597
- if streamd_info[ :closed_write ] then
598
- close_streamd( streamd )
599
- else
600
- streamd_info[ :closing ] = true
601
- @reads.delete( streamd )
602
- add_write( streamd )
603
- end
594
+ add_write( streamd_info[ :tund ] )
604
595
  end
605
596
 
606
597
  ##
607
598
  # set streamd closing write
608
599
  #
609
600
  def set_streamd_closing_write( streamd )
610
- return if streamd.closed?
601
+ return if streamd.closed? || @closing_streamds.include?( streamd )
611
602
 
612
603
  streamd_info = @streamd_infos[ streamd ]
613
- return if streamd_info[ :closed_write ]
604
+ return if streamd_info[ :closing_write ]
614
605
 
615
606
  streamd_info[ :closing_write ] = true
616
607
  add_write( streamd )
@@ -621,10 +612,14 @@ module Girl
621
612
  #
622
613
  def set_tund_closing( tund )
623
614
  return if tund.closed?
615
+
624
616
  tund_info = @tund_infos[ tund ]
617
+ return if tund_info[ :closing ]
618
+
625
619
  tund_info[ :closing ] = true
626
620
  @reads.delete( tund )
627
621
  add_write( tund )
622
+ tund_info[ :dsts ].each{ | _, dst | set_dst_closing( dst ) }
628
623
  end
629
624
 
630
625
  ##
@@ -783,6 +778,8 @@ module Girl
783
778
  # read tcpd
784
779
  #
785
780
  def read_tcpd( tcpd )
781
+ return if tcpd.closed?
782
+
786
783
  begin
787
784
  streamd, addrinfo = tcpd.accept_nonblock
788
785
  rescue IO::WaitReadable, Errno::EINTR
@@ -802,9 +799,7 @@ module Girl
802
799
  domain_port: nil, # dst的目的地和端口
803
800
  wbuff: '', # 写前,写往近端stream
804
801
  paused: false, # 是否已暂停读
805
- closing: false, # 准备关闭
806
- closing_write: false, # 准备关闭写
807
- closed_write: false # 已关闭写
802
+ closing_write: false # 准备关闭写
808
803
  }
809
804
 
810
805
  add_read( streamd, :streamd )
@@ -907,7 +902,7 @@ module Girl
907
902
  return if data.empty?
908
903
  end
909
904
 
910
- unless dst.closed? then
905
+ if !dst.closed? && !@closing_dsts.include?( dst ) then
911
906
  dst_info = @dst_infos[ dst ]
912
907
  data = @custom.decode( data )
913
908
  # puts "debug2 add dst.wbuff decoded #{ data.bytesize }"
@@ -950,6 +945,16 @@ module Girl
950
945
  tund_info = @tund_infos[ tund ]
951
946
 
952
947
  # 处理关闭
948
+ if @closing_dsts.any? then
949
+ @closing_dsts.each{ | dst | close_dst( dst ) }
950
+ @closing_dsts.clear
951
+ end
952
+
953
+ if @closing_streamds.any? then
954
+ @closing_streamds.each{ | streamd | close_streamd( streamd ) }
955
+ @closing_streamds.clear
956
+ end
957
+
953
958
  if tund_info[ :closing ] then
954
959
  if tund_info[ :changed_tun_addr ] then
955
960
  data = [ 0, IP_CHANGED ].pack( 'Q>C' )
@@ -988,13 +993,6 @@ module Girl
988
993
  return if dst.closed?
989
994
  dst_info = @dst_infos[ dst ]
990
995
  streamd = dst_info[ :streamd ]
991
-
992
- # 处理关闭
993
- if dst_info[ :closing ] then
994
- close_dst( dst )
995
- return
996
- end
997
-
998
996
  data = dst_info[ :wbuff ]
999
997
 
1000
998
  # 写前为空,处理关闭写
@@ -1034,13 +1032,6 @@ module Girl
1034
1032
  return if streamd.closed?
1035
1033
  streamd_info = @streamd_infos[ streamd ]
1036
1034
  dst = streamd_info[ :dst ]
1037
-
1038
- # 处理关闭
1039
- if streamd_info[ :closing ] then
1040
- close_streamd( streamd )
1041
- return
1042
- end
1043
-
1044
1035
  data = streamd_info[ :wbuff ]
1045
1036
 
1046
1037
  # 写前为空,处理关闭写
@@ -1,3 +1,3 @@
1
1
  module Girl
2
- VERSION = '0.97.0'.freeze
2
+ VERSION = '0.98.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.97.0
4
+ version: 0.98.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - takafan