From e6fc84e97baf31936144831d709398180e17ed43 Mon Sep 17 00:00:00 2001 From: 2022-blake3-chacha12-poly1305 <139959885+xchacha20-ietf-poly1305@users.noreply.github.com> Date: Fri, 11 Aug 2023 10:19:15 +0800 Subject: [PATCH] feat: add sharelink for TUIC --- fmt/Bean2Link.cpp | 17 ++++++++++++++++- fmt/Link2Bean.cpp | 26 +++++++++++++++++++++----- sub/GroupUpdater.cpp | 8 ++++++++ 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/fmt/Bean2Link.cpp b/fmt/Bean2Link.cpp index 848ecd3..bae0295 100644 --- a/fmt/Bean2Link.cpp +++ b/fmt/Bean2Link.cpp @@ -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); } diff --git a/fmt/Link2Bean.cpp b/fmt/Link2Bean.cpp index 443d943..5dd0039 100644 --- a/fmt/Link2Bean.cpp +++ b/fmt/Link2Bean.cpp @@ -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,12 +253,28 @@ 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; } -} // namespace NekoGui_fmt +} // namespace NekoGui_fmt \ No newline at end of file diff --git a/sub/GroupUpdater.cpp b/sub/GroupUpdater.cpp index 1f5db61..9ca0279 100644 --- a/sub/GroupUpdater.cpp +++ b/sub/GroupUpdater.cpp @@ -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