@@ -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