Skip to content

Commit

Permalink
use new algorithm.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-X-Net committed Jul 18, 2023
1 parent 9bd0da8 commit 36b63b3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 0 additions & 1 deletion code/default/x_tunnel/local/cloudflare_front/ip_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ def report_connect_fail(self, ip_str, sni=None, reason="", force_remove=True):

info = self._get_domain(top_domain)
info["fail_times"] += 1
info["last_try"] = time.time()
self.logger.debug("ip %s sni:%s connect fail, reason:%s", ip, sni, reason)

def update_ip(self, ip_str, sni, handshake_time):
Expand Down
8 changes: 6 additions & 2 deletions code/default/x_tunnel/local/tls_relay_front/ip_manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import random
import time
import json

import utils
Expand All @@ -22,10 +22,12 @@ def _get_ip_info(self, ip):
"fail_times": 0,
"links": 0,
"rtt": 1000,
"last_try": 0.0
})
return self.ip_dict[ip]

def get_ip_sni_host(self):
now = time.time()
ips = self.host_manager.ips

best_info = None
Expand All @@ -39,7 +41,7 @@ def get_ip_sni_host(self):
if info["links"] >= self.config.max_links_per_ip:
continue

if info["fail_times"] > 5 and random.randint(0, 10) < 9:
if info["fail_times"] and now - info["last_try"] < 60:
continue

if info["rtt"] < best_rtt:
Expand All @@ -50,6 +52,7 @@ def get_ip_sni_host(self):
return None, None, None

best_info["links"] += 1
best_info["last_try"] = now
# self.logger.debug("get ip:%s", ip)

ip = best_info["ip"]
Expand All @@ -65,6 +68,7 @@ def update_ip(self, ip_str, sni, handshake_time):
info = self._get_ip_info(ip)
info["fail_times"] = 0
info["rtt"] = handshake_time
info["last_try"] = 0.0
# self.logger.debug("ip %s connect success", ip)

def report_connect_fail(self, ip_str, sni=None, reason="", force_remove=False):
Expand Down

0 comments on commit 36b63b3

Please sign in to comment.