girl 0.58.0 → 0.61.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/lib/girl/proxy.rb +40 -36
- data/lib/girl/proxy_worker.rb +170 -98
- data/lib/girl/proxyd.rb +5 -5
- data/lib/girl/proxyd_worker.rb +42 -26
- data/lib/girl/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c43d66efd27844b45b294a58757f9048b73aec8722d3285a642bb03e02a70ba8
|
4
|
+
data.tar.gz: f79ac7e41ccda330001c63bce9b20f611ca388f8da374bdfd66fd5c3a773e3e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cead94f72a7167968a5f506d0a1d80e7cf01d95465be839c1e26b63ef69ae9aef044837ef4777a9d352f154a12a7776606ed89bd05650a6030e0c4e849fbc366
|
7
|
+
data.tar.gz: 70548cfa8185971f22a9f3f1b70e3efd867e3a76c0f430cf466b2af042ef8b5bad5078129dea7d55de4f92f949a7c707581c59e39c85b461e59395b84c0fc8ac
|
data/lib/girl/proxy.rb
CHANGED
@@ -99,7 +99,7 @@ module Girl
|
|
99
99
|
raise "not found direct file #{ direct_path }"
|
100
100
|
end
|
101
101
|
|
102
|
-
directs = ( RESERVED_ROUTE.split( "\n" ) + IO.binread( direct_path ).split( "\n" ) ).map { | line | IPAddr.new( line.strip ) }
|
102
|
+
directs = ( [ Addrinfo.ip( proxyd_host ).ip_address ] + RESERVED_ROUTE.split( "\n" ) + IO.binread( direct_path ).split( "\n" ) ).map { | line | IPAddr.new( line.strip ) }
|
103
103
|
end
|
104
104
|
|
105
105
|
remotes = []
|
@@ -151,47 +151,51 @@ module Girl
|
|
151
151
|
end
|
152
152
|
|
153
153
|
title = "girl proxy #{ Girl::VERSION }"
|
154
|
-
puts
|
155
|
-
puts "
|
156
|
-
puts "
|
157
|
-
puts "
|
158
|
-
puts "
|
159
|
-
puts "
|
160
|
-
puts "
|
161
|
-
puts "
|
162
|
-
puts "
|
163
|
-
puts "
|
164
|
-
puts "
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
154
|
+
puts title
|
155
|
+
puts "proxy port #{ proxy_port }"
|
156
|
+
puts "proxyd host #{ proxyd_host }"
|
157
|
+
puts "proxyd port #{ proxyd_port }"
|
158
|
+
puts "#{ direct_path } #{ directs.size } directs"
|
159
|
+
puts "#{ remote_path } #{ remotes.size } remotes"
|
160
|
+
puts "src chunk dir #{ src_chunk_dir }"
|
161
|
+
puts "dst chunk dir #{ dst_chunk_dir }"
|
162
|
+
puts "tun chunk dir #{ tun_chunk_dir }"
|
163
|
+
puts "im #{ im }"
|
164
|
+
puts "worker count #{ worker_count }"
|
165
|
+
|
166
|
+
if RUBY_PLATFORM.include?( 'linux' )
|
167
|
+
$0 = title
|
168
|
+
workers = []
|
169
|
+
|
170
|
+
worker_count.times do | i |
|
171
|
+
workers << fork do
|
172
|
+
$0 = 'girl proxy worker'
|
173
|
+
worker = Girl::ProxyWorker.new( proxy_port, proxyd_host, proxyd_port, directs, remotes, src_chunk_dir, dst_chunk_dir, tun_chunk_dir, im )
|
174
|
+
|
175
|
+
Signal.trap( :TERM ) do
|
176
|
+
puts "w#{ i } exit"
|
177
|
+
worker.quit!
|
178
|
+
end
|
179
|
+
|
180
|
+
worker.looping
|
177
181
|
end
|
178
|
-
|
179
|
-
worker.looping
|
180
182
|
end
|
181
|
-
end
|
182
183
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
184
|
+
Signal.trap( :TERM ) do
|
185
|
+
puts 'trap TERM'
|
186
|
+
workers.each do | pid |
|
187
|
+
begin
|
188
|
+
Process.kill( :TERM, pid )
|
189
|
+
rescue Errno::ESRCH => e
|
190
|
+
puts e.class
|
191
|
+
end
|
190
192
|
end
|
191
193
|
end
|
192
|
-
end
|
193
194
|
|
194
|
-
|
195
|
+
Process.waitall
|
196
|
+
else
|
197
|
+
Girl::ProxyWorker.new( proxy_port, proxyd_host, proxyd_port, directs, remotes, src_chunk_dir, dst_chunk_dir, tun_chunk_dir, im ).looping
|
198
|
+
end
|
195
199
|
end
|
196
200
|
|
197
201
|
end
|
data/lib/girl/proxy_worker.rb
CHANGED
@@ -78,12 +78,12 @@ module Girl
|
|
78
78
|
#
|
79
79
|
def quit!
|
80
80
|
if @tun && !@tun.closed? && @tun_info[ :tund_addr ]
|
81
|
-
puts "debug1 send tun fin"
|
81
|
+
# puts "debug1 send tun fin"
|
82
82
|
data = [ 0, TUN_FIN ].pack( 'Q>C' )
|
83
83
|
@tun.sendmsg( data, 0, @tun_info[ :tund_addr ] )
|
84
84
|
end
|
85
85
|
|
86
|
-
puts "debug1 exit"
|
86
|
+
# puts "debug1 exit"
|
87
87
|
exit
|
88
88
|
end
|
89
89
|
|
@@ -198,12 +198,12 @@ module Girl
|
|
198
198
|
Thread.new do
|
199
199
|
EXPIRE_NEW.times do
|
200
200
|
if src_ext[ :src ].closed? || src_ext[ :dst_port ]
|
201
|
-
puts "debug1 break loop send a new source #{ src_ext[ :dst_port ] }"
|
201
|
+
# puts "debug1 break loop send a new source #{ src_ext[ :dst_port ] }"
|
202
202
|
break
|
203
203
|
end
|
204
204
|
|
205
205
|
@mutex.synchronize do
|
206
|
-
puts "debug1 send a new source #{ data.inspect }"
|
206
|
+
# puts "debug1 send a new source #{ data.inspect }"
|
207
207
|
add_tun_ctlmsg( data )
|
208
208
|
next_tick
|
209
209
|
end
|
@@ -217,8 +217,14 @@ module Girl
|
|
217
217
|
# resolve domain
|
218
218
|
#
|
219
219
|
def resolve_domain( src, domain )
|
220
|
+
if ( /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\Z/ =~ domain ) && domain.split( '.' ).all? { | part | part.to_i < 256 }
|
221
|
+
# puts "debug1 #{ domain } is a ip"
|
222
|
+
deal_with_destination_ip( src, domain )
|
223
|
+
return
|
224
|
+
end
|
225
|
+
|
220
226
|
if @remotes.any? { | remote | ( domain.size >= remote.size ) && ( domain[ ( remote.size * -1 )..-1 ] == remote ) }
|
221
|
-
puts "debug1 #{ domain } hit remotes"
|
227
|
+
# puts "debug1 #{ domain } hit remotes"
|
222
228
|
new_a_src_ext( src )
|
223
229
|
return
|
224
230
|
end
|
@@ -229,15 +235,18 @@ module Girl
|
|
229
235
|
destination_ip, created_at = resolv_cache
|
230
236
|
|
231
237
|
if Time.new - created_at < RESOLV_CACHE_EXPIRE
|
232
|
-
puts "debug1 #{ domain } hit resolv cache #{ destination_ip }"
|
238
|
+
# puts "debug1 #{ domain } hit resolv cache #{ destination_ip }"
|
233
239
|
deal_with_destination_ip( src, destination_ip )
|
234
240
|
return
|
235
241
|
end
|
236
242
|
|
237
|
-
puts "debug1 expire #{ domain } resolv cache"
|
243
|
+
# puts "debug1 expire #{ domain } resolv cache"
|
238
244
|
@resolv_caches.delete( domain )
|
239
245
|
end
|
240
246
|
|
247
|
+
src_info = @src_infos[ src ]
|
248
|
+
src_info[ :proxy_type ] = :checking
|
249
|
+
|
241
250
|
Thread.new do
|
242
251
|
begin
|
243
252
|
ip_info = Addrinfo.ip( domain )
|
@@ -248,7 +257,7 @@ module Girl
|
|
248
257
|
@mutex.synchronize do
|
249
258
|
if ip_info
|
250
259
|
destination_ip = ip_info.ip_address
|
251
|
-
puts "debug1 resolved #{ domain } #{ destination_ip }"
|
260
|
+
# puts "debug1 resolved #{ domain } #{ destination_ip }"
|
252
261
|
@resolv_caches[ domain ] = [ destination_ip, Time.new ]
|
253
262
|
|
254
263
|
unless src.closed?
|
@@ -269,7 +278,7 @@ module Girl
|
|
269
278
|
def deal_with_destination_ip( src, destination_ip )
|
270
279
|
if @directs.any? { | direct | direct.include?( destination_ip ) }
|
271
280
|
# ip命中直连列表,直连
|
272
|
-
puts "debug1 #{ destination_ip } hit directs"
|
281
|
+
# puts "debug1 #{ destination_ip } hit directs"
|
273
282
|
new_a_dst( src, destination_ip )
|
274
283
|
else
|
275
284
|
# 走远端
|
@@ -283,8 +292,12 @@ module Girl
|
|
283
292
|
def new_a_proxy( proxy_port )
|
284
293
|
proxy = Socket.new( Socket::AF_INET, Socket::SOCK_STREAM, 0 )
|
285
294
|
proxy.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEADDR, 1 )
|
286
|
-
|
287
|
-
|
295
|
+
|
296
|
+
if RUBY_PLATFORM.include?( 'linux' )
|
297
|
+
proxy.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEPORT, 1 )
|
298
|
+
proxy.setsockopt( Socket::SOL_TCP, Socket::TCP_NODELAY, 1 )
|
299
|
+
end
|
300
|
+
|
288
301
|
proxy.bind( Socket.sockaddr_in( proxy_port, '0.0.0.0' ) )
|
289
302
|
proxy.listen( 511 )
|
290
303
|
puts "p#{ Process.pid } #{ Time.new } proxy listen on #{ proxy_port }"
|
@@ -323,7 +336,7 @@ module Girl
|
|
323
336
|
add_read( tun, :tun )
|
324
337
|
data = @custom.hello
|
325
338
|
puts "p#{ Process.pid } #{ Time.new } hello i'm tun"
|
326
|
-
puts "debug1 #{ data.inspect }"
|
339
|
+
# puts "debug1 #{ data.inspect }"
|
327
340
|
add_tun_ctlmsg( data, @proxyd_addr )
|
328
341
|
end
|
329
342
|
|
@@ -334,7 +347,10 @@ module Girl
|
|
334
347
|
src_info = @src_infos[ src ]
|
335
348
|
destination_addr = Socket.sockaddr_in( src_info[ :destination_port ], destination_ip )
|
336
349
|
dst = Socket.new( Socket::AF_INET, Socket::SOCK_STREAM, 0 )
|
337
|
-
|
350
|
+
|
351
|
+
if RUBY_PLATFORM.include?( 'linux' )
|
352
|
+
dst.setsockopt( Socket::SOL_TCP, Socket::TCP_NODELAY, 1 )
|
353
|
+
end
|
338
354
|
|
339
355
|
begin
|
340
356
|
dst.connect_nonblock( destination_addr )
|
@@ -346,7 +362,7 @@ module Girl
|
|
346
362
|
return
|
347
363
|
end
|
348
364
|
|
349
|
-
puts "debug1 a new dst #{ dst.local_address.inspect }"
|
365
|
+
# puts "debug1 a new dst #{ dst.local_address.inspect }"
|
350
366
|
local_port = dst.local_address.ip_unpack
|
351
367
|
@dsts[ local_port ] = dst
|
352
368
|
@dst_infos[ dst ] = {
|
@@ -369,12 +385,12 @@ module Girl
|
|
369
385
|
datas = src_info[ :rbuffs ]
|
370
386
|
|
371
387
|
if datas.empty?
|
372
|
-
#
|
373
|
-
puts "debug1 add src wbuff http ok"
|
388
|
+
# CONNECT
|
389
|
+
# puts "debug1 add src wbuff http ok"
|
374
390
|
add_src_wbuff( src, HTTP_OK )
|
375
391
|
else
|
376
|
-
#
|
377
|
-
puts "debug1 add src rbuffs to dst wbuff"
|
392
|
+
# not CONNECT
|
393
|
+
# puts "debug1 add src rbuffs to dst wbuff"
|
378
394
|
|
379
395
|
datas.each do | data |
|
380
396
|
add_dst_wbuff( dst, data )
|
@@ -430,10 +446,25 @@ module Girl
|
|
430
446
|
# +----+-----+-------+------+----------+----------+
|
431
447
|
proxy_ip, proxy_port = @proxy_local_address.ip_unpack
|
432
448
|
data = [ [ 5, 0, 0, 1 ].pack( 'C4' ), IPAddr.new( proxy_ip ).hton, [ proxy_port ].pack( 'n' ) ].join
|
433
|
-
puts "debug1 add src wbuff socks5 conn reply #{ data.inspect }"
|
449
|
+
# puts "debug1 add src wbuff socks5 conn reply #{ data.inspect }"
|
434
450
|
add_src_wbuff( src, data )
|
435
451
|
end
|
436
452
|
|
453
|
+
##
|
454
|
+
# sub http request
|
455
|
+
#
|
456
|
+
def sub_http_request( data )
|
457
|
+
method, url, proto = data.split( "\r\n" ).first.split( ' ' )
|
458
|
+
|
459
|
+
if proto && url && proto[ 0, 4 ] == 'HTTP' && url[ 0, 7 ] == 'http://'
|
460
|
+
domain_and_port = url.split( '/' )[ 2 ]
|
461
|
+
data = data.sub( "http://#{ domain_and_port }", '' )
|
462
|
+
# puts "debug1 subed #{ data.inspect } #{ domain_and_port }"
|
463
|
+
end
|
464
|
+
|
465
|
+
[ data, domain_and_port ]
|
466
|
+
end
|
467
|
+
|
437
468
|
##
|
438
469
|
# add tun ctlmsg
|
439
470
|
#
|
@@ -460,8 +491,16 @@ module Girl
|
|
460
491
|
spring = @tun_info[ :chunks ].size > 0 ? ( @tun_info[ :spring ] + 1 ) : 0
|
461
492
|
filename = "#{ Process.pid }-#{ @tun_info[ :port ] }.#{ spring }"
|
462
493
|
chunk_path = File.join( @tun_chunk_dir, filename )
|
463
|
-
wbuffs = @tun_info[ :wbuffs ].map{ | _src_addr, _data | [ _src_addr, _data.bytesize.pack( 'n' ), _data ].join }
|
464
|
-
|
494
|
+
wbuffs = @tun_info[ :wbuffs ].map{ | _src_addr, _data | [ _src_addr, [ _data.bytesize ].pack( 'n' ), _data ].join }
|
495
|
+
|
496
|
+
begin
|
497
|
+
IO.binwrite( chunk_path, wbuffs.join )
|
498
|
+
rescue Errno::ENOSPC => e
|
499
|
+
puts "p#{ Process.pid } #{ Time.new } #{ e.class }, close tun"
|
500
|
+
set_is_closing( @tun )
|
501
|
+
return
|
502
|
+
end
|
503
|
+
|
465
504
|
@tun_info[ :chunks ] << filename
|
466
505
|
@tun_info[ :spring ] = spring
|
467
506
|
@tun_info[ :wbuffs ].clear
|
@@ -481,7 +520,15 @@ module Girl
|
|
481
520
|
spring = src_info[ :chunks ].size > 0 ? ( src_info[ :spring ] + 1 ) : 0
|
482
521
|
filename = "#{ Process.pid }-#{ Addrinfo.new( src_info[ :src_addr ] ).ip_unpack.join( '-' ) }.#{ spring }"
|
483
522
|
chunk_path = File.join( @src_chunk_dir, filename )
|
484
|
-
|
523
|
+
|
524
|
+
begin
|
525
|
+
IO.binwrite( chunk_path, src_info[ :wbuff ] )
|
526
|
+
rescue Errno::ENOSPC => e
|
527
|
+
puts "p#{ Process.pid } #{ Time.new } #{ e.class }, close src"
|
528
|
+
set_is_closing( src )
|
529
|
+
return
|
530
|
+
end
|
531
|
+
|
485
532
|
src_info[ :chunks ] << filename
|
486
533
|
src_info[ :spring ] = spring
|
487
534
|
src_info[ :wbuff ].clear
|
@@ -501,7 +548,15 @@ module Girl
|
|
501
548
|
spring = dst_info[ :chunks ].size > 0 ? ( dst_info[ :spring ] + 1 ) : 0
|
502
549
|
filename = "#{ Process.pid }-#{ dst_info[ :local_port ] }.#{ spring }"
|
503
550
|
chunk_path = File.join( @dst_chunk_dir, filename )
|
504
|
-
|
551
|
+
|
552
|
+
begin
|
553
|
+
IO.binwrite( chunk_path, dst_info[ :wbuff ] )
|
554
|
+
rescue Errno::ENOSPC => e
|
555
|
+
puts "p#{ Process.pid } #{ Time.new } #{ e.class }, close dst"
|
556
|
+
set_is_closing( dst )
|
557
|
+
return
|
558
|
+
end
|
559
|
+
|
505
560
|
dst_info[ :chunks ] << filename
|
506
561
|
dst_info[ :spring ] = spring
|
507
562
|
dst_info[ :wbuff ].clear
|
@@ -536,7 +591,7 @@ module Girl
|
|
536
591
|
def set_is_closing( sock )
|
537
592
|
if sock && !sock.closed?
|
538
593
|
role = @roles[ sock ]
|
539
|
-
puts "debug1 set #{ role.to_s } is closing"
|
594
|
+
# puts "debug1 set #{ role.to_s } is closing"
|
540
595
|
|
541
596
|
case role
|
542
597
|
when :src
|
@@ -558,7 +613,7 @@ module Girl
|
|
558
613
|
# close src
|
559
614
|
#
|
560
615
|
def close_src( src )
|
561
|
-
puts "debug1 close src"
|
616
|
+
# puts "debug1 close src"
|
562
617
|
close_sock( src )
|
563
618
|
src_info = @src_infos.delete( src )
|
564
619
|
|
@@ -578,12 +633,12 @@ module Girl
|
|
578
633
|
return if src_ext.nil? || src_ext[ :dst_port ].nil?
|
579
634
|
|
580
635
|
if src_ext[ :is_dst_closed ]
|
581
|
-
puts "debug1 2-2. after close src -> dst closed ? yes -> del src ext -> send fin2"
|
636
|
+
# puts "debug1 2-2. after close src -> dst closed ? yes -> del src ext -> send fin2"
|
582
637
|
del_src_ext( src_addr )
|
583
638
|
data = [ [ 0, FIN2 ].pack( 'Q>C' ), src_addr ].join
|
584
639
|
add_tun_ctlmsg( data )
|
585
640
|
else
|
586
|
-
puts "debug1 1-1. after close src -> dst closed ? no -> send fin1"
|
641
|
+
# puts "debug1 1-1. after close src -> dst closed ? no -> send fin1"
|
587
642
|
data = [ [ 0, FIN1 ].pack( 'Q>C' ), src_addr, [ src_ext[ :biggest_pack_id ], src_ext[ :continue_dst_pack_id ] ].pack( 'Q>Q>' ) ].join
|
588
643
|
add_tun_ctlmsg( data )
|
589
644
|
end
|
@@ -596,7 +651,7 @@ module Girl
|
|
596
651
|
# close dst
|
597
652
|
#
|
598
653
|
def close_dst( dst )
|
599
|
-
puts "debug1 close dst"
|
654
|
+
# puts "debug1 close dst"
|
600
655
|
close_sock( dst )
|
601
656
|
dst_info = @dst_infos.delete( dst )
|
602
657
|
|
@@ -615,7 +670,7 @@ module Girl
|
|
615
670
|
# close tun
|
616
671
|
#
|
617
672
|
def close_tun( tun )
|
618
|
-
puts "debug1 close tun"
|
673
|
+
# puts "debug1 close tun"
|
619
674
|
close_sock( tun )
|
620
675
|
|
621
676
|
@tun_info[ :chunks ].each do | filename |
|
@@ -764,7 +819,7 @@ module Girl
|
|
764
819
|
rescue IO::WaitWritable, Errno::EINTR
|
765
820
|
return
|
766
821
|
rescue Exception => e
|
767
|
-
puts "debug1 write dst #{ e.class }"
|
822
|
+
# puts "debug1 write dst #{ e.class }"
|
768
823
|
close_dst( dst )
|
769
824
|
return
|
770
825
|
end
|
@@ -873,7 +928,7 @@ module Girl
|
|
873
928
|
|
874
929
|
if pack_id <= CONFUSE_UNTIL
|
875
930
|
data = @custom.encode( data )
|
876
|
-
puts "debug1 encoded pack #{ pack_id }"
|
931
|
+
# puts "debug1 encoded pack #{ pack_id }"
|
877
932
|
end
|
878
933
|
|
879
934
|
data = [ [ pack_id ].pack( 'Q>' ), src_addr, data ].join
|
@@ -911,12 +966,12 @@ module Girl
|
|
911
966
|
return
|
912
967
|
end
|
913
968
|
|
914
|
-
puts "debug1 accept a src #{ addrinfo.inspect }"
|
969
|
+
# puts "debug1 accept a src #{ addrinfo.inspect }"
|
915
970
|
src_addr = addrinfo.to_sockaddr
|
916
971
|
@src_infos[ src ] = {
|
917
972
|
src_addr: src_addr, # src地址
|
918
|
-
proxy_proto: :
|
919
|
-
proxy_type: :
|
973
|
+
proxy_proto: :uncheck, # :uncheck / :http / :socks5
|
974
|
+
proxy_type: :uncheck, # :uncheck / :checking / :direct / :tunnel / :negotiation
|
920
975
|
dst: nil, # :direct的场合,对应的dst
|
921
976
|
destination_domain: nil, # 目的地域名
|
922
977
|
destination_port: nil, # 目的地端口
|
@@ -942,7 +997,7 @@ module Girl
|
|
942
997
|
rescue IO::WaitReadable, Errno::EINTR
|
943
998
|
return
|
944
999
|
rescue Exception => e
|
945
|
-
puts "debug1 read src #{ e.class }"
|
1000
|
+
# puts "debug1 read src #{ e.class }"
|
946
1001
|
set_is_closing( src )
|
947
1002
|
return
|
948
1003
|
end
|
@@ -953,74 +1008,83 @@ module Girl
|
|
953
1008
|
proxy_type = src_info[ :proxy_type ]
|
954
1009
|
|
955
1010
|
case proxy_type
|
956
|
-
when :
|
1011
|
+
when :uncheck
|
957
1012
|
if data[ 0, 7 ] == 'CONNECT'
|
958
|
-
puts "debug1
|
1013
|
+
# puts "debug1 CONNECT"
|
1014
|
+
domain_and_port = data.split( "\r\n" )[ 0 ].split( ' ' )[ 1 ]
|
1015
|
+
elsif data[ 0 ].unpack( 'C' ).first == 5
|
1016
|
+
# puts "debug1 socks5 #{ data.inspect }"
|
959
1017
|
|
960
|
-
connect_to = data.split( "\r\n" )[ 0 ].split( ' ' )[ 1 ]
|
961
|
-
domain, port = connect_to.split( ':' )
|
962
|
-
port = port.to_i
|
963
|
-
else
|
964
1018
|
# https://tools.ietf.org/html/rfc1928
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
set_is_closing( src )
|
978
|
-
return
|
979
|
-
end
|
980
|
-
|
981
|
-
# +----+--------+
|
982
|
-
# |VER | METHOD |
|
983
|
-
# +----+--------+
|
984
|
-
# | 1 | 1 |
|
985
|
-
# +----+--------+
|
986
|
-
data2 = [ 5, 0 ].pack( 'CC' )
|
987
|
-
add_src_wbuff( src, data2 )
|
988
|
-
|
989
|
-
src_info[ :proxy_proto ] = :socks5
|
990
|
-
src_info[ :proxy_type ] = :negotiation
|
1019
|
+
#
|
1020
|
+
# +----+----------+----------+
|
1021
|
+
# |VER | NMETHODS | METHODS |
|
1022
|
+
# +----+----------+----------+
|
1023
|
+
# | 1 | 1 | 1 to 255 |
|
1024
|
+
# +----+----------+----------+
|
1025
|
+
nmethods = data[ 1 ].unpack( 'C' ).first
|
1026
|
+
methods = data[ 2, nmethods ].unpack( 'C*' )
|
1027
|
+
|
1028
|
+
unless methods.include?( 0 )
|
1029
|
+
puts "p#{ Process.pid } #{ Time.new } miss method 00"
|
1030
|
+
set_is_closing( src )
|
991
1031
|
return
|
992
1032
|
end
|
993
1033
|
|
994
|
-
|
995
|
-
|
1034
|
+
# +----+--------+
|
1035
|
+
# |VER | METHOD |
|
1036
|
+
# +----+--------+
|
1037
|
+
# | 1 | 1 |
|
1038
|
+
# +----+--------+
|
1039
|
+
data2 = [ 5, 0 ].pack( 'CC' )
|
1040
|
+
add_src_wbuff( src, data2 )
|
996
1041
|
|
997
|
-
|
998
|
-
|
1042
|
+
src_info[ :proxy_proto ] = :socks5
|
1043
|
+
src_info[ :proxy_type ] = :negotiation
|
1044
|
+
|
1045
|
+
return
|
1046
|
+
else
|
1047
|
+
# puts "debug1 not CONNECT #{ data.inspect }"
|
1048
|
+
host_line = data.split( "\r\n" ).find { | _line | _line[ 0, 6 ] == 'Host: ' }
|
1049
|
+
|
1050
|
+
unless host_line
|
1051
|
+
# puts "debug1 not found host line"
|
999
1052
|
set_is_closing( src )
|
1000
1053
|
return
|
1001
1054
|
end
|
1002
1055
|
|
1003
|
-
|
1004
|
-
|
1056
|
+
data, domain_and_port = sub_http_request( data )
|
1057
|
+
|
1058
|
+
unless domain_and_port
|
1059
|
+
# puts "debug1 not HTTP"
|
1060
|
+
domain_and_port = host_line.split( ' ' )[ 1 ]
|
1061
|
+
end
|
1062
|
+
|
1005
1063
|
src_info[ :rbuffs ] << data
|
1006
1064
|
end
|
1007
1065
|
|
1066
|
+
domain, port = domain_and_port.split( ':' )
|
1067
|
+
port = port ? port.to_i : 80
|
1068
|
+
|
1008
1069
|
src_info[ :proxy_proto ] = :http
|
1009
1070
|
src_info[ :destination_domain ] = domain
|
1010
1071
|
src_info[ :destination_port ] = port
|
1011
1072
|
|
1012
1073
|
resolve_domain( src, domain )
|
1074
|
+
when :checking
|
1075
|
+
# puts "debug1 add src rbuff while checking #{ data.inspect }"
|
1076
|
+
src_info[ :rbuffs ] << data
|
1013
1077
|
when :negotiation
|
1014
1078
|
# +----+-----+-------+------+----------+----------+
|
1015
1079
|
# |VER | CMD | RSV | ATYP | DST.ADDR | DST.PORT |
|
1016
1080
|
# +----+-----+-------+------+----------+----------+
|
1017
1081
|
# | 1 | 1 | X'00' | 1 | Variable | 2 |
|
1018
1082
|
# +----+-----+-------+------+----------+----------+
|
1019
|
-
puts "debug1 negotiation #{ data.inspect }"
|
1083
|
+
# puts "debug1 negotiation #{ data.inspect }"
|
1020
1084
|
ver, cmd, rsv, atyp = data[ 0, 4 ].unpack( 'C4' )
|
1021
1085
|
|
1022
1086
|
if cmd == 1
|
1023
|
-
puts "debug1 socks5 CONNECT"
|
1087
|
+
# puts "debug1 socks5 CONNECT"
|
1024
1088
|
|
1025
1089
|
if atyp == 1
|
1026
1090
|
destination_host, destination_port = data[ 4, 6 ].unpack( 'Nn' )
|
@@ -1029,7 +1093,7 @@ module Girl
|
|
1029
1093
|
destination_ip = destination_addrinfo.ip_address
|
1030
1094
|
src_info[ :destination_domain ] = destination_ip
|
1031
1095
|
src_info[ :destination_port ] = destination_port
|
1032
|
-
puts "debug1 IP V4 address #{ destination_addrinfo.inspect }"
|
1096
|
+
# puts "debug1 IP V4 address #{ destination_addrinfo.inspect }"
|
1033
1097
|
deal_with_destination_ip( src, destination_ip )
|
1034
1098
|
elsif atyp == 3
|
1035
1099
|
domain_len = data[ 4 ].unpack( 'C' ).first
|
@@ -1039,33 +1103,37 @@ module Girl
|
|
1039
1103
|
port = data[ ( 5 + domain_len ), 2 ].unpack( 'n' ).first
|
1040
1104
|
src_info[ :destination_domain ] = domain
|
1041
1105
|
src_info[ :destination_port ] = port
|
1042
|
-
puts "debug1 DOMAINNAME #{ domain } #{ port }"
|
1106
|
+
# puts "debug1 DOMAINNAME #{ domain } #{ port }"
|
1043
1107
|
resolve_domain( src, domain )
|
1044
1108
|
end
|
1045
1109
|
end
|
1046
1110
|
else
|
1047
|
-
puts "
|
1111
|
+
puts "p#{ Process.pid } #{ Time.new } socks5 cmd #{ cmd } not implement"
|
1048
1112
|
end
|
1049
1113
|
when :tunnel
|
1050
1114
|
src_addr = src_info[ :src_addr ]
|
1051
1115
|
src_ext = @tun_info[ :src_exts ][ src_addr ]
|
1052
1116
|
|
1053
1117
|
unless src_ext
|
1054
|
-
puts "debug1 not found src ext"
|
1118
|
+
# puts "debug1 not found src ext"
|
1055
1119
|
set_is_closing( src )
|
1056
1120
|
return
|
1057
1121
|
end
|
1058
1122
|
|
1059
1123
|
if src_ext[ :dst_port ]
|
1060
1124
|
if @tun.closed?
|
1061
|
-
puts "debug1 tun closed, close src"
|
1125
|
+
# puts "debug1 tun closed, close src"
|
1062
1126
|
set_is_closing( src )
|
1063
1127
|
return
|
1064
1128
|
end
|
1065
1129
|
|
1130
|
+
if src_info[ :rbuffs ].any?
|
1131
|
+
data, _ = sub_http_request( data )
|
1132
|
+
end
|
1133
|
+
|
1066
1134
|
add_tun_wbuff( src_addr, data )
|
1067
1135
|
else
|
1068
|
-
puts "debug1 remote dst not ready, save data to src rbuff"
|
1136
|
+
# puts "debug1 remote dst not ready, save data to src rbuff"
|
1069
1137
|
src_info[ :rbuffs ] << data
|
1070
1138
|
end
|
1071
1139
|
when :direct
|
@@ -1073,14 +1141,18 @@ module Girl
|
|
1073
1141
|
|
1074
1142
|
if dst
|
1075
1143
|
if dst.closed?
|
1076
|
-
puts "debug1 dst closed, close src"
|
1144
|
+
# puts "debug1 dst closed, close src"
|
1077
1145
|
set_is_closing( src )
|
1078
1146
|
return
|
1079
1147
|
end
|
1080
1148
|
|
1149
|
+
if src_info[ :rbuffs ].any?
|
1150
|
+
data, _ = sub_http_request( data )
|
1151
|
+
end
|
1152
|
+
|
1081
1153
|
add_dst_wbuff( dst, data )
|
1082
1154
|
else
|
1083
|
-
puts "debug1 dst not ready, save data to src rbuff"
|
1155
|
+
# puts "debug1 dst not ready, save data to src rbuff"
|
1084
1156
|
src_info[ :rbuffs ] << data
|
1085
1157
|
end
|
1086
1158
|
end
|
@@ -1095,7 +1167,7 @@ module Girl
|
|
1095
1167
|
rescue IO::WaitReadable, Errno::EINTR
|
1096
1168
|
return
|
1097
1169
|
rescue Exception => e
|
1098
|
-
puts "debug1 read dst #{ e.class }"
|
1170
|
+
# puts "debug1 read dst #{ e.class }"
|
1099
1171
|
set_is_closing( dst )
|
1100
1172
|
return
|
1101
1173
|
end
|
@@ -1133,12 +1205,12 @@ module Girl
|
|
1133
1205
|
@tun_info[ :last_recv_at ] = now
|
1134
1206
|
tund_port = data[ 9, 2 ].unpack( 'n' ).first
|
1135
1207
|
|
1136
|
-
puts "debug1 got tund port #{ tund_port }"
|
1208
|
+
# puts "debug1 got tund port #{ tund_port }"
|
1137
1209
|
tund_addr = Socket.sockaddr_in( tund_port, @proxyd_host )
|
1138
1210
|
@tun_info[ :tund_addr ] = tund_addr
|
1139
1211
|
|
1140
1212
|
if @tun_info[ :ctlmsg_rbuffs ].any?
|
1141
|
-
puts "debug1 move #{ @tun_info[ :ctlmsg_rbuffs ].size } ctlmsg rbuffs to ctlmsgs"
|
1213
|
+
# puts "debug1 move #{ @tun_info[ :ctlmsg_rbuffs ].size } ctlmsg rbuffs to ctlmsgs"
|
1142
1214
|
@tun_info[ :ctlmsgs ] += @tun_info[ :ctlmsg_rbuffs ].map{ | _data | [ tund_addr, _data ] }
|
1143
1215
|
@tun_info[ :ctlmsg_rbuffs ].clear
|
1144
1216
|
add_write( tun )
|
@@ -1157,7 +1229,7 @@ module Girl
|
|
1157
1229
|
|
1158
1230
|
@tun_info[ :last_recv_at ] = now
|
1159
1231
|
|
1160
|
-
puts "debug1 got paired #{ Addrinfo.new( src_addr ).inspect } #{ dst_port }"
|
1232
|
+
# puts "debug1 got paired #{ Addrinfo.new( src_addr ).inspect } #{ dst_port }"
|
1161
1233
|
|
1162
1234
|
if dst_port == 0
|
1163
1235
|
set_is_closing( src )
|
@@ -1173,12 +1245,12 @@ module Girl
|
|
1173
1245
|
datas = src_info[ :rbuffs ]
|
1174
1246
|
|
1175
1247
|
if datas.empty?
|
1176
|
-
#
|
1177
|
-
puts "debug1 add src wbuff http ok"
|
1248
|
+
# CONNECT
|
1249
|
+
# puts "debug1 add src wbuff http ok"
|
1178
1250
|
add_src_wbuff( src, HTTP_OK )
|
1179
1251
|
else
|
1180
|
-
#
|
1181
|
-
puts "debug1 add src rbuffs to tun wbuffs"
|
1252
|
+
# not CONNECT
|
1253
|
+
# puts "debug1 add src rbuffs to tun wbuffs"
|
1182
1254
|
|
1183
1255
|
datas.each do | _data |
|
1184
1256
|
add_tun_wbuff( src_addr, _data )
|
@@ -1208,7 +1280,7 @@ module Girl
|
|
1208
1280
|
|
1209
1281
|
# 接到对面状态,若对面已关闭,且最后一个包已经进写前,关闭src
|
1210
1282
|
if src_ext[ :is_dst_closed ] && ( biggest_dst_pack_id == src_ext[ :continue_dst_pack_id ] )
|
1211
|
-
puts "debug1 2-1. recv traffic/fin1/dst status -> dst closed and all traffic received ? -> close src after write"
|
1283
|
+
# puts "debug1 2-1. recv traffic/fin1/dst status -> dst closed and all traffic received ? -> close src after write"
|
1212
1284
|
set_is_closing( src_ext[ :src ] )
|
1213
1285
|
end
|
1214
1286
|
end
|
@@ -1233,7 +1305,7 @@ module Girl
|
|
1233
1305
|
end
|
1234
1306
|
|
1235
1307
|
pack_count = 0
|
1236
|
-
puts "debug1 continue/biggest #{ src_ext[ :continue_dst_pack_id ] }/#{ src_ext[ :biggest_dst_pack_id ] } send MISS #{ ranges.size }"
|
1308
|
+
# puts "debug1 continue/biggest #{ src_ext[ :continue_dst_pack_id ] }/#{ src_ext[ :biggest_dst_pack_id ] } send MISS #{ ranges.size }"
|
1237
1309
|
|
1238
1310
|
ranges.each do | pack_id_begin, pack_id_end |
|
1239
1311
|
if pack_count >= BREAK_SEND_MISS
|
@@ -1280,14 +1352,14 @@ module Girl
|
|
1280
1352
|
|
1281
1353
|
@tun_info[ :last_recv_at ] = now
|
1282
1354
|
|
1283
|
-
puts "debug1 got fin1 #{ dst_port } biggest dst pack #{ biggest_dst_pack_id } completed src pack #{ continue_src_pack_id }"
|
1355
|
+
# puts "debug1 got fin1 #{ dst_port } biggest dst pack #{ biggest_dst_pack_id } completed src pack #{ continue_src_pack_id }"
|
1284
1356
|
src_ext[ :is_dst_closed ] = true
|
1285
1357
|
src_ext[ :biggest_dst_pack_id ] = biggest_dst_pack_id
|
1286
1358
|
release_wmems( src_ext, continue_src_pack_id )
|
1287
1359
|
|
1288
1360
|
# 接到对面已关闭,若最后一个包已经进写前,关闭src
|
1289
1361
|
if ( biggest_dst_pack_id == src_ext[ :continue_dst_pack_id ] )
|
1290
|
-
puts "debug1 2-1. recv fin1 -> set dst closed -> all traffic received ? -> close src after write"
|
1362
|
+
# puts "debug1 2-1. recv fin1 -> set dst closed -> all traffic received ? -> close src after write"
|
1291
1363
|
set_is_closing( src_ext[ :src ] )
|
1292
1364
|
end
|
1293
1365
|
when FIN2
|
@@ -1300,7 +1372,7 @@ module Girl
|
|
1300
1372
|
|
1301
1373
|
@tun_info[ :last_recv_at ] = now
|
1302
1374
|
|
1303
|
-
puts "debug1 1-2. recv fin2 -> del src ext"
|
1375
|
+
# puts "debug1 1-2. recv fin2 -> del src ext"
|
1304
1376
|
del_src_ext( src_addr )
|
1305
1377
|
when TUND_FIN
|
1306
1378
|
return if from_addr != @tun_info[ :tund_addr ]
|
@@ -1333,7 +1405,7 @@ module Girl
|
|
1333
1405
|
if pack_id <= CONFUSE_UNTIL
|
1334
1406
|
# puts "debug2 #{ data.inspect }"
|
1335
1407
|
data = @custom.decode( data )
|
1336
|
-
puts "debug1 decoded pack #{ pack_id }"
|
1408
|
+
# puts "debug1 decoded pack #{ pack_id }"
|
1337
1409
|
end
|
1338
1410
|
|
1339
1411
|
# 放进写前,跳号放碎片缓存
|
@@ -1350,7 +1422,7 @@ module Girl
|
|
1350
1422
|
|
1351
1423
|
# 接到流量,若对面已关闭,且流量正好收全,关闭src
|
1352
1424
|
if src_ext[ :is_dst_closed ] && ( pack_id == src_ext[ :biggest_dst_pack_id ] )
|
1353
|
-
puts "debug1 2-1. recv traffic/fin1/dst status -> dst closed and all traffic received ? -> close src after write"
|
1425
|
+
# puts "debug1 2-1. recv traffic/fin1/dst status -> dst closed and all traffic received ? -> close src after write"
|
1354
1426
|
set_is_closing( src_ext[ :src ] )
|
1355
1427
|
end
|
1356
1428
|
else
|
data/lib/girl/proxyd.rb
CHANGED
@@ -67,11 +67,11 @@ module Girl
|
|
67
67
|
end
|
68
68
|
|
69
69
|
title = "girl proxyd #{ Girl::VERSION }"
|
70
|
-
puts
|
71
|
-
puts "
|
72
|
-
puts "
|
73
|
-
puts "
|
74
|
-
puts "
|
70
|
+
puts title
|
71
|
+
puts "proxyd port #{ proxyd_port }"
|
72
|
+
puts "dst chunk dir #{ dst_chunk_dir }"
|
73
|
+
puts "tund chunk dir #{ tund_chunk_dir }"
|
74
|
+
puts "worker count #{ worker_count }"
|
75
75
|
|
76
76
|
$0 = title
|
77
77
|
workers = []
|
data/lib/girl/proxyd_worker.rb
CHANGED
@@ -75,12 +75,12 @@ module Girl
|
|
75
75
|
|
76
76
|
@tund_infos.each do | tund, tund_info |
|
77
77
|
if !tund.closed? && tund_info[ :tun_addr ]
|
78
|
-
puts "debug1 send tund fin"
|
78
|
+
# puts "debug1 send tund fin"
|
79
79
|
tund.sendmsg( data, 0, tund_info[ :tun_addr ] )
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
puts "debug1 exit"
|
83
|
+
# puts "debug1 exit"
|
84
84
|
exit
|
85
85
|
end
|
86
86
|
|
@@ -190,12 +190,12 @@ module Girl
|
|
190
190
|
destination_addr, created_at = resolv_cache
|
191
191
|
|
192
192
|
if Time.new - created_at < RESOLV_CACHE_EXPIRE
|
193
|
-
puts "debug1 #{ destination_domain_port } hit resolv cache #{ Addrinfo.new( destination_addr ).inspect }"
|
193
|
+
# puts "debug1 #{ destination_domain_port } hit resolv cache #{ Addrinfo.new( destination_addr ).inspect }"
|
194
194
|
deal_with_destination_addr( tund, src_addr, destination_addr )
|
195
195
|
return
|
196
196
|
end
|
197
197
|
|
198
|
-
puts "debug1 expire #{ destination_domain_port } resolv cache"
|
198
|
+
# puts "debug1 expire #{ destination_domain_port } resolv cache"
|
199
199
|
@resolv_caches.delete( destination_domain_port )
|
200
200
|
end
|
201
201
|
|
@@ -211,7 +211,7 @@ module Girl
|
|
211
211
|
|
212
212
|
@mutex.synchronize do
|
213
213
|
if destination_addr
|
214
|
-
puts "debug1 resolved #{ destination_domain_port } #{ Addrinfo.new( destination_addr ).inspect }"
|
214
|
+
# puts "debug1 resolved #{ destination_domain_port } #{ Addrinfo.new( destination_addr ).inspect }"
|
215
215
|
@resolv_caches[ destination_domain_port ] = [ destination_addr, Time.new ]
|
216
216
|
|
217
217
|
unless tund.closed?
|
@@ -271,7 +271,7 @@ module Girl
|
|
271
271
|
}
|
272
272
|
|
273
273
|
data = [ [ 0, PAIRED ].pack( 'Q>C' ), src_addr, [ local_port ].pack( 'n' ) ].join
|
274
|
-
puts "debug1 add ctlmsg paired #{ data.inspect }"
|
274
|
+
# puts "debug1 add ctlmsg paired #{ data.inspect }"
|
275
275
|
add_tund_ctlmsg( tund, data )
|
276
276
|
|
277
277
|
true
|
@@ -320,7 +320,15 @@ module Girl
|
|
320
320
|
filename = "#{ Process.pid }-#{ tund_info[ :port ] }.#{ spring }"
|
321
321
|
chunk_path = File.join( @tund_chunk_dir, filename )
|
322
322
|
wbuffs = tund_info[ :wbuffs ].map{ | _dst_local_port, _data | [ [ _dst_local_port, _data.bytesize ].pack( 'nn' ), _data ].join }
|
323
|
-
|
323
|
+
|
324
|
+
begin
|
325
|
+
IO.binwrite( chunk_path, wbuffs.join )
|
326
|
+
rescue Errno::ENOSPC => e
|
327
|
+
puts "p#{ Process.pid } #{ Time.new } #{ e.class }, close tund"
|
328
|
+
set_is_closing( tund )
|
329
|
+
return
|
330
|
+
end
|
331
|
+
|
324
332
|
tund_info[ :chunks ] << filename
|
325
333
|
tund_info[ :spring ] = spring
|
326
334
|
tund_info[ :wbuffs ].clear
|
@@ -340,7 +348,15 @@ module Girl
|
|
340
348
|
spring = dst_info[ :chunks ].size > 0 ? ( dst_info[ :spring ] + 1 ) : 0
|
341
349
|
filename = "#{ Process.pid }-#{ dst_info[ :local_port ] }.#{ spring }"
|
342
350
|
chunk_path = File.join( @dst_chunk_dir, filename )
|
343
|
-
|
351
|
+
|
352
|
+
begin
|
353
|
+
IO.binwrite( chunk_path, dst_info[ :wbuff ] )
|
354
|
+
rescue Errno::ENOSPC => e
|
355
|
+
puts "p#{ Process.pid } #{ Time.new } #{ e.class }, close dst"
|
356
|
+
set_is_closing( dst )
|
357
|
+
return
|
358
|
+
end
|
359
|
+
|
344
360
|
dst_info[ :chunks ] << filename
|
345
361
|
dst_info[ :spring ] = spring
|
346
362
|
dst_info[ :wbuff ].clear
|
@@ -375,7 +391,7 @@ module Girl
|
|
375
391
|
def set_is_closing( sock )
|
376
392
|
if sock && !sock.closed?
|
377
393
|
role = @roles[ sock ]
|
378
|
-
puts "debug1 set #{ role.to_s } is closing"
|
394
|
+
# puts "debug1 set #{ role.to_s } is closing"
|
379
395
|
|
380
396
|
case role
|
381
397
|
when :dst
|
@@ -395,7 +411,7 @@ module Girl
|
|
395
411
|
# close dst
|
396
412
|
#
|
397
413
|
def close_dst( dst )
|
398
|
-
puts "debug1 close dst"
|
414
|
+
# puts "debug1 close dst"
|
399
415
|
close_sock( dst )
|
400
416
|
dst_info = @dst_infos.delete( dst )
|
401
417
|
|
@@ -415,12 +431,12 @@ module Girl
|
|
415
431
|
return unless dst_ext
|
416
432
|
|
417
433
|
if dst_ext[ :is_src_closed ]
|
418
|
-
puts "debug1 2-2. after close dst -> src closed ? yes -> del dst ext -> send fin2"
|
434
|
+
# puts "debug1 2-2. after close dst -> src closed ? yes -> del dst ext -> send fin2"
|
419
435
|
del_dst_ext( tund, local_port )
|
420
436
|
data = [ 0, FIN2, local_port ].pack( 'Q>Cn' )
|
421
437
|
add_tund_ctlmsg( tund, data )
|
422
438
|
else
|
423
|
-
puts "debug1 1-1. after close dst -> src closed ? no -> send fin1"
|
439
|
+
# puts "debug1 1-1. after close dst -> src closed ? no -> send fin1"
|
424
440
|
data = [ 0, FIN1, local_port, dst_ext[ :biggest_pack_id ], dst_ext[ :continue_src_pack_id ] ].pack( 'Q>CnQ>Q>' )
|
425
441
|
add_tund_ctlmsg( tund, data )
|
426
442
|
end
|
@@ -430,7 +446,7 @@ module Girl
|
|
430
446
|
# close tun
|
431
447
|
#
|
432
448
|
def close_tund( tund )
|
433
|
-
puts "debug1 close tund"
|
449
|
+
# puts "debug1 close tund"
|
434
450
|
close_sock( tund )
|
435
451
|
|
436
452
|
tund_info = @tund_infos.delete( tund )
|
@@ -553,7 +569,7 @@ module Girl
|
|
553
569
|
rescue IO::WaitWritable, Errno::EINTR
|
554
570
|
return
|
555
571
|
rescue Exception => e
|
556
|
-
puts "debug1 write dst #{ e.class }"
|
572
|
+
# puts "debug1 write dst #{ e.class }"
|
557
573
|
close_dst( dst )
|
558
574
|
return
|
559
575
|
end
|
@@ -661,7 +677,7 @@ module Girl
|
|
661
677
|
|
662
678
|
if pack_id <= CONFUSE_UNTIL
|
663
679
|
data = @custom.encode( data )
|
664
|
-
puts "debug1 encoded pack #{ pack_id }"
|
680
|
+
# puts "debug1 encoded pack #{ pack_id }"
|
665
681
|
end
|
666
682
|
|
667
683
|
data = [ [ pack_id, dst_local_port ].pack( 'Q>n' ), data ].join
|
@@ -746,7 +762,7 @@ module Girl
|
|
746
762
|
rescue IO::WaitReadable, Errno::EINTR
|
747
763
|
return
|
748
764
|
rescue Exception => e
|
749
|
-
puts "debug1 read dst #{ e.class }"
|
765
|
+
# puts "debug1 read dst #{ e.class }"
|
750
766
|
set_is_closing( dst )
|
751
767
|
return
|
752
768
|
end
|
@@ -789,7 +805,7 @@ module Girl
|
|
789
805
|
when A_NEW_SOURCE
|
790
806
|
src_addr = data[ 9, 16 ]
|
791
807
|
dst_local_port = tund_info[ :dst_local_ports ][ src_addr ]
|
792
|
-
puts "debug1 got a new source #{ Addrinfo.new( src_addr ).inspect }"
|
808
|
+
# puts "debug1 got a new source #{ Addrinfo.new( src_addr ).inspect }"
|
793
809
|
|
794
810
|
if dst_local_port
|
795
811
|
dst_ext = tund_info[ :dst_exts ][ dst_local_port ]
|
@@ -799,7 +815,7 @@ module Girl
|
|
799
815
|
dst_local_port = 0
|
800
816
|
end
|
801
817
|
|
802
|
-
puts "debug1 readd ctlmsg paired #{ dst_local_port }"
|
818
|
+
# puts "debug1 readd ctlmsg paired #{ dst_local_port }"
|
803
819
|
data2 = [ [ 0, PAIRED ].pack( 'Q>C' ), src_addr, [ dst_local_port ].pack( 'n' ) ].join
|
804
820
|
add_tund_ctlmsg( tund, data2 )
|
805
821
|
return
|
@@ -808,7 +824,7 @@ module Girl
|
|
808
824
|
tund_info[ :last_recv_at ] = now
|
809
825
|
|
810
826
|
data = data[ 25..-1 ]
|
811
|
-
puts "debug1 #{ data }"
|
827
|
+
# puts "debug1 #{ data }"
|
812
828
|
destination_domain_port = @custom.decode( data )
|
813
829
|
resolve_domain( tund, src_addr, destination_domain_port )
|
814
830
|
when SOURCE_STATUS
|
@@ -831,7 +847,7 @@ module Girl
|
|
831
847
|
|
832
848
|
# 接到对面状态,若对面已关闭,且最后一个包已经进写前,关闭dst
|
833
849
|
if dst_ext[ :is_src_closed ] && ( biggest_src_pack_id == dst_ext[ :continue_src_pack_id ] )
|
834
|
-
puts "debug1 2-1. recv traffic/fin1/src status -> src closed and all traffic received ? -> close dst after write"
|
850
|
+
# puts "debug1 2-1. recv traffic/fin1/src status -> src closed and all traffic received ? -> close dst after write"
|
835
851
|
set_is_closing( dst_ext[ :dst ] )
|
836
852
|
end
|
837
853
|
end
|
@@ -856,7 +872,7 @@ module Girl
|
|
856
872
|
end
|
857
873
|
|
858
874
|
pack_count = 0
|
859
|
-
puts "debug1 continue/biggest #{ dst_ext[ :continue_src_pack_id ] }/#{ dst_ext[ :biggest_src_pack_id ] } send MISS #{ ranges.size }"
|
875
|
+
# puts "debug1 continue/biggest #{ dst_ext[ :continue_src_pack_id ] }/#{ dst_ext[ :biggest_src_pack_id ] } send MISS #{ ranges.size }"
|
860
876
|
|
861
877
|
ranges.each do | pack_id_begin, pack_id_end |
|
862
878
|
if pack_count >= BREAK_SEND_MISS
|
@@ -899,14 +915,14 @@ module Girl
|
|
899
915
|
|
900
916
|
tund_info[ :last_recv_at ] = now
|
901
917
|
|
902
|
-
puts "debug1 got fin1 #{ Addrinfo.new( src_addr ).inspect } biggest src pack #{ biggest_src_pack_id } completed dst pack #{ continue_dst_pack_id }"
|
918
|
+
# puts "debug1 got fin1 #{ Addrinfo.new( src_addr ).inspect } biggest src pack #{ biggest_src_pack_id } completed dst pack #{ continue_dst_pack_id }"
|
903
919
|
dst_ext[ :is_src_closed ] = true
|
904
920
|
dst_ext[ :biggest_src_pack_id ] = biggest_src_pack_id
|
905
921
|
release_wmems( dst_ext, continue_dst_pack_id )
|
906
922
|
|
907
923
|
# 接到对面已关闭,若最后一个包已经进写前,关闭dst
|
908
924
|
if biggest_src_pack_id == dst_ext[ :continue_src_pack_id ]
|
909
|
-
puts "debug1 2-1. recv traffic/fin1/src status -> src closed and all traffic received ? -> close dst after write"
|
925
|
+
# puts "debug1 2-1. recv traffic/fin1/src status -> src closed and all traffic received ? -> close dst after write"
|
910
926
|
set_is_closing( dst_ext[ :dst ] )
|
911
927
|
end
|
912
928
|
when FIN2
|
@@ -917,7 +933,7 @@ module Girl
|
|
917
933
|
|
918
934
|
tund_info[ :last_recv_at ] = now
|
919
935
|
|
920
|
-
puts "debug1 1-2. recv fin2 -> del dst ext"
|
936
|
+
# puts "debug1 1-2. recv fin2 -> del dst ext"
|
921
937
|
del_dst_ext( tund, dst_local_port )
|
922
938
|
when TUN_FIN
|
923
939
|
puts "p#{ Process.pid } #{ Time.new } recv tun fin"
|
@@ -945,7 +961,7 @@ module Girl
|
|
945
961
|
if pack_id <= CONFUSE_UNTIL
|
946
962
|
# puts "debug2 #{ data.inspect }"
|
947
963
|
data = @custom.decode( data )
|
948
|
-
puts "debug1 decoded pack #{ pack_id }"
|
964
|
+
# puts "debug1 decoded pack #{ pack_id }"
|
949
965
|
end
|
950
966
|
|
951
967
|
# 放进写前,跳号放碎片缓存
|
@@ -962,7 +978,7 @@ module Girl
|
|
962
978
|
|
963
979
|
# 接到流量,若对面已关闭,且流量正好收全,关闭dst
|
964
980
|
if dst_ext[ :is_src_closed ] && ( pack_id == dst_ext[ :biggest_src_pack_id ] )
|
965
|
-
puts "debug1 2-1. recv traffic/fin1/src status -> src closed and all traffic received ? -> close dst after write"
|
981
|
+
# puts "debug1 2-1. recv traffic/fin1/src status -> src closed and all traffic received ? -> close dst after write"
|
966
982
|
set_is_closing( dst_ext[ :dst ] )
|
967
983
|
return
|
968
984
|
end
|
data/lib/girl/version.rb
CHANGED
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: 0.
|
4
|
+
version: 0.61.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- takafan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: while internet is evil, here's a girl.
|
14
14
|
email:
|