From 1c74d622ce2cae66167ff7af001e481708f8b233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=AC=E9=97=B4=E7=99=BD=E7=8C=AB?= <139044047+honmashironeko@users.noreply.github.com> Date: Fri, 14 Mar 2025 15:36:28 +0800 Subject: [PATCH] Update --- ProxyCat-Manual/logs.md | 6 ++++++ app.py | 2 +- modules/modules.py | 3 +-- modules/proxyserver.py | 11 ++++++++--- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/ProxyCat-Manual/logs.md b/ProxyCat-Manual/logs.md index cc037f4..8104a84 100644 --- a/ProxyCat-Manual/logs.md +++ b/ProxyCat-Manual/logs.md @@ -1,3 +1,9 @@ +### 2025/03/14 + +- 修复'_last_used'报错问题,连接关闭方式修正 +- 修复本地代理读取时切换逻辑失效问题 +- 增加切换时间间隔设置为0时进入每次请求都更换IP + ### 2025/03/03 - 美化 Web管理界面 diff --git a/app.py b/app.py index ec4c996..737040e 100644 --- a/app.py +++ b/app.py @@ -523,7 +523,7 @@ def check_version(): original_level = httpx_logger.level httpx_logger.setLevel(logging.WARNING) - CURRENT_VERSION = "ProxyCat-V2.0.1" + CURRENT_VERSION = "ProxyCat-V2.0.2" try: client = httpx.Client(transport=httpx.HTTPTransport(retries=3)) diff --git a/modules/modules.py b/modules/modules.py index 8bec194..0ab9639 100644 --- a/modules/modules.py +++ b/modules/modules.py @@ -480,7 +480,6 @@ def load_config(config_file='config/config.ini'): result = dict(config.items('Server')) - # 添加用户配置 if config.has_section('Users'): result['Users'] = dict(config.items('Users')) @@ -638,7 +637,7 @@ async def check_for_updates(language='cn'): match = re.search(r'
(ProxyCat-V\d+\.\d+\.\d+)
', content) if match: latest_version = match.group(1) - CURRENT_VERSION = "ProxyCat-V2.0.1" + CURRENT_VERSION = "ProxyCat-V2.0.2" if version.parse(latest_version.split('-V')[1]) > version.parse(CURRENT_VERSION.split('-V')[1]): print(f"{Fore.YELLOW}{get_message('new_version_found', language)} 当前版本: {CURRENT_VERSION}, 最新版本: {latest_version}{Style.RESET_ALL}") print(f"{Fore.YELLOW}{get_message('visit_quark', language)}{Style.RESET_ALL}") diff --git a/modules/proxyserver.py b/modules/proxyserver.py index 60dee86..31d134e 100644 --- a/modules/proxyserver.py +++ b/modules/proxyserver.py @@ -185,11 +185,12 @@ class AsyncProxyServer: try: current_time = time.time() - if self.switching_proxy or (current_time - self.last_switch_attempt < self.switch_cooldown): + if self.interval != 0 and (self.switching_proxy or (current_time - self.last_switch_attempt < self.switch_cooldown)): return self.current_proxy if (self.use_getip and (not self.current_proxy or - current_time - self.last_switch_time >= self.interval)): + current_time - self.last_switch_time >= self.interval)) or \ + (not self.use_getip and self.interval == 0): try: self.switching_proxy = True self.last_switch_attempt = current_time @@ -337,7 +338,7 @@ class AsyncProxyServer: else: proxy_url = f"{proxy_type}://{proxy_addr}" - return httpx.AsyncClient( + client = httpx.AsyncClient( proxies={"all://": proxy_url}, limits=httpx.Limits( max_keepalive_connections=100, @@ -348,6 +349,8 @@ class AsyncProxyServer: http2=True, verify=False ) + client._last_used = time.time() + return client async def _cleanup_connections(self): current_time = time.time() @@ -903,6 +906,7 @@ class AsyncProxyServer: if proxy in self.proxy_pool: conn = self.proxy_pool[proxy] if not conn.is_closed: + conn._last_used = time.time() return conn proxy_type, proxy_addr = proxy.split('://') @@ -928,6 +932,7 @@ class AsyncProxyServer: ) if len(self.proxy_pool) < self.max_pool_size: + conn._last_used = time.time() self.proxy_pool[proxy] = conn return conn