girl 0.71.2 → 0.75.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of girl might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9770be339624c9742372d65ead4bc2c59a6f7559984bc9d95212b8beddf05787
4
- data.tar.gz: f7ee6b87f034c447a169f1f41c606bd5a02c676525a40e82e74ff259b5090840
3
+ metadata.gz: ac2f8ddb303a57e5c898754c88710847686e84b3ef406c053ef926424da78e2b
4
+ data.tar.gz: 4506688a3176c9effe1804e3d247379a79d96906e4c8417d6f0660ecaa082141
5
5
  SHA512:
6
- metadata.gz: f7798af85a3cfacf28179420f562dd1b65f10d839248c5075969005af42f44cd735f0181f558a7c76c89c70807200eb68e77a12193d49d8a86763b39bcce8962
7
- data.tar.gz: 4b7841420ac86f88af4920eaae61d0f606de9f726ee2a458c51d6d2bd05bf7988fe97f574c0193cf81228b48ac0c89a1f81995d67593e6954125187b6236ad20
6
+ metadata.gz: 34559a0ab1375eb9b07bab0fbea3d762e94ac7282ed8868e3ab672aa816f87f6edc3273b1204c565c189201bd2a49e993477a6da525b472e95c18b804526323e
7
+ data.tar.gz: d7580c92099e6974287fbc8384010d3b5ed34966832ff9c1a0bda42cdeac923768fa431b84c83dee8926c3b4bc8f2b0761bdb9a4a14212870a2dde3abb89f338
@@ -113,7 +113,7 @@ module Girl
113
113
 
114
114
  @tun_info[ :src_exts ].each do | src_id, src_ext |
115
115
  if src_ext[ :src ].closed? && ( now - src_ext[ :last_continue_at ] > EXPIRE_AFTER )
116
- puts "p#{ Process.pid } #{ Time.new } expire src ext #{ src_id }"
116
+ puts "p#{ Process.pid } #{ Time.new } expire src ext #{ src_ext[ :destination_domain ] }"
117
117
  del_src_ext( src_id )
118
118
  end
119
119
  end
@@ -123,20 +123,16 @@ module Girl
123
123
  end
124
124
 
125
125
  @src_infos.each do | src, src_info |
126
- is_expired = src_info[ :last_recv_at ].nil? && ( now - src_info[ :created_at ] > EXPIRE_NEW )
127
-
128
- if is_expired
129
- puts "p#{ Process.pid } #{ Time.new } expire src"
126
+ if now - src_info[ :last_continue_at ] > EXPIRE_AFTER
127
+ puts "p#{ Process.pid } #{ Time.new } expire src #{ src_info[ :destination_domain ] }"
130
128
  set_is_closing( src )
131
129
  need_trigger = true
132
130
  end
133
131
  end
134
132
 
135
133
  @dst_infos.each do | dst, dst_info |
136
- is_expired = dst_info[ :last_recv_at ].nil? && ( now - dst_info[ :created_at ] > EXPIRE_NEW )
137
-
138
- if is_expired
139
- puts "p#{ Process.pid } #{ Time.new } expire dst"
134
+ if now - dst_info[ :last_continue_at ] > EXPIRE_AFTER
135
+ puts "p#{ Process.pid } #{ Time.new } expire dst #{ dst_info[ :domain ] }"
140
136
  set_is_closing( dst )
141
137
  need_trigger = true
142
138
  end
@@ -216,12 +212,6 @@ module Girl
216
212
  # resolve domain
217
213
  #
218
214
  def resolve_domain( src, domain )
219
- if ( /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\Z/ =~ domain ) && domain.split( '.' ).all? { | part | part.to_i < 256 }
220
- # puts "debug1 #{ domain } is a ip"
221
- deal_with_destination_ip( src, domain )
222
- return
223
- end
224
-
225
215
  if @remotes.any? { | remote | ( domain.size >= remote.size ) && ( domain[ ( remote.size * -1 )..-1 ] == remote ) }
226
216
  # puts "debug1 #{ domain } hit remotes"
227
217
  new_a_src_ext( src )
@@ -231,11 +221,11 @@ module Girl
231
221
  resolv_cache = @resolv_caches[ domain ]
232
222
 
233
223
  if resolv_cache
234
- destination_ip, created_at = resolv_cache
224
+ ip_info, created_at = resolv_cache
235
225
 
236
226
  if Time.new - created_at < RESOLV_CACHE_EXPIRE
237
- # puts "debug1 #{ domain } hit resolv cache #{ destination_ip }"
238
- deal_with_destination_ip( src, destination_ip )
227
+ # puts "debug1 #{ domain } hit resolv cache #{ ip_info.inspect }"
228
+ deal_with_destination_ip( src, ip_info )
239
229
  return
240
230
  end
241
231
 
@@ -255,12 +245,11 @@ module Girl
255
245
 
256
246
  @mutex.synchronize do
257
247
  if ip_info
258
- destination_ip = ip_info.ip_address
259
- # puts "debug1 resolved #{ domain } #{ destination_ip }"
260
- @resolv_caches[ domain ] = [ destination_ip, Time.new ]
248
+ @resolv_caches[ domain ] = [ ip_info, Time.new ]
261
249
 
262
250
  unless src.closed?
263
- deal_with_destination_ip( src, destination_ip )
251
+ puts "p#{ Process.pid } #{ Time.new } resolved #{ domain } #{ ip_info.ip_address }"
252
+ deal_with_destination_ip( src, ip_info )
264
253
  end
265
254
  else
266
255
  set_is_closing( src )
@@ -274,11 +263,11 @@ module Girl
274
263
  ##
275
264
  # deal with destination ip
276
265
  #
277
- def deal_with_destination_ip( src, destination_ip )
278
- if @directs.any? { | direct | direct.include?( destination_ip ) }
266
+ def deal_with_destination_ip( src, ip_info )
267
+ if @directs.any? { | direct | direct.include?( ip_info.ip_address ) }
279
268
  # ip命中直连列表,直连
280
- # puts "debug1 #{ destination_ip } hit directs"
281
- new_a_dst( src, destination_ip )
269
+ # puts "debug1 #{ ip_info.inspect } hit directs"
270
+ new_a_dst( src, ip_info )
282
271
  else
283
272
  # 走远端
284
273
  new_a_src_ext( src )
@@ -342,10 +331,11 @@ module Girl
342
331
  ##
343
332
  # new a dst
344
333
  #
345
- def new_a_dst( src, destination_ip )
334
+ def new_a_dst( src, ip_info )
346
335
  src_info = @src_infos[ src ]
347
- destination_addr = Socket.sockaddr_in( src_info[ :destination_port ], destination_ip )
348
- dst = Socket.new( Socket::AF_INET, Socket::SOCK_STREAM, 0 )
336
+ domain = src_info[ :destination_domain ]
337
+ destination_addr = Socket.sockaddr_in( src_info[ :destination_port ], ip_info.ip_address )
338
+ dst = Socket.new( ip_info.ipv4? ? Socket::AF_INET : Socket::AF_INET6, Socket::SOCK_STREAM, 0 )
349
339
 
350
340
  if RUBY_PLATFORM.include?( 'linux' )
351
341
  dst.setsockopt( Socket::SOL_TCP, Socket::TCP_NODELAY, 1 )
@@ -364,15 +354,15 @@ module Girl
364
354
  # puts "debug1 a new dst #{ dst.local_address.inspect }"
365
355
  local_port = dst.local_address.ip_port
366
356
  @dst_infos[ dst ] = {
367
- local_port: local_port, # 本地端口
368
- src: src, # 对应src
369
- wbuff: '', # 写前
370
- cache: '', # 块读出缓存
371
- chunks: [], # 块队列,写前达到块大小时结一个块 filename
372
- spring: 0, # 块后缀,结块时,如果块队列不为空,则自增,为空,则置为0
373
- created_at: Time.new, # 创建时间
374
- last_recv_at: nil, # 上一次收到流量的时间,过期关闭
375
- is_closing: false # 是否准备关闭
357
+ local_port: local_port, # 本地端口
358
+ src: src, # 对应src
359
+ domain: domain, # 域名
360
+ wbuff: '', # 写前
361
+ cache: '', # 块读出缓存
362
+ chunks: [], # 块队列,写前达到块大小时结一个块 filename
363
+ spring: 0, # 块后缀,结块时,如果块队列不为空,则自增,为空,则置为0
364
+ last_continue_at: Time.new, # 上一次发生流量的时间
365
+ is_closing: false # 是否准备关闭
376
366
  }
377
367
 
378
368
  add_read( dst, :dst )
@@ -403,27 +393,29 @@ module Girl
403
393
  new_a_tun
404
394
  end
405
395
 
396
+ src_info = @src_infos[ src ]
397
+ src_id = src_info[ :id ]
398
+ destination_port = src_info[ :destination_port ]
399
+ destination_domain = src_info[ :destination_domain ]
400
+
406
401
  src_ext = {
407
- src: src, # src
408
- dst_port: nil, # 远端dst端口
409
- wmems: {}, # 写后 pack_id => data
410
- send_ats: {}, # 上一次发出时间 pack_id => send_at
411
- relay_pack_id: 0, # 转发到几
412
- continue_dst_pack_id: 0, # 收到几
413
- pieces: {}, # 跳号包 dst_pack_id => data
414
- is_dst_closed: false, # dst是否已关闭
415
- biggest_dst_pack_id: 0, # dst最大包号码
416
- completed_pack_id: 0, # 完成到几(对面收到几)
417
- last_continue_at: Time.new # 创建,或者上一次收到连续流量,或者发出新包的时间
402
+ src: src, # src
403
+ dst_port: nil, # 远端dst端口
404
+ destination_domain: destination_domain, # 目的地域名
405
+ wmems: {}, # 写后 pack_id => data
406
+ send_ats: {}, # 上一次发出时间 pack_id => send_at
407
+ relay_pack_id: 0, # 转发到几
408
+ continue_dst_pack_id: 0, # 收到几
409
+ pieces: {}, # 跳号包 dst_pack_id => data
410
+ is_dst_closed: false, # dst是否已关闭
411
+ biggest_dst_pack_id: 0, # dst最大包号码
412
+ completed_pack_id: 0, # 完成到几(对面收到几)
413
+ last_continue_at: Time.new # 上一次发生流量的时间
418
414
  }
419
415
 
420
- src_info = @src_infos[ src ]
421
- src_id = src_info[ :id ]
422
416
  @tun_info[ :src_exts ][ src_id ] = src_ext
423
417
  src_info[ :proxy_type ] = :tunnel
424
418
 
425
- destination_port = src_info[ :destination_port ]
426
- destination_domain = src_info[ :destination_domain ]
427
419
  destination_domain_port = [ destination_domain, destination_port ].join( ':' )
428
420
  data = [ [ 0, A_NEW_SOURCE, src_id ].pack( 'Q>CQ>' ), @custom.encode( destination_domain_port ) ].join
429
421
  loop_send_a_new_source( src_ext, data )
@@ -609,6 +601,23 @@ module Girl
609
601
  end
610
602
  end
611
603
 
604
+ ##
605
+ # send data
606
+ #
607
+ def send_data( tun, data, to_addr )
608
+ begin
609
+ tun.sendmsg( data, 0, to_addr )
610
+ rescue IO::WaitWritable, Errno::EINTR
611
+ return false
612
+ rescue Errno::EHOSTUNREACH, Errno::ENETUNREACH, Errno::ENETDOWN => e
613
+ puts "#{ Time.new } #{ e.class }, close tun"
614
+ close_tun( tun )
615
+ return false
616
+ end
617
+
618
+ true
619
+ end
620
+
612
621
  ##
613
622
  # close src
614
623
  #
@@ -775,6 +784,7 @@ module Girl
775
784
  # puts "debug2 write src #{ written }"
776
785
  data = data[ written..-1 ]
777
786
  src_info[ from ] = data
787
+ src_info[ :last_continue_at ] = Time.new
778
788
  end
779
789
 
780
790
  ##
@@ -826,6 +836,7 @@ module Girl
826
836
  # puts "debug2 write dst #{ written }"
827
837
  data = data[ written..-1 ]
828
838
  dst_info[ from ] = data
839
+ dst_info[ :last_continue_at ] = Time.new
829
840
  end
830
841
 
831
842
  ##
@@ -843,9 +854,7 @@ module Girl
843
854
  while @tun_info[ :ctlmsgs ].any?
844
855
  to_addr, data = @tun_info[ :ctlmsgs ].first
845
856
 
846
- begin
847
- tun.sendmsg( data, 0, to_addr )
848
- rescue IO::WaitWritable, Errno::EINTR
857
+ unless send_data( tun, data, to_addr )
849
858
  return
850
859
  end
851
860
 
@@ -861,9 +870,7 @@ module Girl
861
870
  data = src_ext[ :wmems ][ pack_id ]
862
871
 
863
872
  if data
864
- begin
865
- tun.sendmsg( data, 0, @tun_info[ :tund_addr ] )
866
- rescue IO::WaitWritable, Errno::EINTR
873
+ unless send_data( tun, data, @tun_info[ :tund_addr ] )
867
874
  return
868
875
  end
869
876
  end
@@ -929,9 +936,7 @@ module Girl
929
936
 
930
937
  data = [ [ pack_id, src_id ].pack( 'Q>Q>' ), data ].join
931
938
 
932
- begin
933
- tun.sendmsg( data, 0, @tun_info[ :tund_addr ] )
934
- rescue IO::WaitWritable, Errno::EINTR
939
+ unless send_data( tun, data, @tun_info[ :tund_addr ] )
935
940
  return
936
941
  end
937
942
 
@@ -966,22 +971,21 @@ module Girl
966
971
  # puts "debug1 accept a src #{ addrinfo.inspect } #{ id }"
967
972
 
968
973
  @src_infos[ src ] = {
969
- id: id, # id
970
- proxy_proto: :uncheck, # :uncheck / :http / :socks5
971
- proxy_type: :uncheck, # :uncheck / :checking / :direct / :tunnel / :negotiation
972
- dst: nil, # :direct的场合,对应的dst
973
- destination_domain: nil, # 目的地域名
974
- destination_port: nil, # 目的地端口
975
- biggest_pack_id: 0, # 最大包号码
976
- is_connect: true, # 代理协议是http的场合,是否是CONNECT
977
- rbuffs: [], # 非CONNECT,dst或者远端dst未准备好,暂存流量 [ pack_id, data ]
978
- wbuff: '', # 写前
979
- cache: '', # 块读出缓存
980
- chunks: [], # 块队列,写前达到块大小时结一个块 filename
981
- spring: 0, # 块后缀,结块时,如果块队列不为空,则自增,为空,则置为0
982
- created_at: Time.new, # 创建时间
983
- last_recv_at: nil, # 上一次收到流量的时间,过期关闭
984
- is_closing: false # 是否准备关闭
974
+ id: id, # id
975
+ proxy_proto: :uncheck, # :uncheck / :http / :socks5
976
+ proxy_type: :uncheck, # :uncheck / :checking / :direct / :tunnel / :negotiation
977
+ dst: nil, # :direct的场合,对应的dst
978
+ destination_domain: nil, # 目的地域名
979
+ destination_port: nil, # 目的地端口
980
+ biggest_pack_id: 0, # 最大包号码
981
+ is_connect: true, # 代理协议是http的场合,是否是CONNECT
982
+ rbuffs: [], # 非CONNECT,dst或者远端dst未准备好,暂存流量 [ pack_id, data ]
983
+ wbuff: '', # 写前
984
+ cache: '', # 块读出缓存
985
+ chunks: [], # 块队列,写前达到块大小时结一个块 filename
986
+ spring: 0, # 块后缀,结块时,如果块队列不为空,则自增,为空,则置为0
987
+ last_continue_at: Time.new, # 上一次发生流量的时间
988
+ is_closing: false # 是否准备关闭
985
989
  }
986
990
 
987
991
  add_read( src, :src )
@@ -1003,7 +1007,7 @@ module Girl
1003
1007
 
1004
1008
  # puts "debug2 read src #{ data.inspect }"
1005
1009
  src_info = @src_infos[ src ]
1006
- src_info[ :last_recv_at ] = Time.new
1010
+ src_info[ :last_continue_at ] = Time.new
1007
1011
  proxy_type = src_info[ :proxy_type ]
1008
1012
 
1009
1013
  case proxy_type
@@ -1110,7 +1114,7 @@ module Girl
1110
1114
  src_info[ :destination_domain ] = destination_ip
1111
1115
  src_info[ :destination_port ] = destination_port
1112
1116
  # puts "debug1 IP V4 address #{ destination_addrinfo.inspect }"
1113
- deal_with_destination_ip( src, destination_ip )
1117
+ deal_with_destination_ip( src, destination_addrinfo )
1114
1118
  elsif atyp == 3
1115
1119
  domain_len = data[ 4 ].unpack( 'C' ).first
1116
1120
 
@@ -1193,7 +1197,7 @@ module Girl
1193
1197
 
1194
1198
  # puts "debug2 read dst #{ data.inspect }"
1195
1199
  dst_info = @dst_infos[ dst ]
1196
- dst_info[ :last_recv_at ] = Time.new
1200
+ dst_info[ :last_continue_at ] = Time.new
1197
1201
  src = dst_info[ :src ]
1198
1202
 
1199
1203
  if src.closed?
@@ -112,7 +112,7 @@ module Girl
112
112
 
113
113
  tund_info[ :dst_exts ].each do | dst_local_port, dst_ext |
114
114
  if dst_ext[ :dst ].closed? && ( now - dst_ext[ :last_continue_at ] > EXPIRE_AFTER )
115
- puts "p#{ Process.pid } #{ Time.new } expire dst ext #{ dst_local_port }"
115
+ puts "p#{ Process.pid } #{ Time.new } expire dst ext #{ dst_ext[ :domain_port ] }"
116
116
  del_dst_ext( tund, dst_local_port )
117
117
  end
118
118
  end
@@ -123,10 +123,8 @@ module Girl
123
123
  end
124
124
 
125
125
  @dst_infos.each do | dst, dst_info |
126
- is_expired = dst_info[ :last_recv_at ].nil? && ( now - dst_info[ :created_at ] > EXPIRE_NEW )
127
-
128
- if is_expired
129
- puts "p#{ Process.pid } #{ Time.new } expire dst"
126
+ if now - dst_info[ :last_continue_at ] > EXPIRE_AFTER
127
+ puts "p#{ Process.pid } #{ Time.new } expire dst #{ dst_info[ :domain_port ] }"
130
128
  set_is_closing( dst )
131
129
  need_trigger = true
132
130
  end
@@ -195,7 +193,7 @@ module Girl
195
193
 
196
194
  if Time.new - created_at < RESOLV_CACHE_EXPIRE
197
195
  # puts "debug1 #{ destination_domain_port } hit resolv cache #{ Addrinfo.new( destination_addr ).inspect }"
198
- deal_with_destination_addr( tund, src_id, destination_addr )
196
+ deal_with_destination_addr( tund, src_id, destination_addr, destination_domain_port )
199
197
  return
200
198
  end
201
199
 
@@ -204,13 +202,17 @@ module Girl
204
202
  end
205
203
 
206
204
  Thread.new do
207
- destination_domain, destination_port = destination_domain_port.split( ':' )
208
- destination_port = destination_port.to_i
205
+ colon_idx = destination_domain_port.rindex( ':' )
209
206
 
210
- begin
211
- destination_addr = Socket.sockaddr_in( destination_port, destination_domain )
212
- rescue Exception => e
213
- puts "p#{ Process.pid } #{ Time.new } sockaddr in #{ destination_domain_port } #{ e.class }"
207
+ if colon_idx
208
+ destination_domain = destination_domain_port[ 0...colon_idx ]
209
+ destination_port = destination_domain_port[ ( colon_idx + 1 )..-1 ].to_i
210
+
211
+ begin
212
+ destination_addr = Socket.sockaddr_in( destination_port, destination_domain )
213
+ rescue Exception => e
214
+ puts "p#{ Process.pid } #{ Time.new } sockaddr in #{ destination_domain_port } #{ e.class }"
215
+ end
214
216
  end
215
217
 
216
218
  @mutex.synchronize do
@@ -219,7 +221,7 @@ module Girl
219
221
  @resolv_caches[ destination_domain_port ] = [ destination_addr, Time.new ]
220
222
 
221
223
  unless tund.closed?
222
- if deal_with_destination_addr( tund, src_id, destination_addr )
224
+ if deal_with_destination_addr( tund, src_id, destination_addr, destination_domain_port )
223
225
  next_tick
224
226
  end
225
227
  end
@@ -231,8 +233,8 @@ module Girl
231
233
  ##
232
234
  # deal with destination addr
233
235
  #
234
- def deal_with_destination_addr( tund, src_id, destination_addr )
235
- dst = Socket.new( Socket::AF_INET, Socket::SOCK_STREAM, 0 )
236
+ def deal_with_destination_addr( tund, src_id, destination_addr, destination_domain_port )
237
+ dst = Socket.new( Addrinfo.new( destination_addr ).ipv4? ? Socket::AF_INET : Socket::AF_INET6, Socket::SOCK_STREAM, 0 )
236
238
  dst.setsockopt( Socket::SOL_TCP, Socket::TCP_NODELAY, 1 )
237
239
 
238
240
  begin
@@ -246,33 +248,34 @@ module Girl
246
248
  local_port = dst.local_address.ip_port
247
249
 
248
250
  @dst_infos[ dst ] = {
249
- local_port: local_port, # 本地端口
250
- tund: tund, # 对应tund
251
- biggest_pack_id: 0, # 最大包号码
252
- wbuff: '', # 写前
253
- cache: '', # 块读出缓存
254
- chunks: [], # 块队列,写前达到块大小时结一个块 filename
255
- spring: 0, # 块后缀,结块时,如果块队列不为空,则自增,为空,则置为0
256
- created_at: Time.new, # 创建时间
257
- last_recv_at: nil, # 上一次收到流量的时间,过期关闭
258
- is_closing: false # 是否准备关闭
251
+ local_port: local_port, # 本地端口
252
+ tund: tund, # 对应tund
253
+ domain_port: destination_domain_port, # 域名和端口
254
+ biggest_pack_id: 0, # 最大包号码
255
+ wbuff: '', # 写前
256
+ cache: '', # 块读出缓存
257
+ chunks: [], # 块队列,写前达到块大小时结一个块 filename
258
+ spring: 0, # 块后缀,结块时,如果块队列不为空,则自增,为空,则置为0
259
+ last_continue_at: Time.new, # 上一次发生流量的时间
260
+ is_closing: false # 是否准备关闭
259
261
  }
260
262
  add_read( dst, :dst )
261
263
 
262
264
  tund_info = @tund_infos[ tund ]
263
265
  tund_info[ :dst_local_ports ][ src_id ] = local_port
264
266
  tund_info[ :dst_exts ][ local_port ] = {
265
- dst: dst, # dst
266
- src_id: src_id, # 近端src id
267
- wmems: {}, # 写后 pack_id => data
268
- send_ats: {}, # 上一次发出时间 pack_id => send_at
269
- relay_pack_id: 0, # 转发到几
270
- continue_src_pack_id: 0, # 收到几
271
- pieces: {}, # 跳号包 src_pack_id => data
272
- is_src_closed: false, # src是否已关闭
273
- biggest_src_pack_id: 0, # src最大包号码
274
- completed_pack_id: 0, # 完成到几(对面收到几)
275
- last_continue_at: Time.new # 创建,或者上一次收到连续流量,或者发出新包的时间
267
+ dst: dst, # dst
268
+ src_id: src_id, # 近端src id
269
+ domain_port: destination_domain_port, # 域名和端口
270
+ wmems: {}, # 写后 pack_id => data
271
+ send_ats: {}, # 上一次发出时间 pack_id => send_at
272
+ relay_pack_id: 0, # 转发到几
273
+ continue_src_pack_id: 0, # 收到几
274
+ pieces: {}, # 跳号包 src_pack_id => data
275
+ is_src_closed: false, # src是否已关闭
276
+ biggest_src_pack_id: 0, # src最大包号码
277
+ completed_pack_id: 0, # 完成到几(对面收到几)
278
+ last_continue_at: Time.new # 上一次发生流量的时间
276
279
  }
277
280
 
278
281
  data = [ 0, PAIRED, src_id, local_port ].pack( 'Q>CQ>n' )
@@ -412,6 +415,23 @@ module Girl
412
415
  end
413
416
  end
414
417
 
418
+ ##
419
+ # send data
420
+ #
421
+ def send_data( tund, data, to_addr )
422
+ begin
423
+ tund.sendmsg( data, 0, to_addr )
424
+ rescue IO::WaitWritable, Errno::EINTR
425
+ return false
426
+ rescue Errno::EHOSTUNREACH, Errno::ENETUNREACH, Errno::ENETDOWN => e
427
+ puts "#{ Time.new } #{ e.class }, close tund"
428
+ close_tund( tund )
429
+ return false
430
+ end
431
+
432
+ true
433
+ end
434
+
415
435
  ##
416
436
  # close dst
417
437
  #
@@ -582,6 +602,7 @@ module Girl
582
602
  # puts "debug2 write dst #{ written }"
583
603
  data = data[ written..-1 ]
584
604
  dst_info[ from ] = data
605
+ dst_info[ :last_continue_at ] = Time.new
585
606
  end
586
607
 
587
608
  ##
@@ -599,9 +620,7 @@ module Girl
599
620
  while tund_info[ :ctlmsgs ].any?
600
621
  data = tund_info[ :ctlmsgs ].first
601
622
 
602
- begin
603
- tund.sendmsg( data, 0, tund_info[ :tun_addr ] )
604
- rescue IO::WaitWritable, Errno::EINTR
623
+ unless send_data( tund, data, tund_info[ :tun_addr ] )
605
624
  return
606
625
  end
607
626
 
@@ -617,9 +636,7 @@ module Girl
617
636
  data = dst_ext[ :wmems ][ pack_id ]
618
637
 
619
638
  if data
620
- begin
621
- tund.sendmsg( data, 0, tund_info[ :tun_addr ] )
622
- rescue IO::WaitWritable, Errno::EINTR
639
+ unless send_data( tund, data, tund_info[ :tun_addr ] )
623
640
  return
624
641
  end
625
642
  end
@@ -685,9 +702,7 @@ module Girl
685
702
 
686
703
  data = [ [ pack_id, dst_local_port ].pack( 'Q>n' ), data ].join
687
704
 
688
- begin
689
- tund.sendmsg( data, 0, tund_info[ :tun_addr ] )
690
- rescue IO::WaitWritable, Errno::EINTR
705
+ unless send_data( tund, data, tund_info[ :tun_addr ] )
691
706
  return
692
707
  end
693
708
 
@@ -771,7 +786,7 @@ module Girl
771
786
 
772
787
  # puts "debug2 read dst #{ data.inspect }"
773
788
  dst_info = @dst_infos[ dst ]
774
- dst_info[ :last_recv_at ] = Time.new
789
+ dst_info[ :last_continue_at ] = Time.new
775
790
  tund = dst_info[ :tund ]
776
791
 
777
792
  if tund.closed?
@@ -814,7 +829,6 @@ module Girl
814
829
  when A_NEW_SOURCE
815
830
  src_id = data[ 9, 8 ].unpack( 'Q>' ).first
816
831
  dst_local_port = tund_info[ :dst_local_ports ][ src_id ]
817
- # puts "debug1 got a new source #{ src_id }"
818
832
 
819
833
  if dst_local_port
820
834
  dst_ext = tund_info[ :dst_exts ][ dst_local_port ]
@@ -831,8 +845,8 @@ module Girl
831
845
  end
832
846
 
833
847
  data = data[ 17..-1 ]
834
- # puts "debug1 #{ data }"
835
848
  destination_domain_port = @custom.decode( data )
849
+ puts "p#{ Process.pid } #{ Time.new } a new source #{ src_id } #{ destination_domain_port }"
836
850
  resolve_domain( tund, src_id, destination_domain_port )
837
851
  when SOURCE_STATUS
838
852
  src_id, relay_src_pack_id, continue_dst_pack_id = data[ 9, 24 ].unpack( 'Q>Q>Q>' )
@@ -1,3 +1,3 @@
1
1
  module Girl
2
- VERSION = '0.71.2'.freeze
2
+ VERSION = '0.75.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: girl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.71.2
4
+ version: 0.75.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - takafan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-03 00:00:00.000000000 Z
11
+ date: 2020-07-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: while internet is evil, here's a girl.
14
14
  email: