Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add underlying-proxy, smart policy group support for surge and renaming surge wireguard section #747

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ subconverter.exe
cmake-build-debug
.idea
base/cache
build
13 changes: 13 additions & 0 deletions src/config/binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ namespace toml
case "ssid"_hash:
conf.Type = ProxyGroupType::SSID;
break;
case "smart"_hash:
conf.Type = ProxyGroupType::Smart;
conf.Url = toml::find<String>(v, "url");
conf.Interval = toml::find<Integer>(v, "interval");
conf.Tolerance = toml::find_or<Integer>(v, "tolerance", 0);
if(v.contains("lazy"))
conf.Lazy = toml::find_or<bool>(v, "lazy", false);
if(v.contains("evaluate-before-use"))
conf.EvaluateBeforeUse = toml::find_or(v, "evaluate-before-use", conf.EvaluateBeforeUse.get());
break;
default:
throw toml::syntax_error("Proxy Group has incorrect type, should be one of following:\n select, url-test, load-balance, fallback, relay, ssid", v.at("type").location());
}
Expand Down Expand Up @@ -220,6 +230,9 @@ namespace INIBinding
case "ssid"_hash:
conf.Type = ProxyGroupType::SSID;
break;
case "smart"_hash:
conf.Type = ProxyGroupType::Smart;
break;
default:
continue;
}
Expand Down
4 changes: 3 additions & 1 deletion src/config/proxygroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ enum class ProxyGroupType
Fallback,
LoadBalance,
Relay,
SSID
SSID,
Smart
};

enum class BalanceStrategy
Expand Down Expand Up @@ -45,6 +46,7 @@ struct ProxyGroupConfig
case ProxyGroupType::Fallback: return "fallback";
case ProxyGroupType::Relay: return "relay";
case ProxyGroupType::SSID: return "ssid";
case ProxyGroupType::Smart: return "smart";
}
return "";
}
Expand Down
22 changes: 17 additions & 5 deletions src/generator/config/subexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,10 @@ void proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGr
string_array filtered_nodelist;

singlegroup["name"] = x.Name;
singlegroup["type"] = x.TypeStr();
if (x.Type == ProxyGroupType::Smart)
singlegroup["type"] = "url-test";
else
singlegroup["type"] = x.TypeStr();

switch(x.Type)
{
Expand All @@ -528,6 +531,8 @@ void proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGr
case ProxyGroupType::LoadBalance:
singlegroup["strategy"] = x.StrategyStr();
[[fallthrough]];
case ProxyGroupType::Smart:
[[fallthrough]];
case ProxyGroupType::URLTest:
if(!x.Lazy.is_undef())
singlegroup["lazy"] = x.Lazy.get();
Expand Down Expand Up @@ -691,7 +696,7 @@ std::string proxyToSurge(std::vector<Proxy> &nodes, const std::string &base_conf

processRemark(x.Remark, remarks_list);

std::string &hostname = x.Hostname, &username = x.Username, &password = x.Password, &method = x.EncryptMethod, &id = x.UserId, &transproto = x.TransferProtocol, &host = x.Host, &edge = x.Edge, &path = x.Path, &protocol = x.Protocol, &protoparam = x.ProtocolParam, &obfs = x.OBFS, &obfsparam = x.OBFSParam, &plugin = x.Plugin, &pluginopts = x.PluginOption;
std::string &hostname = x.Hostname, &username = x.Username, &password = x.Password, &method = x.EncryptMethod, &id = x.UserId, &transproto = x.TransferProtocol, &host = x.Host, &edge = x.Edge, &path = x.Path, &protocol = x.Protocol, &protoparam = x.ProtocolParam, &obfs = x.OBFS, &obfsparam = x.OBFSParam, &plugin = x.Plugin, &pluginopts = x.PluginOption, &underlying_proxy = x.UnderlyingProxy;
std::string port = std::to_string(x.Port);
bool &tlssecure = x.TLSSecure;

Expand All @@ -704,7 +709,9 @@ std::string proxyToSurge(std::vector<Proxy> &nodes, const std::string &base_conf
std::string proxy, section, real_section;
string_array args, headers;

switch(x.Type)
std::stringstream ss;

switch (x.Type)
{
case ProxyType::Shadowsocks:
if(surge_ver >= 3 || surge_ver == -3)
Expand Down Expand Up @@ -833,7 +840,8 @@ std::string proxyToSurge(std::vector<Proxy> &nodes, const std::string &base_conf
case ProxyType::WireGuard:
if(surge_ver < 4 && surge_ver != -3)
continue;
section = randomStr(5);
ss << std::hex << hash_(x.Remark);
section = ss.str().substr(0, 5);
real_section = "WireGuard " + section;
proxy = "wireguard, section-name=" + section;
if(!x.TestUrl.empty())
Expand Down Expand Up @@ -861,7 +869,10 @@ std::string proxyToSurge(std::vector<Proxy> &nodes, const std::string &base_conf
if(!udp.is_undef())
proxy += ", udp-relay=" + udp.get_str();

if(ext.nodelist)
if (underlying_proxy != "")
proxy += ", underlying-proxy=" + underlying_proxy;

if (ext.nodelist)
output_nodelist += x.Remark + " = " + proxy + "\n";
else
{
Expand All @@ -884,6 +895,7 @@ std::string proxyToSurge(std::vector<Proxy> &nodes, const std::string &base_conf
switch(x.Type)
{
case ProxyGroupType::Select:
case ProxyGroupType::Smart:
case ProxyGroupType::URLTest:
case ProxyGroupType::Fallback:
break;
Expand Down
2 changes: 2 additions & 0 deletions src/parser/config/proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ struct Proxy
tribool AllowInsecure;
tribool TLS13;

String UnderlyingProxy;

uint16_t SnellVersion = 0;
String ServerName;

Expand Down