Skip to content

Commit

Permalink
support http/2 for vmess
Browse files Browse the repository at this point in the history
  • Loading branch information
cocomeow committed Dec 8, 2021
1 parent d232c60 commit 72a302c
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 27 deletions.
34 changes: 17 additions & 17 deletions i18n/across_zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1225,55 +1225,55 @@
<context>
<name>across::GroupList</name>
<message>
<location filename="../src/view_models/grouplist.cpp" line="408"/>
<location filename="../src/view_models/grouplist.cpp" line="412"/>
<location filename="../src/view_models/grouplist.cpp" line="429"/>
<location filename="../src/view_models/grouplist.cpp" line="433"/>
<location filename="../../../ACross/src/view_models/grouplist.cpp" line="408"/>
<location filename="../../../ACross/src/view_models/grouplist.cpp" line="412"/>
<location filename="../../../ACross/src/view_models/grouplist.cpp" line="429"/>
<location filename="../../../ACross/src/view_models/grouplist.cpp" line="433"/>
<source>Copy [%1] URL to clipboard</source>
<translation>复制 [%1] 链接到剪贴板</translation>
</message>
</context>
<context>
<name>across::NodeFormModel</name>
<message>
<location filename="../src/view_models/nodeformmodel.cpp" line="446"/>
<location filename="../../../ACross/src/view_models/nodeformmodel.cpp" line="462"/>
<source>custom configuration encoding to url is not supported</source>
<translation>未支持自定义配置编码到链接格式</translation>
</message>
</context>
<context>
<name>across::NodeList</name>
<message>
<location filename="../src/view_models/nodelist.cpp" line="344"/>
<location filename="../../../ACross/src/view_models/nodelist.cpp" line="344"/>
<source>Copy [%1] URL to clipboard</source>
<translation>复制 [%1] 链接到剪贴板</translation>
</message>
</context>
<context>
<name>across::SystemTray</name>
<message>
<location filename="../src/view_models/systemtray.cpp" line="149"/>
<location filename="../src/view_models/systemtray.cpp" line="169"/>
<location filename="../../../ACross/src/view_models/systemtray.cpp" line="149"/>
<location filename="../../../ACross/src/view_models/systemtray.cpp" line="169"/>
<source>Show</source>
<translation>显示</translation>
</message>
<message>
<location filename="../src/view_models/systemtray.cpp" line="170"/>
<location filename="../../../ACross/src/view_models/systemtray.cpp" line="170"/>
<source>Connect</source>
<translation>连接</translation>
</message>
<message>
<location filename="../src/view_models/systemtray.cpp" line="171"/>
<location filename="../../../ACross/src/view_models/systemtray.cpp" line="171"/>
<source>Disconnect</source>
<translation>断开</translation>
</message>
<message>
<location filename="../src/view_models/systemtray.cpp" line="172"/>
<location filename="../../../ACross/src/view_models/systemtray.cpp" line="172"/>
<source>Reconnect</source>
<translation>重连</translation>
</message>
<message>
<location filename="../src/view_models/systemtray.cpp" line="173"/>
<location filename="../../../ACross/src/view_models/systemtray.cpp" line="173"/>
<source>Quit</source>
<translation>退出</translation>
</message>
Expand All @@ -1282,25 +1282,25 @@
<translation type="vanished">入站</translation>
</message>
<message>
<location filename="../src/view_models/systemtray.cpp" line="151"/>
<location filename="../../../ACross/src/view_models/systemtray.cpp" line="151"/>
<source>Hide</source>
<translation>隐藏</translation>
</message>
<message>
<location filename="../src/view_models/systemtray.cpp" line="181"/>
<location filename="../../../ACross/src/view_models/systemtray.cpp" line="181"/>
<source>OFF</source>
<translation>关闭</translation>
</message>
</context>
<context>
<name>across::setting::ConfigTools</name>
<message>
<location filename="../src/view_models/configtools.cpp" line="1054"/>
<location filename="../../../ACross/src/view_models/configtools.cpp" line="1054"/>
<source>Failed to parse version</source>
<translation>无法解析版本</translation>
</message>
<message>
<location filename="../src/view_models/configtools.cpp" line="1057"/>
<location filename="../../../ACross/src/view_models/configtools.cpp" line="1057"/>
<source>New Version: v%1</source>
<translation>新版本:v%1</translation>
</message>
Expand All @@ -1309,7 +1309,7 @@
<translation type="vanished">新版本:%1</translation>
</message>
<message>
<location filename="../src/view_models/configtools.cpp" line="1059"/>
<location filename="../../../ACross/src/view_models/configtools.cpp" line="1059"/>
<source>Already the latest version</source>
<translation>已经是最新版本</translation>
</message>
Expand Down
44 changes: 43 additions & 1 deletion src/models/serializetools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,35 @@ SerializeTools::vmessBase64Decode(const std::string &url_str) {

do {
if (stream->network() == "tcp") {
// TODO: get tcpsetting
// TODO: fake header support
// auto tcp = stream->mutable_tcpsettings();

// if (root.contains("type")) {
// auto header = tcp->mutable_header();
// header->set_type(root["type"].get<std::string>());
// }
break;
}

if (stream->network() == "h2") {
auto http2 = stream->mutable_httpsettings();

if (root.contains("host")) {
auto content =
QString::fromStdString(root["host"].get<std::string>())
.trimmed()
.split(",");
for (const auto &host : content) {
if (!host.isEmpty())
http2->add_host(host.trimmed().toStdString());
}
}

if (root.contains("path")) {
http2->set_path(root["path"].get<std::string>());
}
}

if (stream->network() == "ws") {
auto websocket = stream->mutable_wssettings();

Expand Down Expand Up @@ -418,6 +443,23 @@ SerializeTools::vmessBase64Encode(const URLMetaObject &meta) {
root["net"] = stream.network();

do {
if (stream.network() == "h2" && stream.has_httpsettings()) {
const auto &http2 = stream.httpsettings();
std::string hosts;

for (const auto &host : stream.httpsettings().host()) {
if (!host.empty()) {
hosts.append(host);
hosts.append(",");
}
}

hosts = hosts.substr(0, hosts.length() - 1);
root["host"] = hosts;
root["path"] = http2.path();
break;
}

if (stream.network() == "ws" && stream.has_wssettings()) {
const auto& websocket = stream.wssettings();
root["host"] = websocket.headers().at("Host");
Expand Down
16 changes: 16 additions & 0 deletions src/view_models/nodeformmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,22 @@ bool NodeFormModel::setVMessOutboud(NodeInfo &node, const QVariantMap &values) {
}

do {
if (stream->network() == "h2") {
auto http2 = stream->mutable_httpsettings();

if (values.contains("host")) {
for (const auto &host :
values.value("host").toString().trimmed().split(",")) {
http2->add_host(host.toStdString());
}
}

if (values.contains("path")) {
http2->set_path(values.value("path").toString().toStdString());
}
break;
}

if (stream->network() == "ws") {
auto websocket = stream->mutable_wssettings();

Expand Down
2 changes: 1 addition & 1 deletion src/views/home/VMESSSetting.qml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Item {
id: networkSelect
Layout.fillWidth: true
Layout.columnSpan: 3
model: ["tcp", "ws", "grpc", "quic"]
model: ["none", "h2", "ws", "grpc", "quic"]

onCurrentIndexChanged: HomeJS.networkSelectToggle(currentIndex, {
"typeLabel": typeLabel,
Expand Down
84 changes: 84 additions & 0 deletions src/views/routing/RulePanel.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

import ACross

CardBox {
id: control
implicitWidth: 240
implicitHeight: 720

property string title: "Direct"
property bool isEdited: false

GridLayout {
anchors.fill: parent
anchors.margins: acrossConfig.itemSpacing * 4
columns: 4

Label {
text: control.title
font.pointSize: fontSize
color: acrossConfig.textColor
}

Item {
Layout.fillWidth: true
Layout.preferredHeight: 22
Layout.columnSpan: 3

RowLayout {
anchors.fill: parent

Item {
Layout.fillWidth: true
}

SVGBox {
source: "qrc:/misc/icons/" + acrossConfig.iconStyle + "/trash.svg"
sourceHeight: 24
sourceWidth: 24
}

SVGBox {
source: "qrc:/misc/icons/" + acrossConfig.iconStyle + "/edit.svg"
sourceHeight: 24
sourceWidth: 24

MouseArea {
anchors.fill: parent

onClicked: {
control.isEdited = !control.isEdited
}
}
}
}
}

ListView {
id: directRuleList
Layout.fillWidth: true
Layout.columnSpan: 4
Layout.fillHeight: true
clip: true

model: ["baidu.com", "qq.com", "geosite:cn", "ext:customizedGeoSiteFile.dat:cn", "0.0.0.0/8", "10.0.0.0/8", "fc00::/7", "fe80::/10", "geoip:cn", "geoip:!cn", "ext:customizedGeoIPFile.dat:cn", "ext:customizedGeoIPFile.dat:!cn", "ext-ip:customizedGeoIPFile.dat:cn", "ext-ip:customizedGeoIPFile.dat:!cn"]
delegate: RuleItemCard {
state: control.isEdited ? "EditState" : "NormalState"
width: directRuleList.width
}
}

// SVGBox {
// source: "qrc:/misc/icons/" + acrossConfig.iconStyle + "/add.svg"
// sourceHeight: 24
// sourceWidth: 24
// }
TextFieldBox {
Layout.fillWidth: true
Layout.columnSpan: 4
}
}
}
31 changes: 27 additions & 4 deletions src/views/typescripts/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,30 @@ function networkSelectToggle(currentIndex, components, control = null) {
let quicSecuritySelect = components["quicSecuritySelect"];
hideAllTypeSetting([hostLabel, hostText, pathLabel, pathText, typeLabel, typeSelect, quicSecurityLabel, quicSecuritySelect]);
switch (currentIndex) {
case 0: // tcp
case 0: // none
break;
case 1: // ws
case 1:
hostLabel.visible = true;
hostLabel.text = "Host";
hostText.visible = true;
pathLabel.visible = true;
pathLabel.text = "Path";
pathText.visible = true;
break;
case 2: // ws
hostLabel.visible = true;
hostLabel.text = "Host";
hostText.visible = true;
pathLabel.visible = true;
pathLabel.text = "Path";
pathText.visible = true;
break;
case 2: // grpc
case 3: // grpc
pathLabel.visible = true;
pathLabel.text = "Service Name";
pathText.visible = true;
break;
case 3: // quic
case 4: // quic
typeLabel.visible = true;
typeSelect.visible = true;
quicSecurityLabel.visible = true;
Expand Down Expand Up @@ -99,6 +107,21 @@ function visibleChangeToggle(visible, components, model = null) {
let network = streamSettings["network"];
networkSelect.currentIndex = networkSelect.find(network);
switch (network) {
case "h2":
if (streamSettings.hasOwnProperty("httpSettings")) {
let httpSettings = streamSettings["httpSettings"];
if (httpSettings.hasOwnProperty("host") && hostText !== null) {
let hosts = "";
for (const host of httpSettings["host"]) {
hosts = hosts.concat(host, ",");
}
hostText.text = hosts.substring(0, hosts.length - 1).trim();
}
if (httpSettings.hasOwnProperty("path") && pathText !== null) {
pathText.text = httpSettings["path"];
}
}
break;
case "ws":
if (streamSettings.hasOwnProperty("wsSettings")) {
let wsSettings = streamSettings["wsSettings"];
Expand Down
Loading

0 comments on commit 72a302c

Please sign in to comment.