From 43ccc2d71a537ffc6d05bccd3ed64f638811efbe Mon Sep 17 00:00:00 2001 From: Mohammad Date: Sun, 15 Dec 2024 16:31:00 +0330 Subject: [PATCH] don't send `keepAlivePeriod` if it not in the config (#1517) --- app/subscription/v2ray.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/subscription/v2ray.py b/app/subscription/v2ray.py index 33f644c0e..d6d994744 100644 --- a/app/subscription/v2ray.py +++ b/app/subscription/v2ray.py @@ -6,12 +6,12 @@ from typing import Union from urllib.parse import quote from uuid import UUID -from app.utils.helpers import UUIDEncoder from jinja2.exceptions import TemplateNotFound from app.subscription.funcs import get_grpc_gun, get_grpc_multi from app.templates import render_template +from app.utils.helpers import UUIDEncoder from config import ( EXTERNAL_CONFIG, GRPC_USER_AGENT_TEMPLATE, @@ -240,11 +240,12 @@ def vmess( "scMinPostsIntervalMs": sc_min_posts_interval_ms, "xPaddingBytes": x_padding_bytes, "noGRPCHeader": noGRPCHeader, - "keepAlivePeriod": keepAlivePeriod, } if xmux: extra["xmux"] = xmux payload["type"] = mode + if keepAlivePeriod > 0: + extra["keepAlivePeriod"] = keepAlivePeriod payload["extra"] = extra elif net == "ws": @@ -320,8 +321,9 @@ def vless(cls, "scMinPostsIntervalMs": sc_min_posts_interval_ms, "xPaddingBytes": x_padding_bytes, "noGRPCHeader": noGRPCHeader, - "keepAlivePeriod": keepAlivePeriod, } + if keepAlivePeriod > 0: + extra["keepAlivePeriod"] = keepAlivePeriod if xmux: extra["xmux"] = xmux payload["extra"] = json.dumps(extra) @@ -423,8 +425,9 @@ def trojan(cls, "scMinPostsIntervalMs": sc_min_posts_interval_ms, "xPaddingBytes": x_padding_bytes, "noGRPCHeader": noGRPCHeader, - "keepAlivePeriod": keepAlivePeriod, } + if keepAlivePeriod > 0: + extra["keepAlivePeriod"] = keepAlivePeriod if xmux: extra["xmux"] = xmux payload["extra"] = json.dumps(extra) @@ -518,7 +521,7 @@ def add_config(self, remarks, outbounds): def render(self, reverse=False): if reverse: self.config.reverse() - return json.dumps(self.config, indent=4,cls=UUIDEncoder) + return json.dumps(self.config, indent=4, cls=UUIDEncoder) @staticmethod def tls_config(sni=None, fp=None, alpn=None, ais: bool = False) -> dict: @@ -617,7 +620,8 @@ def splithttp_config(self, path: str = "", host: str = "", random_user_agent: bo config["noGRPCHeader"] = noGRPCHeader if xmux: config["xmux"] = xmux - config["keepAlivePeriod"] = keepAlivePeriod + if keepAlivePeriod > 0: + config["keepAlivePeriod"] = keepAlivePeriod # core will ignore unknown variables return config