girl 0.69.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b16f67f52bf05cd498b16e480ee9d29577217ef93fd8964c0256e3816eb837e6
4
- data.tar.gz: 38a5178d59930baa536a2ea882b8e17d86bb5e194386bcf9fc5ef7615d8e120e
3
+ metadata.gz: fb6d1abdce7bdbf84b4fa3c745be76cf5a990ebc0e7533deae6a97567e043524
4
+ data.tar.gz: 501bf156af3a02a6ef17f98e8ea16d71c152c02da3e1eba3593e11f6dd0f1541
5
5
  SHA512:
6
- metadata.gz: 139f1ea8a12a8e58d236e873ef1b3cb2944768ac1f2940fc986afb3ed5095e82550235f89fa1a81981b1981d6422f5bebd7918874a8cfe2fef7ab586af1d22fa
7
- data.tar.gz: 0554a3541237a4f62d838309b3ff703b18480218646bf6f3920e218d477aed0d41e21ef1cd944e4f042539c0d0d17a73a15f0fedcd4d8356d350b7052c1071a5
6
+ metadata.gz: 7485329397159e630ad15807d9d973a9080261ab44ce18a99fc0a1eb6832b70b82ff177968049b59383a79cc23db00f951d265cf22d2ad9fbdeaf1332a314185
7
+ data.tar.gz: b60356633483e23338e2f926905cfa0fd3d2d39e98a6b638705d26831406564082bea91ba7bab4d02b3eab77abd020854677be9597890ac070b05edd916c8081
@@ -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
@@ -7,7 +7,6 @@ module Girl
7
7
  EXPIRE_NEW = 10 # 创建之后多久没有流量进来,过期
8
8
  EXPIRE_AFTER = 300 # 多久没有新流量,过期
9
9
  CHECK_EXPIRE_INTERVAL = 30 # 检查过期间隔
10
- HEARTBEAT_INTERVAL = 30 # 心跳间隔
11
10
  STATUS_INTERVAL = 0.5 # 发送状态间隔
12
11
  SEND_STATUS_UNTIL = 10 # 持续的告之对面状态,直到没有流量往来,持续多少秒
13
12
  BREAK_SEND_MISS = 10_000 # miss包个数上限,达到上限忽略要后面的段,可控碎片缓存
@@ -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
@@ -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>: src_id -> encoded destination address
28
- # 4 paired -> Q>: src_id -> n: dst_port
29
- # 5 dst status -> n: dst_port -> Q>Q>: biggest_dst_pack_id continue_src_pack_id
30
- # 6 src status -> Q>: src_id -> Q>Q>: biggest_src_pack_id continue_dst_pack_id
31
- # 7 miss -> Q>: src_id/n: dst_port -> Q>Q>: pack_id_begin pack_id_end
32
- # 8 fin1 -> Q>: src_id/n: dst_port -> Q>Q>: biggest_src_pack_id continue_dst_pack_id / biggest_dst_pack_id continue_src_pack_id
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>: src_id/n: dst_port
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>: src_id/n: dst_port -> traffic
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 traffic/fin1/dst status -> dst closed and all traffic received ? -> close src after write
48
- # 2-2. after close src -> dst closed ? yes -> del src ext -> send fin2
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
@@ -168,8 +168,7 @@ module Girl
168
168
 
169
169
  @tun_info[ :src_exts ].each do | src_id, src_ext |
170
170
  if src_ext[ :dst_port ] && ( now - src_ext[ :last_continue_at ] < SEND_STATUS_UNTIL )
171
- # puts "debug2 ctl send status biggest #{ src_ext[ :biggest_pack_id ] } continue dst #{ src_ext[ :continue_dst_pack_id ] }"
172
- 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>' )
173
172
  add_tun_ctlmsg( data )
174
173
  need_trigger = true
175
174
  end
@@ -180,11 +179,6 @@ module Girl
180
179
  puts "p#{ Process.pid } #{ Time.new } resume tun"
181
180
  @tun_info[ :paused ] = false
182
181
  add_write( @tun )
183
-
184
- @tun_info[ :src_exts ].each do | _, src_ext |
185
- add_write( src_ext[ :src ] )
186
- end
187
-
188
182
  need_trigger = true
189
183
  end
190
184
 
@@ -197,28 +191,6 @@ module Girl
197
191
  end
198
192
  end
199
193
 
200
- ##
201
- # loop send a new source
202
- #
203
- def loop_send_a_new_source( src_ext, data )
204
- Thread.new do
205
- EXPIRE_NEW.times do
206
- if src_ext[ :src ].closed? || src_ext[ :dst_port ]
207
- # puts "debug1 break loop send a new source #{ src_ext[ :dst_port ] }"
208
- break
209
- end
210
-
211
- @mutex.synchronize do
212
- # puts "debug1 send a new source #{ data.inspect }"
213
- add_tun_ctlmsg( data )
214
- next_tick
215
- end
216
-
217
- sleep 1
218
- end
219
- end
220
- end
221
-
222
194
  ##
223
195
  # resolve domain
224
196
  #
@@ -322,8 +294,8 @@ module Girl
322
294
  port: port, # 端口
323
295
  ctlmsg_rbuffs: [], # 还没配上tund,暂存的ctlmsg
324
296
  ctlmsgs: [], # [ to_addr, data ]
325
- wbuffs: [], # 写前缓存 [ src_id, data ]
326
- caches: [], # 块读出缓存 [ src_id, data ]
297
+ wbuffs: [], # 写前缓存 [ src_id, pack_id, data ]
298
+ caches: [], # 块读出缓存 [ src_id, pack_id, data ]
327
299
  chunks: [], # 块队列 filename
328
300
  spring: 0, # 块后缀,结块时,如果块队列不为空,则自增,为空,则置为0
329
301
  tund_addr: nil, # tund地址
@@ -388,9 +360,7 @@ module Girl
388
360
  src_info[ :dst ] = dst
389
361
 
390
362
  if src_info[ :proxy_proto ] == :http
391
- datas = src_info[ :rbuffs ]
392
-
393
- if datas.empty?
363
+ if src_info[ :is_connect ]
394
364
  # CONNECT
395
365
  # puts "debug1 add src wbuff http ok"
396
366
  add_src_wbuff( src, HTTP_OK )
@@ -398,7 +368,7 @@ module Girl
398
368
  # not CONNECT
399
369
  # puts "debug1 add src rbuffs to dst wbuff"
400
370
 
401
- datas.each do | data |
371
+ src_info[ :rbuffs ].each do | _, data |
402
372
  add_dst_wbuff( dst, data )
403
373
  end
404
374
  end
@@ -420,11 +390,11 @@ module Girl
420
390
  dst_port: nil, # 远端dst端口
421
391
  wmems: {}, # 写后 pack_id => data
422
392
  send_ats: {}, # 上一次发出时间 pack_id => send_at
423
- biggest_pack_id: 0, # 发到几
393
+ relay_pack_id: 0, # 转发到几
424
394
  continue_dst_pack_id: 0, # 收到几
425
395
  pieces: {}, # 跳号包 dst_pack_id => data
426
- is_dst_closed: false, # 对面是否已关闭
427
- biggest_dst_pack_id: 0, # 对面发到几
396
+ is_dst_closed: false, # dst是否已关闭
397
+ biggest_dst_pack_id: 0, # dst最大包号码
428
398
  completed_pack_id: 0, # 完成到几(对面收到几)
429
399
  last_continue_at: Time.new # 创建,或者上一次收到连续流量,或者发出新包的时间
430
400
  }
@@ -438,7 +408,7 @@ module Girl
438
408
  destination_domain = src_info[ :destination_domain ]
439
409
  destination_domain_port = [ destination_domain, destination_port ].join( ':' )
440
410
  data = [ [ 0, A_NEW_SOURCE, src_id ].pack( 'Q>CQ>' ), @custom.encode( destination_domain_port ) ].join
441
- loop_send_a_new_source( src_ext, data )
411
+ add_tun_ctlmsg( data )
442
412
  end
443
413
 
444
414
  ##
@@ -496,17 +466,17 @@ module Girl
496
466
  ##
497
467
  # add tun wbuff
498
468
  #
499
- def add_tun_wbuff( src_id, data )
500
- @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 ]
501
471
 
502
472
  if @tun_info[ :wbuffs ].size >= WBUFFS_LIMIT
503
473
  spring = @tun_info[ :chunks ].size > 0 ? ( @tun_info[ :spring ] + 1 ) : 0
504
474
  filename = "#{ Process.pid }-#{ @tun_info[ :port ] }.#{ spring }"
505
475
  chunk_path = File.join( @tun_chunk_dir, filename )
506
- wbuffs = @tun_info[ :wbuffs ].map{ | _src_id, _data | [ [ _src_id, _data.bytesize ].pack( 'Q>n' ), _data ].join }
476
+ datas = @tun_info[ :wbuffs ].map{ | _src_id, _pack_id, _data | [ [ _src_id, _pack_id, _data.bytesize ].pack( 'Q>Q>n' ), _data ].join }
507
477
 
508
478
  begin
509
- IO.binwrite( chunk_path, wbuffs.join )
479
+ IO.binwrite( chunk_path, datas.join )
510
480
  rescue Errno::ENOSPC => e
511
481
  puts "p#{ Process.pid } #{ Time.new } #{ e.class }, close tun"
512
482
  set_is_closing( @tun )
@@ -645,13 +615,13 @@ module Girl
645
615
  return if src_ext.nil? || src_ext[ :dst_port ].nil?
646
616
 
647
617
  if src_ext[ :is_dst_closed ]
648
- # puts "debug1 2-2. after close src -> dst closed ? yes -> del src ext -> send fin2"
618
+ # puts "debug1 2-3. after close src -> dst closed ? yes -> del src ext -> send fin2"
649
619
  del_src_ext( src_id )
650
620
  data = [ 0, FIN2, src_id ].pack( 'Q>CQ>' )
651
621
  add_tun_ctlmsg( data )
652
622
  else
653
623
  # puts "debug1 1-1. after close src -> dst closed ? no -> send fin1"
654
- data = [ 0, FIN1, src_id, src_ext[ :biggest_pack_id ], src_ext[ :continue_dst_pack_id ] ].pack( 'Q>CQ>Q>Q>' )
624
+ data = [ 0, FIN1, src_id, src_info[ :biggest_pack_id ], src_ext[ :continue_dst_pack_id ] ].pack( 'Q>CQ>Q>Q>' )
655
625
  add_tun_ctlmsg( data )
656
626
  end
657
627
  elsif src_info[ :proxy_type ] == :direct
@@ -768,19 +738,7 @@ module Girl
768
738
 
769
739
  if data.empty?
770
740
  if src_info[ :is_closing ]
771
- if @tun
772
- if @tun.closed?
773
- close_src( src )
774
- elsif @tun_info[ :paused ]
775
- @writes.delete( src )
776
- elsif !@writes.include?( @tun )
777
- # 转发光了,正式关闭
778
- # puts "debug2 close src after tun empty"
779
- close_src( src )
780
- end
781
- else
782
- close_src( src )
783
- end
741
+ close_src( src )
784
742
  else
785
743
  @writes.delete( src )
786
744
  end
@@ -911,7 +869,7 @@ module Girl
911
869
 
912
870
  # 取写前
913
871
  if @tun_info[ :caches ].any?
914
- src_id, data = @tun_info[ :caches ].first
872
+ src_id, pack_id, data = @tun_info[ :caches ].first
915
873
  from = :caches
916
874
  elsif @tun_info[ :chunks ].any?
917
875
  path = File.join( @tun_chunk_dir, @tun_info[ :chunks ].shift )
@@ -928,16 +886,16 @@ module Girl
928
886
  caches = []
929
887
 
930
888
  until data.empty?
931
- _src_id, pack_size = data[ 0, 10 ].unpack( 'Q>n' )
932
- caches << [ _src_id, data[ 10, pack_size ] ]
933
- data = data[ ( 10 + pack_size )..-1 ]
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 ]
934
892
  end
935
893
 
936
894
  @tun_info[ :caches ] = caches
937
- src_id, data = caches.first
895
+ src_id, pack_id, data = caches.first
938
896
  from = :caches
939
897
  elsif @tun_info[ :wbuffs ].any?
940
- src_id, data = @tun_info[ :wbuffs ].first
898
+ src_id, pack_id, data = @tun_info[ :wbuffs ].first
941
899
  from = :wbuffs
942
900
  else
943
901
  @writes.delete( tun )
@@ -947,8 +905,6 @@ module Girl
947
905
  src_ext = @tun_info[ :src_exts ][ src_id ]
948
906
 
949
907
  if src_ext
950
- pack_id = src_ext[ :biggest_pack_id ] + 1
951
-
952
908
  if pack_id <= CONFUSE_UNTIL
953
909
  data = @custom.encode( data )
954
910
  # puts "debug1 encoded pack #{ pack_id }"
@@ -963,7 +919,7 @@ module Girl
963
919
  end
964
920
 
965
921
  # puts "debug2 written pack #{ pack_id }"
966
- src_ext[ :biggest_pack_id ] = pack_id
922
+ src_ext[ :relay_pack_id ] = pack_id
967
923
  src_ext[ :wmems ][ pack_id ] = data
968
924
  src_ext[ :send_ats ][ pack_id ] = now
969
925
  src_ext[ :last_continue_at ] = now
@@ -999,7 +955,9 @@ module Girl
999
955
  dst: nil, # :direct的场合,对应的dst
1000
956
  destination_domain: nil, # 目的地域名
1001
957
  destination_port: nil, # 目的地端口
1002
- rbuffs: [], # 非CONNECT,dst或者远端dst未准备好,暂存流量
958
+ biggest_pack_id: 0, # 最大包号码
959
+ is_connect: true, # 代理协议是http的场合,是否是CONNECT
960
+ rbuffs: [], # 非CONNECT,dst或者远端dst未准备好,暂存流量 [ pack_id, data ]
1003
961
  wbuff: '', # 写前
1004
962
  cache: '', # 块读出缓存
1005
963
  chunks: [], # 块队列,写前达到块大小时结一个块 filename
@@ -1096,7 +1054,10 @@ module Girl
1096
1054
  end
1097
1055
  end
1098
1056
 
1099
- src_info[ :rbuffs ] << data
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 ]
1100
1061
  end
1101
1062
 
1102
1063
  domain, port = domain_and_port.split( ':' )
@@ -1109,7 +1070,9 @@ module Girl
1109
1070
  resolve_domain( src, domain )
1110
1071
  when :checking
1111
1072
  # puts "debug1 add src rbuff while checking #{ data.inspect }"
1112
- src_info[ :rbuffs ] << data
1073
+ pack_id = src_info[ :biggest_pack_id ] + 1
1074
+ src_info[ :biggest_pack_id ] = pack_id
1075
+ src_info[ :rbuffs ] << [ pack_id, data ]
1113
1076
  when :negotiation
1114
1077
  # +----+-----+-------+------+----------+----------+
1115
1078
  # |VER | CMD | RSV | ATYP | DST.ADDR | DST.PORT |
@@ -1156,6 +1119,9 @@ module Girl
1156
1119
  return
1157
1120
  end
1158
1121
 
1122
+ pack_id = src_info[ :biggest_pack_id ] + 1
1123
+ src_info[ :biggest_pack_id ] = pack_id
1124
+
1159
1125
  if src_ext[ :dst_port ]
1160
1126
  if @tun.closed?
1161
1127
  # puts "debug1 tun closed, close src"
@@ -1163,14 +1129,14 @@ module Girl
1163
1129
  return
1164
1130
  end
1165
1131
 
1166
- if src_info[ :rbuffs ].any?
1132
+ unless src_info[ :is_connect ]
1167
1133
  data, _ = sub_http_request( data )
1168
1134
  end
1169
1135
 
1170
- add_tun_wbuff( src_id, data )
1136
+ add_tun_wbuff( src_id, pack_id, data )
1171
1137
  else
1172
1138
  # puts "debug1 remote dst not ready, save data to src rbuff"
1173
- src_info[ :rbuffs ] << data
1139
+ src_info[ :rbuffs ] << [ pack_id, data ]
1174
1140
  end
1175
1141
  when :direct
1176
1142
  dst = src_info[ :dst ]
@@ -1182,14 +1148,14 @@ module Girl
1182
1148
  return
1183
1149
  end
1184
1150
 
1185
- if src_info[ :rbuffs ].any?
1151
+ unless src_info[ :is_connect ]
1186
1152
  data, _ = sub_http_request( data )
1187
1153
  end
1188
1154
 
1189
1155
  add_dst_wbuff( dst, data )
1190
1156
  else
1191
1157
  # puts "debug1 dst not ready, save data to src rbuff"
1192
- src_info[ :rbuffs ] << data
1158
+ src_info[ :rbuffs ] << [ nil, data ]
1193
1159
  end
1194
1160
  end
1195
1161
  end
@@ -1275,9 +1241,7 @@ module Girl
1275
1241
  src_info = @src_infos[ src ]
1276
1242
 
1277
1243
  if src_info[ :proxy_proto ] == :http
1278
- datas = src_info[ :rbuffs ]
1279
-
1280
- if datas.empty?
1244
+ if src_info[ :is_connect ]
1281
1245
  # CONNECT
1282
1246
  # puts "debug1 add src wbuff http ok"
1283
1247
  add_src_wbuff( src, HTTP_OK )
@@ -1285,8 +1249,8 @@ module Girl
1285
1249
  # not CONNECT
1286
1250
  # puts "debug1 add src rbuffs to tun wbuffs"
1287
1251
 
1288
- datas.each do | _data |
1289
- add_tun_wbuff( src_id, _data )
1252
+ src_info[ :rbuffs ].each do | pack_id, _data |
1253
+ add_tun_wbuff( src_id, pack_id, _data )
1290
1254
  end
1291
1255
  end
1292
1256
  elsif src_info[ :proxy_proto ] == :socks5
@@ -1295,7 +1259,7 @@ module Girl
1295
1259
  when DEST_STATUS
1296
1260
  return if from_addr != @tun_info[ :tund_addr ]
1297
1261
 
1298
- dst_port, biggest_dst_pack_id, continue_src_pack_id = data[ 9, 18 ].unpack( 'nQ>Q>' )
1262
+ dst_port, relay_dst_pack_id, continue_src_pack_id = data[ 9, 18 ].unpack( 'nQ>Q>' )
1299
1263
 
1300
1264
  src_id = @tun_info[ :src_ids ][ dst_port ]
1301
1265
  return unless src_id
@@ -1305,22 +1269,10 @@ module Girl
1305
1269
 
1306
1270
  # puts "debug2 got dest status"
1307
1271
 
1308
- # 更新对面发到几
1309
- if biggest_dst_pack_id > src_ext[ :biggest_dst_pack_id ]
1310
- # puts "debug2 update biggest dst pack #{ biggest_dst_pack_id }"
1311
- src_ext[ :biggest_dst_pack_id ] = biggest_dst_pack_id
1312
-
1313
- # 接到对面状态,若对面已关闭,且最后一个包已经进写前,关闭src
1314
- if src_ext[ :is_dst_closed ] && ( biggest_dst_pack_id == src_ext[ :continue_dst_pack_id ] )
1315
- # puts "debug1 2-1. recv traffic/fin1/dst status -> dst closed and all traffic received ? -> close src after write"
1316
- set_is_closing( src_ext[ :src ] )
1317
- end
1318
- end
1319
-
1320
1272
  release_wmems( src_ext, continue_src_pack_id )
1321
1273
 
1322
1274
  # 发miss
1323
- if !src_ext[ :src ].closed? && ( src_ext[ :continue_dst_pack_id ] < src_ext[ :biggest_dst_pack_id ] )
1275
+ if !src_ext[ :src ].closed? && ( src_ext[ :continue_dst_pack_id ] < relay_dst_pack_id )
1324
1276
  ranges = []
1325
1277
  curr_pack_id = src_ext[ :continue_dst_pack_id ] + 1
1326
1278
 
@@ -1332,12 +1284,12 @@ module Girl
1332
1284
  curr_pack_id = pack_id + 1
1333
1285
  end
1334
1286
 
1335
- if curr_pack_id <= src_ext[ :biggest_dst_pack_id ]
1336
- ranges << [ curr_pack_id, src_ext[ :biggest_dst_pack_id ] ]
1287
+ if curr_pack_id <= relay_dst_pack_id
1288
+ ranges << [ curr_pack_id, relay_dst_pack_id ]
1337
1289
  end
1338
1290
 
1339
1291
  pack_count = 0
1340
- # puts "debug1 continue/biggest #{ src_ext[ :continue_dst_pack_id ] }/#{ src_ext[ :biggest_dst_pack_id ] } send MISS #{ ranges.size }"
1292
+ # puts "debug1 continue/relay #{ src_ext[ :continue_dst_pack_id ] }/#{ relay_dst_pack_id } send MISS #{ ranges.size }"
1341
1293
 
1342
1294
  ranges.each do | pack_id_begin, pack_id_end |
1343
1295
  if pack_count >= BREAK_SEND_MISS
@@ -1386,7 +1338,7 @@ module Girl
1386
1338
 
1387
1339
  # 接到对面已关闭,若最后一个包已经进写前,关闭src
1388
1340
  if ( biggest_dst_pack_id == src_ext[ :continue_dst_pack_id ] )
1389
- # puts "debug1 2-1. recv fin1 -> set dst closed -> all traffic received ? -> close src after write"
1341
+ # puts "debug1 2-1. tun recv fin1 -> all traffic received ? -> close src after write"
1390
1342
  set_is_closing( src_ext[ :src ] )
1391
1343
  end
1392
1344
  when FIN2
@@ -1397,7 +1349,7 @@ module Girl
1397
1349
  src_id = @tun_info[ :src_ids ][ dst_port ]
1398
1350
  return unless src_id
1399
1351
 
1400
- # puts "debug1 1-2. recv fin2 -> del src ext"
1352
+ # puts "debug1 1-2. tun recv fin2 -> del src ext"
1401
1353
  del_src_ext( src_id )
1402
1354
  when TUND_FIN
1403
1355
  return if from_addr != @tun_info[ :tund_addr ]
@@ -1443,7 +1395,7 @@ module Girl
1443
1395
 
1444
1396
  # 接到流量,若对面已关闭,且流量正好收全,关闭src
1445
1397
  if src_ext[ :is_dst_closed ] && ( pack_id == src_ext[ :biggest_dst_pack_id ] )
1446
- # puts "debug1 2-1. recv traffic/fin1/dst status -> dst closed and all traffic received ? -> close src after write"
1398
+ # puts "debug1 2-2. tun recv traffic -> dst closed and all traffic received ? -> close src after write"
1447
1399
  set_is_closing( src_ext[ :src ] )
1448
1400
  end
1449
1401
  else