Add hysteria gui

This commit is contained in:
arm64v8a
2023-04-27 21:00:21 +09:00
parent bc9c5799b1
commit 8b52d46a06
22 changed files with 769 additions and 121 deletions

View File

@@ -31,13 +31,28 @@ namespace NekoRay::fmt {
return 1;
}
int CustomBean::NeedExternal(bool isFirstProfile, bool isVPN) {
if (core == "internal" || core == "internal-full") return 0;
if (core == "hysteria") {
int HysteriaBean::NeedExternal(bool isFirstProfile, bool isVPN) {
if (IS_NEKO_BOX) {
if (protocol == hysteria_protocol_udp && hopPort.trimmed().isEmpty()) {
// sing-box support
return 0;
} else {
// hysteria core support
if (isFirstProfile && !isVPN) {
return 2;
}
return 1;
}
} else {
if (isFirstProfile && !isVPN) {
return 2;
}
return 1;
}
}
int CustomBean::NeedExternal(bool isFirstProfile, bool isVPN) {
if (core == "internal" || core == "internal-full") return 0;
return 1;
}
@@ -64,8 +79,8 @@ namespace NekoRay::fmt {
if (domain_address != connect_address)
result.arguments += "--host-resolver-rules=MAP " + domain_address + " " + connect_address;
if (insecure_concurrency > 0) result.arguments += "--insecure-concurrency=" + Int2String(insecure_concurrency);
if (!extra_headers.isEmpty()) result.arguments += "--extra-headers=" + extra_headers;
if (!certificate.isEmpty()) {
if (!extra_headers.trimmed().isEmpty()) result.arguments += "--extra-headers=" + extra_headers;
if (!certificate.trimmed().isEmpty()) {
WriteTempFile("naive_" + GetRandomString(10) + ".crt", certificate.toUtf8());
result.env += "SSL_CERT_FILE=" + TempFile;
}
@@ -77,6 +92,67 @@ namespace NekoRay::fmt {
return result;
}
ExternalBuildResult HysteriaBean::BuildExternal(int mapping_port, int socks_port, int external_stat) {
ExternalBuildResult result{dataStore->extraCore->Get("hysteria")};
QJsonObject config;
// determine server format
auto is_direct = external_stat == 2;
auto sni2 = sni;
if (sni.isEmpty() && is_direct) sni2 = serverAddress;
auto server = serverAddress;
if (!hopPort.trimmed().isEmpty()) {
server = WrapIPV6Host(server) + ":" + hopPort;
} else {
server = WrapIPV6Host(server) + ":" + Int2String(serverPort);
}
config["server"] = is_direct ? server : "127.0.0.1:" + Int2String(mapping_port);
// listen
config["socks5"] = QJsonObject{
{"listen", "127.0.0.1:" + Int2String(socks_port)},
};
// misc
config["retry"] = 5;
config["fast_open"] = true;
config["lazy_start"] = true;
config["obfs"] = obfsPassword;
config["up_mbps"] = uploadMbps;
config["down_mbps"] = downloadMbps;
if (authPayloadType == hysteria_auth_base64) config["auth"] = authPayload;
if (authPayloadType == hysteria_auth_string) config["auth_str"] = authPayload;
if (protocol == hysteria_protocol_facktcp) config["protocol"] = "faketcp";
if (protocol == hysteria_protocol_wechat_video) config["protocol"] = "wechat-video";
if (!sni2.isEmpty()) config["server_name"] = sni2;
if (!alpn.isEmpty()) config["alpn"] = alpn;
if (!caText.trimmed().isEmpty()) {
WriteTempFile("hysteria_" + GetRandomString(10) + ".crt", caText.toUtf8());
config["ca"] = TempFile;
}
if (allowInsecure) config["insecure"] = true;
if (streamReceiveWindow > 0) config["recv_window_conn"] = streamReceiveWindow;
if (connectionReceiveWindow > 0) config["recv_window"] = connectionReceiveWindow;
if (disableMtuDiscovery) config["disable_mtu_discovery"] = true;
config["hop_interval"] = hopInterval;
//
result.config_export = QJsonObject2QString(config, false);
WriteTempFile("hysteria_" + GetRandomString(10) + ".json", result.config_export.toUtf8());
result.arguments = QStringList{"--no-check", "-c", TempFile};
return result;
}
ExternalBuildResult CustomBean::BuildExternal(int mapping_port, int socks_port, int external_stat) {
ExternalBuildResult result{dataStore->extraCore->Get(core)};
@@ -107,14 +183,6 @@ namespace NekoRay::fmt {
suffix = ".json";
}
// known core direct out
if (external_stat == 2) {
if (core == "hysteria") {
config = config.replace(QString("\"127.0.0.1:%1\"").arg(mapping_port),
"\"" + DisplayAddress() + "\"");
}
}
// write config
WriteTempFile("custom_" + GetRandomString(10) + suffix, config.toUtf8());
for (int i = 0; i < result.arguments.count(); i++) {