From dde50e5eb8b6c8ed9acfbbcac62b4ef9d54c8495 Mon Sep 17 00:00:00 2001 From: Nova Date: Mon, 8 Dec 2025 13:13:37 +0330 Subject: [PATCH] Add xray vless headers --- CMakeLists.txt | 3 + include/configs/common/Outbound.h | 2 + include/configs/common/xrayMultiplex.h | 23 ++++ include/configs/common/xrayStreamSetting.h | 122 +++++++++++++++++++++ include/configs/outbounds/xrayVless.h | 38 +++++++ 5 files changed, 188 insertions(+) create mode 100644 include/configs/common/xrayMultiplex.h create mode 100644 include/configs/common/xrayStreamSetting.h create mode 100644 include/configs/outbounds/xrayVless.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 7907308..8e31392 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -290,6 +290,9 @@ set(PROJECT_SOURCES include/ui/profile/edit_advanced.h src/ui/profile/edit_advanced.cpp include/ui/profile/edit_advanced.ui + include/configs/common/xrayStreamSetting.h + include/configs/outbounds/xrayVless.h + include/configs/common/xrayMultiplex.h ) if (NOT APPLE AND Qt6_VERSION VERSION_GREATER_EQUAL 6.9.0) diff --git a/include/configs/common/Outbound.h b/include/configs/common/Outbound.h index a6231be..d27f64f 100644 --- a/include/configs/common/Outbound.h +++ b/include/configs/common/Outbound.h @@ -78,6 +78,8 @@ namespace Configs return QString("[%1] %2").arg(DisplayType(), DisplayName()); } + virtual bool IsXray() { return false; } + virtual bool HasMux() { return false; } virtual bool HasTransport() { return false; } diff --git a/include/configs/common/xrayMultiplex.h b/include/configs/common/xrayMultiplex.h new file mode 100644 index 0000000..a8c7c10 --- /dev/null +++ b/include/configs/common/xrayMultiplex.h @@ -0,0 +1,23 @@ +#pragma once +#include "include/configs/baseConfig.h" + +namespace Configs { + class xrayMultiplex : public baseConfig { + public: + bool enabled = false; + int concurrency = 0; + int xudpConcurrency = 16; + + xrayMultiplex() { + _add(new configItem("enabled", &enabled, boolean)); + _add(new configItem("concurrency", &concurrency, integer)); + _add(new configItem("xudpConcurrency", &xudpConcurrency, integer)); + } + + bool ParseFromLink(const QString& link) override; + bool ParseFromJson(const QJsonObject& object) override; + QString ExportToLink() override; + QJsonObject ExportToJson() override; + BuildResult Build() override; + }; +} diff --git a/include/configs/common/xrayStreamSetting.h b/include/configs/common/xrayStreamSetting.h new file mode 100644 index 0000000..1bf1359 --- /dev/null +++ b/include/configs/common/xrayStreamSetting.h @@ -0,0 +1,122 @@ +#pragma once +#include "include/configs/baseConfig.h" + +namespace Configs { + inline QStringList XrayNetworks = {"raw", "xhttp"}; + inline QStringList XrayXHTTPModes = {"auto", "packet-up", "stream-up", "stream-one"}; + + class xrayTLS : public baseConfig { + public: + QString serverName; + bool allowInsecure = false; + QStringList alpn; + QString fingerprint; + + xrayTLS() { + _add(new configItem("serverName", &serverName, string)); + _add(new configItem("allowInsecure", &allowInsecure, boolean)); + _add(new configItem("alpn", &alpn, stringList)); + _add(new configItem("fingerprint", &fingerprint, string)); + } + + bool ParseFromLink(const QString& link) override; + bool ParseFromJson(const QJsonObject& object) override; + QString ExportToLink() override; + QJsonObject ExportToJson() override; + BuildResult Build() override; + }; + + class xrayReality : public baseConfig { + public: + QString target; + QString privateKey; + QString fingerprint; + QString serverName; + QString password; + QString shortId; + QString spiderX; + + xrayReality() { + _add(new configItem("target", &target, string)); + _add(new configItem("privateKey", &privateKey, string)); + _add(new configItem("fingerprint", &fingerprint, string)); + _add(new configItem("serverName", &serverName, string)); + _add(new configItem("password", &password, string)); + _add(new configItem("shortId", &shortId, string)); + _add(new configItem("spiderX", &spiderX, string)); + } + + bool ParseFromLink(const QString& link) override; + bool ParseFromJson(const QJsonObject& object) override; + QString ExportToLink() override; + QJsonObject ExportToJson() override; + BuildResult Build() override; + }; + + class xrayXHTTP : public baseConfig { + public: + QString host; + QString path; + QString mode; + // extra + QStringList headers; + QString xPaddingBytes; + bool noGRPCHeader = false; + int scMaxEachPostBytes = 1000000; // packet-up only + int scMinPostsIntervalMs = 30; // packet-up only + // extra/xmux + QString maxConcurrency; + int maxConnections; + int cMaxReuseTimes; + QString hMaxRequestTimes; + QString hMaxReusableSecs; + int hKeepAlivePeriod; + // todo do we need to add downloadsettings or is it useless? + + xrayXHTTP() { + _add(new configItem("host", &host, string)); + _add(new configItem("path", &path, string)); + _add(new configItem("mode", &mode, string)); + _add(new configItem("headers", &headers, stringList)); + _add(new configItem("xPaddingBytes", &xPaddingBytes, string)); + _add(new configItem("noGRPCHeader", &noGRPCHeader, boolean)); + _add(new configItem("scMaxEachPostBytes", &scMaxEachPostBytes, integer)); + _add(new configItem("scMinPostsIntervalMs", &scMinPostsIntervalMs, integer)); + _add(new configItem("maxConcurrency", &maxConcurrency, string)); + _add(new configItem("maxConnections", &maxConnections, integer)); + _add(new configItem("cMaxReuseTimes", &cMaxReuseTimes, integer)); + _add(new configItem("hMaxRequestTimes", &hMaxRequestTimes, string)); + _add(new configItem("hMaxReusableSecs", &hMaxReusableSecs, string)); + _add(new configItem("hKeepAlivePeriod", &hKeepAlivePeriod, integer)); + } + + bool ParseFromLink(const QString& link) override; + bool ParseFromJson(const QJsonObject& object) override; + QString ExportToLink() override; + QJsonObject ExportToJson() override; + BuildResult Build() override; + }; + + class xrayStreamSetting : public baseConfig { + public: + QString network; + QString security; + std::shared_ptr TLS = std::make_shared(); + std::shared_ptr reality = std::make_shared(); + std::shared_ptr xhttp = std::make_shared(); + + xrayStreamSetting() { + _add(new configItem("network", &network, string)); + _add(new configItem("security", &security, string)); + _add(new configItem("tls", dynamic_cast(TLS.get()), jsonStore)); + _add(new configItem("reality", dynamic_cast(reality.get()), jsonStore)); + _add(new configItem("xhttp", dynamic_cast(xhttp.get()), jsonStore)); + } + + bool ParseFromLink(const QString& link) override; + bool ParseFromJson(const QJsonObject& object) override; + QString ExportToLink() override; + QJsonObject ExportToJson() override; + BuildResult Build() override; + }; +} diff --git a/include/configs/outbounds/xrayVless.h b/include/configs/outbounds/xrayVless.h new file mode 100644 index 0000000..8288190 --- /dev/null +++ b/include/configs/outbounds/xrayVless.h @@ -0,0 +1,38 @@ +#pragma once +#include "include/configs/common/Outbound.h" +#include "include/configs/common/xrayMultiplex.h" +#include "include/configs/common/xrayStreamSetting.h" + +namespace Configs { + inline QStringList xrayFlows = {"", "xtls-rprx-vision", "xtls-rprx-vision-udp443"}; + + class xrayVless : public outbound { + public: + QString uuid; + QString encryption = "none"; + QString flow; + std::shared_ptr streamSetting = std::make_shared(); + std::shared_ptr multiplex = std::make_shared(); + + xrayVless() : outbound() { + _add(new configItem("uuid", &uuid, string)); + _add(new configItem("encryption", &encryption, string)); + _add(new configItem("flow", &flow, string)); + _add(new configItem("streamSetting", dynamic_cast(streamSetting.get()), jsonStore)); + _add(new configItem("multiplex", dynamic_cast(multiplex.get()), jsonStore)); + } + + bool ParseFromLink(const QString& link) override; + bool ParseFromJson(const QJsonObject& object) override; + QString ExportToLink() override; + QJsonObject ExportToJson() override; + BuildResult Build() override; + + QString DisplayType() override { + return "VLESS (Xray)"; + } + bool IsXray() override { + return true; + } + }; +}