feat: add sharelink for TUIC

This commit is contained in:
2022-blake3-chacha12-poly1305
2023-08-11 10:19:15 +08:00
committed by HystericalDragon
parent 1c6fe29ea6
commit e6fc84e97b
3 changed files with 45 additions and 6 deletions

View File

@@ -198,8 +198,23 @@ namespace NekoGui_fmt {
if (streamReceiveWindow > 0) q.addQueryItem("recv_window_conn", Int2String(streamReceiveWindow));
if (!q.isEmpty()) url.setQuery(q);
if (!name.isEmpty()) url.setFragment(name);
} else if (proxy_type == proxy_TUIC) {
// TODO std link
url.setScheme("tuic");
url.setUserName(uuid);
url.setPassword(password);
url.setHost(serverAddress);
url.setPort(serverPort);
QUrlQuery q;
if (!congestionControl.isEmpty()) q.addQueryItem("congestion_control", congestionControl);
if (!alpn.isEmpty()) q.addQueryItem("alpn", alpn);
if (!sni.isEmpty()) q.addQueryItem("sni", sni);
if (!udpRelayMode.isEmpty()) q.addQueryItem("udp_relay_mode", udpRelayMode);
if (allowInsecure) q.addQueryItem("allow_insecure", "1");
if (disableSni) q.addQueryItem("disable_sni", "1");
if (!q.isEmpty()) url.setQuery(q);
if (!name.isEmpty()) url.setFragment(name);
}
return url.toString(QUrl::FullyEncoded);
}

View File

@@ -218,12 +218,12 @@ namespace NekoGui_fmt {
}
bool QUICBean::TryParseLink(const QString &link) {
// https://hysteria.network/docs/uri-scheme/
auto url = QUrl(link);
auto query = QUrlQuery(url.query());
if (url.host().isEmpty() || url.port() == -1) return false;
if (url.scheme() == "hysteria") {
// https://hysteria.network/docs/uri-scheme/
if (!query.hasQueryItem("upmbps") || !query.hasQueryItem("downmbps")) return false;
name = url.fragment();
@@ -253,9 +253,25 @@ namespace NekoGui_fmt {
connectionReceiveWindow = query.queryItemValue("recv_window").toInt();
streamReceiveWindow = query.queryItemValue("recv_window_conn").toInt();
} else {
// TODO TUIC std link
return false;
} else if (url.scheme() == "tuic") {
// by daeuniverse
// https://github.com/daeuniverse/dae/discussions/182
name = url.fragment();
serverAddress = url.host();
if (serverPort == -1) serverPort = 443;
serverPort = url.port();
uuid = url.userName();
password = url.password();
congestionControl = query.queryItemValue("congestion_control");
alpn = query.queryItemValue("alpn");
sni = query.queryItemValue("sni");
udpRelayMode = query.queryItemValue("udp_relay_mode");
allowInsecure = query.queryItemValue("allow_insecure") == "1";
disableSni = query.queryItemValue("disable_sni") == "1";
}
return true;

View File

@@ -133,6 +133,14 @@ namespace NekoGui_sub {
if (!ok) return;
}
// TUIC
if (str.startsWith("tuic://")) {
needFix = false;
ent = NekoGui::ProfileManager::NewProxyEntity("tuic");
auto ok = ent->QUICBean()->TryParseLink(str);
if (!ok) return;
}
if (ent == nullptr) return;
// Fix