girl 0.65.0 → 0.70.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 +4 -4
- data/girl.gemspec +0 -5
- data/lib/girl/head.rb +2 -5
- data/lib/girl/proxy.rb +19 -11
- data/lib/girl/proxy_worker.rb +55 -85
- data/lib/girl/proxyd.rb +0 -9
- data/lib/girl/proxyd_worker.rb +43 -63
- data/lib/girl/version.rb +1 -1
- metadata +2 -7
- data/lib/girl/hex.rb +0 -24
- data/lib/girl/resolv.rb +0 -200
- data/lib/girl/resolvd.rb +0 -169
- data/lib/girl/tun.rb +0 -997
- data/lib/girl/tund.rb +0 -897
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb6d1abdce7bdbf84b4fa3c745be76cf5a990ebc0e7533deae6a97567e043524
|
4
|
+
data.tar.gz: 501bf156af3a02a6ef17f98e8ea16d71c152c02da3e1eba3593e11f6dd0f1541
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7485329397159e630ad15807d9d973a9080261ab44ce18a99fc0a1eb6832b70b82ff177968049b59383a79cc23db00f951d265cf22d2ad9fbdeaf1332a314185
|
7
|
+
data.tar.gz: b60356633483e23338e2f926905cfa0fd3d2d39e98a6b638705d26831406564082bea91ba7bab4d02b3eab77abd020854677be9597890ac070b05edd916c8081
|
data/girl.gemspec
CHANGED
@@ -19,17 +19,12 @@ girl.gemspec
|
|
19
19
|
lib/girl.rb
|
20
20
|
lib/girl/custom.rb
|
21
21
|
lib/girl/head.rb
|
22
|
-
lib/girl/hex.rb
|
23
22
|
lib/girl/proxy_custom.rb
|
24
23
|
lib/girl/proxy_worker.rb
|
25
24
|
lib/girl/proxy.rb
|
26
25
|
lib/girl/proxyd_custom.rb
|
27
26
|
lib/girl/proxyd_worker.rb
|
28
27
|
lib/girl/proxyd.rb
|
29
|
-
lib/girl/resolv.rb
|
30
|
-
lib/girl/resolvd.rb
|
31
|
-
lib/girl/tun.rb
|
32
|
-
lib/girl/tund.rb
|
33
28
|
lib/girl/udp.rb
|
34
29
|
lib/girl/udpd.rb
|
35
30
|
lib/girl/version.rb
|
data/lib/girl/head.rb
CHANGED
@@ -5,10 +5,9 @@ module Girl
|
|
5
5
|
WMEMS_LIMIT = 100_000 # 写后上限,达到上限暂停写
|
6
6
|
RESUME_BELOW = 50_000 # 降到多少以下恢复写
|
7
7
|
EXPIRE_NEW = 10 # 创建之后多久没有流量进来,过期
|
8
|
-
EXPIRE_AFTER =
|
8
|
+
EXPIRE_AFTER = 300 # 多久没有新流量,过期
|
9
9
|
CHECK_EXPIRE_INTERVAL = 30 # 检查过期间隔
|
10
|
-
|
11
|
-
STATUS_INTERVAL = 0.3 # 发送状态间隔
|
10
|
+
STATUS_INTERVAL = 0.5 # 发送状态间隔
|
12
11
|
SEND_STATUS_UNTIL = 10 # 持续的告之对面状态,直到没有流量往来,持续多少秒
|
13
12
|
BREAK_SEND_MISS = 10_000 # miss包个数上限,达到上限忽略要后面的段,可控碎片缓存
|
14
13
|
CONFUSE_UNTIL = 5 # 混淆前几个包
|
@@ -26,8 +25,6 @@ module Girl
|
|
26
25
|
GOT_FIN2 = 11
|
27
26
|
TUND_FIN = 12
|
28
27
|
TUN_FIN = 13
|
29
|
-
CTL_CLOSE = 1
|
30
|
-
CTL_RESUME = 2
|
31
28
|
HTTP_OK = "HTTP/1.1 200 OK\r\n\r\n"
|
32
29
|
# https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
|
33
30
|
RESERVED_ROUTE = <<EOF
|
data/lib/girl/proxy.rb
CHANGED
@@ -24,28 +24,36 @@ require 'socket'
|
|
24
24
|
# tun-tund:
|
25
25
|
#
|
26
26
|
# Q>: 0 ctlmsg -> C: 2 heartbeat -> C: random char
|
27
|
-
# 3 a new src -> Q>:
|
28
|
-
# 4 paired -> Q>:
|
29
|
-
# 5 dst status -> n:
|
30
|
-
# 6 src status -> Q>:
|
31
|
-
# 7 miss -> Q
|
32
|
-
# 8 fin1 -> Q>:
|
27
|
+
# 3 a new src -> Q>: src id -> encoded destination address
|
28
|
+
# 4 paired -> Q>: src id -> n: dst port
|
29
|
+
# 5 dst status -> n: dst port -> Q>: biggest relayed dst pack id -> Q>: continue src pack id
|
30
|
+
# 6 src status -> Q>: src id -> Q>: biggest relayed src pack id -> Q>: continue dst pack id
|
31
|
+
# 7 miss -> Q>/n: src id / dst port -> Q>: pack id begin -> Q>: pack id end
|
32
|
+
# 8 fin1 -> Q>/n: src id / dst port -> Q>: biggest src pack id / biggest dst pack id -> Q>: continue dst pack id / continue src pack id
|
33
33
|
# 9 not use
|
34
|
-
# 10 fin2 -> Q
|
34
|
+
# 10 fin2 -> Q>/n: src id / dst port
|
35
35
|
# 11 not use
|
36
36
|
# 12 tund fin
|
37
37
|
# 13 tun fin
|
38
38
|
#
|
39
|
-
# Q>: 1+ pack_id -> Q
|
39
|
+
# Q>: 1+ pack_id -> Q>/n: src id / dst port -> traffic
|
40
40
|
#
|
41
41
|
# close logic
|
42
42
|
# ===========
|
43
43
|
#
|
44
44
|
# 1-1. after close src -> dst closed ? no -> send fin1
|
45
|
-
# 1-2. recv fin2 -> del src ext
|
45
|
+
# 1-2. tun recv fin2 -> del src ext
|
46
46
|
#
|
47
|
-
# 2-1. recv
|
48
|
-
# 2-2.
|
47
|
+
# 2-1. tun recv fin1 -> all traffic received ? -> close src after write
|
48
|
+
# 2-2. tun recv traffic -> dst closed and all traffic received ? -> close src after write
|
49
|
+
# 2-3. after close src -> dst closed ? yes -> del src ext -> send fin2
|
50
|
+
#
|
51
|
+
# 3-1. after close dst -> src closed ? no -> send fin1
|
52
|
+
# 3-2. tund recv fin2 -> del dst ext
|
53
|
+
#
|
54
|
+
# 4-1. tund recv fin1 -> all traffic received ? -> close dst after write
|
55
|
+
# 4-2. tund recv traffic -> src closed and all traffic received ? -> close dst after write
|
56
|
+
# 4-3. after close dst -> src closed ? yes -> del dst ext -> send fin2
|
49
57
|
#
|
50
58
|
module Girl
|
51
59
|
class Proxy
|
data/lib/girl/proxy_worker.rb
CHANGED
@@ -102,13 +102,14 @@ module Girl
|
|
102
102
|
now = Time.new
|
103
103
|
|
104
104
|
if @tun && !@tun.closed?
|
105
|
-
is_expired = @tun_info[ :last_recv_at ]
|
105
|
+
is_expired = @tun_info[ :last_recv_at ] ? ( now - @tun_info[ :last_recv_at ] > EXPIRE_AFTER ) : ( now - @tun_info[ :created_at ] > EXPIRE_NEW )
|
106
106
|
|
107
107
|
if is_expired
|
108
108
|
puts "p#{ Process.pid } #{ Time.new } expire tun"
|
109
109
|
set_is_closing( @tun )
|
110
110
|
else
|
111
111
|
data = [ 0, HEARTBEAT, rand( 128 ) ].pack( 'Q>CC' )
|
112
|
+
# puts "debug1 #{ Time.new } heartbeat"
|
112
113
|
add_tun_ctlmsg( data )
|
113
114
|
|
114
115
|
@tun_info[ :src_exts ].each do | src_id, src_ext |
|
@@ -167,8 +168,7 @@ module Girl
|
|
167
168
|
|
168
169
|
@tun_info[ :src_exts ].each do | src_id, src_ext |
|
169
170
|
if src_ext[ :dst_port ] && ( now - src_ext[ :last_continue_at ] < SEND_STATUS_UNTIL )
|
170
|
-
|
171
|
-
data = [ 0, SOURCE_STATUS, src_id, src_ext[ :biggest_pack_id ], src_ext[ :continue_dst_pack_id ] ].pack( 'Q>CQ>Q>Q>' )
|
171
|
+
data = [ 0, SOURCE_STATUS, src_id, src_ext[ :relay_pack_id ], src_ext[ :continue_dst_pack_id ] ].pack( 'Q>CQ>Q>Q>' )
|
172
172
|
add_tun_ctlmsg( data )
|
173
173
|
need_trigger = true
|
174
174
|
end
|
@@ -191,28 +191,6 @@ module Girl
|
|
191
191
|
end
|
192
192
|
end
|
193
193
|
|
194
|
-
##
|
195
|
-
# loop send a new source
|
196
|
-
#
|
197
|
-
def loop_send_a_new_source( src_ext, data )
|
198
|
-
Thread.new do
|
199
|
-
EXPIRE_NEW.times do
|
200
|
-
if src_ext[ :src ].closed? || src_ext[ :dst_port ]
|
201
|
-
# puts "debug1 break loop send a new source #{ src_ext[ :dst_port ] }"
|
202
|
-
break
|
203
|
-
end
|
204
|
-
|
205
|
-
@mutex.synchronize do
|
206
|
-
# puts "debug1 send a new source #{ data.inspect }"
|
207
|
-
add_tun_ctlmsg( data )
|
208
|
-
next_tick
|
209
|
-
end
|
210
|
-
|
211
|
-
sleep 1
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
194
|
##
|
217
195
|
# resolve domain
|
218
196
|
#
|
@@ -316,8 +294,8 @@ module Girl
|
|
316
294
|
port: port, # 端口
|
317
295
|
ctlmsg_rbuffs: [], # 还没配上tund,暂存的ctlmsg
|
318
296
|
ctlmsgs: [], # [ to_addr, data ]
|
319
|
-
wbuffs: [], # 写前缓存 [ src_id, data ]
|
320
|
-
caches: [], # 块读出缓存 [ src_id, data ]
|
297
|
+
wbuffs: [], # 写前缓存 [ src_id, pack_id, data ]
|
298
|
+
caches: [], # 块读出缓存 [ src_id, pack_id, data ]
|
321
299
|
chunks: [], # 块队列 filename
|
322
300
|
spring: 0, # 块后缀,结块时,如果块队列不为空,则自增,为空,则置为0
|
323
301
|
tund_addr: nil, # tund地址
|
@@ -382,9 +360,7 @@ module Girl
|
|
382
360
|
src_info[ :dst ] = dst
|
383
361
|
|
384
362
|
if src_info[ :proxy_proto ] == :http
|
385
|
-
|
386
|
-
|
387
|
-
if datas.empty?
|
363
|
+
if src_info[ :is_connect ]
|
388
364
|
# CONNECT
|
389
365
|
# puts "debug1 add src wbuff http ok"
|
390
366
|
add_src_wbuff( src, HTTP_OK )
|
@@ -392,7 +368,7 @@ module Girl
|
|
392
368
|
# not CONNECT
|
393
369
|
# puts "debug1 add src rbuffs to dst wbuff"
|
394
370
|
|
395
|
-
|
371
|
+
src_info[ :rbuffs ].each do | _, data |
|
396
372
|
add_dst_wbuff( dst, data )
|
397
373
|
end
|
398
374
|
end
|
@@ -414,11 +390,11 @@ module Girl
|
|
414
390
|
dst_port: nil, # 远端dst端口
|
415
391
|
wmems: {}, # 写后 pack_id => data
|
416
392
|
send_ats: {}, # 上一次发出时间 pack_id => send_at
|
417
|
-
|
393
|
+
relay_pack_id: 0, # 转发到几
|
418
394
|
continue_dst_pack_id: 0, # 收到几
|
419
395
|
pieces: {}, # 跳号包 dst_pack_id => data
|
420
|
-
is_dst_closed: false, #
|
421
|
-
biggest_dst_pack_id: 0, #
|
396
|
+
is_dst_closed: false, # dst是否已关闭
|
397
|
+
biggest_dst_pack_id: 0, # dst最大包号码
|
422
398
|
completed_pack_id: 0, # 完成到几(对面收到几)
|
423
399
|
last_continue_at: Time.new # 创建,或者上一次收到连续流量,或者发出新包的时间
|
424
400
|
}
|
@@ -432,7 +408,7 @@ module Girl
|
|
432
408
|
destination_domain = src_info[ :destination_domain ]
|
433
409
|
destination_domain_port = [ destination_domain, destination_port ].join( ':' )
|
434
410
|
data = [ [ 0, A_NEW_SOURCE, src_id ].pack( 'Q>CQ>' ), @custom.encode( destination_domain_port ) ].join
|
435
|
-
|
411
|
+
add_tun_ctlmsg( data )
|
436
412
|
end
|
437
413
|
|
438
414
|
##
|
@@ -490,17 +466,17 @@ module Girl
|
|
490
466
|
##
|
491
467
|
# add tun wbuff
|
492
468
|
#
|
493
|
-
def add_tun_wbuff( src_id, data )
|
494
|
-
@tun_info[ :wbuffs ] << [ src_id, data ]
|
469
|
+
def add_tun_wbuff( src_id, pack_id, data )
|
470
|
+
@tun_info[ :wbuffs ] << [ src_id, pack_id, data ]
|
495
471
|
|
496
472
|
if @tun_info[ :wbuffs ].size >= WBUFFS_LIMIT
|
497
473
|
spring = @tun_info[ :chunks ].size > 0 ? ( @tun_info[ :spring ] + 1 ) : 0
|
498
474
|
filename = "#{ Process.pid }-#{ @tun_info[ :port ] }.#{ spring }"
|
499
475
|
chunk_path = File.join( @tun_chunk_dir, filename )
|
500
|
-
|
476
|
+
datas = @tun_info[ :wbuffs ].map{ | _src_id, _pack_id, _data | [ [ _src_id, _pack_id, _data.bytesize ].pack( 'Q>Q>n' ), _data ].join }
|
501
477
|
|
502
478
|
begin
|
503
|
-
IO.binwrite( chunk_path,
|
479
|
+
IO.binwrite( chunk_path, datas.join )
|
504
480
|
rescue Errno::ENOSPC => e
|
505
481
|
puts "p#{ Process.pid } #{ Time.new } #{ e.class }, close tun"
|
506
482
|
set_is_closing( @tun )
|
@@ -586,7 +562,7 @@ module Girl
|
|
586
562
|
# add write
|
587
563
|
#
|
588
564
|
def add_write( sock )
|
589
|
-
|
565
|
+
if sock && !sock.closed? && !@writes.include?( sock )
|
590
566
|
@writes << sock
|
591
567
|
end
|
592
568
|
end
|
@@ -639,13 +615,13 @@ module Girl
|
|
639
615
|
return if src_ext.nil? || src_ext[ :dst_port ].nil?
|
640
616
|
|
641
617
|
if src_ext[ :is_dst_closed ]
|
642
|
-
# puts "debug1 2-
|
618
|
+
# puts "debug1 2-3. after close src -> dst closed ? yes -> del src ext -> send fin2"
|
643
619
|
del_src_ext( src_id )
|
644
620
|
data = [ 0, FIN2, src_id ].pack( 'Q>CQ>' )
|
645
621
|
add_tun_ctlmsg( data )
|
646
622
|
else
|
647
623
|
# puts "debug1 1-1. after close src -> dst closed ? no -> send fin1"
|
648
|
-
data = [ 0, FIN1, src_id,
|
624
|
+
data = [ 0, FIN1, src_id, src_info[ :biggest_pack_id ], src_ext[ :continue_dst_pack_id ] ].pack( 'Q>CQ>Q>Q>' )
|
649
625
|
add_tun_ctlmsg( data )
|
650
626
|
end
|
651
627
|
elsif src_info[ :proxy_type ] == :direct
|
@@ -893,7 +869,7 @@ module Girl
|
|
893
869
|
|
894
870
|
# 取写前
|
895
871
|
if @tun_info[ :caches ].any?
|
896
|
-
src_id, data = @tun_info[ :caches ].first
|
872
|
+
src_id, pack_id, data = @tun_info[ :caches ].first
|
897
873
|
from = :caches
|
898
874
|
elsif @tun_info[ :chunks ].any?
|
899
875
|
path = File.join( @tun_chunk_dir, @tun_info[ :chunks ].shift )
|
@@ -910,16 +886,16 @@ module Girl
|
|
910
886
|
caches = []
|
911
887
|
|
912
888
|
until data.empty?
|
913
|
-
_src_id, pack_size = data[ 0,
|
914
|
-
caches << [ _src_id, data[
|
915
|
-
data = data[ (
|
889
|
+
_src_id, _pack_id, pack_size = data[ 0, 18 ].unpack( 'Q>Q>n' )
|
890
|
+
caches << [ _src_id, _pack_id, data[ 18, pack_size ] ]
|
891
|
+
data = data[ ( 18 + pack_size )..-1 ]
|
916
892
|
end
|
917
893
|
|
918
894
|
@tun_info[ :caches ] = caches
|
919
|
-
src_id, data = caches.first
|
895
|
+
src_id, pack_id, data = caches.first
|
920
896
|
from = :caches
|
921
897
|
elsif @tun_info[ :wbuffs ].any?
|
922
|
-
src_id, data = @tun_info[ :wbuffs ].first
|
898
|
+
src_id, pack_id, data = @tun_info[ :wbuffs ].first
|
923
899
|
from = :wbuffs
|
924
900
|
else
|
925
901
|
@writes.delete( tun )
|
@@ -929,8 +905,6 @@ module Girl
|
|
929
905
|
src_ext = @tun_info[ :src_exts ][ src_id ]
|
930
906
|
|
931
907
|
if src_ext
|
932
|
-
pack_id = src_ext[ :biggest_pack_id ] + 1
|
933
|
-
|
934
908
|
if pack_id <= CONFUSE_UNTIL
|
935
909
|
data = @custom.encode( data )
|
936
910
|
# puts "debug1 encoded pack #{ pack_id }"
|
@@ -945,7 +919,7 @@ module Girl
|
|
945
919
|
end
|
946
920
|
|
947
921
|
# puts "debug2 written pack #{ pack_id }"
|
948
|
-
src_ext[ :
|
922
|
+
src_ext[ :relay_pack_id ] = pack_id
|
949
923
|
src_ext[ :wmems ][ pack_id ] = data
|
950
924
|
src_ext[ :send_ats ][ pack_id ] = now
|
951
925
|
src_ext[ :last_continue_at ] = now
|
@@ -981,7 +955,9 @@ module Girl
|
|
981
955
|
dst: nil, # :direct的场合,对应的dst
|
982
956
|
destination_domain: nil, # 目的地域名
|
983
957
|
destination_port: nil, # 目的地端口
|
984
|
-
|
958
|
+
biggest_pack_id: 0, # 最大包号码
|
959
|
+
is_connect: true, # 代理协议是http的场合,是否是CONNECT
|
960
|
+
rbuffs: [], # 非CONNECT,dst或者远端dst未准备好,暂存流量 [ pack_id, data ]
|
985
961
|
wbuff: '', # 写前
|
986
962
|
cache: '', # 块读出缓存
|
987
963
|
chunks: [], # 块队列,写前达到块大小时结一个块 filename
|
@@ -1078,7 +1054,10 @@ module Girl
|
|
1078
1054
|
end
|
1079
1055
|
end
|
1080
1056
|
|
1081
|
-
src_info[ :
|
1057
|
+
src_info[ :is_connect ] = false
|
1058
|
+
pack_id = src_info[ :biggest_pack_id ] + 1
|
1059
|
+
src_info[ :biggest_pack_id ] = pack_id
|
1060
|
+
src_info[ :rbuffs ] << [ pack_id, data ]
|
1082
1061
|
end
|
1083
1062
|
|
1084
1063
|
domain, port = domain_and_port.split( ':' )
|
@@ -1091,7 +1070,9 @@ module Girl
|
|
1091
1070
|
resolve_domain( src, domain )
|
1092
1071
|
when :checking
|
1093
1072
|
# puts "debug1 add src rbuff while checking #{ data.inspect }"
|
1094
|
-
src_info[ :
|
1073
|
+
pack_id = src_info[ :biggest_pack_id ] + 1
|
1074
|
+
src_info[ :biggest_pack_id ] = pack_id
|
1075
|
+
src_info[ :rbuffs ] << [ pack_id, data ]
|
1095
1076
|
when :negotiation
|
1096
1077
|
# +----+-----+-------+------+----------+----------+
|
1097
1078
|
# |VER | CMD | RSV | ATYP | DST.ADDR | DST.PORT |
|
@@ -1138,6 +1119,9 @@ module Girl
|
|
1138
1119
|
return
|
1139
1120
|
end
|
1140
1121
|
|
1122
|
+
pack_id = src_info[ :biggest_pack_id ] + 1
|
1123
|
+
src_info[ :biggest_pack_id ] = pack_id
|
1124
|
+
|
1141
1125
|
if src_ext[ :dst_port ]
|
1142
1126
|
if @tun.closed?
|
1143
1127
|
# puts "debug1 tun closed, close src"
|
@@ -1145,14 +1129,14 @@ module Girl
|
|
1145
1129
|
return
|
1146
1130
|
end
|
1147
1131
|
|
1148
|
-
|
1132
|
+
unless src_info[ :is_connect ]
|
1149
1133
|
data, _ = sub_http_request( data )
|
1150
1134
|
end
|
1151
1135
|
|
1152
|
-
add_tun_wbuff( src_id, data )
|
1136
|
+
add_tun_wbuff( src_id, pack_id, data )
|
1153
1137
|
else
|
1154
1138
|
# puts "debug1 remote dst not ready, save data to src rbuff"
|
1155
|
-
src_info[ :rbuffs ] << data
|
1139
|
+
src_info[ :rbuffs ] << [ pack_id, data ]
|
1156
1140
|
end
|
1157
1141
|
when :direct
|
1158
1142
|
dst = src_info[ :dst ]
|
@@ -1164,14 +1148,14 @@ module Girl
|
|
1164
1148
|
return
|
1165
1149
|
end
|
1166
1150
|
|
1167
|
-
|
1151
|
+
unless src_info[ :is_connect ]
|
1168
1152
|
data, _ = sub_http_request( data )
|
1169
1153
|
end
|
1170
1154
|
|
1171
1155
|
add_dst_wbuff( dst, data )
|
1172
1156
|
else
|
1173
1157
|
# puts "debug1 dst not ready, save data to src rbuff"
|
1174
|
-
src_info[ :rbuffs ] << data
|
1158
|
+
src_info[ :rbuffs ] << [ nil, data ]
|
1175
1159
|
end
|
1176
1160
|
end
|
1177
1161
|
end
|
@@ -1211,8 +1195,8 @@ module Girl
|
|
1211
1195
|
data, addrinfo, rflags, *controls = tun.recvmsg
|
1212
1196
|
from_addr = addrinfo.to_sockaddr
|
1213
1197
|
now = Time.new
|
1214
|
-
pack_id = data[ 0, 8 ].unpack( 'Q>' ).first
|
1215
1198
|
@tun_info[ :last_recv_at ] = now
|
1199
|
+
pack_id = data[ 0, 8 ].unpack( 'Q>' ).first
|
1216
1200
|
|
1217
1201
|
if pack_id == 0
|
1218
1202
|
ctl_num = data[ 8 ].unpack( 'C' ).first
|
@@ -1257,9 +1241,7 @@ module Girl
|
|
1257
1241
|
src_info = @src_infos[ src ]
|
1258
1242
|
|
1259
1243
|
if src_info[ :proxy_proto ] == :http
|
1260
|
-
|
1261
|
-
|
1262
|
-
if datas.empty?
|
1244
|
+
if src_info[ :is_connect ]
|
1263
1245
|
# CONNECT
|
1264
1246
|
# puts "debug1 add src wbuff http ok"
|
1265
1247
|
add_src_wbuff( src, HTTP_OK )
|
@@ -1267,8 +1249,8 @@ module Girl
|
|
1267
1249
|
# not CONNECT
|
1268
1250
|
# puts "debug1 add src rbuffs to tun wbuffs"
|
1269
1251
|
|
1270
|
-
|
1271
|
-
add_tun_wbuff( src_id, _data )
|
1252
|
+
src_info[ :rbuffs ].each do | pack_id, _data |
|
1253
|
+
add_tun_wbuff( src_id, pack_id, _data )
|
1272
1254
|
end
|
1273
1255
|
end
|
1274
1256
|
elsif src_info[ :proxy_proto ] == :socks5
|
@@ -1277,7 +1259,7 @@ module Girl
|
|
1277
1259
|
when DEST_STATUS
|
1278
1260
|
return if from_addr != @tun_info[ :tund_addr ]
|
1279
1261
|
|
1280
|
-
dst_port,
|
1262
|
+
dst_port, relay_dst_pack_id, continue_src_pack_id = data[ 9, 18 ].unpack( 'nQ>Q>' )
|
1281
1263
|
|
1282
1264
|
src_id = @tun_info[ :src_ids ][ dst_port ]
|
1283
1265
|
return unless src_id
|
@@ -1287,22 +1269,10 @@ module Girl
|
|
1287
1269
|
|
1288
1270
|
# puts "debug2 got dest status"
|
1289
1271
|
|
1290
|
-
# 更新对面发到几
|
1291
|
-
if biggest_dst_pack_id > src_ext[ :biggest_dst_pack_id ]
|
1292
|
-
# puts "debug2 update biggest dst pack #{ biggest_dst_pack_id }"
|
1293
|
-
src_ext[ :biggest_dst_pack_id ] = biggest_dst_pack_id
|
1294
|
-
|
1295
|
-
# 接到对面状态,若对面已关闭,且最后一个包已经进写前,关闭src
|
1296
|
-
if src_ext[ :is_dst_closed ] && ( biggest_dst_pack_id == src_ext[ :continue_dst_pack_id ] )
|
1297
|
-
# puts "debug1 2-1. recv traffic/fin1/dst status -> dst closed and all traffic received ? -> close src after write"
|
1298
|
-
set_is_closing( src_ext[ :src ] )
|
1299
|
-
end
|
1300
|
-
end
|
1301
|
-
|
1302
1272
|
release_wmems( src_ext, continue_src_pack_id )
|
1303
1273
|
|
1304
1274
|
# 发miss
|
1305
|
-
if !src_ext[ :src ].closed? && ( src_ext[ :continue_dst_pack_id ] <
|
1275
|
+
if !src_ext[ :src ].closed? && ( src_ext[ :continue_dst_pack_id ] < relay_dst_pack_id )
|
1306
1276
|
ranges = []
|
1307
1277
|
curr_pack_id = src_ext[ :continue_dst_pack_id ] + 1
|
1308
1278
|
|
@@ -1314,12 +1284,12 @@ module Girl
|
|
1314
1284
|
curr_pack_id = pack_id + 1
|
1315
1285
|
end
|
1316
1286
|
|
1317
|
-
if curr_pack_id <=
|
1318
|
-
ranges << [ curr_pack_id,
|
1287
|
+
if curr_pack_id <= relay_dst_pack_id
|
1288
|
+
ranges << [ curr_pack_id, relay_dst_pack_id ]
|
1319
1289
|
end
|
1320
1290
|
|
1321
1291
|
pack_count = 0
|
1322
|
-
# puts "debug1 continue/
|
1292
|
+
# puts "debug1 continue/relay #{ src_ext[ :continue_dst_pack_id ] }/#{ relay_dst_pack_id } send MISS #{ ranges.size }"
|
1323
1293
|
|
1324
1294
|
ranges.each do | pack_id_begin, pack_id_end |
|
1325
1295
|
if pack_count >= BREAK_SEND_MISS
|
@@ -1368,7 +1338,7 @@ module Girl
|
|
1368
1338
|
|
1369
1339
|
# 接到对面已关闭,若最后一个包已经进写前,关闭src
|
1370
1340
|
if ( biggest_dst_pack_id == src_ext[ :continue_dst_pack_id ] )
|
1371
|
-
# puts "debug1 2-1. recv fin1 ->
|
1341
|
+
# puts "debug1 2-1. tun recv fin1 -> all traffic received ? -> close src after write"
|
1372
1342
|
set_is_closing( src_ext[ :src ] )
|
1373
1343
|
end
|
1374
1344
|
when FIN2
|
@@ -1379,7 +1349,7 @@ module Girl
|
|
1379
1349
|
src_id = @tun_info[ :src_ids ][ dst_port ]
|
1380
1350
|
return unless src_id
|
1381
1351
|
|
1382
|
-
# puts "debug1 1-2. recv fin2 -> del src ext"
|
1352
|
+
# puts "debug1 1-2. tun recv fin2 -> del src ext"
|
1383
1353
|
del_src_ext( src_id )
|
1384
1354
|
when TUND_FIN
|
1385
1355
|
return if from_addr != @tun_info[ :tund_addr ]
|
@@ -1425,7 +1395,7 @@ module Girl
|
|
1425
1395
|
|
1426
1396
|
# 接到流量,若对面已关闭,且流量正好收全,关闭src
|
1427
1397
|
if src_ext[ :is_dst_closed ] && ( pack_id == src_ext[ :biggest_dst_pack_id ] )
|
1428
|
-
# puts "debug1 2-
|
1398
|
+
# puts "debug1 2-2. tun recv traffic -> dst closed and all traffic received ? -> close src after write"
|
1429
1399
|
set_is_closing( src_ext[ :src ] )
|
1430
1400
|
end
|
1431
1401
|
else
|