Enhancements

Fix a typo which cause the server to hang.
Add option to enable reload pref config on request.
Optimize codes.
This commit is contained in:
Tindy X committed 2023-11-14 16:42:22 +08:00
1 parent b71cd1e668
commit 885a63b837
7 files changed
+26 -15

No files matched your search

+13 -13
View File
@@ -172,7 +172,7 @@ void processRemark(std::string &remark, const string_array &remarks_list, bool p
}
std::string tempRemark = remark;
int cnt = 2;
while(std::find(remarks_list.cbegin(), remarks_list.cend(), tempRemark) != remarks_list.cbegin())
while(std::find(remarks_list.cbegin(), remarks_list.cend(), tempRemark) != remarks_list.cend())
{
tempRemark = remark + " " + std::to_string(cnt);
cnt++;
@@ -2078,7 +2078,7 @@ static rapidjson::Value buildSingBoxTransport(const Proxy& proxy, rapidjson::Mem
return transport;
}
void addSingBoxCommonMembers(rapidjson::Value &proxy, const Proxy &x, const rapidjson::GenericStringRef<rapidjson::Value::Ch> &type, rapidjson::MemoryPoolAllocator<> &allocator)
static void addSingBoxCommonMembers(rapidjson::Value &proxy, const Proxy &x, const rapidjson::GenericStringRef<rapidjson::Value::Ch> &type, rapidjson::MemoryPoolAllocator<> &allocator)
{
proxy.AddMember("type", type, allocator);
proxy.AddMember("tag", rapidjson::StringRef(x.Remark.c_str()), allocator);
@@ -2086,6 +2086,15 @@ void addSingBoxCommonMembers(rapidjson::Value &proxy, const Proxy &x, const rapi
proxy.AddMember("server_port", x.Port, allocator);
}
static rapidjson::Value stringArrayToJsonArray(const std::string &array, const std::string &delimiter, rapidjson::MemoryPoolAllocator<> &allocator)
{
rapidjson::Value result(rapidjson::kArrayType);
string_array vArray = split(array, delimiter);
for (const auto &x : vArray)
result.PushBack(rapidjson::Value(trim(x).c_str(), allocator), allocator);
return result;
}
void proxyToSingBox(std::vector<Proxy> &nodes, rapidjson::Document &json, std::vector<RulesetContent> &ruleset_content_array, const ProxyGroupConfigs &extra_proxy_group, extra_settings &ext) {
using namespace rapidjson_ext;
rapidjson::Document::AllocatorType &allocator = json.GetAllocator();
@@ -2181,22 +2190,13 @@ void proxyToSingBox(std::vector<Proxy> &nodes, rapidjson::Document &json, std::v
if (!x.AllowedIPs.empty())
{
auto allowed = split(x.AllowedIPs, ",");
rapidjson::Value allowed_ips(rapidjson::kArrayType);
for (const auto &ip: allowed) {
allowed_ips.PushBack(rapidjson::Value(trim(ip).c_str(), allocator), allocator);
}
auto allowed_ips = stringArrayToJsonArray(x.AllowedIPs, ",", allocator);
peer.AddMember("allowed_ips", allowed_ips, allocator);
}
if (!x.ClientId.empty())
{
auto client_id = split(x.ClientId, ",");
rapidjson::Value reserved(rapidjson::kArrayType);
for (const auto &id : client_id)
{
reserved.PushBack(to_int(trim(id)), allocator);
}
auto reserved = stringArrayToJsonArray(x.ClientId, ",", allocator);
peer.AddMember("reserved", reserved, allocator);
}