girl 9.1.0 → 9.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/girl/proxy.rb +6 -3
- data/lib/girl/proxy_worker.rb +324 -9
- 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: 6178ab1062943992b8187decc04a6916c5aaee75aa23e259c3ba5edcdbde7c7d
|
4
|
+
data.tar.gz: ff195a6fb415da6f045adc4678655acdc367b2f1c8894319f19309085fb3ee9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c102ea1026056ce877c50e895b10e7d054475406e8ee4e62aa4082f07270f6b89fc110cf0762a61e10c0d48d18017674b8c7d23e6e7873b8f0443ded5589a91
|
7
|
+
data.tar.gz: 7201e5651a8443f7a2c115e9dfbb24d84ae13cd13263f2e754e3db2993e7478f2831d784e3ed098fae0bcb534e1f23e292a5123615aedb9a8a449080fcdf4acf
|
data/lib/girl/proxy.rb
CHANGED
@@ -25,6 +25,7 @@ module Girl
|
|
25
25
|
puts "load #{ config_path } #{ conf.inspect }"
|
26
26
|
redir_port = conf[ :redir_port ]
|
27
27
|
memd_port = conf[ :memd_port ]
|
28
|
+
relayd_port = conf[ :relayd_port ]
|
28
29
|
tspd_port = conf[ :tspd_port ]
|
29
30
|
proxyd_host = conf[ :proxyd_host ]
|
30
31
|
proxyd_port = conf[ :proxyd_port ]
|
@@ -54,7 +55,7 @@ module Girl
|
|
54
55
|
h_src_underhalf = conf[ :h_src_underhalf ] # V
|
55
56
|
h_dst_overflow = conf[ :h_dst_overflow ] # W
|
56
57
|
h_dst_underhalf = conf[ :h_dst_underhalf ] # X
|
57
|
-
|
58
|
+
|
58
59
|
expire_connecting = conf[ :expire_connecting ] # 连接多久没有建成关闭(秒)
|
59
60
|
expire_long_after = conf[ :expire_long_after ] # 长连接多久没有新流量关闭(秒)
|
60
61
|
expire_proxy_after = conf[ :expire_proxy_after ] # proxy多久没有收到流量重建(秒)
|
@@ -64,6 +65,7 @@ module Girl
|
|
64
65
|
|
65
66
|
redir_port = redir_port ? redir_port.to_i : 6666
|
66
67
|
memd_port = memd_port ? memd_port.to_i : redir_port + 1
|
68
|
+
relayd_port = relayd_port ? relayd_port.to_i : redir_port + 2
|
67
69
|
tspd_port = tspd_port ? tspd_port.to_i : 7777
|
68
70
|
raise "missing proxyd host" unless proxyd_host
|
69
71
|
proxyd_port = proxyd_port ? proxyd_port.to_i : 6060
|
@@ -128,8 +130,8 @@ module Girl
|
|
128
130
|
end
|
129
131
|
end
|
130
132
|
|
131
|
-
puts "girl proxy #{ Girl::VERSION } #{ im }"
|
132
|
-
puts "#{
|
133
|
+
puts "girl proxy #{ Girl::VERSION } #{ im } #{ redir_port } #{ relayd_port } #{ tspd_port }"
|
134
|
+
puts "#{ proxyd_host } #{ proxyd_port } #{ appd_host } #{ appd_port } #{ nameservers.inspect } #{ is_client_fastopen } #{ is_server_fastopen }"
|
133
135
|
puts "#{ direct_path } #{ directs.size } directs"
|
134
136
|
puts "#{ remote_path } #{ remotes.size } remotes"
|
135
137
|
|
@@ -141,6 +143,7 @@ module Girl
|
|
141
143
|
worker = Girl::ProxyWorker.new(
|
142
144
|
redir_port,
|
143
145
|
memd_port,
|
146
|
+
relayd_port,
|
144
147
|
tspd_port,
|
145
148
|
proxyd_host,
|
146
149
|
proxyd_port,
|
data/lib/girl/proxy_worker.rb
CHANGED
@@ -5,6 +5,7 @@ module Girl
|
|
5
5
|
def initialize(
|
6
6
|
redir_port,
|
7
7
|
memd_port,
|
8
|
+
relayd_port,
|
8
9
|
tspd_port,
|
9
10
|
proxyd_host,
|
10
11
|
proxyd_port,
|
@@ -51,14 +52,16 @@ module Girl
|
|
51
52
|
@remotes = remotes
|
52
53
|
@local_ips = Socket.ip_address_list.select{ | info | info.ipv4? }.map{ | info | info.ip_address }
|
53
54
|
@update_roles = [ :dns, :dst, :mem, :p1, :src, :rsv ] # 参与淘汰的角色
|
54
|
-
@updates_limit =
|
55
|
+
@updates_limit = 1007 # 淘汰池上限,1015(mac) - info, infod, memd, proxy, redir, relayd, rsvd, tspd
|
55
56
|
@eliminate_count = 0 # 淘汰次数
|
56
57
|
@reads = [] # 读池
|
57
58
|
@writes = [] # 写池
|
58
|
-
@roles = {} # sock => :dns / :dst / :infod / :mem / :memd / :p1 / :proxy / :redir / :rsv / :rsvd / :src / :tspd
|
59
|
+
@roles = {} # sock => :dns / :dst / :girl / :infod / :mem / :memd / :p1 / :proxy / :redir / :relay / :relayd / :rsv / :rsvd / :src / :tspd
|
59
60
|
@updates = {} # sock => updated_at
|
60
61
|
@proxy_infos = {} # proxy => { :is_syn :paused_p1s :paused_srcs :rbuff :recv_at :wbuff }
|
61
62
|
@mem_infos = {} # mem => { :wbuff }
|
63
|
+
@relay_infos = {} # relay => { :addrinfo :closing :girl :overflowing :wbuff }
|
64
|
+
@girl_infos = {} # girl => { :closing :connected :is_syn :overflowing :relay :wbuff }
|
62
65
|
@src_infos = {} # src => { :addrinfo :closing :destination_domain :destination_port :dst :is_connect :overflowing :proxy_proto :proxy_type :rbuff :src_id :wbuff }
|
63
66
|
@dst_infos = {} # dst => { :closing :connected :domain :ip :overflowing :port :src :wbuff }
|
64
67
|
@dns_infos = {} # dns => { :domain :src }
|
@@ -103,6 +106,7 @@ module Girl
|
|
103
106
|
new_a_redir( redir_port )
|
104
107
|
new_a_infod( redir_port )
|
105
108
|
new_a_memd( memd_port )
|
109
|
+
new_a_relayd( relayd_port )
|
106
110
|
new_a_rsvd( tspd_port )
|
107
111
|
new_a_tspd( tspd_port )
|
108
112
|
new_a_proxy
|
@@ -123,6 +127,8 @@ module Girl
|
|
123
127
|
read_dns( sock )
|
124
128
|
when :dst then
|
125
129
|
read_dst( sock )
|
130
|
+
when :girl then
|
131
|
+
read_girl( sock )
|
126
132
|
when :infod then
|
127
133
|
read_infod( sock )
|
128
134
|
when :mem then
|
@@ -135,6 +141,10 @@ module Girl
|
|
135
141
|
read_proxy( sock )
|
136
142
|
when :redir then
|
137
143
|
read_redir( sock )
|
144
|
+
when :relay then
|
145
|
+
read_relay( sock )
|
146
|
+
when :relayd then
|
147
|
+
read_relayd( sock )
|
138
148
|
when :rsv then
|
139
149
|
read_rsv( sock )
|
140
150
|
when :rsvd then
|
@@ -154,12 +164,16 @@ module Girl
|
|
154
164
|
case role
|
155
165
|
when :dst then
|
156
166
|
write_dst( sock )
|
167
|
+
when :girl then
|
168
|
+
write_girl( sock )
|
157
169
|
when :mem then
|
158
170
|
write_mem( sock )
|
159
171
|
when :p1 then
|
160
172
|
write_p1( sock )
|
161
173
|
when :proxy then
|
162
174
|
write_proxy( sock )
|
175
|
+
when :relay then
|
176
|
+
write_relay( sock )
|
163
177
|
when :src then
|
164
178
|
write_src( sock )
|
165
179
|
else
|
@@ -184,6 +198,12 @@ module Girl
|
|
184
198
|
dst_info[ :wbuff ] << data
|
185
199
|
bytesize = dst_info[ :wbuff ].bytesize
|
186
200
|
|
201
|
+
if bytesize >= CLOSE_ABOVE then
|
202
|
+
puts "close overflow dst #{ dst_info[ :domain ] }"
|
203
|
+
close_dst( dst )
|
204
|
+
return
|
205
|
+
end
|
206
|
+
|
187
207
|
if !dst_info[ :overflowing ] && ( bytesize >= WBUFF_LIMIT ) then
|
188
208
|
puts "dst overflow pause src #{ dst_info[ :domain ] }"
|
189
209
|
@reads.delete( dst_info[ :src ] )
|
@@ -193,6 +213,27 @@ module Girl
|
|
193
213
|
add_write( dst )
|
194
214
|
end
|
195
215
|
|
216
|
+
def add_girl_wbuff( girl, data )
|
217
|
+
return if girl.nil? || girl.closed? || data.nil? || data.empty?
|
218
|
+
girl_info = @girl_infos[ girl ]
|
219
|
+
girl_info[ :wbuff ] << data
|
220
|
+
bytesize = girl_info[ :wbuff ].bytesize
|
221
|
+
|
222
|
+
if bytesize >= CLOSE_ABOVE then
|
223
|
+
puts "close overflow girl"
|
224
|
+
close_girl( girl )
|
225
|
+
return
|
226
|
+
end
|
227
|
+
|
228
|
+
if !girl_info[ :overflowing ] && ( bytesize >= WBUFF_LIMIT ) then
|
229
|
+
puts "girl overflow pause relay"
|
230
|
+
@reads.delete( girl_info[ :relay ] )
|
231
|
+
girl_info[ :overflowing ] = true
|
232
|
+
end
|
233
|
+
|
234
|
+
add_write( girl )
|
235
|
+
end
|
236
|
+
|
196
237
|
def add_mem_wbuff( mem, data )
|
197
238
|
return if mem.nil? || mem.closed? || data.nil? || data.empty?
|
198
239
|
mem_info = @mem_infos[ mem ]
|
@@ -219,7 +260,7 @@ module Girl
|
|
219
260
|
add_proxy_wbuff( pack_a_chunk( msg ) )
|
220
261
|
p1_info[ :overflowing ] = true
|
221
262
|
end
|
222
|
-
|
263
|
+
|
223
264
|
add_write( p1 )
|
224
265
|
end
|
225
266
|
|
@@ -253,6 +294,27 @@ module Girl
|
|
253
294
|
end
|
254
295
|
end
|
255
296
|
|
297
|
+
def add_relay_wbuff( relay, data )
|
298
|
+
return if relay.nil? || relay.closed? || data.nil? || data.empty?
|
299
|
+
relay_info = @relay_infos[ relay ]
|
300
|
+
relay_info[ :wbuff ] << data
|
301
|
+
bytesize = relay_info[ :wbuff ].bytesize
|
302
|
+
|
303
|
+
if bytesize >= CLOSE_ABOVE then
|
304
|
+
puts "close overflow relay #{ relay_info[ :addrinfo ].ip_unpack.inspect }"
|
305
|
+
close_relay( relay )
|
306
|
+
return
|
307
|
+
end
|
308
|
+
|
309
|
+
if !relay_info[ :overflowing ] && ( bytesize >= WBUFF_LIMIT ) then
|
310
|
+
puts "relay overflow pause girl #{ relay_info[ :addrinfo ].ip_unpack.inspect }"
|
311
|
+
@reads.delete( relay_info[ :girl ] )
|
312
|
+
relay_info[ :overflowing ] = true
|
313
|
+
end
|
314
|
+
|
315
|
+
add_write( relay )
|
316
|
+
end
|
317
|
+
|
256
318
|
def add_socks5_conn_reply( src )
|
257
319
|
# +----+-----+-------+------+----------+----------+
|
258
320
|
# |VER | REP | RSV | ATYP | BND.ADDR | BND.PORT |
|
@@ -334,6 +396,15 @@ module Girl
|
|
334
396
|
end
|
335
397
|
end
|
336
398
|
|
399
|
+
def check_expire_girls
|
400
|
+
now = Time.new
|
401
|
+
|
402
|
+
@girl_infos.select{ | girl, info | info[ :connected ] ? ( now.to_i - @updates[ girl ].to_i >= @expire_long_after ) : ( now.to_i - @updates[ girl ].to_i >= @expire_connecting ) }.each do | girl, _ |
|
403
|
+
puts "expire girl" if @is_debug
|
404
|
+
close_girl( girl )
|
405
|
+
end
|
406
|
+
end
|
407
|
+
|
337
408
|
def check_expire_mems
|
338
409
|
now = Time.new
|
339
410
|
|
@@ -361,6 +432,15 @@ module Girl
|
|
361
432
|
end
|
362
433
|
end
|
363
434
|
|
435
|
+
def check_expire_relays
|
436
|
+
now = Time.new
|
437
|
+
|
438
|
+
@relay_infos.select{ | relay, _ | now.to_i - @updates[ relay ].to_i >= @expire_long_after }.each do | relay, info |
|
439
|
+
puts "expire relay #{ info[ :addrinfo ].ip_unpack.inspect }" if @is_debug
|
440
|
+
close_relay( relay )
|
441
|
+
end
|
442
|
+
end
|
443
|
+
|
364
444
|
def check_expire_rsvs
|
365
445
|
now = Time.new
|
366
446
|
|
@@ -396,6 +476,15 @@ module Girl
|
|
396
476
|
dst_info
|
397
477
|
end
|
398
478
|
|
479
|
+
def close_girl( girl )
|
480
|
+
return nil if girl.nil? || girl.closed?
|
481
|
+
close_sock( girl )
|
482
|
+
girl_info = @girl_infos.delete( girl )
|
483
|
+
puts "close girl" if @is_debug
|
484
|
+
set_relay_closing( girl_info[ :relay ] ) if girl_info
|
485
|
+
girl_info
|
486
|
+
end
|
487
|
+
|
399
488
|
def close_mem( mem )
|
400
489
|
return nil if mem.nil? || mem.closed?
|
401
490
|
close_sock( mem )
|
@@ -406,7 +495,7 @@ module Girl
|
|
406
495
|
return nil if p1.nil? || p1.closed?
|
407
496
|
close_sock( p1 )
|
408
497
|
p1_info = @p1_infos.delete( p1 )
|
409
|
-
|
498
|
+
|
410
499
|
unless @proxy.closed? then
|
411
500
|
proxy_info = @proxy_infos[ @proxy ]
|
412
501
|
proxy_info[ :paused_p1s ].delete( p1 )
|
@@ -429,6 +518,15 @@ module Girl
|
|
429
518
|
proxy_info
|
430
519
|
end
|
431
520
|
|
521
|
+
def close_relay( relay )
|
522
|
+
return nil if relay.nil? || relay.closed?
|
523
|
+
close_sock( relay )
|
524
|
+
relay_info = @relay_infos.delete( relay )
|
525
|
+
puts "close relay" if @is_debug
|
526
|
+
set_girl_closing( relay_info[ :girl ] ) if relay_info
|
527
|
+
relay_info
|
528
|
+
end
|
529
|
+
|
432
530
|
def close_rsv( rsv )
|
433
531
|
return nil if rsv.nil? || rsv.closed?
|
434
532
|
close_sock( rsv )
|
@@ -453,7 +551,7 @@ module Girl
|
|
453
551
|
src_id = src_info[ :src_id ]
|
454
552
|
domain = src_info[ :destination_domain ]
|
455
553
|
puts "close src #{ domain }" if @is_debug
|
456
|
-
|
554
|
+
|
457
555
|
if src_info[ :proxy_type ] == :direct then
|
458
556
|
set_dst_closing( src_info[ :dst ] )
|
459
557
|
elsif ( src_info[ :proxy_type ] == :remote ) && !@proxy.closed? then
|
@@ -709,6 +807,45 @@ module Girl
|
|
709
807
|
end
|
710
808
|
end
|
711
809
|
|
810
|
+
def new_a_girl( relay )
|
811
|
+
return if relay.nil? || relay.closed?
|
812
|
+
check_expire_girls
|
813
|
+
|
814
|
+
begin
|
815
|
+
girl = Socket.new( Socket::AF_INET, Socket::SOCK_STREAM, 0 )
|
816
|
+
rescue Exception => e
|
817
|
+
puts "new a girl #{ e.class }"
|
818
|
+
close_girl( girl )
|
819
|
+
return
|
820
|
+
end
|
821
|
+
|
822
|
+
girl.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1 )
|
823
|
+
|
824
|
+
begin
|
825
|
+
girl.connect_nonblock( @proxyd_addr )
|
826
|
+
rescue IO::WaitWritable
|
827
|
+
rescue Exception => e
|
828
|
+
puts "girl connect proxyd #{ e.class }"
|
829
|
+
girl.close
|
830
|
+
close_girl( girl )
|
831
|
+
return
|
832
|
+
end
|
833
|
+
|
834
|
+
girl_info = {
|
835
|
+
closing: false,
|
836
|
+
connected: false,
|
837
|
+
is_syn: @is_client_fastopen,
|
838
|
+
overflowing: false,
|
839
|
+
relay: relay,
|
840
|
+
wbuff: ''
|
841
|
+
}
|
842
|
+
|
843
|
+
@girl_infos[ girl ] = girl_info
|
844
|
+
add_read( girl, :girl )
|
845
|
+
add_write( girl )
|
846
|
+
girl
|
847
|
+
end
|
848
|
+
|
712
849
|
def new_a_infod( infod_port )
|
713
850
|
infod_ip = '127.0.0.1'
|
714
851
|
infod_addr = Socket.sockaddr_in( infod_port, infod_ip )
|
@@ -822,6 +959,19 @@ module Girl
|
|
822
959
|
@redir_local_address = redir.local_address
|
823
960
|
end
|
824
961
|
|
962
|
+
def new_a_relayd( relayd_port )
|
963
|
+
relayd_ip = '0.0.0.0'
|
964
|
+
relayd = Socket.new( Socket::AF_INET, Socket::SOCK_STREAM, 0 )
|
965
|
+
relayd.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1 )
|
966
|
+
relayd.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEADDR, 1 )
|
967
|
+
relayd.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEPORT, 1 ) if RUBY_PLATFORM.include?( 'linux' )
|
968
|
+
relayd.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_FASTOPEN, BACKLOG ) if @is_server_fastopen
|
969
|
+
relayd.bind( Socket.sockaddr_in( relayd_port, relayd_ip ) )
|
970
|
+
relayd.listen( BACKLOG )
|
971
|
+
puts "relayd listen on #{ relayd_ip } #{ relayd_port }"
|
972
|
+
add_read( relayd, :relayd )
|
973
|
+
end
|
974
|
+
|
825
975
|
def new_a_rsv( data, addrinfo, domain, type )
|
826
976
|
check_expire_rsvs
|
827
977
|
rsv = Socket.new( Socket::AF_INET, Socket::SOCK_DGRAM, 0 )
|
@@ -955,6 +1105,22 @@ module Girl
|
|
955
1105
|
add_src_wbuff( src, data )
|
956
1106
|
end
|
957
1107
|
|
1108
|
+
def read_girl( girl )
|
1109
|
+
begin
|
1110
|
+
data = girl.read_nonblock( READ_SIZE )
|
1111
|
+
rescue Errno::ENOTCONN => e
|
1112
|
+
return
|
1113
|
+
rescue Exception => e
|
1114
|
+
close_girl( girl )
|
1115
|
+
return
|
1116
|
+
end
|
1117
|
+
|
1118
|
+
set_update( girl )
|
1119
|
+
girl_info = @girl_infos[ girl ]
|
1120
|
+
relay = girl_info[ :relay ]
|
1121
|
+
add_relay_wbuff( relay, data )
|
1122
|
+
end
|
1123
|
+
|
958
1124
|
def read_infod( infod )
|
959
1125
|
begin
|
960
1126
|
data, addrinfo, rflags, *controls = infod.recvmsg
|
@@ -1026,6 +1192,8 @@ module Girl
|
|
1026
1192
|
updates: @updates.size,
|
1027
1193
|
proxy_infos: @proxy_infos.size,
|
1028
1194
|
mem_infos: @mem_infos.size,
|
1195
|
+
relay_infos: @relay_infos.size,
|
1196
|
+
girl_infos: @girl_infos.size,
|
1029
1197
|
src_infos: @src_infos.size,
|
1030
1198
|
dst_infos: @dst_infos.size,
|
1031
1199
|
dns_infos: @dns_infos.size,
|
@@ -1148,6 +1316,47 @@ module Girl
|
|
1148
1316
|
add_read( src, :src )
|
1149
1317
|
end
|
1150
1318
|
|
1319
|
+
def read_relay( relay )
|
1320
|
+
begin
|
1321
|
+
data = relay.read_nonblock( READ_SIZE )
|
1322
|
+
rescue Errno::ENOTCONN => e
|
1323
|
+
return
|
1324
|
+
rescue Exception => e
|
1325
|
+
close_relay( relay )
|
1326
|
+
return
|
1327
|
+
end
|
1328
|
+
|
1329
|
+
set_update( relay )
|
1330
|
+
relay_info = @relay_infos[ relay ]
|
1331
|
+
girl = relay_info[ :girl ]
|
1332
|
+
add_girl_wbuff( girl, data )
|
1333
|
+
end
|
1334
|
+
|
1335
|
+
def read_relayd( relayd )
|
1336
|
+
check_expire_relays
|
1337
|
+
|
1338
|
+
begin
|
1339
|
+
relay, addrinfo = relayd.accept_nonblock
|
1340
|
+
rescue IO::WaitReadable, Errno::EINTR => e
|
1341
|
+
puts "relayd accept #{ e.class }"
|
1342
|
+
return
|
1343
|
+
end
|
1344
|
+
|
1345
|
+
puts "relayd accept a relay #{ addrinfo.ip_unpack.inspect }"
|
1346
|
+
|
1347
|
+
relay_info = {
|
1348
|
+
addrinfo: addrinfo,
|
1349
|
+
closing: false,
|
1350
|
+
girl: nil,
|
1351
|
+
overflowing: false,
|
1352
|
+
wbuff: ''
|
1353
|
+
}
|
1354
|
+
|
1355
|
+
@relay_infos[ relay ] = relay_info
|
1356
|
+
add_read( relay, :relay )
|
1357
|
+
relay_info[ :girl ] = new_a_girl( relay )
|
1358
|
+
end
|
1359
|
+
|
1151
1360
|
def read_rsv( rsv )
|
1152
1361
|
begin
|
1153
1362
|
data, addrinfo, rflags, *controls = rsv.recvmsg
|
@@ -1409,7 +1618,7 @@ module Girl
|
|
1409
1618
|
unless @proxy.closed? then
|
1410
1619
|
proxy_info = @proxy_infos[ @proxy ]
|
1411
1620
|
bytesize = proxy_info[ :wbuff ].bytesize
|
1412
|
-
|
1621
|
+
|
1413
1622
|
if ( bytesize >= WBUFF_LIMIT ) && !proxy_info[ :paused_srcs ].include?( src ) then
|
1414
1623
|
puts "proxy overflow pause src #{ src_id } #{ src_info[ :destination_domain ] }"
|
1415
1624
|
@reads.delete( src )
|
@@ -1559,6 +1768,14 @@ module Girl
|
|
1559
1768
|
add_write( dst )
|
1560
1769
|
end
|
1561
1770
|
|
1771
|
+
def set_girl_closing( girl )
|
1772
|
+
return if girl.nil? || girl.closed?
|
1773
|
+
girl_info = @girl_infos[ girl ]
|
1774
|
+
return if girl_info.nil? || girl_info[ :closing ]
|
1775
|
+
girl_info[ :closing ] = true
|
1776
|
+
add_write( girl )
|
1777
|
+
end
|
1778
|
+
|
1562
1779
|
def set_p1_closing( p1 )
|
1563
1780
|
return if p1.nil? || p1.closed?
|
1564
1781
|
p1_info = @p1_infos[ p1 ]
|
@@ -1567,6 +1784,14 @@ module Girl
|
|
1567
1784
|
add_write( p1 )
|
1568
1785
|
end
|
1569
1786
|
|
1787
|
+
def set_relay_closing( relay )
|
1788
|
+
return if relay.nil? || relay.closed?
|
1789
|
+
relay_info = @relay_infos[ relay ]
|
1790
|
+
return if relay_info.nil? || relay_info[ :closing ]
|
1791
|
+
relay_info[ :closing ] = true
|
1792
|
+
add_write( relay )
|
1793
|
+
end
|
1794
|
+
|
1570
1795
|
def set_remote( src )
|
1571
1796
|
return if src.nil? || src.closed?
|
1572
1797
|
|
@@ -1574,7 +1799,7 @@ module Girl
|
|
1574
1799
|
close_src( src )
|
1575
1800
|
return
|
1576
1801
|
end
|
1577
|
-
|
1802
|
+
|
1578
1803
|
src_info = @src_infos[ src ]
|
1579
1804
|
src_info[ :proxy_type ] = :remote
|
1580
1805
|
|
@@ -1627,10 +1852,14 @@ module Girl
|
|
1627
1852
|
close_dns( _sock )
|
1628
1853
|
when :dst
|
1629
1854
|
close_dst( _sock )
|
1855
|
+
when :girl
|
1856
|
+
close_girl( _sock )
|
1630
1857
|
when :mem
|
1631
1858
|
close_mem( _sock )
|
1632
1859
|
when :p1
|
1633
1860
|
close_p1( _sock )
|
1861
|
+
when :relay
|
1862
|
+
close_relay( _sock )
|
1634
1863
|
when :rsv
|
1635
1864
|
close_rsv( _sock )
|
1636
1865
|
when :src
|
@@ -1685,6 +1914,52 @@ module Girl
|
|
1685
1914
|
end
|
1686
1915
|
end
|
1687
1916
|
|
1917
|
+
def write_girl( girl )
|
1918
|
+
if girl.closed? then
|
1919
|
+
puts "write closed girl?"
|
1920
|
+
return
|
1921
|
+
end
|
1922
|
+
|
1923
|
+
girl_info = @girl_infos[ girl ]
|
1924
|
+
girl_info[ :connected ] = true
|
1925
|
+
data = girl_info[ :wbuff ]
|
1926
|
+
|
1927
|
+
if data.empty? then
|
1928
|
+
if girl_info[ :closing ] then
|
1929
|
+
close_girl( girl )
|
1930
|
+
else
|
1931
|
+
@writes.delete( girl )
|
1932
|
+
end
|
1933
|
+
|
1934
|
+
return
|
1935
|
+
end
|
1936
|
+
|
1937
|
+
begin
|
1938
|
+
if girl_info[ :is_syn ] then
|
1939
|
+
written = girl.sendmsg_nonblock( data, 536870912, @proxyd_addr )
|
1940
|
+
girl_info[ :is_syn ] = false
|
1941
|
+
else
|
1942
|
+
written = girl.write_nonblock( data )
|
1943
|
+
end
|
1944
|
+
rescue Errno::EINPROGRESS
|
1945
|
+
return
|
1946
|
+
rescue Exception => e
|
1947
|
+
close_girl( girl )
|
1948
|
+
return
|
1949
|
+
end
|
1950
|
+
|
1951
|
+
set_update( girl )
|
1952
|
+
data = data[ written..-1 ]
|
1953
|
+
girl_info[ :wbuff ] = data
|
1954
|
+
bytesize = girl_info[ :wbuff ].bytesize
|
1955
|
+
|
1956
|
+
if girl_info[ :overflowing ] && ( bytesize < RESUME_BELOW ) then
|
1957
|
+
puts "girl underhalf"
|
1958
|
+
add_read( girl_info[ :relay ] )
|
1959
|
+
girl_info[ :overflowing ] = false
|
1960
|
+
end
|
1961
|
+
end
|
1962
|
+
|
1688
1963
|
def write_mem( mem )
|
1689
1964
|
if mem.closed? then
|
1690
1965
|
puts "write closed mem?"
|
@@ -1797,7 +2072,7 @@ module Girl
|
|
1797
2072
|
proxy_info[ :paused_srcs ].each{ | src | add_read( src ) }
|
1798
2073
|
proxy_info[ :paused_srcs ].clear
|
1799
2074
|
end
|
1800
|
-
|
2075
|
+
|
1801
2076
|
if proxy_info[ :paused_p1s ].any? then
|
1802
2077
|
puts "proxy underhalf resume p1s #{ proxy_info[ :paused_p1s ].size }"
|
1803
2078
|
proxy_info[ :paused_p1s ].each{ | p1 | add_read( p1 ) }
|
@@ -1838,7 +2113,7 @@ module Girl
|
|
1838
2113
|
data = data[ written..-1 ]
|
1839
2114
|
src_info[ :wbuff ] = data
|
1840
2115
|
bytesize = src_info[ :wbuff ].bytesize
|
1841
|
-
|
2116
|
+
|
1842
2117
|
if src_info[ :overflowing ] && ( bytesize < RESUME_BELOW ) then
|
1843
2118
|
src_id = src_info[ :src_id ]
|
1844
2119
|
domain = src_info[ :destination_domain ]
|
@@ -1856,5 +2131,45 @@ module Girl
|
|
1856
2131
|
end
|
1857
2132
|
end
|
1858
2133
|
|
2134
|
+
def write_relay( relay )
|
2135
|
+
if relay.closed? then
|
2136
|
+
puts "write closed relay?"
|
2137
|
+
return
|
2138
|
+
end
|
2139
|
+
|
2140
|
+
relay_info = @relay_infos[ relay ]
|
2141
|
+
data = relay_info[ :wbuff ]
|
2142
|
+
|
2143
|
+
if data.empty? then
|
2144
|
+
if relay_info[ :closing ] then
|
2145
|
+
close_relay( relay )
|
2146
|
+
else
|
2147
|
+
@writes.delete( relay )
|
2148
|
+
end
|
2149
|
+
|
2150
|
+
return
|
2151
|
+
end
|
2152
|
+
|
2153
|
+
begin
|
2154
|
+
written = relay.write_nonblock( data )
|
2155
|
+
rescue Errno::EINPROGRESS
|
2156
|
+
return
|
2157
|
+
rescue Exception => e
|
2158
|
+
close_relay( relay )
|
2159
|
+
return
|
2160
|
+
end
|
2161
|
+
|
2162
|
+
set_update( relay )
|
2163
|
+
data = data[ written..-1 ]
|
2164
|
+
relay_info[ :wbuff ] = data
|
2165
|
+
bytesize = relay_info[ :wbuff ].bytesize
|
2166
|
+
|
2167
|
+
if relay_info[ :overflowing ] && ( bytesize < RESUME_BELOW ) then
|
2168
|
+
puts "relay underhalf"
|
2169
|
+
add_read( relay_info[ :girl ] )
|
2170
|
+
relay_info[ :overflowing ] = false
|
2171
|
+
end
|
2172
|
+
end
|
2173
|
+
|
1859
2174
|
end
|
1860
2175
|
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: 9.1.
|
4
|
+
version: 9.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- takafan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: escape evil.
|
14
14
|
email:
|