Skip to content

Commit

Permalink
Add basic support for VMess h2 & grpc protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
tindy2013 committed Jul 28, 2021
1 parent 3ad1c00 commit 867602f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/generator/config/subexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,17 @@ void proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const string_
if(x.Edge.size())
singleproxy["http-opts"]["headers"]["Edge"].push_back(x.Edge);
break;
case "h2"_hash:
singleproxy["network"] = x.TransferProtocol;
singleproxy["h2-opts"]["path"] = x.Path;
if(x.Host.size())
singleproxy["h2-opts"]["host"].push_back(x.Host);
break;
case "grpc"_hash:
singleproxy["network"] = x.TransferProtocol;
singleproxy["servername"] = x.Host;
singleproxy["grpc-opts"]["grpc-service-name"] = x.Path;
break;
default:
continue;
}
Expand Down
19 changes: 15 additions & 4 deletions src/parser/subparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -960,17 +960,28 @@ void explodeClash(Node yamlnode, std::vector<Proxy> &nodes)
singleproxy["alterId"] >>= aid;
singleproxy["cipher"] >>= cipher;
net = singleproxy["network"].IsDefined() ? safe_as<std::string>(singleproxy["network"]) : "tcp";
if(net == "http")
switch(hash_(net))
{
case "http"_hash:
singleproxy["http-opts"]["path"][0] >>= path;
singleproxy["http-opts"]["headers"]["Host"][0] >>= host;
edge.clear();
}
else
{
break;
case "ws"_hash:
path = singleproxy["ws-path"].IsDefined() ? safe_as<std::string>(singleproxy["ws-path"]) : "/";
singleproxy["ws-headers"]["Host"] >>= host;
singleproxy["ws-headers"]["Edge"] >>= edge;
break;
case "h2"_hash:
singleproxy["h2-opts"]["path"] >>= path;
singleproxy["h2-opts"]["host"][0] >>= host;
edge.clear();
break;
case "grpc"_hash:
singleproxy["servername"] >>= host;
singleproxy["grpc-opts"]["grpc-service-name"] >>= path;
edge.clear();
break;
}
tls = safe_as<std::string>(singleproxy["tls"]) == "true" ? "tls" : "";

Expand Down

0 comments on commit 867602f

Please sign in to comment.