girl 9.1.3 → 9.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/girl/head.rb +7 -8
- data/lib/girl/proxy.rb +6 -34
- data/lib/girl/proxy_worker.rb +348 -506
- data/lib/girl/proxyd.rb +7 -31
- data/lib/girl/proxyd_worker.rb +531 -272
- data/lib/girl/version.rb +1 -1
- metadata +1 -1
data/lib/girl/proxy_worker.rb
CHANGED
|
@@ -6,12 +6,11 @@ module Girl
|
|
|
6
6
|
redir_host,
|
|
7
7
|
redir_port,
|
|
8
8
|
memd_port,
|
|
9
|
-
relayd_host,
|
|
10
|
-
relayd_port,
|
|
11
9
|
tspd_host,
|
|
12
10
|
tspd_port,
|
|
13
11
|
proxyd_host,
|
|
14
12
|
proxyd_port,
|
|
13
|
+
bigd_port,
|
|
15
14
|
nameservers,
|
|
16
15
|
im,
|
|
17
16
|
directs,
|
|
@@ -26,18 +25,10 @@ module Girl
|
|
|
26
25
|
h_p1_close,
|
|
27
26
|
h_p2_close,
|
|
28
27
|
h_p2_traffic,
|
|
29
|
-
h_p1_overflow,
|
|
30
|
-
h_p1_underhalf,
|
|
31
|
-
h_p2_overflow,
|
|
32
|
-
h_p2_underhalf,
|
|
33
28
|
h_query,
|
|
34
29
|
h_response,
|
|
35
30
|
h_src_close,
|
|
36
31
|
h_traffic,
|
|
37
|
-
h_src_overflow,
|
|
38
|
-
h_src_underhalf,
|
|
39
|
-
h_dst_overflow,
|
|
40
|
-
h_dst_underhalf,
|
|
41
32
|
expire_connecting,
|
|
42
33
|
expire_long_after,
|
|
43
34
|
expire_proxy_after,
|
|
@@ -45,38 +36,36 @@ module Girl
|
|
|
45
36
|
expire_short_after,
|
|
46
37
|
is_debug,
|
|
47
38
|
is_client_fastopen,
|
|
48
|
-
is_server_fastopen
|
|
49
|
-
|
|
39
|
+
is_server_fastopen)
|
|
50
40
|
@proxyd_host = proxyd_host
|
|
51
41
|
@proxyd_addr = Socket.sockaddr_in(proxyd_port, proxyd_host)
|
|
42
|
+
@bigd_addr = Socket.sockaddr_in(bigd_port, proxyd_host)
|
|
52
43
|
@nameserver_addrs = nameservers.map{|n| Socket.sockaddr_in(53, n)}
|
|
53
44
|
@im = im
|
|
54
45
|
@directs = directs
|
|
55
46
|
@remotes = remotes
|
|
56
47
|
@local_ips = Socket.ip_address_list.select{|info| info.ipv4?}.map{|info| info.ip_address}
|
|
57
48
|
@update_roles = [:dns, :dst, :mem, :p1, :src, :rsv] # 参与淘汰的角色
|
|
58
|
-
@updates_limit =
|
|
49
|
+
@updates_limit = 1008 # 淘汰池上限,1015(mac) - [info infod memd proxy redir rsvd tspd]
|
|
59
50
|
@eliminate_count = 0 # 淘汰次数
|
|
60
51
|
@reads = [] # 读池
|
|
61
52
|
@writes = [] # 写池
|
|
62
|
-
@roles = {} # sock => :
|
|
53
|
+
@roles = {} # sock => :big / :dns / :dst / :infod / :mem / :memd / :p1 / :proxy / :redir / :rsv / :rsvd / :src / :tspd
|
|
63
54
|
@updates = {} # sock => updated_at
|
|
64
|
-
@proxy_infos = {} # proxy => {:is_syn :
|
|
55
|
+
@proxy_infos = {} # proxy => {:is_syn :rbuff :recv_at :wbuff}
|
|
56
|
+
@big_infos = {} # big => {:is_syn :overflowing :rbuff :recv_at :wbuff}
|
|
65
57
|
@mem_infos = {} # mem => {:wbuff}
|
|
66
|
-
@
|
|
67
|
-
@girl_infos = {} # girl => {:closing :connected :is_syn :overflowing :relay :wbuff}
|
|
68
|
-
@src_infos = {} # src => {:addrinfo :closing :destination_domain :destination_port :dst :is_connect :overflowing :proxy_proto :proxy_type :rbuff :src_id :wbuff}
|
|
58
|
+
@src_infos = {} # src => {:addrinfo :closing :destination_domain :destination_port :dst :in :is_big :is_connect :overflowing :proxy_proto :proxy_type :rbuff :src_id :wbuff}
|
|
69
59
|
@dst_infos = {} # dst => {:closing :connected :domain :ip :overflowing :port :src :wbuff}
|
|
70
60
|
@dns_infos = {} # dns => {:domain :src}
|
|
71
61
|
@rsv_infos = {} # rsv => {:addrinfo :domain :type}
|
|
72
62
|
@near_infos = {} # near_id => {:addrinfo :created_at :domain :id :type}
|
|
73
|
-
@resolv_caches = {} # domain => [ip
|
|
63
|
+
@resolv_caches = {} # domain => [ip created_at]
|
|
74
64
|
@is_direct_caches = {} # ip => true / false
|
|
75
|
-
@response_caches = {} # domain => [response
|
|
76
|
-
@response6_caches = {} # domain => [response
|
|
77
|
-
@p1_infos = {} # p1 => {:closing :connected :overflowing :p2_id :wbuff}
|
|
65
|
+
@response_caches = {} # domain => [response created_at ip is_remote]
|
|
66
|
+
@response6_caches = {} # domain => [response created_at ip is_remote]
|
|
67
|
+
@p1_infos = {} # p1 => {:closing :connected :in :is_big :overflowing :p2_id :wbuff}
|
|
78
68
|
@appd_addr = Socket.sockaddr_in(appd_port, appd_host)
|
|
79
|
-
|
|
80
69
|
@head_len = head_len
|
|
81
70
|
@h_a_new_source = h_a_new_source
|
|
82
71
|
@h_a_new_p2 = h_a_new_p2
|
|
@@ -85,18 +74,10 @@ module Girl
|
|
|
85
74
|
@h_p1_close = h_p1_close
|
|
86
75
|
@h_p2_close = h_p2_close
|
|
87
76
|
@h_p2_traffic = h_p2_traffic
|
|
88
|
-
@h_p1_overflow = h_p1_overflow
|
|
89
|
-
@h_p1_underhalf = h_p1_underhalf
|
|
90
|
-
@h_p2_overflow = h_p2_overflow
|
|
91
|
-
@h_p2_underhalf = h_p2_underhalf
|
|
92
77
|
@h_query = h_query
|
|
93
78
|
@h_response = h_response
|
|
94
79
|
@h_src_close = h_src_close
|
|
95
80
|
@h_traffic = h_traffic
|
|
96
|
-
@h_src_overflow = h_src_overflow
|
|
97
|
-
@h_src_underhalf = h_src_underhalf
|
|
98
|
-
@h_dst_overflow = h_dst_overflow
|
|
99
|
-
@h_dst_underhalf = h_dst_underhalf
|
|
100
81
|
@expire_connecting = expire_connecting
|
|
101
82
|
@expire_long_after = expire_long_after
|
|
102
83
|
@expire_proxy_after = expire_proxy_after
|
|
@@ -105,14 +86,13 @@ module Girl
|
|
|
105
86
|
@is_debug = is_debug
|
|
106
87
|
@is_client_fastopen = is_client_fastopen
|
|
107
88
|
@is_server_fastopen = is_server_fastopen
|
|
108
|
-
|
|
109
89
|
new_a_redir(redir_host, redir_port)
|
|
110
90
|
new_a_infod(redir_port)
|
|
111
91
|
new_a_memd(memd_port)
|
|
112
|
-
new_a_relayd(relayd_host, relayd_port)
|
|
113
92
|
new_a_rsvd(tspd_host, tspd_port)
|
|
114
93
|
new_a_tspd(tspd_host, tspd_port)
|
|
115
94
|
new_a_proxy
|
|
95
|
+
new_a_big
|
|
116
96
|
end
|
|
117
97
|
|
|
118
98
|
def looping
|
|
@@ -126,12 +106,12 @@ module Girl
|
|
|
126
106
|
role = @roles[sock]
|
|
127
107
|
|
|
128
108
|
case role
|
|
109
|
+
when :big
|
|
110
|
+
read_big(sock)
|
|
129
111
|
when :dns
|
|
130
112
|
read_dns(sock)
|
|
131
113
|
when :dst
|
|
132
114
|
read_dst(sock)
|
|
133
|
-
when :girl
|
|
134
|
-
read_girl(sock)
|
|
135
115
|
when :infod
|
|
136
116
|
read_infod(sock)
|
|
137
117
|
when :mem
|
|
@@ -144,10 +124,6 @@ module Girl
|
|
|
144
124
|
read_proxy(sock)
|
|
145
125
|
when :redir
|
|
146
126
|
read_redir(sock)
|
|
147
|
-
when :relay
|
|
148
|
-
read_relay(sock)
|
|
149
|
-
when :relayd
|
|
150
|
-
read_relayd(sock)
|
|
151
127
|
when :rsv
|
|
152
128
|
read_rsv(sock)
|
|
153
129
|
when :rsvd
|
|
@@ -165,18 +141,16 @@ module Girl
|
|
|
165
141
|
role = @roles[sock]
|
|
166
142
|
|
|
167
143
|
case role
|
|
144
|
+
when :big
|
|
145
|
+
write_big(sock)
|
|
168
146
|
when :dst
|
|
169
147
|
write_dst(sock)
|
|
170
|
-
when :girl
|
|
171
|
-
write_girl(sock)
|
|
172
148
|
when :mem
|
|
173
149
|
write_mem(sock)
|
|
174
150
|
when :p1
|
|
175
151
|
write_p1(sock)
|
|
176
152
|
when :proxy
|
|
177
153
|
write_proxy(sock)
|
|
178
|
-
when :relay
|
|
179
|
-
write_relay(sock)
|
|
180
154
|
when :src
|
|
181
155
|
write_src(sock)
|
|
182
156
|
else
|
|
@@ -195,46 +169,48 @@ module Girl
|
|
|
195
169
|
|
|
196
170
|
private
|
|
197
171
|
|
|
198
|
-
def
|
|
199
|
-
return if
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
bytesize =
|
|
172
|
+
def add_big_wbuff(data)
|
|
173
|
+
return if @big.closed? || data.nil? || data.empty?
|
|
174
|
+
big_info = @big_infos[@big]
|
|
175
|
+
big_info[:wbuff] << data
|
|
176
|
+
bytesize = big_info[:wbuff].bytesize
|
|
203
177
|
|
|
204
178
|
if bytesize >= CLOSE_ABOVE
|
|
205
|
-
puts "close overflow
|
|
206
|
-
|
|
179
|
+
puts "close overflow big"
|
|
180
|
+
close_big(@big)
|
|
207
181
|
return
|
|
208
182
|
end
|
|
209
183
|
|
|
210
|
-
if !
|
|
211
|
-
puts "
|
|
212
|
-
|
|
213
|
-
dst_info[:overflowing] = true
|
|
184
|
+
if !big_info[:overflowing] && (bytesize >= WBUFF_LIMIT)
|
|
185
|
+
puts "big overflow"
|
|
186
|
+
big_info[:overflowing] = true
|
|
214
187
|
end
|
|
215
188
|
|
|
216
|
-
add_write(
|
|
189
|
+
add_write(@big)
|
|
190
|
+
big_info[:overflowing]
|
|
217
191
|
end
|
|
218
192
|
|
|
219
|
-
def
|
|
220
|
-
return if
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
bytesize =
|
|
193
|
+
def add_dst_wbuff(dst, data)
|
|
194
|
+
return if dst.nil? || dst.closed? || data.nil? || data.empty?
|
|
195
|
+
dst_info = @dst_infos[dst]
|
|
196
|
+
dst_info[:wbuff] << data
|
|
197
|
+
bytesize = dst_info[:wbuff].bytesize
|
|
198
|
+
domain = dst_info[:domain]
|
|
224
199
|
|
|
225
200
|
if bytesize >= CLOSE_ABOVE
|
|
226
|
-
puts "close overflow
|
|
227
|
-
|
|
201
|
+
puts "close overflow dst #{domain}"
|
|
202
|
+
close_dst(dst)
|
|
228
203
|
return
|
|
229
204
|
end
|
|
230
205
|
|
|
231
|
-
if !
|
|
232
|
-
puts "
|
|
233
|
-
|
|
234
|
-
|
|
206
|
+
if !dst_info[:overflowing] && (bytesize >= WBUFF_LIMIT)
|
|
207
|
+
puts "dst overflow #{domain}"
|
|
208
|
+
dst_info[:overflowing] = true
|
|
209
|
+
puts "pause src"
|
|
210
|
+
@reads.delete(dst_info[:src])
|
|
235
211
|
end
|
|
236
212
|
|
|
237
|
-
add_write(
|
|
213
|
+
add_write(dst)
|
|
238
214
|
end
|
|
239
215
|
|
|
240
216
|
def add_mem_wbuff(mem, data)
|
|
@@ -258,10 +234,13 @@ module Girl
|
|
|
258
234
|
end
|
|
259
235
|
|
|
260
236
|
if !p1_info[:overflowing] && (bytesize >= WBUFF_LIMIT)
|
|
261
|
-
puts "
|
|
262
|
-
msg = "#{@h_p1_overflow}#{[p2_id].pack('Q>')}"
|
|
263
|
-
add_proxy_wbuff(pack_a_chunk(msg))
|
|
237
|
+
puts "p1 overflow #{p2_id}"
|
|
264
238
|
p1_info[:overflowing] = true
|
|
239
|
+
|
|
240
|
+
if @big
|
|
241
|
+
puts 'pause big'
|
|
242
|
+
@reads.delete(@big)
|
|
243
|
+
end
|
|
265
244
|
end
|
|
266
245
|
|
|
267
246
|
add_write(p1)
|
|
@@ -295,27 +274,6 @@ module Girl
|
|
|
295
274
|
set_update(sock) if @update_roles.include?(role)
|
|
296
275
|
end
|
|
297
276
|
|
|
298
|
-
def add_relay_wbuff(relay, data)
|
|
299
|
-
return if relay.nil? || relay.closed? || data.nil? || data.empty?
|
|
300
|
-
relay_info = @relay_infos[relay]
|
|
301
|
-
relay_info[:wbuff] << data
|
|
302
|
-
bytesize = relay_info[:wbuff].bytesize
|
|
303
|
-
|
|
304
|
-
if bytesize >= CLOSE_ABOVE
|
|
305
|
-
puts "close overflow relay #{relay_info[:addrinfo].ip_unpack.inspect}"
|
|
306
|
-
close_relay(relay)
|
|
307
|
-
return
|
|
308
|
-
end
|
|
309
|
-
|
|
310
|
-
if !relay_info[:overflowing] && (bytesize >= WBUFF_LIMIT)
|
|
311
|
-
puts "relay overflow pause girl #{relay_info[:addrinfo].ip_unpack.inspect}"
|
|
312
|
-
@reads.delete(relay_info[:girl])
|
|
313
|
-
relay_info[:overflowing] = true
|
|
314
|
-
end
|
|
315
|
-
|
|
316
|
-
add_write(relay)
|
|
317
|
-
end
|
|
318
|
-
|
|
319
277
|
def add_socks5_conn_reply(src)
|
|
320
278
|
# +----+-----+-------+------+----------+----------+
|
|
321
279
|
# |VER | REP | RSV | ATYP | BND.ADDR | BND.PORT |
|
|
@@ -354,16 +312,16 @@ module Girl
|
|
|
354
312
|
end
|
|
355
313
|
|
|
356
314
|
if !src_info[:overflowing] && (bytesize >= WBUFF_LIMIT)
|
|
315
|
+
puts "src overflow #{src_id} #{domain}"
|
|
316
|
+
src_info[:overflowing] = true
|
|
317
|
+
|
|
357
318
|
if src_info[:proxy_type] == :direct
|
|
358
|
-
puts "
|
|
319
|
+
puts "pause dst"
|
|
359
320
|
@reads.delete(src_info[:dst])
|
|
360
321
|
elsif src_info[:proxy_type] == :remote
|
|
361
|
-
puts "
|
|
362
|
-
|
|
363
|
-
add_proxy_wbuff(pack_a_chunk(msg))
|
|
322
|
+
puts "pause big"
|
|
323
|
+
@reads.delete(@big)
|
|
364
324
|
end
|
|
365
|
-
|
|
366
|
-
src_info[:overflowing] = true
|
|
367
325
|
end
|
|
368
326
|
|
|
369
327
|
add_write(src)
|
|
@@ -394,15 +352,6 @@ module Girl
|
|
|
394
352
|
end
|
|
395
353
|
end
|
|
396
354
|
|
|
397
|
-
def check_expire_girls
|
|
398
|
-
now = Time.new
|
|
399
|
-
|
|
400
|
-
@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, _|
|
|
401
|
-
puts "expire girl" if @is_debug
|
|
402
|
-
close_girl(girl)
|
|
403
|
-
end
|
|
404
|
-
end
|
|
405
|
-
|
|
406
355
|
def check_expire_mems
|
|
407
356
|
now = Time.new
|
|
408
357
|
|
|
@@ -430,15 +379,6 @@ module Girl
|
|
|
430
379
|
end
|
|
431
380
|
end
|
|
432
381
|
|
|
433
|
-
def check_expire_relays
|
|
434
|
-
now = Time.new
|
|
435
|
-
|
|
436
|
-
@relay_infos.select{|relay, _| now.to_i - @updates[relay].to_i >= @expire_long_after}.each do |relay, info|
|
|
437
|
-
puts "expire relay #{info[:addrinfo].ip_unpack.inspect}" if @is_debug
|
|
438
|
-
close_relay(relay)
|
|
439
|
-
end
|
|
440
|
-
end
|
|
441
|
-
|
|
442
382
|
def check_expire_rsvs
|
|
443
383
|
now = Time.new
|
|
444
384
|
|
|
@@ -457,11 +397,24 @@ module Girl
|
|
|
457
397
|
end
|
|
458
398
|
end
|
|
459
399
|
|
|
400
|
+
def close_big(big)
|
|
401
|
+
return if big.nil? || big.closed?
|
|
402
|
+
close_sock(big)
|
|
403
|
+
big_info = @big_infos.delete(big)
|
|
404
|
+
puts "close big"
|
|
405
|
+
big_info
|
|
406
|
+
end
|
|
407
|
+
|
|
460
408
|
def close_dns(dns)
|
|
461
409
|
return nil if dns.nil? || dns.closed?
|
|
462
410
|
close_sock(dns)
|
|
463
411
|
dns_info = @dns_infos.delete(dns)
|
|
464
|
-
|
|
412
|
+
|
|
413
|
+
if dns_info
|
|
414
|
+
domain = dns_info[:domain]
|
|
415
|
+
puts "close dns #{domain}" if @is_debug
|
|
416
|
+
end
|
|
417
|
+
|
|
465
418
|
dns_info
|
|
466
419
|
end
|
|
467
420
|
|
|
@@ -469,18 +422,14 @@ module Girl
|
|
|
469
422
|
return nil if dst.nil? || dst.closed?
|
|
470
423
|
close_sock(dst)
|
|
471
424
|
dst_info = @dst_infos.delete(dst)
|
|
472
|
-
puts "close dst #{dst_info[:domain]}" if @is_debug
|
|
473
|
-
set_src_closing(dst_info[:src]) if dst_info
|
|
474
|
-
dst_info
|
|
475
|
-
end
|
|
476
425
|
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
426
|
+
if dst_info
|
|
427
|
+
domain = dst_info[:domain]
|
|
428
|
+
puts "close dst #{domain}" if @is_debug
|
|
429
|
+
set_src_closing(dst_info[:src])
|
|
430
|
+
end
|
|
431
|
+
|
|
432
|
+
dst_info
|
|
484
433
|
end
|
|
485
434
|
|
|
486
435
|
def close_mem(mem)
|
|
@@ -494,9 +443,7 @@ module Girl
|
|
|
494
443
|
close_sock(p1)
|
|
495
444
|
p1_info = @p1_infos.delete(p1)
|
|
496
445
|
|
|
497
|
-
|
|
498
|
-
proxy_info = @proxy_infos[@proxy]
|
|
499
|
-
proxy_info[:paused_p1s].delete(p1)
|
|
446
|
+
if p1_info
|
|
500
447
|
p2_id = p1_info[:p2_id]
|
|
501
448
|
puts "add h_p1_close #{p2_id}"
|
|
502
449
|
msg = "#{@h_p1_close}#{[p2_id].pack('Q>')}"
|
|
@@ -516,20 +463,16 @@ module Girl
|
|
|
516
463
|
proxy_info
|
|
517
464
|
end
|
|
518
465
|
|
|
519
|
-
def close_relay(relay)
|
|
520
|
-
return nil if relay.nil? || relay.closed?
|
|
521
|
-
close_sock(relay)
|
|
522
|
-
relay_info = @relay_infos.delete(relay)
|
|
523
|
-
puts "close relay" if @is_debug
|
|
524
|
-
set_girl_closing(relay_info[:girl]) if relay_info
|
|
525
|
-
relay_info
|
|
526
|
-
end
|
|
527
|
-
|
|
528
466
|
def close_rsv(rsv)
|
|
529
467
|
return nil if rsv.nil? || rsv.closed?
|
|
530
468
|
close_sock(rsv)
|
|
531
469
|
rsv_info = @rsv_infos.delete(rsv)
|
|
532
|
-
|
|
470
|
+
|
|
471
|
+
if rsv_info
|
|
472
|
+
domain = rsv_info[:domain]
|
|
473
|
+
puts "close rsv #{domain}" if @is_debug
|
|
474
|
+
end
|
|
475
|
+
|
|
533
476
|
rsv_info
|
|
534
477
|
end
|
|
535
478
|
|
|
@@ -546,23 +489,50 @@ module Girl
|
|
|
546
489
|
return nil if src.nil? || src.closed?
|
|
547
490
|
close_sock(src)
|
|
548
491
|
src_info = @src_infos.delete(src)
|
|
549
|
-
src_id = src_info[:src_id]
|
|
550
|
-
domain = src_info[:destination_domain]
|
|
551
|
-
puts "close src #{domain}" if @is_debug
|
|
552
492
|
|
|
553
|
-
if src_info
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
493
|
+
if src_info
|
|
494
|
+
src_id = src_info[:src_id]
|
|
495
|
+
domain = src_info[:destination_domain]
|
|
496
|
+
proxy_type = src_info[:proxy_type]
|
|
497
|
+
puts "close src #{domain}" if @is_debug
|
|
498
|
+
|
|
499
|
+
if proxy_type == :direct
|
|
500
|
+
set_dst_closing(src_info[:dst])
|
|
501
|
+
elsif proxy_type == :remote
|
|
502
|
+
puts "add h_src_close #{src_id}" if @is_debug
|
|
503
|
+
msg = "#{@h_src_close}#{[src_id].pack('Q>')}"
|
|
504
|
+
add_proxy_wbuff(pack_a_chunk(msg))
|
|
505
|
+
end
|
|
561
506
|
end
|
|
562
507
|
|
|
563
508
|
src_info
|
|
564
509
|
end
|
|
565
510
|
|
|
511
|
+
def deal_big_msg(data)
|
|
512
|
+
return if data.nil? || data.empty? || @big.closed?
|
|
513
|
+
big_info = @big_infos[@big]
|
|
514
|
+
now = Time.new
|
|
515
|
+
big_info[:recv_at] = now
|
|
516
|
+
h = data[0]
|
|
517
|
+
|
|
518
|
+
case h
|
|
519
|
+
when @h_p2_traffic
|
|
520
|
+
return if data.bytesize < 9
|
|
521
|
+
p2_id = data[1, 8].unpack('Q>').first
|
|
522
|
+
data = data[9..-1]
|
|
523
|
+
# puts "big got h_p2_traffic #{p2_id} #{data.bytesize}" if @is_debug
|
|
524
|
+
p1, _ = @p1_infos.find{|_, info| info[:p2_id] == p2_id}
|
|
525
|
+
add_p1_wbuff(p1, data)
|
|
526
|
+
when @h_traffic
|
|
527
|
+
return if data.bytesize < 9
|
|
528
|
+
src_id = data[1, 8].unpack('Q>').first
|
|
529
|
+
data = data[9..-1]
|
|
530
|
+
# puts "big got h_traffic #{src_id} #{data.bytesize}" if @is_debug
|
|
531
|
+
src, _ = @src_infos.find{|_, info| info[:src_id] == src_id}
|
|
532
|
+
add_src_wbuff(src, data)
|
|
533
|
+
end
|
|
534
|
+
end
|
|
535
|
+
|
|
566
536
|
def deal_msg(data)
|
|
567
537
|
return if data.nil? || data.empty? || @proxy.closed?
|
|
568
538
|
proxy_info = @proxy_infos[@proxy]
|
|
@@ -582,8 +552,6 @@ module Girl
|
|
|
582
552
|
puts "got h_dst_close #{src_id}" if @is_debug
|
|
583
553
|
src, _ = @src_infos.find{|_, info| info[:src_id] == src_id}
|
|
584
554
|
set_src_closing(src)
|
|
585
|
-
when @h_heartbeat
|
|
586
|
-
puts "got h_heartbeat" if @is_debug
|
|
587
555
|
when @h_p2_close
|
|
588
556
|
return if data.bytesize < 9
|
|
589
557
|
p2_id = data[1, 8].unpack('Q>').first
|
|
@@ -594,22 +562,8 @@ module Girl
|
|
|
594
562
|
return if data.bytesize < 9
|
|
595
563
|
p2_id = data[1, 8].unpack('Q>').first
|
|
596
564
|
data = data[9..-1]
|
|
597
|
-
# puts "got h_p2_traffic #{p2_id} #{data.bytesize}" if @is_debug
|
|
598
565
|
p1, _ = @p1_infos.find{|_, info| info[:p2_id] == p2_id}
|
|
599
566
|
add_p1_wbuff(p1, data)
|
|
600
|
-
when @h_p2_overflow
|
|
601
|
-
return if data.bytesize < 9
|
|
602
|
-
p2_id = data[1, 8].unpack('Q>').first
|
|
603
|
-
puts "got h_p2_overflow pause p1 #{p2_id}"
|
|
604
|
-
p1, _ = @p1_infos.find{|_, info| info[:p2_id] == p2_id}
|
|
605
|
-
@reads.delete(p1)
|
|
606
|
-
proxy_info[:paused_p1s].delete(p1)
|
|
607
|
-
when @h_p2_underhalf
|
|
608
|
-
return if data.bytesize < 9
|
|
609
|
-
p2_id = data[1, 8].unpack('Q>').first
|
|
610
|
-
puts "got h_p2_underhalf #{p2_id}"
|
|
611
|
-
p1, _ = @p1_infos.find{|_, info| info[:p2_id] == p2_id}
|
|
612
|
-
add_read(p1)
|
|
613
567
|
when @h_response
|
|
614
568
|
return if data.bytesize < 3
|
|
615
569
|
near_id = data[1, 8].unpack('Q>').first
|
|
@@ -643,22 +597,8 @@ module Girl
|
|
|
643
597
|
return if data.bytesize < 9
|
|
644
598
|
src_id = data[1, 8].unpack('Q>').first
|
|
645
599
|
data = data[9..-1]
|
|
646
|
-
# puts "got h_traffic #{src_id} #{data.bytesize}" if @is_debug
|
|
647
600
|
src, _ = @src_infos.find{|_, info| info[:src_id] == src_id}
|
|
648
601
|
add_src_wbuff(src, data)
|
|
649
|
-
when @h_dst_overflow
|
|
650
|
-
return if data.bytesize < 9
|
|
651
|
-
src_id = data[1, 8].unpack('Q>').first
|
|
652
|
-
puts "got h_dst_overflow pause src #{src_id}"
|
|
653
|
-
src, _ = @src_infos.find{|_, info| info[:src_id] == src_id}
|
|
654
|
-
@reads.delete(src)
|
|
655
|
-
proxy_info[:paused_srcs].delete(src)
|
|
656
|
-
when @h_dst_underhalf
|
|
657
|
-
return if data.bytesize < 9
|
|
658
|
-
src_id = data[1, 8].unpack('Q>').first
|
|
659
|
-
puts "got h_dst_underhalf #{src_id}"
|
|
660
|
-
src, _ = @src_infos.find{|_, info| info[:src_id] == src_id}
|
|
661
|
-
add_read(src)
|
|
662
602
|
end
|
|
663
603
|
end
|
|
664
604
|
|
|
@@ -708,7 +648,7 @@ module Girl
|
|
|
708
648
|
domain = src_info[:destination_domain]
|
|
709
649
|
port = src_info[:destination_port]
|
|
710
650
|
|
|
711
|
-
if @local_ips.include?(ip) && [@redir_port, @
|
|
651
|
+
if @local_ips.include?(ip) && [@redir_port, @tspd_port].include?(port)
|
|
712
652
|
puts "ignore #{ip}:#{port}"
|
|
713
653
|
close_src(src)
|
|
714
654
|
return
|
|
@@ -742,6 +682,39 @@ module Girl
|
|
|
742
682
|
end
|
|
743
683
|
end
|
|
744
684
|
|
|
685
|
+
def new_a_big
|
|
686
|
+
big = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
|
|
687
|
+
big.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
|
688
|
+
|
|
689
|
+
if @is_client_fastopen
|
|
690
|
+
big.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_FASTOPEN, 5)
|
|
691
|
+
else
|
|
692
|
+
begin
|
|
693
|
+
big.connect_nonblock(@bigd_addr)
|
|
694
|
+
rescue IO::WaitWritable
|
|
695
|
+
rescue Exception => e
|
|
696
|
+
puts "connect bigd #{e.class}"
|
|
697
|
+
big.close
|
|
698
|
+
return
|
|
699
|
+
end
|
|
700
|
+
end
|
|
701
|
+
|
|
702
|
+
puts "big im #{@im}"
|
|
703
|
+
chars = []
|
|
704
|
+
@head_len.times{chars << rand(256)}
|
|
705
|
+
head = "#{chars.pack('C*')}#{[@im.bytesize].pack('C')}#{@im}"
|
|
706
|
+
@big = big
|
|
707
|
+
@big_infos[big] = {
|
|
708
|
+
is_syn: @is_client_fastopen,
|
|
709
|
+
overflowing: false,
|
|
710
|
+
rbuff: '',
|
|
711
|
+
recv_at: Time.new,
|
|
712
|
+
wbuff: head
|
|
713
|
+
}
|
|
714
|
+
add_read(big, :big)
|
|
715
|
+
add_write(big)
|
|
716
|
+
end
|
|
717
|
+
|
|
745
718
|
def new_a_dst(ip, src)
|
|
746
719
|
return if src.nil? || src.closed?
|
|
747
720
|
src_info = @src_infos[src]
|
|
@@ -770,7 +743,7 @@ module Girl
|
|
|
770
743
|
return
|
|
771
744
|
end
|
|
772
745
|
|
|
773
|
-
|
|
746
|
+
@dst_infos[dst] = {
|
|
774
747
|
closing: false,
|
|
775
748
|
connected: false,
|
|
776
749
|
domain: domain,
|
|
@@ -780,8 +753,6 @@ module Girl
|
|
|
780
753
|
src: src,
|
|
781
754
|
wbuff: ''
|
|
782
755
|
}
|
|
783
|
-
|
|
784
|
-
@dst_infos[dst] = dst_info
|
|
785
756
|
src_info[:proxy_type] = :direct
|
|
786
757
|
src_info[:dst] = dst
|
|
787
758
|
|
|
@@ -805,45 +776,6 @@ module Girl
|
|
|
805
776
|
end
|
|
806
777
|
end
|
|
807
778
|
|
|
808
|
-
def new_a_girl(relay)
|
|
809
|
-
return if relay.nil? || relay.closed?
|
|
810
|
-
check_expire_girls
|
|
811
|
-
|
|
812
|
-
begin
|
|
813
|
-
girl = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
|
|
814
|
-
rescue Exception => e
|
|
815
|
-
puts "new a girl #{e.class}"
|
|
816
|
-
close_girl(girl)
|
|
817
|
-
return
|
|
818
|
-
end
|
|
819
|
-
|
|
820
|
-
girl.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
|
821
|
-
|
|
822
|
-
begin
|
|
823
|
-
girl.connect_nonblock(@proxyd_addr)
|
|
824
|
-
rescue IO::WaitWritable
|
|
825
|
-
rescue Exception => e
|
|
826
|
-
puts "girl connect proxyd #{e.class}"
|
|
827
|
-
girl.close
|
|
828
|
-
close_girl(girl)
|
|
829
|
-
return
|
|
830
|
-
end
|
|
831
|
-
|
|
832
|
-
girl_info = {
|
|
833
|
-
closing: false,
|
|
834
|
-
connected: false,
|
|
835
|
-
is_syn: @is_client_fastopen,
|
|
836
|
-
overflowing: false,
|
|
837
|
-
relay: relay,
|
|
838
|
-
wbuff: ''
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
@girl_infos[girl] = girl_info
|
|
842
|
-
add_read(girl, :girl)
|
|
843
|
-
add_write(girl)
|
|
844
|
-
girl
|
|
845
|
-
end
|
|
846
|
-
|
|
847
779
|
def new_a_infod(infod_port)
|
|
848
780
|
infod_host = '127.0.0.1'
|
|
849
781
|
infod_addr = Socket.sockaddr_in(infod_port, infod_host)
|
|
@@ -891,15 +823,15 @@ module Girl
|
|
|
891
823
|
return
|
|
892
824
|
end
|
|
893
825
|
|
|
894
|
-
|
|
826
|
+
@p1_infos[p1] = {
|
|
895
827
|
closing: false,
|
|
896
828
|
connected: false,
|
|
829
|
+
in: 0,
|
|
830
|
+
is_big: false,
|
|
897
831
|
overflowing: false,
|
|
898
832
|
p2_id: p2_id,
|
|
899
833
|
wbuff: ''
|
|
900
834
|
}
|
|
901
|
-
|
|
902
|
-
@p1_infos[p1] = p1_info
|
|
903
835
|
add_read(p1, :p1)
|
|
904
836
|
add_write(p1)
|
|
905
837
|
end
|
|
@@ -921,25 +853,19 @@ module Girl
|
|
|
921
853
|
end
|
|
922
854
|
end
|
|
923
855
|
|
|
924
|
-
puts "im #{@im}"
|
|
856
|
+
puts "proxy im #{@im}"
|
|
925
857
|
chars = []
|
|
926
858
|
@head_len.times{chars << rand(256)}
|
|
927
859
|
head = "#{chars.pack('C*')}#{[@im.bytesize].pack('C')}#{@im}"
|
|
928
|
-
|
|
929
|
-
|
|
860
|
+
@proxy = proxy
|
|
861
|
+
@proxy_infos[proxy] = {
|
|
930
862
|
is_syn: @is_client_fastopen,
|
|
931
|
-
paused_p1s: [],
|
|
932
|
-
paused_srcs: [],
|
|
933
863
|
rbuff: '',
|
|
934
|
-
recv_at:
|
|
864
|
+
recv_at: Time.new,
|
|
935
865
|
wbuff: head
|
|
936
866
|
}
|
|
937
|
-
|
|
938
|
-
@proxy = proxy
|
|
939
|
-
@proxy_infos[proxy] = proxy_info
|
|
940
867
|
add_read(proxy, :proxy)
|
|
941
868
|
add_write(proxy)
|
|
942
|
-
proxy_info
|
|
943
869
|
end
|
|
944
870
|
|
|
945
871
|
def new_a_redir(redir_host, redir_port)
|
|
@@ -956,19 +882,6 @@ module Girl
|
|
|
956
882
|
@redir_local_address = redir.local_address
|
|
957
883
|
end
|
|
958
884
|
|
|
959
|
-
def new_a_relayd(relayd_host, relayd_port)
|
|
960
|
-
relayd = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
|
|
961
|
-
relayd.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
|
962
|
-
relayd.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, 1)
|
|
963
|
-
relayd.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEPORT, 1) if RUBY_PLATFORM.include?('linux')
|
|
964
|
-
relayd.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_FASTOPEN, BACKLOG) if @is_server_fastopen
|
|
965
|
-
relayd.bind(Socket.sockaddr_in(relayd_port, relayd_host))
|
|
966
|
-
relayd.listen(BACKLOG)
|
|
967
|
-
puts "relayd listen on #{relayd_host} #{relayd_port}"
|
|
968
|
-
add_read(relayd, :relayd)
|
|
969
|
-
@relayd_port = relayd_port
|
|
970
|
-
end
|
|
971
|
-
|
|
972
885
|
def new_a_rsv(data, addrinfo, domain, type)
|
|
973
886
|
check_expire_rsvs
|
|
974
887
|
rsv = Socket.new(Socket::AF_INET, Socket::SOCK_DGRAM, 0)
|
|
@@ -981,13 +894,11 @@ module Girl
|
|
|
981
894
|
return
|
|
982
895
|
end
|
|
983
896
|
|
|
984
|
-
|
|
897
|
+
@rsv_infos[rsv] = {
|
|
985
898
|
addrinfo: addrinfo,
|
|
986
899
|
domain: domain,
|
|
987
900
|
type: type
|
|
988
901
|
}
|
|
989
|
-
|
|
990
|
-
@rsv_infos[rsv] = rsv_info
|
|
991
902
|
add_read(rsv, :rsv)
|
|
992
903
|
end
|
|
993
904
|
|
|
@@ -1023,7 +934,6 @@ module Girl
|
|
|
1023
934
|
|
|
1024
935
|
loop do
|
|
1025
936
|
part = data[0, 65526]
|
|
1026
|
-
# puts "add h_p2_traffic #{p2_id} #{part.bytesize}" if @is_debug
|
|
1027
937
|
msg = "#{@h_p2_traffic}#{[p2_id].pack('Q>')}#{part}"
|
|
1028
938
|
chunks << pack_a_chunk(msg)
|
|
1029
939
|
data = data[part.bytesize..-1]
|
|
@@ -1038,7 +948,6 @@ module Girl
|
|
|
1038
948
|
|
|
1039
949
|
loop do
|
|
1040
950
|
part = data[0, 65526]
|
|
1041
|
-
# puts "add h_traffic #{src_id} #{part.bytesize}" if @is_debug
|
|
1042
951
|
msg = "#{@h_traffic}#{[src_id].pack('Q>')}#{part}"
|
|
1043
952
|
chunks << pack_a_chunk(msg)
|
|
1044
953
|
data = data[part.bytesize..-1]
|
|
@@ -1048,6 +957,25 @@ module Girl
|
|
|
1048
957
|
chunks
|
|
1049
958
|
end
|
|
1050
959
|
|
|
960
|
+
def read_big(big)
|
|
961
|
+
begin
|
|
962
|
+
data = big.read_nonblock(READ_SIZE)
|
|
963
|
+
rescue Errno::ENOTCONN => e
|
|
964
|
+
return
|
|
965
|
+
rescue Exception => e
|
|
966
|
+
puts "read big #{e.class}" if @is_debug
|
|
967
|
+
close_big(big)
|
|
968
|
+
return
|
|
969
|
+
end
|
|
970
|
+
|
|
971
|
+
set_update(big)
|
|
972
|
+
big_info = @big_infos[big]
|
|
973
|
+
data = "#{big_info[:rbuff]}#{data}"
|
|
974
|
+
msgs, part = decode_to_msgs(data)
|
|
975
|
+
msgs.each{|msg| deal_big_msg(msg)}
|
|
976
|
+
big_info[:rbuff] = part
|
|
977
|
+
end
|
|
978
|
+
|
|
1051
979
|
def read_dns(dns)
|
|
1052
980
|
begin
|
|
1053
981
|
data, addrinfo, rflags, *controls = dns.recvmsg
|
|
@@ -1089,33 +1017,17 @@ module Girl
|
|
|
1089
1017
|
rescue Errno::ENOTCONN => e
|
|
1090
1018
|
return
|
|
1091
1019
|
rescue Exception => e
|
|
1020
|
+
puts "read dst #{e.class}" if @is_debug
|
|
1092
1021
|
close_dst(dst)
|
|
1093
1022
|
return
|
|
1094
1023
|
end
|
|
1095
1024
|
|
|
1096
1025
|
set_update(dst)
|
|
1097
1026
|
dst_info = @dst_infos[dst]
|
|
1098
|
-
# puts "read dst #{dst_info[:domain]} #{data.bytesize}" if @is_debug
|
|
1099
1027
|
src = dst_info[:src]
|
|
1100
1028
|
add_src_wbuff(src, data)
|
|
1101
1029
|
end
|
|
1102
1030
|
|
|
1103
|
-
def read_girl(girl)
|
|
1104
|
-
begin
|
|
1105
|
-
data = girl.read_nonblock(READ_SIZE)
|
|
1106
|
-
rescue Errno::ENOTCONN => e
|
|
1107
|
-
return
|
|
1108
|
-
rescue Exception => e
|
|
1109
|
-
close_girl(girl)
|
|
1110
|
-
return
|
|
1111
|
-
end
|
|
1112
|
-
|
|
1113
|
-
set_update(girl)
|
|
1114
|
-
girl_info = @girl_infos[girl]
|
|
1115
|
-
relay = girl_info[:relay]
|
|
1116
|
-
add_relay_wbuff(relay, data)
|
|
1117
|
-
end
|
|
1118
|
-
|
|
1119
1031
|
def read_infod(infod)
|
|
1120
1032
|
begin
|
|
1121
1033
|
data, addrinfo, rflags, *controls = infod.recvmsg
|
|
@@ -1137,18 +1049,26 @@ module Girl
|
|
|
1137
1049
|
|
|
1138
1050
|
case message_type
|
|
1139
1051
|
when 'heartbeat'
|
|
1140
|
-
if @proxy.closed?
|
|
1052
|
+
new_a_proxy if @proxy.closed?
|
|
1053
|
+
new_a_big if @big.closed?
|
|
1054
|
+
proxy_info = @proxy_infos[@proxy]
|
|
1055
|
+
|
|
1056
|
+
if Time.new.to_i - proxy_info[:recv_at].to_i >= @expire_proxy_after
|
|
1057
|
+
puts "renew proxy"
|
|
1058
|
+
close_proxy(@proxy)
|
|
1141
1059
|
new_a_proxy
|
|
1142
1060
|
else
|
|
1143
|
-
|
|
1061
|
+
add_proxy_wbuff(pack_a_chunk(@h_heartbeat))
|
|
1062
|
+
end
|
|
1144
1063
|
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1064
|
+
big_info = @big_infos[@big]
|
|
1065
|
+
|
|
1066
|
+
if Time.new.to_i - big_info[:recv_at].to_i >= @expire_proxy_after
|
|
1067
|
+
puts "renew big"
|
|
1068
|
+
close_big(@big)
|
|
1069
|
+
new_a_big
|
|
1070
|
+
else
|
|
1071
|
+
add_big_wbuff(pack_a_chunk(@h_heartbeat))
|
|
1152
1072
|
end
|
|
1153
1073
|
end
|
|
1154
1074
|
end
|
|
@@ -1186,9 +1106,8 @@ module Girl
|
|
|
1186
1106
|
roles: @roles.size,
|
|
1187
1107
|
updates: @updates.size,
|
|
1188
1108
|
proxy_infos: @proxy_infos.size,
|
|
1109
|
+
big_infos: @big_infos.size,
|
|
1189
1110
|
mem_infos: @mem_infos.size,
|
|
1190
|
-
relay_infos: @relay_infos.size,
|
|
1191
|
-
girl_infos: @girl_infos.size,
|
|
1192
1111
|
src_infos: @src_infos.size,
|
|
1193
1112
|
dst_infos: @dst_infos.size,
|
|
1194
1113
|
dns_infos: @dns_infos.size,
|
|
@@ -1232,31 +1151,42 @@ module Girl
|
|
|
1232
1151
|
rescue Errno::ENOTCONN => e
|
|
1233
1152
|
return
|
|
1234
1153
|
rescue Exception => e
|
|
1154
|
+
puts "read p1 #{e.class}" if @is_debug
|
|
1235
1155
|
close_p1(p1)
|
|
1236
1156
|
return
|
|
1237
1157
|
end
|
|
1238
1158
|
|
|
1239
1159
|
set_update(p1)
|
|
1160
|
+
p1_info = @p1_infos[p1]
|
|
1161
|
+
p1_info[:in] += data.bytesize
|
|
1162
|
+
p2_id = p1_info[:p2_id]
|
|
1240
1163
|
|
|
1241
|
-
if
|
|
1242
|
-
|
|
1243
|
-
|
|
1164
|
+
if !p1_info[:is_big] && (p1_info[:in] >= READ_SIZE)
|
|
1165
|
+
puts "set p1 is big #{p2_id}"
|
|
1166
|
+
p1_info[:is_big] = true
|
|
1244
1167
|
end
|
|
1245
1168
|
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1169
|
+
data = pack_p2_traffic(p2_id, data)
|
|
1170
|
+
|
|
1171
|
+
if p1_info[:is_big]
|
|
1172
|
+
if @big.closed?
|
|
1173
|
+
close_p1(p1)
|
|
1174
|
+
return
|
|
1175
|
+
end
|
|
1250
1176
|
|
|
1251
|
-
|
|
1252
|
-
proxy_info = @proxy_infos[@proxy]
|
|
1253
|
-
bytesize = proxy_info[:wbuff].bytesize
|
|
1177
|
+
overflowing = add_big_wbuff(data)
|
|
1254
1178
|
|
|
1255
|
-
if
|
|
1256
|
-
puts "
|
|
1179
|
+
if overflowing
|
|
1180
|
+
puts "big overflowing pause p1 #{p2_id}"
|
|
1257
1181
|
@reads.delete(p1)
|
|
1258
|
-
proxy_info[:paused_p1s] << p1
|
|
1259
1182
|
end
|
|
1183
|
+
else
|
|
1184
|
+
if @proxy.closed?
|
|
1185
|
+
close_p1(p1)
|
|
1186
|
+
return
|
|
1187
|
+
end
|
|
1188
|
+
|
|
1189
|
+
add_proxy_wbuff(data)
|
|
1260
1190
|
end
|
|
1261
1191
|
end
|
|
1262
1192
|
|
|
@@ -1266,6 +1196,7 @@ module Girl
|
|
|
1266
1196
|
rescue Errno::ENOTCONN => e
|
|
1267
1197
|
return
|
|
1268
1198
|
rescue Exception => e
|
|
1199
|
+
puts "read proxy #{e.class}" if @is_debug
|
|
1269
1200
|
close_proxy(proxy)
|
|
1270
1201
|
return
|
|
1271
1202
|
end
|
|
@@ -1273,7 +1204,6 @@ module Girl
|
|
|
1273
1204
|
set_update(proxy)
|
|
1274
1205
|
proxy_info = @proxy_infos[proxy]
|
|
1275
1206
|
data = "#{proxy_info[:rbuff]}#{data}"
|
|
1276
|
-
|
|
1277
1207
|
msgs, part = decode_to_msgs(data)
|
|
1278
1208
|
msgs.each{|msg| deal_msg(msg)}
|
|
1279
1209
|
proxy_info[:rbuff] = part
|
|
@@ -1291,13 +1221,14 @@ module Girl
|
|
|
1291
1221
|
|
|
1292
1222
|
puts "redir accept a src #{addrinfo.ip_unpack.inspect}" if @is_debug
|
|
1293
1223
|
src_id = rand((2 ** 64) - 2) + 1
|
|
1294
|
-
|
|
1295
|
-
src_info = {
|
|
1224
|
+
@src_infos[src] = {
|
|
1296
1225
|
addrinfo: addrinfo,
|
|
1297
1226
|
closing: false,
|
|
1298
1227
|
destination_domain: nil,
|
|
1299
1228
|
destination_port: nil,
|
|
1300
1229
|
dst: nil,
|
|
1230
|
+
in: 0,
|
|
1231
|
+
is_big: false,
|
|
1301
1232
|
is_connect: true,
|
|
1302
1233
|
overflowing: false,
|
|
1303
1234
|
proxy_proto: :uncheck, # :uncheck / :http / :socks5
|
|
@@ -1306,52 +1237,9 @@ module Girl
|
|
|
1306
1237
|
src_id: src_id,
|
|
1307
1238
|
wbuff: ''
|
|
1308
1239
|
}
|
|
1309
|
-
|
|
1310
|
-
@src_infos[src] = src_info
|
|
1311
1240
|
add_read(src, :src)
|
|
1312
1241
|
end
|
|
1313
1242
|
|
|
1314
|
-
def read_relay(relay)
|
|
1315
|
-
begin
|
|
1316
|
-
data = relay.read_nonblock(READ_SIZE)
|
|
1317
|
-
rescue Errno::ENOTCONN => e
|
|
1318
|
-
return
|
|
1319
|
-
rescue Exception => e
|
|
1320
|
-
close_relay(relay)
|
|
1321
|
-
return
|
|
1322
|
-
end
|
|
1323
|
-
|
|
1324
|
-
set_update(relay)
|
|
1325
|
-
relay_info = @relay_infos[relay]
|
|
1326
|
-
girl = relay_info[:girl]
|
|
1327
|
-
add_girl_wbuff(girl, data)
|
|
1328
|
-
end
|
|
1329
|
-
|
|
1330
|
-
def read_relayd(relayd)
|
|
1331
|
-
check_expire_relays
|
|
1332
|
-
|
|
1333
|
-
begin
|
|
1334
|
-
relay, addrinfo = relayd.accept_nonblock
|
|
1335
|
-
rescue IO::WaitReadable, Errno::EINTR => e
|
|
1336
|
-
puts "relayd accept #{e.class}"
|
|
1337
|
-
return
|
|
1338
|
-
end
|
|
1339
|
-
|
|
1340
|
-
puts "relayd accept a relay #{addrinfo.ip_unpack.inspect}"
|
|
1341
|
-
|
|
1342
|
-
relay_info = {
|
|
1343
|
-
addrinfo: addrinfo,
|
|
1344
|
-
closing: false,
|
|
1345
|
-
girl: nil,
|
|
1346
|
-
overflowing: false,
|
|
1347
|
-
wbuff: ''
|
|
1348
|
-
}
|
|
1349
|
-
|
|
1350
|
-
@relay_infos[relay] = relay_info
|
|
1351
|
-
add_read(relay, :relay)
|
|
1352
|
-
relay_info[:girl] = new_a_girl(relay)
|
|
1353
|
-
end
|
|
1354
|
-
|
|
1355
1243
|
def read_rsv(rsv)
|
|
1356
1244
|
begin
|
|
1357
1245
|
data, addrinfo, rflags, *controls = rsv.recvmsg
|
|
@@ -1439,16 +1327,13 @@ module Girl
|
|
|
1439
1327
|
if @remotes.any?{|r| domain.include?(r)}
|
|
1440
1328
|
check_expire_nears
|
|
1441
1329
|
near_id = rand((2 ** 64) - 2) + 1
|
|
1442
|
-
|
|
1443
|
-
near_info = {
|
|
1330
|
+
@near_infos[near_id] = {
|
|
1444
1331
|
addrinfo: addrinfo,
|
|
1445
1332
|
created_at: Time.new,
|
|
1446
1333
|
domain: domain,
|
|
1447
1334
|
id: id,
|
|
1448
1335
|
type: type
|
|
1449
1336
|
}
|
|
1450
|
-
|
|
1451
|
-
@near_infos[near_id] = near_info
|
|
1452
1337
|
puts "add h_query #{near_id} #{type} #{domain}" if @is_debug
|
|
1453
1338
|
msg = "#{@h_query}#{[near_id, type].pack('Q>C')}#{domain}"
|
|
1454
1339
|
add_proxy_wbuff(pack_a_chunk(msg))
|
|
@@ -1464,6 +1349,7 @@ module Girl
|
|
|
1464
1349
|
rescue Errno::ENOTCONN => e
|
|
1465
1350
|
return
|
|
1466
1351
|
rescue Exception => e
|
|
1352
|
+
puts "read src #{e.class}" if @is_debug
|
|
1467
1353
|
close_src(src)
|
|
1468
1354
|
return
|
|
1469
1355
|
end
|
|
@@ -1607,18 +1493,36 @@ module Girl
|
|
|
1607
1493
|
close_src(src)
|
|
1608
1494
|
end
|
|
1609
1495
|
when :remote
|
|
1496
|
+
src_info[:in] += data.bytesize
|
|
1610
1497
|
src_id = src_info[:src_id]
|
|
1611
|
-
|
|
1498
|
+
domain = src_info[:destination_domain]
|
|
1612
1499
|
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1500
|
+
if !src_info[:is_big] && (src_info[:in] >= READ_SIZE)
|
|
1501
|
+
puts "set src is big #{src_id} #{domain}"
|
|
1502
|
+
src_info[:is_big] = true
|
|
1503
|
+
end
|
|
1504
|
+
|
|
1505
|
+
data = pack_traffic(src_id, data)
|
|
1616
1506
|
|
|
1617
|
-
|
|
1618
|
-
|
|
1507
|
+
if src_info[:is_big]
|
|
1508
|
+
if @big.closed?
|
|
1509
|
+
close_src(src)
|
|
1510
|
+
return
|
|
1511
|
+
end
|
|
1512
|
+
|
|
1513
|
+
overflowing = add_big_wbuff(data)
|
|
1514
|
+
|
|
1515
|
+
if overflowing
|
|
1516
|
+
puts "big overflowing pause src #{src_id} #{domain}"
|
|
1619
1517
|
@reads.delete(src)
|
|
1620
|
-
proxy_info[:paused_srcs] << src
|
|
1621
1518
|
end
|
|
1519
|
+
else
|
|
1520
|
+
if @proxy.closed?
|
|
1521
|
+
close_src(src)
|
|
1522
|
+
return
|
|
1523
|
+
end
|
|
1524
|
+
|
|
1525
|
+
add_proxy_wbuff(data)
|
|
1622
1526
|
end
|
|
1623
1527
|
when :direct
|
|
1624
1528
|
dst = src_info[:dst]
|
|
@@ -1657,8 +1561,7 @@ module Girl
|
|
|
1657
1561
|
dest_addrinfo = Addrinfo.new(dest_addr)
|
|
1658
1562
|
dest_ip = dest_addrinfo.ip_address
|
|
1659
1563
|
src_id = rand((2 ** 64) - 2) + 1
|
|
1660
|
-
|
|
1661
|
-
src_info = {
|
|
1564
|
+
@src_infos[src] = {
|
|
1662
1565
|
addrinfo: addrinfo,
|
|
1663
1566
|
closing: false,
|
|
1664
1567
|
destination_domain: dest_ip,
|
|
@@ -1672,8 +1575,6 @@ module Girl
|
|
|
1672
1575
|
src_id: src_id,
|
|
1673
1576
|
wbuff: ''
|
|
1674
1577
|
}
|
|
1675
|
-
|
|
1676
|
-
@src_infos[src] = src_info
|
|
1677
1578
|
add_read(src, :src)
|
|
1678
1579
|
make_tunnel(dest_ip, src)
|
|
1679
1580
|
end
|
|
@@ -1688,7 +1589,7 @@ module Girl
|
|
|
1688
1589
|
return
|
|
1689
1590
|
end
|
|
1690
1591
|
|
|
1691
|
-
domain =
|
|
1592
|
+
domain =' 127.0.0.1' if domain == 'localhost'
|
|
1692
1593
|
|
|
1693
1594
|
if domain =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}$/
|
|
1694
1595
|
# ipv4
|
|
@@ -1734,12 +1635,10 @@ module Girl
|
|
|
1734
1635
|
return
|
|
1735
1636
|
end
|
|
1736
1637
|
|
|
1737
|
-
|
|
1638
|
+
@dns_infos[dns] = {
|
|
1738
1639
|
domain: domain,
|
|
1739
1640
|
src: src
|
|
1740
1641
|
}
|
|
1741
|
-
|
|
1742
|
-
@dns_infos[dns] = dns_info
|
|
1743
1642
|
add_read(dns, :dns)
|
|
1744
1643
|
src_info = @src_infos[src]
|
|
1745
1644
|
src_info[:proxy_type] = :checking
|
|
@@ -1761,14 +1660,6 @@ module Girl
|
|
|
1761
1660
|
add_write(dst)
|
|
1762
1661
|
end
|
|
1763
1662
|
|
|
1764
|
-
def set_girl_closing(girl)
|
|
1765
|
-
return if girl.nil? || girl.closed?
|
|
1766
|
-
girl_info = @girl_infos[girl]
|
|
1767
|
-
return if girl_info.nil? || girl_info[:closing]
|
|
1768
|
-
girl_info[:closing] = true
|
|
1769
|
-
add_write(girl)
|
|
1770
|
-
end
|
|
1771
|
-
|
|
1772
1663
|
def set_p1_closing(p1)
|
|
1773
1664
|
return if p1.nil? || p1.closed?
|
|
1774
1665
|
p1_info = @p1_infos[p1]
|
|
@@ -1777,14 +1668,6 @@ module Girl
|
|
|
1777
1668
|
add_write(p1)
|
|
1778
1669
|
end
|
|
1779
1670
|
|
|
1780
|
-
def set_relay_closing(relay)
|
|
1781
|
-
return if relay.nil? || relay.closed?
|
|
1782
|
-
relay_info = @relay_infos[relay]
|
|
1783
|
-
return if relay_info.nil? || relay_info[:closing]
|
|
1784
|
-
relay_info[:closing] = true
|
|
1785
|
-
add_write(relay)
|
|
1786
|
-
end
|
|
1787
|
-
|
|
1788
1671
|
def set_remote(src)
|
|
1789
1672
|
return if src.nil? || src.closed?
|
|
1790
1673
|
|
|
@@ -1842,14 +1725,10 @@ module Girl
|
|
|
1842
1725
|
close_dns(_sock)
|
|
1843
1726
|
when :dst
|
|
1844
1727
|
close_dst(_sock)
|
|
1845
|
-
when :girl
|
|
1846
|
-
close_girl(_sock)
|
|
1847
1728
|
when :mem
|
|
1848
1729
|
close_mem(_sock)
|
|
1849
1730
|
when :p1
|
|
1850
1731
|
close_p1(_sock)
|
|
1851
|
-
when :relay
|
|
1852
|
-
close_relay(_sock)
|
|
1853
1732
|
when :rsv
|
|
1854
1733
|
close_rsv(_sock)
|
|
1855
1734
|
when :src
|
|
@@ -1863,100 +1742,113 @@ module Girl
|
|
|
1863
1742
|
end
|
|
1864
1743
|
end
|
|
1865
1744
|
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1745
|
+
def write_big(big)
|
|
1746
|
+
big_info = @big_infos[big]
|
|
1747
|
+
|
|
1748
|
+
unless big_info
|
|
1749
|
+
puts "big info not found delete big"
|
|
1750
|
+
@writes.delete(big)
|
|
1869
1751
|
return
|
|
1870
1752
|
end
|
|
1871
1753
|
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
data =
|
|
1754
|
+
return if @writes.include?(@proxy)
|
|
1755
|
+
|
|
1756
|
+
data = big_info[:wbuff]
|
|
1875
1757
|
|
|
1876
1758
|
if data.empty?
|
|
1877
|
-
|
|
1878
|
-
close_dst(dst)
|
|
1879
|
-
else
|
|
1880
|
-
@writes.delete(dst)
|
|
1881
|
-
end
|
|
1882
|
-
|
|
1759
|
+
@writes.delete(big)
|
|
1883
1760
|
return
|
|
1884
1761
|
end
|
|
1885
1762
|
|
|
1886
1763
|
begin
|
|
1887
|
-
|
|
1764
|
+
if big_info[:is_syn]
|
|
1765
|
+
written = big.sendmsg_nonblock(data, 536870912, @bigd_addr)
|
|
1766
|
+
big_info[:is_syn] = false
|
|
1767
|
+
else
|
|
1768
|
+
written = big.write_nonblock(data)
|
|
1769
|
+
end
|
|
1888
1770
|
rescue Errno::EINPROGRESS
|
|
1889
1771
|
return
|
|
1890
1772
|
rescue Exception => e
|
|
1891
|
-
|
|
1773
|
+
puts "write big #{e.class}" if @is_debug
|
|
1774
|
+
close_big(big)
|
|
1892
1775
|
return
|
|
1893
1776
|
end
|
|
1894
1777
|
|
|
1895
|
-
set_update(
|
|
1778
|
+
set_update(big)
|
|
1896
1779
|
data = data[written..-1]
|
|
1897
|
-
|
|
1898
|
-
bytesize = dst_info[:wbuff].bytesize
|
|
1780
|
+
big_info[:wbuff] = data
|
|
1899
1781
|
|
|
1900
|
-
if
|
|
1901
|
-
puts "
|
|
1902
|
-
|
|
1903
|
-
|
|
1782
|
+
if big_info[:wbuff].empty? && big_info[:overflowing]
|
|
1783
|
+
puts "big empty"
|
|
1784
|
+
big_info[:overflowing] = false
|
|
1785
|
+
|
|
1786
|
+
@src_infos.select{|_, info| info[:is_big]}.each do |src, info|
|
|
1787
|
+
puts "resume src #{info[:src_id]} #{info[:destination_domain]}"
|
|
1788
|
+
add_read(src)
|
|
1789
|
+
end
|
|
1790
|
+
|
|
1791
|
+
@p1_infos.select{|_, info| info[:is_big]}.each do |p1, info|
|
|
1792
|
+
puts "resume p1 #{info[:p2_id]}"
|
|
1793
|
+
add_read(p1)
|
|
1794
|
+
end
|
|
1904
1795
|
end
|
|
1905
1796
|
end
|
|
1906
1797
|
|
|
1907
|
-
def
|
|
1908
|
-
|
|
1909
|
-
|
|
1798
|
+
def write_dst(dst)
|
|
1799
|
+
dst_info = @dst_infos[dst]
|
|
1800
|
+
|
|
1801
|
+
unless dst_info
|
|
1802
|
+
puts "dst info not found delete dst"
|
|
1803
|
+
@writes.delete(dst)
|
|
1910
1804
|
return
|
|
1911
1805
|
end
|
|
1912
1806
|
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
data = girl_info[:wbuff]
|
|
1807
|
+
dst_info[:connected] = true
|
|
1808
|
+
data = dst_info[:wbuff]
|
|
1916
1809
|
|
|
1917
1810
|
if data.empty?
|
|
1918
|
-
if
|
|
1919
|
-
|
|
1811
|
+
if dst_info[:closing]
|
|
1812
|
+
close_dst(dst)
|
|
1920
1813
|
else
|
|
1921
|
-
@writes.delete(
|
|
1814
|
+
@writes.delete(dst)
|
|
1922
1815
|
end
|
|
1923
1816
|
|
|
1924
1817
|
return
|
|
1925
1818
|
end
|
|
1926
1819
|
|
|
1927
1820
|
begin
|
|
1928
|
-
|
|
1929
|
-
written = girl.sendmsg_nonblock(data, 536870912, @proxyd_addr)
|
|
1930
|
-
girl_info[:is_syn] = false
|
|
1931
|
-
else
|
|
1932
|
-
written = girl.write_nonblock(data)
|
|
1933
|
-
end
|
|
1821
|
+
written = dst.write_nonblock(data)
|
|
1934
1822
|
rescue Errno::EINPROGRESS
|
|
1935
1823
|
return
|
|
1936
1824
|
rescue Exception => e
|
|
1937
|
-
|
|
1825
|
+
puts "write dst #{e.class}" if @is_debug
|
|
1826
|
+
close_dst(dst)
|
|
1938
1827
|
return
|
|
1939
1828
|
end
|
|
1940
1829
|
|
|
1941
|
-
set_update(
|
|
1830
|
+
set_update(dst)
|
|
1942
1831
|
data = data[written..-1]
|
|
1943
|
-
|
|
1944
|
-
|
|
1832
|
+
dst_info[:wbuff] = data
|
|
1833
|
+
domain = dst_info[:domain]
|
|
1945
1834
|
|
|
1946
|
-
if
|
|
1947
|
-
puts "
|
|
1948
|
-
|
|
1949
|
-
|
|
1835
|
+
if dst_info[:overflowing] && dst_info[:wbuff].empty?
|
|
1836
|
+
puts "dst empty #{domain}"
|
|
1837
|
+
dst_info[:overflowing] = false
|
|
1838
|
+
puts "resume src"
|
|
1839
|
+
add_read(dst_info[:src])
|
|
1950
1840
|
end
|
|
1951
1841
|
end
|
|
1952
1842
|
|
|
1953
1843
|
def write_mem(mem)
|
|
1954
|
-
|
|
1955
|
-
|
|
1844
|
+
mem_info = @mem_infos[mem]
|
|
1845
|
+
|
|
1846
|
+
unless mem_info
|
|
1847
|
+
puts "mem info not found delete mem"
|
|
1848
|
+
@writes.delete(mem)
|
|
1956
1849
|
return
|
|
1957
1850
|
end
|
|
1958
1851
|
|
|
1959
|
-
mem_info = @mem_infos[mem]
|
|
1960
1852
|
data = mem_info[:wbuff]
|
|
1961
1853
|
|
|
1962
1854
|
if data.empty?
|
|
@@ -1980,12 +1872,14 @@ module Girl
|
|
|
1980
1872
|
end
|
|
1981
1873
|
|
|
1982
1874
|
def write_p1(p1)
|
|
1983
|
-
|
|
1984
|
-
|
|
1875
|
+
p1_info = @p1_infos[p1]
|
|
1876
|
+
|
|
1877
|
+
unless p1_info
|
|
1878
|
+
puts "p1 info not found delete p1"
|
|
1879
|
+
@writes.delete(p1)
|
|
1985
1880
|
return
|
|
1986
1881
|
end
|
|
1987
1882
|
|
|
1988
|
-
p1_info = @p1_infos[p1]
|
|
1989
1883
|
p1_info[:connected] = true
|
|
1990
1884
|
data = p1_info[:wbuff]
|
|
1991
1885
|
|
|
@@ -2004,6 +1898,7 @@ module Girl
|
|
|
2004
1898
|
rescue Errno::EINPROGRESS
|
|
2005
1899
|
return
|
|
2006
1900
|
rescue Exception => e
|
|
1901
|
+
puts "write p1 #{e.class}" if @is_debug
|
|
2007
1902
|
close_p1(p1)
|
|
2008
1903
|
return
|
|
2009
1904
|
end
|
|
@@ -2011,24 +1906,25 @@ module Girl
|
|
|
2011
1906
|
set_update(p1)
|
|
2012
1907
|
data = data[written..-1]
|
|
2013
1908
|
p1_info[:wbuff] = data
|
|
2014
|
-
|
|
1909
|
+
p2_id = p1_info[:p2_id]
|
|
2015
1910
|
|
|
2016
|
-
if p1_info[:overflowing] &&
|
|
2017
|
-
|
|
2018
|
-
puts "add h_p1_underhalf #{p2_id}"
|
|
2019
|
-
msg = "#{@h_p1_underhalf}#{[p2_id].pack('Q>')}"
|
|
2020
|
-
add_proxy_wbuff(pack_a_chunk(msg))
|
|
1911
|
+
if p1_info[:overflowing] && p1_info[:wbuff].empty?
|
|
1912
|
+
puts "p1 empty #{p2_id}"
|
|
2021
1913
|
p1_info[:overflowing] = false
|
|
1914
|
+
puts "resume big"
|
|
1915
|
+
add_read(@big)
|
|
2022
1916
|
end
|
|
2023
1917
|
end
|
|
2024
1918
|
|
|
2025
1919
|
def write_proxy(proxy)
|
|
2026
|
-
|
|
2027
|
-
|
|
1920
|
+
proxy_info = @proxy_infos[proxy]
|
|
1921
|
+
|
|
1922
|
+
unless proxy_info
|
|
1923
|
+
puts "proxy info not found delete proxy"
|
|
1924
|
+
@writes.delete(proxy)
|
|
2028
1925
|
return
|
|
2029
1926
|
end
|
|
2030
1927
|
|
|
2031
|
-
proxy_info = @proxy_infos[proxy]
|
|
2032
1928
|
data = proxy_info[:wbuff]
|
|
2033
1929
|
|
|
2034
1930
|
if data.empty?
|
|
@@ -2054,30 +1950,17 @@ module Girl
|
|
|
2054
1950
|
set_update(proxy)
|
|
2055
1951
|
data = data[written..-1]
|
|
2056
1952
|
proxy_info[:wbuff] = data
|
|
2057
|
-
bytesize = proxy_info[:wbuff].bytesize
|
|
2058
|
-
|
|
2059
|
-
if bytesize < RESUME_BELOW
|
|
2060
|
-
if proxy_info[:paused_srcs].any?
|
|
2061
|
-
puts "proxy underhalf resume srcs #{proxy_info[:paused_srcs].size}"
|
|
2062
|
-
proxy_info[:paused_srcs].each{|src| add_read(src)}
|
|
2063
|
-
proxy_info[:paused_srcs].clear
|
|
2064
|
-
end
|
|
2065
|
-
|
|
2066
|
-
if proxy_info[:paused_p1s].any?
|
|
2067
|
-
puts "proxy underhalf resume p1s #{proxy_info[:paused_p1s].size}"
|
|
2068
|
-
proxy_info[:paused_p1s].each{|p1| add_read(p1)}
|
|
2069
|
-
proxy_info[:paused_p1s].clear
|
|
2070
|
-
end
|
|
2071
|
-
end
|
|
2072
1953
|
end
|
|
2073
1954
|
|
|
2074
1955
|
def write_src(src)
|
|
2075
|
-
|
|
2076
|
-
|
|
1956
|
+
src_info = @src_infos[src]
|
|
1957
|
+
|
|
1958
|
+
unless src_info
|
|
1959
|
+
puts "src info not found delete src"
|
|
1960
|
+
@writes.delete(src)
|
|
2077
1961
|
return
|
|
2078
1962
|
end
|
|
2079
1963
|
|
|
2080
|
-
src_info = @src_infos[src]
|
|
2081
1964
|
data = src_info[:wbuff]
|
|
2082
1965
|
|
|
2083
1966
|
if data.empty?
|
|
@@ -2095,6 +1978,7 @@ module Girl
|
|
|
2095
1978
|
rescue Errno::EINPROGRESS
|
|
2096
1979
|
return
|
|
2097
1980
|
rescue Exception => e
|
|
1981
|
+
puts "write src #{e.class}" if @is_debug
|
|
2098
1982
|
close_src(src)
|
|
2099
1983
|
return
|
|
2100
1984
|
end
|
|
@@ -2102,62 +1986,20 @@ module Girl
|
|
|
2102
1986
|
set_update(src)
|
|
2103
1987
|
data = data[written..-1]
|
|
2104
1988
|
src_info[:wbuff] = data
|
|
2105
|
-
bytesize = src_info[:wbuff].bytesize
|
|
2106
1989
|
|
|
2107
|
-
if src_info[:
|
|
1990
|
+
if src_info[:wbuff].empty? && src_info[:overflowing]
|
|
2108
1991
|
src_id = src_info[:src_id]
|
|
2109
1992
|
domain = src_info[:destination_domain]
|
|
1993
|
+
puts "src empty #{src_id} #{domain}"
|
|
1994
|
+
src_info[:overflowing] = false
|
|
2110
1995
|
|
|
2111
1996
|
if src_info[:proxy_type] == :direct
|
|
2112
|
-
puts "
|
|
1997
|
+
puts "resume dst"
|
|
2113
1998
|
add_read(src_info[:dst])
|
|
2114
1999
|
else
|
|
2115
|
-
puts "
|
|
2116
|
-
|
|
2117
|
-
add_proxy_wbuff(pack_a_chunk(msg))
|
|
2118
|
-
end
|
|
2119
|
-
|
|
2120
|
-
src_info[:overflowing] = false
|
|
2121
|
-
end
|
|
2122
|
-
end
|
|
2123
|
-
|
|
2124
|
-
def write_relay(relay)
|
|
2125
|
-
if relay.closed?
|
|
2126
|
-
puts "write closed relay?"
|
|
2127
|
-
return
|
|
2128
|
-
end
|
|
2129
|
-
|
|
2130
|
-
relay_info = @relay_infos[relay]
|
|
2131
|
-
data = relay_info[:wbuff]
|
|
2132
|
-
|
|
2133
|
-
if data.empty?
|
|
2134
|
-
if relay_info[:closing]
|
|
2135
|
-
close_relay(relay)
|
|
2136
|
-
else
|
|
2137
|
-
@writes.delete(relay)
|
|
2000
|
+
puts "resume big"
|
|
2001
|
+
add_read(@big)
|
|
2138
2002
|
end
|
|
2139
|
-
|
|
2140
|
-
return
|
|
2141
|
-
end
|
|
2142
|
-
|
|
2143
|
-
begin
|
|
2144
|
-
written = relay.write_nonblock(data)
|
|
2145
|
-
rescue Errno::EINPROGRESS
|
|
2146
|
-
return
|
|
2147
|
-
rescue Exception => e
|
|
2148
|
-
close_relay(relay)
|
|
2149
|
-
return
|
|
2150
|
-
end
|
|
2151
|
-
|
|
2152
|
-
set_update(relay)
|
|
2153
|
-
data = data[written..-1]
|
|
2154
|
-
relay_info[:wbuff] = data
|
|
2155
|
-
bytesize = relay_info[:wbuff].bytesize
|
|
2156
|
-
|
|
2157
|
-
if relay_info[:overflowing] && (bytesize < RESUME_BELOW)
|
|
2158
|
-
puts "relay underhalf"
|
|
2159
|
-
add_read(relay_info[:girl])
|
|
2160
|
-
relay_info[:overflowing] = false
|
|
2161
2003
|
end
|
|
2162
2004
|
end
|
|
2163
2005
|
|