girl 4.1.0 → 4.2.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 -1
- data/lib/girl/concurrent_hash.rb +26 -26
- data/lib/girl/proxy.rb +4 -6
- data/lib/girl/proxy_custom.rb +16 -16
- data/lib/girl/proxy_worker.rb +19 -36
- data/lib/girl/proxyd_custom.rb +12 -12
- data/lib/girl/proxyd_worker.rb +26 -7
- data/lib/girl/relay.rb +0 -1
- data/lib/girl/relay_worker.rb +10 -32
- data/lib/girl/resolv_custom.rb +2 -2
- data/lib/girl/resolvd_worker.rb +3 -3
- data/lib/girl/ssl_worker.rb +17 -4
- data/lib/girl/version.rb +1 -1
- metadata +2 -3
- data/lib/girl/custom_dns_query.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e6e47afe34c123e702c013b4b2f71c3ef836902edd8ab7508b9fe666c2052c7
|
4
|
+
data.tar.gz: 673a5b27d4863a9c1daa34abc94536e7c7d68549363071e73d9f57a1db4056bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c105f47f7cfd38572adef3c40be156e88fe1b767d6144cd923154e57c19a5508fbaaaff325e2c252f8371ca97c621a8a6b5ce020381c8738b2529bade9840b9
|
7
|
+
data.tar.gz: 3b13786e8062bad65c975e48340c2b1deae88be8965862543bd644783b3ecbab6b446c2e872a64169a8380fef0679d7c504c6fdbfbe08995d5ae2662b67319b8
|
data/girl.gemspec
CHANGED
data/lib/girl/concurrent_hash.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
-
class ConcurrentHash < Hash
|
2
|
-
def initialize
|
3
|
-
super
|
4
|
-
@mutex = Mutex.new
|
5
|
-
end
|
6
|
-
|
7
|
-
def []( *args )
|
8
|
-
@mutex.synchronize { super }
|
9
|
-
end
|
10
|
-
|
11
|
-
def []=( *args )
|
12
|
-
@mutex.synchronize { super }
|
13
|
-
end
|
14
|
-
|
15
|
-
def delete( *args )
|
16
|
-
@mutex.synchronize { super }
|
17
|
-
end
|
18
|
-
|
19
|
-
def each( *args )
|
20
|
-
@mutex.synchronize { super }
|
21
|
-
end
|
22
|
-
|
23
|
-
def clear( *args )
|
24
|
-
@mutex.synchronize { super }
|
25
|
-
end
|
26
|
-
end
|
1
|
+
class ConcurrentHash < Hash
|
2
|
+
def initialize
|
3
|
+
super
|
4
|
+
@mutex = Mutex.new
|
5
|
+
end
|
6
|
+
|
7
|
+
def []( *args )
|
8
|
+
@mutex.synchronize { super }
|
9
|
+
end
|
10
|
+
|
11
|
+
def []=( *args )
|
12
|
+
@mutex.synchronize { super }
|
13
|
+
end
|
14
|
+
|
15
|
+
def delete( *args )
|
16
|
+
@mutex.synchronize { super }
|
17
|
+
end
|
18
|
+
|
19
|
+
def each( *args )
|
20
|
+
@mutex.synchronize { super }
|
21
|
+
end
|
22
|
+
|
23
|
+
def clear( *args )
|
24
|
+
@mutex.synchronize { super }
|
25
|
+
end
|
26
|
+
end
|
data/lib/girl/proxy.rb
CHANGED
@@ -14,8 +14,8 @@ require 'socket'
|
|
14
14
|
#
|
15
15
|
=begin
|
16
16
|
C: 1 hello -> hello
|
17
|
-
2 tund port -> n:
|
18
|
-
3 a new source -> Q>: src id ->
|
17
|
+
2 tund port -> n: atund port -> n: btund port
|
18
|
+
3 a new source -> Q>: src id -> destination
|
19
19
|
4 paired -> Q>: src id -> n: dst id
|
20
20
|
5 dest status NOT USE
|
21
21
|
6 source status NOT USE
|
@@ -32,13 +32,11 @@ C: 1 hello -> hello
|
|
32
32
|
17 continue NOT USE
|
33
33
|
18 is resend ready NOT USE
|
34
34
|
19 resend ready NOT USE
|
35
|
-
20 resolv
|
36
|
-
21 resolved
|
35
|
+
20 resolv NOT USE
|
36
|
+
21 resolved NOT USE
|
37
37
|
22 heartbeat NOT USE
|
38
38
|
23 unknown ctl addr
|
39
39
|
24 ctl fin
|
40
|
-
25 source eof -> Q>: dst id
|
41
|
-
26 dest eof -> Q>: src id
|
42
40
|
101 traff infos
|
43
41
|
101 traff infos -> [ C: im len -> im -> Q>: traff in -> Q>: traff out ]
|
44
42
|
=end
|
data/lib/girl/proxy_custom.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
require 'girl/custom'
|
2
|
-
|
3
|
-
module Girl
|
4
|
-
class ProxyCustom
|
5
|
-
include Custom
|
6
|
-
|
7
|
-
def initialize( im )
|
8
|
-
@im = im
|
9
|
-
end
|
10
|
-
|
11
|
-
def hello
|
12
|
-
@im
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
1
|
+
require 'girl/custom'
|
2
|
+
|
3
|
+
module Girl
|
4
|
+
class ProxyCustom
|
5
|
+
include Custom
|
6
|
+
|
7
|
+
def initialize( im )
|
8
|
+
@im = im
|
9
|
+
end
|
10
|
+
|
11
|
+
def hello
|
12
|
+
@im
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
data/lib/girl/proxy_worker.rb
CHANGED
@@ -6,6 +6,7 @@ module Girl
|
|
6
6
|
#
|
7
7
|
def initialize( redir_port, proxyd_host, proxyd_port, directs, remotes, im )
|
8
8
|
@proxyd_host = proxyd_host
|
9
|
+
@proxyd_port = proxyd_port
|
9
10
|
@proxyd_addr = Socket.sockaddr_in( proxyd_port, proxyd_host )
|
10
11
|
@directs = directs
|
11
12
|
@remotes = remotes
|
@@ -19,7 +20,7 @@ module Girl
|
|
19
20
|
@resume_srcs = []
|
20
21
|
@resume_dsts = []
|
21
22
|
@resume_btuns = []
|
22
|
-
@pending_srcs = [] #
|
23
|
+
@pending_srcs = [] # 还没得到atund和btund地址,暂存的src
|
23
24
|
@roles = ConcurrentHash.new # sock => :dotr / :redir / :ctl / :src / :dst / :atun / :btun
|
24
25
|
@src_infos = ConcurrentHash.new # src => {}
|
25
26
|
@dst_infos = ConcurrentHash.new # dst => {}
|
@@ -296,7 +297,7 @@ module Girl
|
|
296
297
|
close_sock( atun )
|
297
298
|
atun_info = @atun_infos.delete( atun )
|
298
299
|
src = atun_info[ :src ]
|
299
|
-
|
300
|
+
|
300
301
|
if src then
|
301
302
|
@paused_srcs.delete( src )
|
302
303
|
end
|
@@ -430,9 +431,8 @@ module Girl
|
|
430
431
|
return if src.closed?
|
431
432
|
src_info = @src_infos[ src ]
|
432
433
|
|
433
|
-
if
|
434
|
-
|| ip_info.
|
435
|
-
|| ( ( @ip_address_list.any? { | addrinfo | addrinfo.ip_address == ip_info.ip_address } ) && ( src_info[ :destination_port ] == @redir_port ) ) then
|
434
|
+
if ( ( @ip_address_list.any? { | addrinfo | addrinfo.ip_address == ip_info.ip_address } ) && ( src_info[ :destination_port ] == @redir_port ) ) \
|
435
|
+
|| ( ( ip_info.ip_address == @proxyd_host ) && ( src_info[ :destination_port ] == @proxyd_port ) ) then
|
436
436
|
puts "p#{ Process.pid } #{ Time.new } ignore #{ ip_info.ip_address }:#{ src_info[ :destination_port ] }"
|
437
437
|
add_closing_src( src )
|
438
438
|
return
|
@@ -449,7 +449,6 @@ module Girl
|
|
449
449
|
is_direct = @is_direct_caches[ ip_info.ip_address ]
|
450
450
|
else
|
451
451
|
is_direct = @directs.any? { | direct | direct.include?( ip_info.ip_address ) }
|
452
|
-
# 判断直连耗时较长(树莓派 0.27秒),这里可能切去主线程,回来src可能已关闭
|
453
452
|
puts "p#{ Process.pid } #{ Time.new } cache is direct #{ ip_info.ip_address } #{ is_direct }"
|
454
453
|
@is_direct_caches[ ip_info.ip_address ] = is_direct
|
455
454
|
end
|
@@ -458,7 +457,6 @@ module Girl
|
|
458
457
|
# puts "debug #{ ip_info.inspect } hit directs"
|
459
458
|
new_a_dst( src, ip_info )
|
460
459
|
else
|
461
|
-
# 走远端
|
462
460
|
# puts "debug #{ ip_info.inspect } go tunnel"
|
463
461
|
set_proxy_type_tunnel( src )
|
464
462
|
end
|
@@ -724,6 +722,7 @@ module Girl
|
|
724
722
|
# new tuns
|
725
723
|
#
|
726
724
|
def new_tuns( src_id, dst_id )
|
725
|
+
return if @ctl_info[ :atund_addr ].nil? || @ctl_info[ :btund_addr ].nil?
|
727
726
|
src = @srcs[ src_id ]
|
728
727
|
return if src.nil? || src.closed?
|
729
728
|
src_info = @src_infos[ src ]
|
@@ -864,6 +863,7 @@ module Girl
|
|
864
863
|
#
|
865
864
|
def send_ctlmsg( data )
|
866
865
|
return if @ctl.nil? || @ctl.closed?
|
866
|
+
data = @custom.encode( data )
|
867
867
|
|
868
868
|
begin
|
869
869
|
@ctl.sendmsg( data, 0, @proxyd_addr )
|
@@ -925,25 +925,6 @@ module Girl
|
|
925
925
|
add_write( src )
|
926
926
|
end
|
927
927
|
|
928
|
-
##
|
929
|
-
# sub http request
|
930
|
-
#
|
931
|
-
def sub_http_request( data )
|
932
|
-
lines = data.split( "\r\n" )
|
933
|
-
|
934
|
-
return [ data, nil ] if lines.empty?
|
935
|
-
|
936
|
-
method, url, proto = lines.first.split( ' ' )
|
937
|
-
|
938
|
-
if proto && url && proto[ 0, 4 ] == 'HTTP' && url[ 0, 7 ] == 'http://' then
|
939
|
-
domain_port = url.split( '/' )[ 2 ]
|
940
|
-
data = data.sub( "http://#{ domain_port }", '' )
|
941
|
-
# puts "debug subed #{ data.inspect } #{ domain_port }"
|
942
|
-
end
|
943
|
-
|
944
|
-
[ data, domain_port ]
|
945
|
-
end
|
946
|
-
|
947
928
|
##
|
948
929
|
# read dotr
|
949
930
|
#
|
@@ -1042,6 +1023,7 @@ module Girl
|
|
1042
1023
|
return
|
1043
1024
|
end
|
1044
1025
|
|
1026
|
+
data = @custom.decode( data )
|
1045
1027
|
ctl_num = data[ 0 ].unpack( 'C' ).first
|
1046
1028
|
|
1047
1029
|
case ctl_num
|
@@ -1060,7 +1042,7 @@ module Girl
|
|
1060
1042
|
@pending_srcs.clear
|
1061
1043
|
end
|
1062
1044
|
when PAIRED then
|
1063
|
-
return if
|
1045
|
+
return if data.size != 11
|
1064
1046
|
src_id, dst_id = data[ 1, 10 ].unpack( 'Q>n' )
|
1065
1047
|
# puts "debug got paired #{ src_id } #{ dst_id }"
|
1066
1048
|
@ctl_info[ :resends ].delete( [ A_NEW_SOURCE, src_id ].pack( 'CQ>' ) )
|
@@ -1159,7 +1141,16 @@ module Girl
|
|
1159
1141
|
return
|
1160
1142
|
end
|
1161
1143
|
|
1162
|
-
|
1144
|
+
lines = data.split( "\r\n" )
|
1145
|
+
|
1146
|
+
unless lines.empty? then
|
1147
|
+
method, url, proto = lines.first.split( ' ' )
|
1148
|
+
|
1149
|
+
if proto && url && proto[ 0, 4 ] == 'HTTP' && url[ 0, 7 ] == 'http://' then
|
1150
|
+
domain_port = url.split( '/' )[ 2 ]
|
1151
|
+
# puts "debug domain port #{ domain_port }"
|
1152
|
+
end
|
1153
|
+
end
|
1163
1154
|
|
1164
1155
|
unless domain_port then
|
1165
1156
|
# puts "debug not HTTP"
|
@@ -1226,10 +1217,6 @@ module Girl
|
|
1226
1217
|
when :tunnel then
|
1227
1218
|
atun = src_info[ :atun ]
|
1228
1219
|
|
1229
|
-
if atun && !src_info[ :is_connect ] then
|
1230
|
-
data, _ = sub_http_request( data )
|
1231
|
-
end
|
1232
|
-
|
1233
1220
|
if atun then
|
1234
1221
|
add_atun_wbuff( atun, pack_a_chunk( data ) )
|
1235
1222
|
else
|
@@ -1240,10 +1227,6 @@ module Girl
|
|
1240
1227
|
dst = src_info[ :dst ]
|
1241
1228
|
|
1242
1229
|
if dst then
|
1243
|
-
unless src_info[ :is_connect ] then
|
1244
|
-
data, _ = sub_http_request( data )
|
1245
|
-
end
|
1246
|
-
|
1247
1230
|
add_dst_wbuff( dst, data )
|
1248
1231
|
else
|
1249
1232
|
# puts "debug add src.rbuff #{ data.bytesize }"
|
data/lib/girl/proxyd_custom.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
require 'girl/custom'
|
2
|
-
|
3
|
-
module Girl
|
4
|
-
class ProxydCustom
|
5
|
-
include Custom
|
6
|
-
|
7
|
-
def check( data, addrinfo )
|
8
|
-
:success
|
9
|
-
end
|
10
|
-
|
11
|
-
end
|
12
|
-
end
|
1
|
+
require 'girl/custom'
|
2
|
+
|
3
|
+
module Girl
|
4
|
+
class ProxydCustom
|
5
|
+
include Custom
|
6
|
+
|
7
|
+
def check( data, addrinfo )
|
8
|
+
:success
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
data/lib/girl/proxyd_worker.rb
CHANGED
@@ -221,7 +221,7 @@ module Girl
|
|
221
221
|
close_sock( btun )
|
222
222
|
btun_info = @btun_infos.delete( btun )
|
223
223
|
dst = btun_info[ :dst ]
|
224
|
-
|
224
|
+
|
225
225
|
if dst then
|
226
226
|
@paused_dsts.delete( dst )
|
227
227
|
end
|
@@ -519,6 +519,15 @@ module Girl
|
|
519
519
|
@dotw.write( '.' )
|
520
520
|
end
|
521
521
|
|
522
|
+
##
|
523
|
+
# pack a chunk
|
524
|
+
#
|
525
|
+
def pack_a_chunk( data )
|
526
|
+
# puts "debug pack a chunk"
|
527
|
+
data = @custom.encode( data )
|
528
|
+
"#{ [ data.bytesize ].pack( 'n' ) }#{ data }"
|
529
|
+
end
|
530
|
+
|
522
531
|
##
|
523
532
|
# resolve domain
|
524
533
|
#
|
@@ -564,6 +573,8 @@ module Girl
|
|
564
573
|
# send ctlmsg
|
565
574
|
#
|
566
575
|
def send_ctlmsg( data, to_addr )
|
576
|
+
data = @custom.encode( data )
|
577
|
+
|
567
578
|
begin
|
568
579
|
@ctld.sendmsg( data, 0, to_addr )
|
569
580
|
rescue Exception => e
|
@@ -635,6 +646,7 @@ module Girl
|
|
635
646
|
#
|
636
647
|
def read_ctld( ctld )
|
637
648
|
data, addrinfo, rflags, *controls = ctld.recvmsg
|
649
|
+
data = @custom.decode( data )
|
638
650
|
ctl_num = data[ 0 ].unpack( 'C' ).first
|
639
651
|
ctl_addr = addrinfo.to_sockaddr
|
640
652
|
ctl_info = @ctl_infos[ ctl_addr ]
|
@@ -777,12 +789,10 @@ module Girl
|
|
777
789
|
end
|
778
790
|
|
779
791
|
@traff_ins[ dst_info[ :im ] ] += data.bytesize
|
780
|
-
# puts "debug read dst #{ data.bytesize }
|
781
|
-
data = @custom.encode( data )
|
782
|
-
data = "#{ [ data.bytesize ].pack( 'n' ) }#{ data }"
|
792
|
+
# puts "debug read dst #{ data.bytesize }"
|
783
793
|
|
784
794
|
if btun then
|
785
|
-
add_btun_wbuff( btun, data )
|
795
|
+
add_btun_wbuff( btun, pack_a_chunk( data ) )
|
786
796
|
else
|
787
797
|
# puts "debug add dst.rbuff #{ data.bytesize }"
|
788
798
|
add_dst_rbuff( dst, data )
|
@@ -1009,8 +1019,17 @@ module Girl
|
|
1009
1019
|
btun_info[ :domain_port ] = dst_info[ :domain_port ]
|
1010
1020
|
|
1011
1021
|
unless dst_info[ :rbuff ].empty? then
|
1012
|
-
|
1013
|
-
|
1022
|
+
data2 = ''
|
1023
|
+
|
1024
|
+
until dst_info[ :rbuff ].empty? do
|
1025
|
+
_data = dst_info[ :rbuff ][ 0, 65535 ]
|
1026
|
+
data_size = _data.bytesize
|
1027
|
+
# puts "debug move dst.rbuff to btun.wbuff"
|
1028
|
+
data2 << pack_a_chunk( _data )
|
1029
|
+
dst_info[ :rbuff ] = dst_info[ :rbuff ][ data_size..-1 ]
|
1030
|
+
end
|
1031
|
+
|
1032
|
+
add_btun_wbuff( btun, data2 )
|
1014
1033
|
end
|
1015
1034
|
|
1016
1035
|
dst_info[ :btun ] = btun
|
data/lib/girl/relay.rb
CHANGED
data/lib/girl/relay_worker.rb
CHANGED
@@ -13,7 +13,6 @@ module Girl
|
|
13
13
|
@directs = directs
|
14
14
|
@remotes = remotes
|
15
15
|
@custom = Girl::ProxyCustom.new( im )
|
16
|
-
@resolv_custom = Girl::ResolvCustom.new
|
17
16
|
@reads = []
|
18
17
|
@writes = []
|
19
18
|
@closing_rsvs = []
|
@@ -24,7 +23,7 @@ module Girl
|
|
24
23
|
@resume_srcs = []
|
25
24
|
@resume_dsts = []
|
26
25
|
@resume_btuns = []
|
27
|
-
@pending_srcs = [] #
|
26
|
+
@pending_srcs = [] # 还没得到atund和btund地址,暂存的src
|
28
27
|
@roles = ConcurrentHash.new # sock => :dotr / :resolv / :rsv / :redir / :proxy / :src / :dst / :atun / :btun
|
29
28
|
@rsv_infos = ConcurrentHash.new # rsv => {}
|
30
29
|
@src_infos = ConcurrentHash.new # src => {}
|
@@ -445,9 +444,8 @@ module Girl
|
|
445
444
|
return if src.closed?
|
446
445
|
src_info = @src_infos[ src ]
|
447
446
|
|
448
|
-
if
|
449
|
-
|| ip_info.
|
450
|
-
|| ( ( @ip_address_list.any? { | addrinfo | addrinfo.ip_address == ip_info.ip_address } ) && ( src_info[ :destination_port ] == @redir_port ) ) then
|
447
|
+
if ( ( @ip_address_list.any? { | addrinfo | addrinfo.ip_address == ip_info.ip_address } ) && ( src_info[ :destination_port ] == @redir_port ) ) \
|
448
|
+
|| ( ( ip_info.ip_address == @proxyd_host ) && ( src_info[ :destination_port ] == @proxyd_port ) ) then
|
451
449
|
puts "p#{ Process.pid } #{ Time.new } ignore #{ ip_info.ip_address }:#{ src_info[ :destination_port ] }"
|
452
450
|
add_closing_src( src )
|
453
451
|
return
|
@@ -464,7 +462,6 @@ module Girl
|
|
464
462
|
is_direct = @is_direct_caches[ ip_info.ip_address ]
|
465
463
|
else
|
466
464
|
is_direct = @directs.any? { | direct | direct.include?( ip_info.ip_address ) }
|
467
|
-
# 判断直连耗时较长(树莓派 0.27秒),这里可能切去主线程,回来src可能已关闭
|
468
465
|
puts "p#{ Process.pid } #{ Time.new } cache is direct #{ ip_info.ip_address } #{ is_direct }"
|
469
466
|
@is_direct_caches[ ip_info.ip_address ] = is_direct
|
470
467
|
end
|
@@ -473,7 +470,6 @@ module Girl
|
|
473
470
|
# puts "debug #{ ip_info.inspect } hit directs"
|
474
471
|
new_a_dst( src, ip_info )
|
475
472
|
else
|
476
|
-
# 走远端
|
477
473
|
# puts "debug #{ ip_info.inspect } go tunnel"
|
478
474
|
set_proxy_type_tunnel( src )
|
479
475
|
end
|
@@ -754,7 +750,7 @@ module Girl
|
|
754
750
|
rsv.bind( Socket.sockaddr_in( 0, '0.0.0.0' ) )
|
755
751
|
|
756
752
|
if @qnames.any? { | qname | data.include?( qname ) } then
|
757
|
-
data = @
|
753
|
+
data = @custom.encode( data )
|
758
754
|
to_addr = @resolvd_addr
|
759
755
|
else
|
760
756
|
to_addr = @nameserver_addr
|
@@ -774,6 +770,7 @@ module Girl
|
|
774
770
|
# new tuns
|
775
771
|
#
|
776
772
|
def new_tuns( src_id, dst_id )
|
773
|
+
return if @ctl_info[ :atund_addr ].nil? || @ctl_info[ :btund_addr ].nil?
|
777
774
|
src = @srcs[ src_id ]
|
778
775
|
return if src.nil? || src.closed?
|
779
776
|
src_info = @src_infos[ src ]
|
@@ -860,6 +857,7 @@ module Girl
|
|
860
857
|
#
|
861
858
|
def send_ctlmsg( data )
|
862
859
|
return if @ctl.nil? || @ctl.closed?
|
860
|
+
data = @custom.encode( data )
|
863
861
|
|
864
862
|
begin
|
865
863
|
@ctl.sendmsg( data, 0, @proxyd_addr )
|
@@ -888,9 +886,7 @@ module Girl
|
|
888
886
|
def send_data( sock, to_addr, data )
|
889
887
|
begin
|
890
888
|
sock.sendmsg( data, 0, to_addr )
|
891
|
-
rescue
|
892
|
-
print 'w'
|
893
|
-
rescue Errno::EHOSTUNREACH, Errno::ENETUNREACH, Errno::ENETDOWN => e
|
889
|
+
rescue Exception => e
|
894
890
|
puts "p#{ Process.pid } #{ Time.new } sendmsg to #{ to_addr.ip_unpack.inspect } #{ e.class }"
|
895
891
|
end
|
896
892
|
end
|
@@ -933,25 +929,6 @@ module Girl
|
|
933
929
|
add_write( src )
|
934
930
|
end
|
935
931
|
|
936
|
-
##
|
937
|
-
# sub http request
|
938
|
-
#
|
939
|
-
def sub_http_request( data )
|
940
|
-
lines = data.split( "\r\n" )
|
941
|
-
|
942
|
-
return [ data, nil ] if lines.empty?
|
943
|
-
|
944
|
-
method, url, proto = lines.first.split( ' ' )
|
945
|
-
|
946
|
-
if proto && url && proto[ 0, 4 ] == 'HTTP' && url[ 0, 7 ] == 'http://' then
|
947
|
-
domain_port = url.split( '/' )[ 2 ]
|
948
|
-
data = data.sub( "http://#{ domain_port }", '' )
|
949
|
-
# puts "debug subed #{ data.inspect } #{ domain_port }"
|
950
|
-
end
|
951
|
-
|
952
|
-
[ data, domain_port ]
|
953
|
-
end
|
954
|
-
|
955
932
|
##
|
956
933
|
# read dotr
|
957
934
|
#
|
@@ -1018,7 +995,7 @@ module Girl
|
|
1018
995
|
# puts "debug rsv recvmsg #{ addrinfo.ip_unpack.inspect } #{ data.inspect }"
|
1019
996
|
|
1020
997
|
if addrinfo.to_sockaddr == @resolvd_addr then
|
1021
|
-
data = @
|
998
|
+
data = @custom.decode( data )
|
1022
999
|
end
|
1023
1000
|
|
1024
1001
|
rsv_info = @rsv_infos[ rsv ]
|
@@ -1093,6 +1070,7 @@ module Girl
|
|
1093
1070
|
return
|
1094
1071
|
end
|
1095
1072
|
|
1073
|
+
data = @custom.decode( data )
|
1096
1074
|
ctl_num = data[ 0 ].unpack( 'C' ).first
|
1097
1075
|
|
1098
1076
|
case ctl_num
|
@@ -1111,7 +1089,7 @@ module Girl
|
|
1111
1089
|
@pending_srcs.clear
|
1112
1090
|
end
|
1113
1091
|
when PAIRED then
|
1114
|
-
return if
|
1092
|
+
return if data.size != 11
|
1115
1093
|
src_id, dst_id = data[ 1, 10 ].unpack( 'Q>n' )
|
1116
1094
|
# puts "debug got paired #{ src_id } #{ dst_id }"
|
1117
1095
|
@ctl_info[ :resends ].delete( [ A_NEW_SOURCE, src_id ].pack( 'CQ>' ) )
|
data/lib/girl/resolv_custom.rb
CHANGED
data/lib/girl/resolvd_worker.rb
CHANGED
@@ -5,7 +5,7 @@ module Girl
|
|
5
5
|
# initialize
|
6
6
|
#
|
7
7
|
def initialize( resolvd_port, nameserver )
|
8
|
-
@
|
8
|
+
@custom = Girl::ResolvCustom.new
|
9
9
|
@nameserver_addr = Socket.sockaddr_in( 53, nameserver )
|
10
10
|
@roles = ConcurrentHash.new # :resolvd / :dst
|
11
11
|
@reads = []
|
@@ -176,7 +176,7 @@ module Girl
|
|
176
176
|
def read_resolvd( resolvd )
|
177
177
|
data, addrinfo, rflags, *controls = resolvd.recvmsg
|
178
178
|
# puts "debug1 resolvd recvmsg #{ addrinfo.ip_unpack.inspect } #{ data.inspect }"
|
179
|
-
data = @
|
179
|
+
data = @custom.decode( data )
|
180
180
|
new_a_dst( addrinfo.to_sockaddr, data )
|
181
181
|
end
|
182
182
|
|
@@ -187,7 +187,7 @@ module Girl
|
|
187
187
|
data, addrinfo, rflags, *controls = dst.recvmsg
|
188
188
|
# puts "debug1 dst recvmsg #{ addrinfo.ip_unpack.inspect } #{ data.inspect }"
|
189
189
|
dst_info = @dst_infos[ dst ]
|
190
|
-
data = @
|
190
|
+
data = @custom.encode( data )
|
191
191
|
send_data( @resolvd, dst_info[ :src_addr ], data )
|
192
192
|
close_dst( dst )
|
193
193
|
end
|
data/lib/girl/ssl_worker.rb
CHANGED
@@ -236,6 +236,17 @@ module Girl
|
|
236
236
|
end
|
237
237
|
end
|
238
238
|
|
239
|
+
##
|
240
|
+
# close redir
|
241
|
+
#
|
242
|
+
def close_redir( redir )
|
243
|
+
return if redir.closed?
|
244
|
+
redir.close
|
245
|
+
@roles.delete( redir )
|
246
|
+
@reads.delete( redir )
|
247
|
+
@src_infos.each { | src, _ | close_src( src ) }
|
248
|
+
end
|
249
|
+
|
239
250
|
##
|
240
251
|
# close sock
|
241
252
|
#
|
@@ -369,7 +380,7 @@ module Girl
|
|
369
380
|
@paused_dsts.each do | dst |
|
370
381
|
dst_info = @dst_infos[ dst ]
|
371
382
|
src = dst_info[ :src ]
|
372
|
-
|
383
|
+
|
373
384
|
if src && !src.closed? then
|
374
385
|
src_info = @src_infos[ src ]
|
375
386
|
|
@@ -560,15 +571,17 @@ module Girl
|
|
560
571
|
|
561
572
|
unless accepted then
|
562
573
|
puts "p#{ Process.pid } #{ Time.new } accept timeout"
|
563
|
-
redir
|
564
|
-
@roles.delete( redir )
|
565
|
-
@reads.delete( redir )
|
574
|
+
close_redir( redir )
|
566
575
|
new_a_redir
|
567
576
|
end
|
568
577
|
end
|
569
578
|
|
570
579
|
begin
|
571
580
|
src = redir.accept
|
581
|
+
rescue SystemExit => e
|
582
|
+
puts "p#{ Process.pid } #{ Time.new } redir accept #{ e.class }"
|
583
|
+
close_redir( redir )
|
584
|
+
return
|
572
585
|
rescue Exception => e
|
573
586
|
puts "p#{ Process.pid } #{ Time.new } redir accept #{ e.class }"
|
574
587
|
puts e.full_message
|
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: 4.
|
4
|
+
version: 4.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- takafan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: escape evil.
|
14
14
|
email:
|
@@ -21,7 +21,6 @@ files:
|
|
21
21
|
- lib/girl.rb
|
22
22
|
- lib/girl/concurrent_hash.rb
|
23
23
|
- lib/girl/custom.rb
|
24
|
-
- lib/girl/custom_dns_query.rb
|
25
24
|
- lib/girl/head.rb
|
26
25
|
- lib/girl/proxy.rb
|
27
26
|
- lib/girl/proxy_custom.rb
|