Skip to content

Commit ea42c5f

Browse files
committed
fix bug for scan ip
1 parent 0fd20cf commit ea42c5f

File tree

15 files changed

+409
-102
lines changed

15 files changed

+409
-102
lines changed

code/default/gae_proxy/lang/fa_IR/LC_MESSAGES/messages.po

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ msgid ""
33
msgstr ""
44
"Project-Id-Version: PROJECT VERSION\n"
55
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
6-
"POT-Creation-Date: 2016-04-17 22:25+0800\n"
6+
"POT-Creation-Date: 2016-04-30 14:57+0800\n"
77
"PO-Revision-Date: 2015-12-06 09:14+0800\n"
88
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
99
"Language: fa_IR\n"
@@ -246,9 +246,6 @@ msgstr "خودکار تنظیم تعداد موضوع اسکن"
246246
msgid "Max scan thread count"
247247
msgstr "حداکثر تعداد موضوع اسکن"
248248

249-
msgid "Update"
250-
msgstr "به روز رسانی"
251-
252249
msgid "IP range list"
253250
msgstr "لیست محدوده IP"
254251

@@ -270,6 +267,9 @@ msgstr "شبکه محلی ما شکست خورده است."
270267
msgid "IP Number"
271268
msgstr "IP شماره"
272269

270+
msgid "Is Idle"
271+
msgstr "آماده به کار"
272+
273273
msgid "IP Quality"
274274
msgstr "IP کیفیت"
275275

@@ -336,12 +336,6 @@ msgstr "نمایش جزئیات"
336336
msgid "Post to Github issue needs to sign in your Github account"
337337
msgstr "بازخورد یک کلید نیاز به ثبت نام در حساب github خود را"
338338

339-
msgid "To Google Groups"
340-
msgstr "به Google Groups"
341-
342-
msgid "Post to Github Issue..."
343-
msgstr "بررسی مسائل _Github_..."
344-
345339
msgid "GAE Proxy Status Info"
346340
msgstr "GAE پروکسی وضعیت"
347341

@@ -392,6 +386,9 @@ msgstr ""
392386
msgid "No working appid. Please check. "
393387
msgstr "بدون APPID کارگر. لطفا بررسی کنید. "
394388

389+
msgid "System is Idle. "
390+
msgstr ""
391+
395392
msgid "Connection not established yet. "
396393
msgstr "اتصال برقرار نشده است"
397394

@@ -429,7 +426,10 @@ msgstr "شما با استفاده از شناسه های عمومی است."
429426
msgid "new:"
430427
msgstr ""
431428

432-
msgid " used:"
429+
msgid " h1:"
430+
msgstr ""
431+
432+
msgid " h2:"
433433
msgstr ""
434434

435435
msgid "Auto proxy enabled at "
@@ -441,3 +441,7 @@ msgstr "پروکسی را فعال کنید در "
441441
msgid "Proxy disabled"
442442
msgstr "پروکسی غیرفعال"
443443

444+
445+
446+
447+

code/default/gae_proxy/lang/zh_CN/LC_MESSAGES/messages.po

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ msgid ""
33
msgstr ""
44
"Project-Id-Version: PROJECT VERSION\n"
55
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
6-
"POT-Creation-Date: 2016-04-17 22:25+0800\n"
6+
"POT-Creation-Date: 2016-04-30 14:57+0800\n"
77
"PO-Revision-Date: 2015-12-16 15:55+0800\n"
88
"Last-Translator: XX-Net <[email protected]>\n"
99
"Language: zh_Hans_CN\n"
@@ -242,9 +242,6 @@ msgstr "自动调整扫描线程数"
242242
msgid "Max scan thread count"
243243
msgstr "最大扫描线程数"
244244

245-
msgid "Update"
246-
msgstr "更新"
247-
248245
msgid "IP range list"
249246
msgstr "IP段列表"
250247

@@ -266,6 +263,9 @@ msgstr "本地网络状态"
266263
msgid "IP Number"
267264
msgstr "IP数量"
268265

266+
msgid "Is Idle"
267+
msgstr "空闲"
268+
269269
msgid "IP Quality"
270270
msgstr "IP延迟"
271271

@@ -332,12 +332,6 @@ msgstr "显示详细信息"
332332
msgid "Post to Github issue needs to sign in your Github account"
333333
msgstr "贴到Github问题区需要登录Github账号"
334334

335-
msgid "To Google Groups"
336-
msgstr "前往Google论坛"
337-
338-
msgid "Post to Github Issue..."
339-
msgstr "贴到Github问题区..."
340-
341335
msgid "GAE Proxy Status Info"
342336
msgstr "GAEProxy状态信息"
343337

@@ -390,6 +384,9 @@ msgstr ""
390384
msgid "No working appid. Please check. "
391385
msgstr "没有可用APPID,请检查。"
392386

387+
msgid "System is Idle. "
388+
msgstr ""
389+
393390
msgid "Connection not established yet. "
394391
msgstr "尚未建立连接"
395392

@@ -427,8 +424,11 @@ msgstr "你正使用公共AppID"
427424
msgid "new:"
428425
msgstr "新:"
429426

430-
msgid " used:"
431-
msgstr " 已用:"
427+
msgid " h1:"
428+
msgstr ""
429+
430+
msgid " h2:"
431+
msgstr ""
432432

433433
msgid "Auto proxy enabled at "
434434
msgstr "智能代理已启用:"
@@ -439,3 +439,7 @@ msgstr "全局代理已启用:"
439439
msgid "Proxy disabled"
440440
msgstr "全局代理已禁用"
441441

442+
443+
444+
445+

code/default/gae_proxy/local/appids_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def report_not_exist(self, appid, ip):
5252
th.start()
5353

5454
def process_appid_not_exist(self, appid, ip):
55-
if check_ip.test_gae_ip(ip, "xxnet-1"):
55+
if check_ip.test_gae_ip2(ip, "xxnet-1"):
5656
self.set_appid_not_exist(appid)
5757
else:
5858
xlog.warn("process_appid_not_exist, remove ip:%s", ip)

code/default/gae_proxy/local/check_ip.py

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -186,28 +186,6 @@ def check_goagent(ssl_sock, appid):
186186
return True
187187

188188

189-
# export api for google_ip, appid_manager
190-
def test_gae_ip(ip, appid=None):
191-
try:
192-
ssl_sock = connect_ssl(ip, timeout=max_timeout)
193-
get_ssl_cert_domain(ssl_sock)
194-
195-
if not appid:
196-
appid = "xxnet-1"
197-
if not check_goagent(ssl_sock, appid):
198-
return False
199-
200-
return ssl_sock
201-
except socket.timeout:
202-
if __name__ == "__main__":
203-
xlog.warn("connect timeout")
204-
return False
205-
except Exception as e:
206-
if __name__ == "__main__":
207-
xlog.exception("test_gae_ip %s e:%r",ip, e)
208-
return False
209-
210-
211189
def test_gae_ip2(ip, appid="xxnet-1", use_openssl=True):
212190
if use_openssl:
213191
try:
@@ -231,7 +209,9 @@ def test_gae_ip2(ip, appid="xxnet-1", use_openssl=True):
231209
return False
232210
else:
233211
return ssl_sock
234-
except:
212+
except Exception as e:
213+
if __name__ == "__main__":
214+
xlog.exception("check fail:%r", e)
235215
return False
236216
else:
237217
ssl_sock = None

code/default/gae_proxy/local/check_local_network.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,23 @@ def report_network_ok():
7070
last_check_time = time.time()
7171
continue_fail_count = 0
7272

73+
74+
def report_network_fail():
75+
global network_stat, last_check_time, continue_fail_count
76+
continue_fail_count += 1
77+
last_check_time = time.time()
78+
79+
if continue_fail_count > 10:
80+
network_stat = "unkown"
81+
xlog.debug("report_connect_fail continue_fail_count:%d", continue_fail_count)
82+
triger_check_network()
83+
84+
85+
def is_ok():
86+
global network_stat, last_check_time, continue_fail_count
87+
return network_stat == "OK"
88+
89+
7390
def _check_worker():
7491
global _checking_lock, _checking_num, network_stat, last_check_time
7592
time_now = time.time()

code/default/gae_proxy/local/config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ def load(self):
8686
self.HOSTS_DIRECT = tuple(direct_hosts)
8787

8888
self.AUTORANGE_MAXSIZE = self.CONFIG.getint('autorange', 'maxsize')
89-
self.AUTORANGE_WAITSIZE = self.CONFIG.getint('autorange', 'waitsize')
9089
self.AUTORANGE_BUFSIZE = self.CONFIG.getint('autorange', 'bufsize')
9190
self.AUTORANGE_THREADS = self.CONFIG.getint('autorange', 'threads')
9291

code/default/gae_proxy/local/gae_handler.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767

6868
from config import config
6969
from google_ip import google_ip
70+
import check_local_network
7071
from http_dispatcher import http_dispatch
7172
from http_common import *
7273

@@ -231,6 +232,7 @@ def fetch_by_gae(method, url, headers, body):
231232
if response.app_status != 200:
232233
return response
233234

235+
check_local_network.report_network_ok()
234236
try:
235237
data = response.body.get(2)
236238
if len(data) < 2:
@@ -390,7 +392,6 @@ class RangeFetch(object):
390392
threads = config.AUTORANGE_THREADS
391393
maxsize = config.AUTORANGE_MAXSIZE
392394
bufsize = config.AUTORANGE_BUFSIZE
393-
waitsize = config.AUTORANGE_WAITSIZE
394395

395396
def __init__(self, method, url, headers, body, response, wfile):
396397
self.method = method
@@ -441,9 +442,11 @@ def fetch(self):
441442
self.expect_begin = start
442443
for begin in range(end+1, length, self.maxsize):
443444
range_queue.put((begin, min(begin+self.maxsize-1, length-1), None))
444-
for i in xrange(0, self.threads):
445+
446+
thread_num = min(self.threads, range_queue.qsize())
447+
for i in xrange(0, thread_num):
445448
range_delay_size = i * self.maxsize
446-
spawn_later(float(range_delay_size)/self.waitsize, self.__fetchlet, range_queue, data_queue, range_delay_size)
449+
spawn_later(i*0.1, self.__fetchlet, range_queue, data_queue, range_delay_size)
447450

448451
has_peek = hasattr(data_queue, 'peek')
449452
peek_timeout = 120
@@ -496,9 +499,9 @@ def __fetchlet(self, range_queue, data_queue, range_delay_size):
496499
except Queue.Empty:
497500
continue
498501

499-
if self.expect_begin < start and data_queue.qsize() * self.bufsize + range_delay_size > 30*1024*1024:
502+
if start > self.expect_begin and data_queue.qsize() * self.bufsize + range_delay_size > 30*1024*1024:
500503
range_queue.put((start, end, response))
501-
time.sleep(10)
504+
time.sleep(2)
502505
continue
503506
headers['Range'] = 'bytes=%d-%d' % (start, end)
504507

code/default/gae_proxy/local/google_ip.py

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ def save_ip_list(self, force=False):
203203
finally:
204204
self.ip_lock.release()
205205

206+
def _ip_rate(self, ip_info):
207+
return ip_info['handshake_time'] + \
208+
(ip_info['fail_times'] * 1000 ) + \
209+
(ip_info['down_fail'] * 500 )
210+
206211
def try_sort_gws_ip(self, force=False):
207212
if time.time() - self.last_sort_time_for_gws < 10 and not force:
208213
return
@@ -215,9 +220,7 @@ def try_sort_gws_ip(self, force=False):
215220
for ip in self.ip_dict:
216221
if 'gws' not in self.ip_dict[ip]['server']:
217222
continue
218-
ip_rate[ip] = self.ip_dict[ip]['handshake_time'] + \
219-
(self.ip_dict[ip]['fail_times'] * 1000 ) + \
220-
(self.ip_dict[ip]['down_fail'] * 500 )
223+
ip_rate[ip] = self._ip_rate(self.ip_dict[ip])
221224
if self.ip_dict[ip]['fail_times'] == 0:
222225
self.good_ip_num += 1
223226

@@ -246,7 +249,7 @@ def adjust_scan_thread_num(self, max_scan_ip_thread_num=None):
246249
else:
247250
try:
248251
the_100th_ip = self.gws_ip_list[99]
249-
the_100th_handshake_time = self.ip_dict[the_100th_ip]['handshake_time']
252+
the_100th_handshake_time = self._ip_rate(self.ip_dict[the_100th_ip])
250253
scan_ip_thread_num = int( (the_100th_handshake_time - 200)/2 * self.max_scan_ip_thread_num/50 )
251254
except Exception as e:
252255
xlog.warn("adjust_scan_thread_num fail:%r", e)
@@ -400,7 +403,7 @@ def update_ip(self, ip, handshake_time):
400403
return
401404

402405
time_now = time.time()
403-
check_local_network.network_stat = "OK"
406+
check_local_network.report_network_ok()
404407
check_ip.last_check_time = time_now
405408
check_ip.continue_fail_count = 0
406409

@@ -458,15 +461,12 @@ def report_connect_fail(self, ip, force_remove=False):
458461
self.ip_dict[ip]['links'] -= 1
459462

460463
# ignore if system network is disconnected.
461-
if check_local_network.network_stat == "Fail":
464+
if not check_local_network.is_ok():
462465
xlog.debug("report_connect_fail network fail")
463466
return
464467

465-
check_local_network.continue_fail_count += 1
466-
if check_local_network.continue_fail_count > 10:
467-
check_local_network.network_stat = "unknown"
468-
xlog.debug("report_connect_fail continue_fail_count:%d", check_local_network.continue_fail_count)
469-
check_local_network.triger_check_network()
468+
check_local_network.report_network_fail()
469+
if not check_local_network.is_ok():
470470
return
471471

472472
fail_time = self.ip_dict[ip]["fail_time"]
@@ -480,7 +480,6 @@ def report_connect_fail(self, ip, force_remove=False):
480480
self.append_ip_history(ip, "fail")
481481
self.ip_dict[ip]["fail_time"] = time_now
482482

483-
check_local_network.triger_check_network()
484483
self.to_check_ip_queue.put((ip, time_now + 10))
485484
xlog.debug("report_connect_fail:%s", ip)
486485

@@ -541,7 +540,7 @@ def check_ip_process(self):
541540
if time_wait > 0:
542541
time.sleep(time_wait)
543542

544-
if check_local_network.network_stat == "Fail":
543+
if not check_local_network.is_ok():
545544
try:
546545
if self.ip_dict[ip]['fail_times']:
547546
self.ip_dict[ip]['fail_times'] = 0
@@ -550,7 +549,7 @@ def check_ip_process(self):
550549
pass
551550
continue
552551

553-
result = check_ip.test_gae_ip(ip)
552+
result = check_ip.test_gae_ip2(ip)
554553
if result:
555554
self.add_ip(ip, result.handshake_time, result.domain, "gws")
556555
xlog.debug("restore ip:%s", ip)
@@ -588,6 +587,25 @@ def remove_slowest_ip(self):
588587
finally:
589588
self.ip_lock.release()
590589

590+
def recheck_ip(self, ip):
591+
# recheck ip if not work.
592+
# can block.
593+
if not check_local_network.is_ok():
594+
xlog.debug("recheck_ip:%s network is fail", ip)
595+
return
596+
597+
self.report_connect_fail(ip)
598+
599+
connect_control.start_connect_register()
600+
result = check_ip.test_gae_ip2(ip)
601+
connect_control.end_connect_register()
602+
if not result:
603+
self.report_connect_fail(ip, force_remove=True)
604+
xlog.debug("recheck_ip:%s real fail, removed.", ip)
605+
else:
606+
self.add_ip(ip, result.handshake_time, result.domain, "gws")
607+
xlog.debug("recheck_ip:%s restore okl", ip)
608+
591609
def scan_ip_worker(self):
592610
while self.scan_thread_count <= self.scan_ip_thread_num and connect_control.keep_running:
593611
if not connect_control.allow_scan():

0 commit comments

Comments
 (0)