feat: support hysteria

This commit is contained in:
metacubex 2022-12-08 23:00:12 +08:00
parent e66093c868
commit 1f08e15f05
4 changed files with 85 additions and 0 deletions

View File

@ -340,6 +340,24 @@ void proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGr
continue;
}
break;
case ProxyType::Hysteria:
singleproxy["type"] = "hysteria";
singleproxy["auth_str"] = x.Auth;
singleproxy["up"] = x.UpMbps;
singleproxy["down"] = x.DownMbps;
if(!x.FakeType.empty())
singleproxy["protocol"] = x.Type;
if(!x.Host.empty())
singleproxy["sni"] = x.Host;
if(!scv.is_undef())
singleproxy["skip-cert-verify"] = scv.get();
if(x.Insecure == "1")
singleproxy["skip-cert-verify"] = true;
if(!x.Alpn.empty())
singleproxy["apln"].push_back(x.Alpn);
if(!x.OBFSParam.empty())
singleproxy["obfs"] = x.OBFSParam;
break;
case ProxyType::Vless:
singleproxy["type"] = "vless";
singleproxy["uuid"] = x.UserId;

View File

@ -14,6 +14,7 @@ enum ProxyType
ShadowsocksR,
VMess,
Vless,
Hysteria,
Trojan,
Snell,
HTTP,
@ -92,12 +93,19 @@ struct Proxy
uint16_t SnellVersion = 0;
String ServerName;
String Auth;
String Alpn;
String UpMbps;
String DownMbps;
String Insecure;
};
#define SS_DEFAULT_GROUP "SSProvider"
#define SSR_DEFAULT_GROUP "SSRProvider"
#define V2RAY_DEFAULT_GROUP "V2RayProvider"
#define XRAY_DEFAULT_GROUP "XRayProvider"
#define HYSTERIA_DEFAULT_GROUP "HysteriaProvider"
#define SOCKS_DEFAULT_GROUP "SocksProvider"
#define HTTP_DEFAULT_GROUP "HTTPProvider"
#define TROJAN_DEFAULT_GROUP "TrojanProvider"

View File

@ -66,6 +66,19 @@ void vmessConstruct(Proxy &node, const std::string &group, const std::string &re
}
}
void hysteriaConstruct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &add, const std::string &port, const std::string &type, const std::string &auth, const std::string &host, const std::string &up, const std::string &down, const std::string &alpn, const std::string &obfsParam, const std::string &insecure ,tribool udp, tribool tfo, tribool scv, tribool tls13)
{
commonConstruct(node, ProxyType::Hysteria, group, remarks, add, port, udp, tfo, scv, tls13);
node.Auth = auth;
node.Host = (host.empty() && !isIPv4(add) && !isIPv6(add)) ? add.data() : trim(host);
node.UpMbps = up;
node.DownMbps = down;
node.Alpn = alpn;
node.OBFSParam = obfsParam;
node.Insecure = insecure;
node.FakeType = type;
}
void vlessConstruct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &add, const std::string &port, const std::string &type, const std::string &id, const std::string &aid, const std::string &net, const std::string &cipher, const std::string &flow, const std::string &mode, const std::string &path, const std::string &host, const std::string &edge, const std::string &tls, tribool udp, tribool tfo, tribool scv, tribool tls13)
{
commonConstruct(node, ProxyType::Vless, group, remarks, add, port, udp, tfo, scv, tls13);
@ -162,6 +175,15 @@ void explodeVless(std::string vless, Proxy &node)
}
}
void explodeHysteria(std::string hysteria, Proxy &node)
{
if(regMatch(hysteria, "hysteria://(.*?)[:](.*)"))
{
explodeStdHysteria(hysteria, node);
return;
}
}
void explodeVmess(std::string vmess, Proxy &node)
{
std::string version, ps, add, port, type, id, aid, net, path, host, tls, sni, alpn;
@ -1262,6 +1284,38 @@ void explodeStdVMess(std::string vmess, Proxy &node)
return;
}
void explodeStdHysteria(std::string hysteria, Proxy &node)
{
std::string add, port, type, auth, host, insecure, up, down, alpn, obfsParam, remarks;
std::string addition;
hysteria = hysteria.substr(11);
string_size pos;
pos = hysteria.rfind("#");
if(pos != hysteria.npos)
{
remarks = urlDecode(hysteria.substr(pos + 1));
hysteria.erase(pos);
}
const std::string stdhysteria_matcher = R"(^(.*)[:](\d+)[?](.*)$)";
if(regGetMatch(hysteria, stdhysteria_matcher, 4, 0, &add, &port, &addition))
return;
type = getUrlArg(addition,"protocol");
auth = getUrlArg(addition,"auth");
host = getUrlArg(addition,"peer");
insecure = getUrlArg(addition, "insecure");
up = getUrlArg(addition,"upmbps");
down = getUrlArg(addition,"downmbps");
alpn = getUrlArg(addition,"alpn");
obfsParam = getUrlArg(addition,"obfsParam");
if(remarks.empty())
remarks = add + ":" + port;
hysteriaConstruct(node, HYSTERIA_DEFAULT_GROUP, remarks, add, port, type, auth, host, up, down, alpn, obfsParam, insecure);
return;
}
void explodeStdVless(std::string vless, Proxy &node)
{
std::string add, port, type, id, aid, net, flow, mode, path, host, tls, remarks;
@ -2188,6 +2242,8 @@ void explode(const std::string &link, Proxy &node)
explodeVmess(link, node);
else if(strFind(link, "vless://") || strFind(link, "vless1://"))
explodeVless(link, node);
else if(strFind(link, "hysteria://"))
explodeHysteria(link, node);
else if(strFind(link, "ss://"))
explodeSS(link, node);
else if(strFind(link, "socks://") || strFind(link, "https://t.me/socks") || strFind(link, "tg://socks"))

View File

@ -20,6 +20,7 @@ enum class ConfType
Local
};
void hysteriaConstruct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &add, const std::string &port, const std::string &type, const std::string &auth, const std::string &host, const std::string &up, const std::string &down, const std::string &alpn, const std::string &obfsParam, const std::string &insecure ,tribool udp = tribool(), tribool tfo = tribool(), tribool scv = tribool(), tribool tls13 = tribool());
void vmessConstruct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &add, const std::string &port, const std::string &type, const std::string &id, const std::string &aid, const std::string &net, const std::string &cipher, const std::string &path, const std::string &host, const std::string &edge, const std::string &tls, const std::string &sni, const std::string &alpn, tribool udp = tribool(), tribool tfo = tribool(), tribool scv = tribool(), tribool tls13 = tribool());
void vlessConstruct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &add, const std::string &port, const std::string &type, const std::string &id, const std::string &aid, const std::string &net, const std::string &cipher, const std::string &flow, const std::string &mode, const std::string &path, const std::string &host, const std::string &edge, const std::string &tls, tribool udp = tribool(), tribool tfo = tribool(), tribool scv = tribool(), tribool tls13 = tribool());
void ssrConstruct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &server, const std::string &port, const std::string &protocol, const std::string &method, const std::string &obfs, const std::string &password, const std::string &obfsparam, const std::string &protoparam, tribool udp = tribool(), tribool tfo = tribool(), tribool scv = tribool());
@ -30,12 +31,14 @@ void trojanConstruct(Proxy &node, const std::string &group, const std::string &r
void snellConstruct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &server, const std::string &port, const std::string &password, const std::string &obfs, const std::string &host, uint16_t version = 0, tribool udp = tribool(), tribool tfo = tribool(), tribool scv = tribool());
void explodeVmess(std::string vmess, Proxy &node);
void explodeVless(std::string vless, Proxy &node);
void explodeHysteria(std::string hysteria, Proxy &node);
void explodeSSR(std::string ssr, Proxy &node);
void explodeSS(std::string ss, Proxy &node);
void explodeTrojan(std::string trojan, Proxy &node);
void explodeQuan(const std::string &quan, Proxy &node);
void explodeStdVMess(std::string vmess, Proxy &node);
void explodeStdVless(std::string vless, Proxy &node);
void explodeStdHysteria(std::string hysteria, Proxy &node);
void explodeShadowrocket(std::string kit, Proxy &node);
void explodeKitsunebi(std::string kit, Proxy &node);
/// Parse a link