mirror of
https://github.com/Qv2ray/Qv2ray.git
synced 2025-05-20 10:50:23 +08:00
refactor: refactored route generation, WARN: NOT TESTED
This commit is contained in:
parent
13052b5e99
commit
c017401840
@ -1 +1 @@
|
|||||||
5849
|
5850
|
||||||
|
@ -121,7 +121,6 @@ namespace Qv2ray::base::objects
|
|||||||
{
|
{
|
||||||
// Added due to the request of @aliyuchang33
|
// Added due to the request of @aliyuchang33
|
||||||
bool QV2RAY_RULE_ENABLED;
|
bool QV2RAY_RULE_ENABLED;
|
||||||
bool QV2RAY_RULE_USE_BALANCER;
|
|
||||||
QString QV2RAY_RULE_TAG;
|
QString QV2RAY_RULE_TAG;
|
||||||
//
|
//
|
||||||
QString type;
|
QString type;
|
||||||
@ -137,10 +136,10 @@ namespace Qv2ray::base::objects
|
|||||||
QString outboundTag;
|
QString outboundTag;
|
||||||
QString balancerTag;
|
QString balancerTag;
|
||||||
RuleObject()
|
RuleObject()
|
||||||
: QV2RAY_RULE_ENABLED(true), QV2RAY_RULE_USE_BALANCER(false), QV2RAY_RULE_TAG("new rule"), type("field"), domain(), ip(),
|
: QV2RAY_RULE_ENABLED(true), QV2RAY_RULE_TAG("new rule"), type("field"), domain(), ip(), port("1-65535"), network(""), source(),
|
||||||
port("1-65535"), network(""), source(), user(), inboundTag(), protocol(), attrs(), outboundTag(""), balancerTag(""){};
|
user(), inboundTag(), protocol(), attrs(), outboundTag(""), balancerTag(""){};
|
||||||
JSONSTRUCT_REGISTER(RuleObject, F(QV2RAY_RULE_ENABLED, QV2RAY_RULE_USE_BALANCER, QV2RAY_RULE_TAG, type, domain, ip, port, network,
|
JSONSTRUCT_REGISTER(RuleObject, F(QV2RAY_RULE_ENABLED, QV2RAY_RULE_TAG, type, domain, ip, port, network, source, user, inboundTag,
|
||||||
source, user, inboundTag, protocol, attrs, outboundTag, balancerTag))
|
protocol, attrs, outboundTag, balancerTag))
|
||||||
};
|
};
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
@ -67,8 +67,10 @@ namespace Qv2ray::core::connection::generation::filters
|
|||||||
{
|
{
|
||||||
for (auto i = 0; i < root["outbounds"].toArray().count(); i++)
|
for (auto i = 0; i < root["outbounds"].toArray().count(); i++)
|
||||||
{
|
{
|
||||||
bool isEmptySeed = QJsonIO::GetValue(root, "outbounds", i, "streamSettings", "kcpSettings", "seed").toString().isEmpty();
|
const auto seedItem = QJsonIO::GetValue(root, "outbounds", i, "streamSettings", "kcpSettings", "seed");
|
||||||
if (isEmptySeed)
|
bool shouldProcess = !seedItem.isNull() && !seedItem.isUndefined();
|
||||||
|
bool isEmptySeed = seedItem.toString().isEmpty();
|
||||||
|
if (shouldProcess && isEmptySeed)
|
||||||
QJsonIO::SetValue(root, QJsonIO::Undefined, "outbounds", i, "streamSettings", "kcpSettings", "seed");
|
QJsonIO::SetValue(root, QJsonIO::Undefined, "outbounds", i, "streamSettings", "kcpSettings", "seed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,8 +81,8 @@ namespace Qv2ray::core::connection::generation::filters
|
|||||||
{
|
{
|
||||||
if (QJsonIO::GetValue(root, subKey, i, "tag").toString().isEmpty())
|
if (QJsonIO::GetValue(root, subKey, i, "tag").toString().isEmpty())
|
||||||
{
|
{
|
||||||
LOG(MODULE_SETTINGS, "Adding a tag to an inbound.")
|
|
||||||
const auto tag = GenerateRandomString(8);
|
const auto tag = GenerateRandomString(8);
|
||||||
|
LOG(MODULE_SETTINGS, "Adding tag " + tag + " to inbound.")
|
||||||
QJsonIO::SetValue(root, tag, subKey, i, "tag");
|
QJsonIO::SetValue(root, tag, subKey, i, "tag");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,9 +136,9 @@ namespace Qv2ray::core::handler
|
|||||||
// logObject.insert("error", QV2RAY_CONFIG_PATH + QV2RAY_VCORE_LOG_DIRNAME + QV2RAY_VCORE_ERROR_LOG_FILENAME);
|
// logObject.insert("error", QV2RAY_CONFIG_PATH + QV2RAY_VCORE_LOG_DIRNAME + QV2RAY_VCORE_ERROR_LOG_FILENAME);
|
||||||
QJsonIO::SetValue(root, V2RayLogLevel[GlobalConfig.logLevel], "log", "loglevel");
|
QJsonIO::SetValue(root, V2RayLogLevel[GlobalConfig.logLevel], "log", "loglevel");
|
||||||
//
|
//
|
||||||
// Since Qv2ray does not support settings DNS manually for now.
|
// Process DNS
|
||||||
// These settings are being added for both complex config AND simple config.
|
const auto hasDNS = root.contains("dns") && !root.value("dns").toObject().isEmpty();
|
||||||
if (root.contains("dns") && !root.value("dns").toObject().isEmpty())
|
if (hasDNS)
|
||||||
{
|
{
|
||||||
// We assume the users are using THEIR DNS settings.
|
// We assume the users are using THEIR DNS settings.
|
||||||
LOG(MODULE_CONNECTION, "Found DNS settings specified manually, skipping inserting GlobalConfig")
|
LOG(MODULE_CONNECTION, "Found DNS settings specified manually, skipping inserting GlobalConfig")
|
||||||
@ -156,8 +156,8 @@ namespace Qv2ray::core::handler
|
|||||||
{
|
{
|
||||||
#define INCONF GlobalConfig.inboundConfig
|
#define INCONF GlobalConfig.inboundConfig
|
||||||
INBOUNDS inboundsList;
|
INBOUNDS inboundsList;
|
||||||
const QJsonObject sniffingOff{ { "enabled", false } };
|
const static QJsonObject sniffingOff{ { "enabled", false } };
|
||||||
const QJsonObject sniffingOn{ { "enabled", true }, { "destOverride", QJsonArray{ "http", "tls" } } };
|
const static QJsonObject sniffingOn{ { "enabled", true }, { "destOverride", QJsonArray{ "http", "tls" } } };
|
||||||
|
|
||||||
// HTTP Inbound
|
// HTTP Inbound
|
||||||
if (GlobalConfig.inboundConfig.useHTTP)
|
if (GlobalConfig.inboundConfig.useHTTP)
|
||||||
@ -261,12 +261,13 @@ namespace Qv2ray::core::handler
|
|||||||
|
|
||||||
for (const auto &_rule : routing["rules"].toArray())
|
for (const auto &_rule : routing["rules"].toArray())
|
||||||
{
|
{
|
||||||
auto _b = _rule.toObject();
|
auto rule = _rule.toObject();
|
||||||
|
|
||||||
if (_b.contains("QV2RAY_RULE_USE_BALANCER"))
|
// For compatibility
|
||||||
|
if (rule.contains("QV2RAY_RULE_USE_BALANCER"))
|
||||||
{
|
{
|
||||||
// We use balancer, or the normal outbound
|
// We use balancer, or the normal outbound
|
||||||
_b.remove(_b["QV2RAY_RULE_USE_BALANCER"].toBool(false) ? "outboundTag" : "balancerTag");
|
rule.remove(rule["QV2RAY_RULE_USE_BALANCER"].toBool(false) ? "outboundTag" : "balancerTag");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -274,13 +275,13 @@ namespace Qv2ray::core::handler
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If this entry has been disabled.
|
// If this entry has been disabled.
|
||||||
if (_b.contains("QV2RAY_RULE_ENABLED") && _b["QV2RAY_RULE_ENABLED"].toBool() == false)
|
if (rule.contains("QV2RAY_RULE_ENABLED") && rule["QV2RAY_RULE_ENABLED"].toBool() == false)
|
||||||
{
|
{
|
||||||
LOG(MODULE_SETTINGS, "Discarded a rule as it's been set DISABLED")
|
LOG(MODULE_SETTINGS, "Discarded a rule as it's been set DISABLED")
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rules.append(_b);
|
rules.append(rule);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,7 +298,7 @@ namespace Qv2ray::core::handler
|
|||||||
LOG(MODULE_CONNECTION, "WARN: --> The config file has NO routing section, however more than 1 outbounds are detected.")
|
LOG(MODULE_CONNECTION, "WARN: --> The config file has NO routing section, however more than 1 outbounds are detected.")
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
auto tag = getTag(OUTBOUND(QJsonIO::GetValue(root, "outbounds", 0).toObject()));
|
auto tag = QJsonIO::GetValue(root, "outbounds", 0, "tag").toString();
|
||||||
if (tag.isEmpty())
|
if (tag.isEmpty())
|
||||||
{
|
{
|
||||||
LOG(MODULE_CONNECTION, "Applying workaround when an outbound tag is empty")
|
LOG(MODULE_CONNECTION, "Applying workaround when an outbound tag is empty")
|
||||||
@ -329,11 +330,11 @@ namespace Qv2ray::core::handler
|
|||||||
}
|
}
|
||||||
else if (!fpConf.type.isEmpty())
|
else if (!fpConf.type.isEmpty())
|
||||||
{
|
{
|
||||||
DEBUG(MODULE_CONNECTION, "WARNING: Unsupported outbound type: " + fpConf.type)
|
DEBUG(MODULE_CONNECTION, "WARNING: Unsupported forward proxy type: " + fpConf.type)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DEBUG(MODULE_CONNECTION, "WARNING: Empty outbound type.")
|
DEBUG(MODULE_CONNECTION, "WARNING: Empty forward proxy type.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -361,7 +362,7 @@ namespace Qv2ray::core::handler
|
|||||||
{
|
{
|
||||||
const auto hasTProxy = GlobalConfig.inboundConfig.useTPROXY && GlobalConfig.inboundConfig.tProxySettings.hasUDP;
|
const auto hasTProxy = GlobalConfig.inboundConfig.useTPROXY && GlobalConfig.inboundConfig.tProxySettings.hasUDP;
|
||||||
const auto hasIPv6 = hasTProxy && (!GlobalConfig.inboundConfig.tProxySettings.tProxyV6IP.isEmpty());
|
const auto hasIPv6 = hasTProxy && (!GlobalConfig.inboundConfig.tProxySettings.tProxyV6IP.isEmpty());
|
||||||
const bool hasSocksUDP = GlobalConfig.inboundConfig.useSocks && GlobalConfig.inboundConfig.socksSettings.enableUDP;
|
const auto hasSocksUDP = GlobalConfig.inboundConfig.useSocks && GlobalConfig.inboundConfig.socksSettings.enableUDP;
|
||||||
DNSInterceptFilter(root, hasTProxy, hasIPv6, hasSocksUDP);
|
DNSInterceptFilter(root, hasTProxy, hasIPv6, hasSocksUDP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -391,7 +392,7 @@ namespace Qv2ray::core::handler
|
|||||||
// Routes
|
// Routes
|
||||||
QJsonObject routing = root["routing"].toObject();
|
QJsonObject routing = root["routing"].toObject();
|
||||||
QJsonArray routingRules = routing["rules"].toArray();
|
QJsonArray routingRules = routing["rules"].toArray();
|
||||||
QJsonObject APIRouteRoot{ { "type", "field" }, //
|
const static QJsonObject APIRouteRoot{ { "type", "field" }, //
|
||||||
{ "outboundTag", API_TAG_DEFAULT }, //
|
{ "outboundTag", API_TAG_DEFAULT }, //
|
||||||
{ "inboundTag", QJsonArray{ API_TAG_INBOUND } } };
|
{ "inboundTag", QJsonArray{ API_TAG_INBOUND } } };
|
||||||
routingRules.push_front(APIRouteRoot);
|
routingRules.push_front(APIRouteRoot);
|
||||||
|
@ -64,8 +64,7 @@ namespace Qv2ray::ui
|
|||||||
"certificates",
|
"certificates",
|
||||||
"serverName",
|
"serverName",
|
||||||
"QV2RAY_RULE_ENABLED",
|
"QV2RAY_RULE_ENABLED",
|
||||||
"QV2RAY_RULE_TAG",
|
"QV2RAY_RULE_TAG" };
|
||||||
"QV2RAY_RULE_USE_BALANCER" };
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (const QString &pattern : keywordPatterns)
|
for (const QString &pattern : keywordPatterns)
|
||||||
{
|
{
|
||||||
|
@ -70,10 +70,11 @@ void NodeDispatcher::LoadFullConfig(const CONFIGROOT &root)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto outboundTag = rule->QV2RAY_RULE_USE_BALANCER ? rule->balancerTag : rule->outboundTag;
|
for (const auto &outboundTag : { rule->outboundTag, rule->balancerTag })
|
||||||
|
{
|
||||||
if (outboundNodes.contains(outboundTag))
|
if (outboundNodes.contains(outboundTag))
|
||||||
{
|
{
|
||||||
const auto outboundNodeId = outboundNodes[outboundTag];
|
const auto &outboundNodeId = outboundNodes[outboundTag];
|
||||||
ruleScene->createConnection(*ruleScene->node(outboundNodeId), 0, *ruleScene->node(ruleNodeId), 0);
|
ruleScene->createConnection(*ruleScene->node(outboundNodeId), 0, *ruleScene->node(ruleNodeId), 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -81,6 +82,7 @@ void NodeDispatcher::LoadFullConfig(const CONFIGROOT &root)
|
|||||||
LOG(MODULE_NODE, "Could not find outbound: " + outboundTag)
|
LOG(MODULE_NODE, "Could not find outbound: " + outboundTag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
isOperationLocked = false;
|
isOperationLocked = false;
|
||||||
emit OnFullConfigLoadCompleted();
|
emit OnFullConfigLoadCompleted();
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,6 @@ void RuleNodeModel::outputConnectionDeleted(const QtNodes::Connection &c)
|
|||||||
{
|
{
|
||||||
if (dispatcher->IsNodeConstructing())
|
if (dispatcher->IsNodeConstructing())
|
||||||
return;
|
return;
|
||||||
dataptr->QV2RAY_RULE_USE_BALANCER = false;
|
|
||||||
dataptr->balancerTag.clear();
|
dataptr->balancerTag.clear();
|
||||||
dataptr->outboundTag.clear();
|
dataptr->outboundTag.clear();
|
||||||
}
|
}
|
||||||
|
@ -40,24 +40,6 @@ void QvNodeRuleWidget::setValue(std::shared_ptr<RuleObject> _ruleptr)
|
|||||||
ruleTagLineEdit->setEnabled(true);
|
ruleTagLineEdit->setEnabled(true);
|
||||||
LOAD_FLAG_BEGIN
|
LOAD_FLAG_BEGIN
|
||||||
ruleTagLineEdit->setText(rule.QV2RAY_RULE_TAG);
|
ruleTagLineEdit->setText(rule.QV2RAY_RULE_TAG);
|
||||||
// balancerSelectionCombo->clear();
|
|
||||||
|
|
||||||
// for (auto out : outbounds)
|
|
||||||
// {
|
|
||||||
// balancerSelectionCombo->addItem(getTag(OUTBOUND(out)));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// //
|
|
||||||
// // Balancers combo and balancer list.
|
|
||||||
// enableBalancerCB->setChecked(CurrentRule.QV2RAY_RULE_USE_BALANCER);
|
|
||||||
// balancersWidget->setEnabled(CurrentRule.QV2RAY_RULE_USE_BALANCER);
|
|
||||||
|
|
||||||
// if (!CurrentRule.balancerTag.isEmpty())
|
|
||||||
// {
|
|
||||||
// balancerList->clear();
|
|
||||||
// balancerList->addItems(balancers[CurrentRule.balancerTag]);
|
|
||||||
// }
|
|
||||||
|
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
// Networks
|
// Networks
|
||||||
auto network = rule.network.toLower();
|
auto network = rule.network.toLower();
|
||||||
|
Loading…
Reference in New Issue
Block a user