Skip to content

Commit

Permalink
Merge pull request #3 from fengluo2/master
Browse files Browse the repository at this point in the history
hysteria2 add ports parameter
  • Loading branch information
lonelam authored Oct 9, 2024
2 parents 7bbe8b9 + fe956e8 commit c3eef3e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/generator/config/subexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,8 @@ void proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGr
break;
case ProxyType::Hysteria2:
singleproxy["type"] = "hysteria2";
if (!x.Ports.empty())
singleproxy["ports"] = x.Ports;
if (!x.Up.empty())
singleproxy["up"] = x.UpSpeed;
if (!x.Down.empty())
Expand Down
31 changes: 27 additions & 4 deletions src/parser/subparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,29 @@ void hysteriaConstruct(
}
}

void hysteria2Construct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &server, const std::string &port,const std::string &up, const std::string &down, const std::string &password, const std::string &obfs, const std::string &obfs_password, const std::string &sni, const std::string &fingerprint, const std::string &alpn, const std::string &ca, const std::string &ca_str, const std::string &cwnd, tribool tfo, tribool scv) {
void hysteria2Construct(
Proxy &node,
const std::string &group,
const std::string &remarks,
const std::string &server,
const std::string &port,
const std::string &ports,
const std::string &up,
const std::string &down,
const std::string &password,
const std::string &obfs,
const std::string &obfs_password,
const std::string &sni,
const std::string &fingerprint,
const std::string &alpn,
const std::string &ca,
const std::string &ca_str,
const std::string &cwnd,
tribool tfo,
tribool scv
) {
commonConstruct(node, ProxyType::Hysteria2, group, remarks, server, port, tribool(), tfo, scv, tribool());
node.Ports = ports;
node.UpSpeed = to_int(up);
node.DownSpeed = to_int(down);
node.Password = password;
Expand Down Expand Up @@ -1320,6 +1341,7 @@ void explodeClash(Node yamlnode, std::vector<Proxy> &nodes)
break;
case "hysteria2"_hash:
group = HYSTERIA2_DEFAULT_GROUP;
singleproxy["ports"] >>= ports;
singleproxy["up"] >>= up;
singleproxy["down"] >>= down;
singleproxy["password"] >>= password;
Expand All @@ -1337,7 +1359,7 @@ void explodeClash(Node yamlnode, std::vector<Proxy> &nodes)
singleproxy["ca-str"] >>= ca_str;
singleproxy["cwnd"] >>= cwnd;

hysteria2Construct(node, group, ps, server, port, up, down, password, obfs, obfs_password, sni, fingerprint, alpn, ca, ca_str, cwnd, tfo, scv );
hysteria2Construct(node, group, ps, server, port, ports, up, down, password, obfs, obfs_password, sni, fingerprint, alpn, ca, ca_str, cwnd, tfo, scv );
break;

default:
Expand Down Expand Up @@ -1477,7 +1499,7 @@ void explodeKitsunebi(std::string kit, Proxy &node)


void explodeStdHysteria2(std::string hysteria2, Proxy &node) {
std::string add, port, password, host, insecure, up, down, alpn, obfs, obfs_password, remarks, sni, fingerprint;
std::string add, port, ports, password, host, insecure, up, down, alpn, obfs, obfs_password, remarks, sni, fingerprint;
std::string addition;
tribool scv;
hysteria2 = hysteria2.substr(12);
Expand Down Expand Up @@ -1511,6 +1533,7 @@ void explodeStdHysteria2(std::string hysteria2, Proxy &node) {
}

scv = getUrlArg(addition, "insecure");
ports = getUrlArg(addition, "ports");
up = getUrlArg(addition, "up");
down = getUrlArg(addition, "down");
// the alpn is not supported officially yet
Expand All @@ -1522,7 +1545,7 @@ void explodeStdHysteria2(std::string hysteria2, Proxy &node) {
if (remarks.empty())
remarks = add + ":" + port;

hysteria2Construct(node, HYSTERIA2_DEFAULT_GROUP, remarks, add, port, up, down, password, obfs, obfs_password, sni, fingerprint, "", "", "", "", tribool(), scv);
hysteria2Construct(node, HYSTERIA2_DEFAULT_GROUP, remarks, add, port, ports, up, down, password, obfs, obfs_password, sni, fingerprint, "", "", "", "", tribool(), scv);
return;
}

Expand Down
22 changes: 21 additions & 1 deletion src/parser/subparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,27 @@ void hysteriaConstruct(
tribool scv
);

void hysteria2Construct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &server, const std::string &port,const std::string &up, const std::string &down, const std::string &password, const std::string &obfs, const std::string &obfs_password, const std::string &sni, const std::string &fingerprint, const string_array &alpn, const std::string &ca, const std::string &caStr, const std::string &cwnd, tribool tfo, tribool scv);
void hysteria2Construct(
Proxy &node,
const std::string &group,
const std::string &remarks,
const std::string &server,
const std::string &port,
const std::string &ports,
const std::string &up,
const std::string &down,
const std::string &password,
const std::string &obfs,
const std::string &obfs_password,
const std::string &sni,
const std::string &fingerprint,
const string_array &alpn,
const std::string &ca,
const std::string &caStr,
const std::string &cwnd,
tribool tfo,
tribool scv
);

void explodeVmess(std::string vmess, Proxy &node);
void explodeSSR(std::string ssr, Proxy &node);
Expand Down

0 comments on commit c3eef3e

Please sign in to comment.