Skip to content

Commit

Permalink
Merge pull request #1607 from shraiton/master
Browse files Browse the repository at this point in the history
add real upload/download splitting to xhttp
  • Loading branch information
ImMohammad20000 authored Jan 18, 2025
2 parents 2353e3f + d53b46c commit 03dbcc1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from config import ALLOWED_ORIGINS, DOCS, XRAY_SUBSCRIPTION_PATH

__version__ = "0.8.2"
__version__ = "0.8.4"

app = FastAPI(
title="MarzbanAPI",
Expand Down
31 changes: 22 additions & 9 deletions app/subscription/v2ray.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def add(self, remark: str, address: str, inbound: dict, settings: dict):
heartbeatPeriod=inbound.get("heartbeatPeriod", 0),
keepAlivePeriod=inbound.get("keepAlivePeriod", 0),
xmux=inbound.get("xmux", {}),
downloadSettings=inbound.get("downloadSettings",{})
)

elif inbound["protocol"] == "vless":
Expand Down Expand Up @@ -113,6 +114,7 @@ def add(self, remark: str, address: str, inbound: dict, settings: dict):
heartbeatPeriod=inbound.get("heartbeatPeriod", 0),
keepAlivePeriod=inbound.get("keepAlivePeriod", 0),
xmux=inbound.get("xmux", {}),
downloadSettings=inbound.get("downloadSettings",{})
)

elif inbound["protocol"] == "trojan":
Expand Down Expand Up @@ -145,6 +147,7 @@ def add(self, remark: str, address: str, inbound: dict, settings: dict):
heartbeatPeriod=inbound.get("heartbeatPeriod", 0),
keepAlivePeriod=inbound.get("keepAlivePeriod", 0),
xmux=inbound.get("xmux", {}),
downloadSettings=inbound.get("downloadSettings",{})
)

elif inbound["protocol"] == "shadowsocks":
Expand Down Expand Up @@ -190,6 +193,7 @@ def vmess(
heartbeatPeriod: int = 0,
keepAlivePeriod: int = 0,
xmux: dict = {},
downloadSettings: dict = {},
):
payload = {
"add": address,
Expand Down Expand Up @@ -243,10 +247,11 @@ def vmess(
}
if xmux:
extra["xmux"] = xmux
if downloadSettings:
extra["downloadSettings"] = downloadSettings
payload["type"] = mode
if keepAlivePeriod > 0:
extra["keepAlivePeriod"] = keepAlivePeriod
payload["extra"] = extra

payload["extra"] = (json.dumps(extra)).replace(" ","")

elif net == "ws":
if heartbeatPeriod:
Expand Down Expand Up @@ -289,6 +294,7 @@ def vless(cls,
heartbeatPeriod: int = 0,
keepAlivePeriod: int = 0,
xmux: dict = {},
downloadSettings: dict = {},
):

payload = {
Expand Down Expand Up @@ -322,11 +328,11 @@ def vless(cls,
"xPaddingBytes": x_padding_bytes,
"noGRPCHeader": noGRPCHeader,
}
if keepAlivePeriod > 0:
extra["keepAlivePeriod"] = keepAlivePeriod
if xmux:
extra["xmux"] = xmux
payload["extra"] = json.dumps(extra)
if downloadSettings:
extra["downloadSettings"] = downloadSettings
payload["extra"] = (json.dumps(extra)).replace(" ","")

elif net == 'kcp':
payload['seed'] = path
Expand Down Expand Up @@ -397,6 +403,7 @@ def trojan(cls,
heartbeatPeriod: int = 0,
keepAlivePeriod: int = 0,
xmux: dict = {},
downloadSettings: dict = {},
):

payload = {
Expand Down Expand Up @@ -426,11 +433,11 @@ def trojan(cls,
"xPaddingBytes": x_padding_bytes,
"noGRPCHeader": noGRPCHeader,
}
if keepAlivePeriod > 0:
extra["keepAlivePeriod"] = keepAlivePeriod
if xmux:
extra["xmux"] = xmux
payload["extra"] = json.dumps(extra)
if downloadSettings:
extra["downloadSettings"] = downloadSettings
payload["extra"] = (json.dumps(extra)).replace(" ","")

elif net == 'quic':
payload['key'] = path
Expand Down Expand Up @@ -599,6 +606,7 @@ def splithttp_config(self, path: str = "", host: str = "", random_user_agent: bo
sc_min_posts_interval_ms: int = 30,
x_padding_bytes: str = "100-1000",
xmux: dict = {},
downloadSettings: dict = {},
mode: str = "auto",
noGRPCHeader: bool = False,
keepAlivePeriod: int = 0,
Expand All @@ -620,6 +628,8 @@ def splithttp_config(self, path: str = "", host: str = "", random_user_agent: bo
config["noGRPCHeader"] = noGRPCHeader
if xmux:
config["xmux"] = xmux
if downloadSettings:
config["downloadSettings"] = downloadSettings
if keepAlivePeriod > 0:
config["keepAlivePeriod"] = keepAlivePeriod
# core will ignore unknown variables
Expand Down Expand Up @@ -922,6 +932,7 @@ def make_stream_setting(self,
sc_min_posts_interval_ms: int = 30,
x_padding_bytes: str = "100-1000",
xmux: dict = {},
downloadSettings: dict = {},
mode: str = "auto",
noGRPCHeader: bool = False,
heartbeatPeriod: int = 0,
Expand Down Expand Up @@ -956,6 +967,7 @@ def make_stream_setting(self,
sc_min_posts_interval_ms=sc_min_posts_interval_ms,
x_padding_bytes=x_padding_bytes,
xmux=xmux,
downloadSettings=downloadSettings,
mode=mode,
noGRPCHeader=noGRPCHeader,
keepAlivePeriod=keepAlivePeriod,
Expand Down Expand Up @@ -1066,6 +1078,7 @@ def add(self, remark: str, address: str, inbound: dict, settings: dict):
sc_min_posts_interval_ms=inbound.get('scMinPostsIntervalMs', 30),
x_padding_bytes=inbound.get("xPaddingBytes", "100-1000"),
xmux=inbound.get("xmux", {}),
downloadSettings=inbound.get("downloadSettings",{}),
mode=inbound.get("mode", "auto"),
noGRPCHeader=inbound.get("noGRPCHeader", False),
heartbeatPeriod=inbound.get("heartbeatPeriod", 0),
Expand Down
16 changes: 9 additions & 7 deletions app/xray/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,16 @@ def _resolve_inbounds(self):
settings['path'] = net_settings.get('path', '')
host = net_settings.get('host', '')
settings['host'] = [host]
settings['scMaxEachPostBytes'] = net_settings.get('scMaxEachPostBytes', 1000000)
settings['scMaxConcurrentPosts'] = net_settings.get('scMaxConcurrentPosts', 100)
settings['scMinPostsIntervalMs'] = net_settings.get('scMinPostsIntervalMs', 30)
settings['xPaddingBytes'] = net_settings.get('xPaddingBytes', "100-1000")
settings['xmux'] = net_settings.get('xmux', {})
extra = net_settings.get('extra',{})
settings['scMaxEachPostBytes'] = extra.get('scMaxEachPostBytes', 1000000)
settings['scMaxConcurrentPosts'] = extra.get('scMaxConcurrentPosts', 100)
settings['scMinPostsIntervalMs'] = extra.get('scMinPostsIntervalMs', 30)
settings['xPaddingBytes'] = extra.get('xPaddingBytes', "100-1000")
settings["noGRPCHeader"] = extra.get("noGRPCHeader", False)
settings['xmux'] = extra.get('xmux',{})
settings['downloadSettings'] = extra.get('downloadSettings',{})
settings["mode"] = net_settings.get("mode", "auto")
settings["noGRPCHeader"] = net_settings.get("noGRPCHeader", False)
settings["keepAlivePeriod"] = net_settings.get("keepAlivePeriod", 0)
settings["keepAlivePeriod"] = net_settings.get("keepAlivePeriod", 0) #documentation says it's moved to hKeepAlivePeriod

elif net == 'kcp':
header = net_settings.get('header', {})
Expand Down

0 comments on commit 03dbcc1

Please sign in to comment.