mirror of
https://github.com/Qv2ray/Qv2ray.git
synced 2025-05-20 10:50:23 +08:00
add: added nodeDispatcher signals
This commit is contained in:
parent
4adbdbc258
commit
db7677ffa9
@ -1 +1 @@
|
|||||||
5803
|
5804
|
||||||
|
@ -17,13 +17,20 @@ namespace Qv2ray::base::objects::complex
|
|||||||
* |
|
* |
|
||||||
* | Qv2ray-only structures
|
* | Qv2ray-only structures
|
||||||
* | ======================
|
* | ======================
|
||||||
|
* |
|
||||||
* | - Outbounds
|
* | - Outbounds
|
||||||
* | | - Single Orginal Outbound Unmodified
|
* | |
|
||||||
|
* | | - OUTBOUND
|
||||||
|
* | | - Original Outbound Object
|
||||||
* | | ==========================================
|
* | | ==========================================
|
||||||
* | | - QV2RAY_OUTBOUND_METADATA -> OutboundObjectMeta
|
* | | - "QV2RAY_OUTBOUND_METADATA" -> OutboundObjectMeta
|
||||||
* | |
|
* | | - realOutbound -> OUTBOUND A.K.A ref<OUTBOUND>
|
||||||
* | |
|
* | | - chainId -> ChainID
|
||||||
* | |
|
* | | - object -> OutboundObject
|
||||||
|
* | | - metaType -> MetaOutboundObjectType
|
||||||
|
* | | - ORIGINAL -> Enables realOutbound
|
||||||
|
* | | - CHAINED
|
||||||
|
* | | - BALANCER
|
||||||
* | |
|
* | |
|
||||||
* |
|
* |
|
||||||
* |
|
* |
|
||||||
@ -62,9 +69,9 @@ namespace Qv2ray::base::objects::complex
|
|||||||
|
|
||||||
struct OutboundObjectMeta
|
struct OutboundObjectMeta
|
||||||
{
|
{
|
||||||
complex::MetaOutboundObjectType metaType;
|
MetaOutboundObjectType metaType;
|
||||||
complex::ChainId chainId;
|
ChainId chainId;
|
||||||
complex::OutboundObject object;
|
OutboundObject object;
|
||||||
safetype::OUTBOUND realOutbound;
|
safetype::OUTBOUND realOutbound;
|
||||||
JSONSTRUCT_REGISTER(OutboundObjectMeta, F(metaType, chainId, object))
|
JSONSTRUCT_REGISTER(OutboundObjectMeta, F(metaType, chainId, object))
|
||||||
};
|
};
|
||||||
|
@ -31,7 +31,7 @@ using namespace Qv2ray::ui::nodemodels;
|
|||||||
if (this->rules.isEmpty()) \
|
if (this->rules.isEmpty()) \
|
||||||
{ \
|
{ \
|
||||||
LOG(MODULE_UI, "No rules currently, we add one.") \
|
LOG(MODULE_UI, "No rules currently, we add one.") \
|
||||||
AddNewRule(); \
|
nodeDispatcher->CreateRule({}); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LOAD_FLAG_BEGIN isLoading = true;
|
#define LOAD_FLAG_BEGIN isLoading = true;
|
||||||
@ -78,12 +78,15 @@ RouteEditor::RouteEditor(QJsonObject connection, QWidget *parent) : QvDialog(par
|
|||||||
{
|
{
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
QvMessageBusConnect(RouteEditor);
|
QvMessageBusConnect(RouteEditor);
|
||||||
|
//
|
||||||
nodeDispatcher = std::make_shared<NodeDispatcher>(this);
|
nodeDispatcher = std::make_shared<NodeDispatcher>(this);
|
||||||
|
connect(nodeDispatcher.get(), &NodeDispatcher::OnInboundCreated, this, &RouteEditor::OnDispatcherInboundCreated);
|
||||||
|
connect(nodeDispatcher.get(), &NodeDispatcher::OnOutboundCreated, this, &RouteEditor::OnDispatcherOutboundCreated);
|
||||||
|
connect(nodeDispatcher.get(), &NodeDispatcher::OnRuleCreated, this, &RouteEditor::OnDispatcherRuleCreated);
|
||||||
|
//
|
||||||
isLoading = true;
|
isLoading = true;
|
||||||
setWindowFlags(windowFlags() | Qt::WindowMaximizeButtonHint);
|
setWindowFlags(windowFlags() | Qt::WindowMaximizeButtonHint);
|
||||||
//
|
|
||||||
SetupNodeWidget();
|
SetupNodeWidget();
|
||||||
//
|
|
||||||
updateColorScheme();
|
updateColorScheme();
|
||||||
//
|
//
|
||||||
domainStrategy = root["routing"].toObject()["domainStrategy"].toString();
|
domainStrategy = root["routing"].toObject()["domainStrategy"].toString();
|
||||||
@ -92,7 +95,7 @@ RouteEditor::RouteEditor(QJsonObject connection, QWidget *parent) : QvDialog(par
|
|||||||
//// Show connections in the node graph
|
//// Show connections in the node graph
|
||||||
for (const auto &in : root["inbounds"].toArray())
|
for (const auto &in : root["inbounds"].toArray())
|
||||||
{
|
{
|
||||||
AddInbound(INBOUND(in.toObject()));
|
auto _ = nodeDispatcher->CreateInbound(INBOUND(in.toObject()));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &out : root["outbounds"].toArray())
|
for (const auto &out : root["outbounds"].toArray())
|
||||||
@ -100,17 +103,17 @@ RouteEditor::RouteEditor(QJsonObject connection, QWidget *parent) : QvDialog(par
|
|||||||
OutboundObjectMeta meta;
|
OutboundObjectMeta meta;
|
||||||
meta.loadJson(out.toObject()[META_OUTBOUND_KEY_NAME].toObject());
|
meta.loadJson(out.toObject()[META_OUTBOUND_KEY_NAME].toObject());
|
||||||
meta.realOutbound = OUTBOUND(out.toObject());
|
meta.realOutbound = OUTBOUND(out.toObject());
|
||||||
AddOutbound(meta);
|
auto _ = nodeDispatcher->CreateOutbound(meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &item : root["routing"].toObject()["rules"].toArray())
|
for (const auto &item : root["routing"].toObject()["rules"].toArray())
|
||||||
{
|
{
|
||||||
AddRule(RuleObject::fromJson(item.toObject()));
|
auto _ = nodeDispatcher->CreateRule(RuleObject::fromJson(item.toObject()));
|
||||||
}
|
}
|
||||||
|
|
||||||
//// Set default outboung combo text AFTER adding all outbounds.
|
//// Set default outboung combo text AFTER adding all outbounds.
|
||||||
// defaultOutbound = getTag(OUTBOUND(root["outbounds"].toArray().first().toObject()));
|
defaultOutbound = getTag(OUTBOUND(root["outbounds"].toArray().first().toObject()));
|
||||||
// defaultOutboundCombo->setCurrentText(defaultOutbound);
|
defaultOutboundCombo->setCurrentText(defaultOutbound);
|
||||||
//
|
//
|
||||||
//// // Find and add balancers.
|
//// // Find and add balancers.
|
||||||
//// for (auto _balancer : root["routing"].toObject()["balancers"].toArray())
|
//// for (auto _balancer : root["routing"].toObject()["balancers"].toArray())
|
||||||
@ -190,14 +193,13 @@ void RouteEditor::onNodeClicked(Node &n)
|
|||||||
// LOG(MODULE_GRAPH, "Selected an unknown node, RARE.")
|
// LOG(MODULE_GRAPH, "Selected an unknown node, RARE.")
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
void RouteEditor::OnDispatcherInboundCreated(std::shared_ptr<INBOUND> in)
|
||||||
void RouteEditor::OnDispatcherInboundCreated()
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void RouteEditor::OnDispatcherOutboundCreated()
|
void RouteEditor::OnDispatcherOutboundCreated(std::shared_ptr<OutboundObjectMeta> out)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void RouteEditor::OnDispatcherRuleCreated()
|
void RouteEditor::OnDispatcherRuleCreated(std::shared_ptr<RuleObject> rule)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -465,7 +467,7 @@ void RouteEditor::on_addDefaultBtn_clicked()
|
|||||||
_in_HTTP.insert("settings", httpInSettings);
|
_in_HTTP.insert("settings", httpInSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
AddInbound(_in_HTTP);
|
nodeDispatcher->CreateInbound(_in_HTTP);
|
||||||
}
|
}
|
||||||
if (_Inconfig.useSocks)
|
if (_Inconfig.useSocks)
|
||||||
{
|
{
|
||||||
@ -482,36 +484,37 @@ void RouteEditor::on_addDefaultBtn_clicked()
|
|||||||
{
|
{
|
||||||
_in_SOCKS.insert("sniffing", sniffingOn);
|
_in_SOCKS.insert("sniffing", sniffingOn);
|
||||||
}
|
}
|
||||||
AddInbound(_in_SOCKS);
|
nodeDispatcher->CreateInbound(_in_SOCKS);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_Inconfig.useTPROXY)
|
if (_Inconfig.useTPROXY)
|
||||||
{
|
{
|
||||||
QList<QString> networks;
|
QList<QString> networks;
|
||||||
#define _ts_ _Inconfig.tProxySettings
|
#define ts _Inconfig.tProxySettings
|
||||||
if (_ts_.hasTCP)
|
if (ts.hasTCP)
|
||||||
networks << "tcp";
|
networks << "tcp";
|
||||||
if (_ts_.hasUDP)
|
if (ts.hasUDP)
|
||||||
networks << "udp";
|
networks << "udp";
|
||||||
const auto tproxy_network = networks.join(",");
|
const auto tproxy_network = networks.join(",");
|
||||||
auto tproxyInSettings = GenerateDokodemoIN("", 0, tproxy_network, 0, true, 0);
|
auto tproxyInSettings = GenerateDokodemoIN("", 0, tproxy_network, 0, true, 0);
|
||||||
//
|
//
|
||||||
QJsonObject tproxy_sniff{ { "enabled", true }, { "destOverride", QJsonArray{ "http", "tls" } } };
|
//
|
||||||
QJsonObject tproxy_streamSettings{ { "sockopt", QJsonObject{ { "tproxy", _ts_.mode } } } };
|
const static QJsonObject tproxy_sniff{ { "enabled", true }, { "destOverride", QJsonArray{ "http", "tls" } } };
|
||||||
|
const QJsonObject tproxy_streamSettings{ { "sockopt", QJsonObject{ { "tproxy", ts.mode } } } };
|
||||||
|
|
||||||
auto _in_TPROXY = GenerateInboundEntry(_ts_.tProxyIP, _ts_.port, "dokodemo-door", tproxyInSettings, "TPROXY_gConf");
|
auto tProxyIn = GenerateInboundEntry(ts.tProxyIP, ts.port, "dokodemo-door", tproxyInSettings, "TPROXY_gConf");
|
||||||
_in_TPROXY.insert("sniffing", tproxy_sniff);
|
tProxyIn.insert("sniffing", tproxy_sniff);
|
||||||
_in_TPROXY.insert("streamSettings", tproxy_streamSettings);
|
tProxyIn.insert("streamSettings", tproxy_streamSettings);
|
||||||
AddInbound(_in_TPROXY);
|
nodeDispatcher->CreateInbound(tProxyIn);
|
||||||
|
|
||||||
if (!_ts_.tProxyV6IP.isEmpty())
|
if (!ts.tProxyV6IP.isEmpty())
|
||||||
{
|
{
|
||||||
auto _in_TPROXY = GenerateInboundEntry(_ts_.tProxyV6IP, _ts_.port, "dokodemo-door", tproxyInSettings, "TPROXY_gConf_V6");
|
auto tProxyV6In = GenerateInboundEntry(ts.tProxyV6IP, ts.port, "dokodemo-door", tproxyInSettings, "TPROXY_gConf_V6");
|
||||||
_in_TPROXY.insert("sniffing", tproxy_sniff);
|
tProxyV6In.insert("sniffing", tproxy_sniff);
|
||||||
_in_TPROXY.insert("streamSettings", tproxy_streamSettings);
|
tProxyV6In.insert("streamSettings", tproxy_streamSettings);
|
||||||
AddInbound(_in_TPROXY);
|
nodeDispatcher->CreateInbound(tProxyV6In);
|
||||||
}
|
}
|
||||||
#undef _ts_
|
#undef ts
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECKEMPTYRULES
|
CHECKEMPTYRULES
|
||||||
@ -533,7 +536,8 @@ void RouteEditor::on_addInboundBtn_clicked()
|
|||||||
|
|
||||||
if (w.result() == QDialog::Accepted)
|
if (w.result() == QDialog::Accepted)
|
||||||
{
|
{
|
||||||
AddInbound(_result);
|
abort();
|
||||||
|
// nodeDispatcher->CreateOutbound(_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECKEMPTYRULES
|
CHECKEMPTYRULES
|
||||||
@ -645,7 +649,7 @@ void RouteEditor::on_delBtn_clicked()
|
|||||||
}
|
}
|
||||||
void RouteEditor::on_addRouteBtn_clicked()
|
void RouteEditor::on_addRouteBtn_clicked()
|
||||||
{
|
{
|
||||||
auto ruleName = AddNewRule();
|
auto ruleName = nodeDispatcher->CreateRule({});
|
||||||
Q_UNUSED(ruleName)
|
Q_UNUSED(ruleName)
|
||||||
}
|
}
|
||||||
void RouteEditor::on_editBtn_clicked()
|
void RouteEditor::on_editBtn_clicked()
|
||||||
@ -817,12 +821,12 @@ void RouteEditor::on_addBalancerBtn_clicked()
|
|||||||
|
|
||||||
OutboundObjectMeta meta;
|
OutboundObjectMeta meta;
|
||||||
meta.metaType = complex::METAOUTBOUND_BALANCER;
|
meta.metaType = complex::METAOUTBOUND_BALANCER;
|
||||||
AddOutbound(meta);
|
nodeDispatcher->CreateOutbound(meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouteEditor::on_addChainBtn_clicked()
|
void RouteEditor::on_addChainBtn_clicked()
|
||||||
{
|
{
|
||||||
OutboundObjectMeta meta;
|
OutboundObjectMeta meta;
|
||||||
meta.metaType = complex::METAOUTBOUND_CHAINED;
|
meta.metaType = complex::METAOUTBOUND_CHAINED;
|
||||||
AddOutbound(meta);
|
nodeDispatcher->CreateOutbound(meta);
|
||||||
}
|
}
|
||||||
|
@ -73,9 +73,9 @@ class RouteEditor
|
|||||||
void onConnectionDeleted(QtNodes::Connection const &c);
|
void onConnectionDeleted(QtNodes::Connection const &c);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void OnDispatcherInboundCreated();
|
void OnDispatcherInboundCreated(std::shared_ptr<INBOUND>);
|
||||||
void OnDispatcherOutboundCreated();
|
void OnDispatcherOutboundCreated(std::shared_ptr<OutboundObjectMeta>);
|
||||||
void OnDispatcherRuleCreated();
|
void OnDispatcherRuleCreated(std::shared_ptr<RuleObject>);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<NodeDispatcher> nodeDispatcher;
|
std::shared_ptr<NodeDispatcher> nodeDispatcher;
|
||||||
@ -97,9 +97,6 @@ class RouteEditor
|
|||||||
//
|
//
|
||||||
FlowScene *nodeScene;
|
FlowScene *nodeScene;
|
||||||
// ---------------------------- Extra Source File Headers ----------------
|
// ---------------------------- Extra Source File Headers ----------------
|
||||||
void AddInbound(const INBOUND &in);
|
|
||||||
void AddOutbound(OutboundObjectMeta &meta);
|
|
||||||
void AddRule(const RuleObject &rule);
|
|
||||||
QString AddNewRule();
|
QString AddNewRule();
|
||||||
//
|
//
|
||||||
void ResolveDefaultOutboundTag(QString original, QString newTag);
|
void ResolveDefaultOutboundTag(QString original, QString newTag);
|
||||||
|
@ -8,74 +8,74 @@
|
|||||||
#include <nodes/internal/FlowScene.hpp>
|
#include <nodes/internal/FlowScene.hpp>
|
||||||
// Supplementary source file for Routes editor, basically providing
|
// Supplementary source file for Routes editor, basically providing
|
||||||
// routes-related operations.
|
// routes-related operations.
|
||||||
|
//
|
||||||
void RouteEditor::AddInbound(const INBOUND &in)
|
// void RouteEditor::AddInbound(const INBOUND &in)
|
||||||
{
|
//{
|
||||||
const auto tag = getTag(in);
|
// const auto tag = getTag(in);
|
||||||
inbounds << in;
|
// inbounds << in;
|
||||||
auto _nodeData = std::make_unique<InboundNodeModel>(nodeDispatcher, std::make_shared<INBOUND>(inbounds.last()));
|
// auto _nodeData = std::make_unique<InboundNodeModel>(nodeDispatcher, std::make_shared<INBOUND>(inbounds.last()));
|
||||||
auto &node = nodeScene->createNode(std::move(_nodeData));
|
// auto &node = nodeScene->createNode(std::move(_nodeData));
|
||||||
QPointF pos;
|
// QPointF pos;
|
||||||
pos.setX(0 + GRAPH_GLOBAL_OFFSET_X);
|
// pos.setX(0 + GRAPH_GLOBAL_OFFSET_X);
|
||||||
pos.setY(inbounds.count() * 130 + GRAPH_GLOBAL_OFFSET_Y);
|
// pos.setY(inbounds.count() * 130 + GRAPH_GLOBAL_OFFSET_Y);
|
||||||
nodeScene->setNodePosition(node, pos);
|
// nodeScene->setNodePosition(node, pos);
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
void RouteEditor::AddOutbound(OutboundObjectMeta &metaOutboud)
|
// void RouteEditor::AddOutbound(OutboundObjectMeta &metaOutboud)
|
||||||
{
|
//{
|
||||||
QString tag;
|
// QString tag;
|
||||||
switch (metaOutboud.metaType)
|
// switch (metaOutboud.metaType)
|
||||||
{
|
// {
|
||||||
case complex::METAOUTBOUND_ORIGINAL:
|
// case complex::METAOUTBOUND_ORIGINAL:
|
||||||
{
|
// {
|
||||||
tag = getTag(metaOutboud.realOutbound);
|
// tag = getTag(metaOutboud.realOutbound);
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
case complex::METAOUTBOUND_CHAINED:
|
// case complex::METAOUTBOUND_CHAINED:
|
||||||
case complex::METAOUTBOUND_BALANCER:
|
// case complex::METAOUTBOUND_BALANCER:
|
||||||
{
|
// {
|
||||||
tag = metaOutboud.object.externalTag;
|
// tag = metaOutboud.object.externalTag;
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
outbounds << metaOutboud;
|
// outbounds << metaOutboud;
|
||||||
auto _nodeData = std::make_unique<OutboundNodeModel>(nodeDispatcher, std::make_shared<OutboundObjectMeta>(outbounds.last()));
|
// auto _nodeData = std::make_unique<OutboundNodeModel>(nodeDispatcher, std::make_shared<OutboundObjectMeta>(outbounds.last()));
|
||||||
auto pos = nodeGraphWidget->pos();
|
// auto pos = nodeGraphWidget->pos();
|
||||||
pos.setX(pos.x() + 850 + GRAPH_GLOBAL_OFFSET_X);
|
// pos.setX(pos.x() + 850 + GRAPH_GLOBAL_OFFSET_X);
|
||||||
pos.setY(pos.y() + outbounds.count() * 120 + GRAPH_GLOBAL_OFFSET_Y);
|
// pos.setY(pos.y() + outbounds.count() * 120 + GRAPH_GLOBAL_OFFSET_Y);
|
||||||
auto &node = nodeScene->createNode(std::move(_nodeData));
|
// auto &node = nodeScene->createNode(std::move(_nodeData));
|
||||||
nodeScene->setNodePosition(node, pos);
|
// nodeScene->setNodePosition(node, pos);
|
||||||
defaultOutboundCombo->addItem(tag);
|
// defaultOutboundCombo->addItem(tag);
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
QString RouteEditor::AddNewRule()
|
// QString RouteEditor::AddNewRule()
|
||||||
{
|
//{
|
||||||
// Add Route
|
// // Add Route
|
||||||
RuleObject rule;
|
// RuleObject rule;
|
||||||
//
|
// //
|
||||||
rule.QV2RAY_RULE_ENABLED = true;
|
// rule.QV2RAY_RULE_ENABLED = true;
|
||||||
rule.QV2RAY_RULE_USE_BALANCER = false;
|
// rule.QV2RAY_RULE_USE_BALANCER = false;
|
||||||
// Default balancer tag, it's a random string.
|
// // Default balancer tag, it's a random string.
|
||||||
auto bTag = GenerateRandomString();
|
// auto bTag = GenerateRandomString();
|
||||||
rule.QV2RAY_RULE_TAG = rules.isEmpty() ? tr("Default rule") : (tr("rule") + "-" + GenerateRandomString(6));
|
// rule.QV2RAY_RULE_TAG = rules.isEmpty() ? tr("Default rule") : (tr("rule") + "-" + GenerateRandomString(6));
|
||||||
rule.balancerTag = bTag;
|
// rule.balancerTag = bTag;
|
||||||
// balancers[bTag] = QStringList();
|
// // balancers[bTag] = QStringList();
|
||||||
AddRule(rule);
|
// AddRule(rule);
|
||||||
return rule.QV2RAY_RULE_TAG;
|
// return rule.QV2RAY_RULE_TAG;
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
void RouteEditor::AddRule(const RuleObject &rule)
|
// void RouteEditor::AddRule(const RuleObject &rule)
|
||||||
{
|
//{
|
||||||
rules << rule;
|
// rules << rule;
|
||||||
auto pos = nodeGraphWidget->pos();
|
// auto pos = nodeGraphWidget->pos();
|
||||||
pos.setX(pos.x() + 350 + GRAPH_GLOBAL_OFFSET_X);
|
// pos.setX(pos.x() + 350 + GRAPH_GLOBAL_OFFSET_X);
|
||||||
pos.setY(pos.y() + rules.count() * 120 + GRAPH_GLOBAL_OFFSET_Y);
|
// pos.setY(pos.y() + rules.count() * 120 + GRAPH_GLOBAL_OFFSET_Y);
|
||||||
auto _nodeData = std::make_unique<RuleNodeModel>(nodeDispatcher, std::make_shared<RuleObject>(rules.last()));
|
// auto _nodeData = std::make_unique<RuleNodeModel>(nodeDispatcher, std::make_shared<RuleObject>(rules.last()));
|
||||||
auto &node = nodeScene->createNode(std::move(_nodeData));
|
// auto &node = nodeScene->createNode(std::move(_nodeData));
|
||||||
nodeScene->setNodePosition(node, pos);
|
// nodeScene->setNodePosition(node, pos);
|
||||||
|
//
|
||||||
ruleListWidget->addItem(rule.QV2RAY_RULE_TAG);
|
// ruleListWidget->addItem(rule.QV2RAY_RULE_TAG);
|
||||||
}
|
//}
|
||||||
|
|
||||||
// Do not use reference here, we need deep copy of EVERY QString.
|
// Do not use reference here, we need deep copy of EVERY QString.
|
||||||
void RouteEditor::RenameItemTag(ROUTE_EDIT_MODE mode, const QString originalTag, QString *newTag)
|
void RouteEditor::RenameItemTag(ROUTE_EDIT_MODE mode, const QString originalTag, QString *newTag)
|
||||||
|
@ -14,7 +14,7 @@ NodeDispatcher::~NodeDispatcher()
|
|||||||
QString NodeDispatcher::CreateInbound(INBOUND in)
|
QString NodeDispatcher::CreateInbound(INBOUND in)
|
||||||
{
|
{
|
||||||
auto tag = getTag(in);
|
auto tag = getTag(in);
|
||||||
if (inbounds.contains(tag))
|
while (inbounds.contains(tag))
|
||||||
{
|
{
|
||||||
tag += "_" + GenerateRandomString(5);
|
tag += "_" + GenerateRandomString(5);
|
||||||
}
|
}
|
||||||
@ -30,20 +30,38 @@ QString NodeDispatcher::CreateOutbound(OutboundObjectMeta out)
|
|||||||
switch (out.metaType)
|
switch (out.metaType)
|
||||||
{
|
{
|
||||||
case complex::METAOUTBOUND_CHAINED:
|
case complex::METAOUTBOUND_CHAINED:
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case complex::METAOUTBOUND_ORIGINAL:
|
case complex::METAOUTBOUND_ORIGINAL:
|
||||||
{
|
{
|
||||||
|
tag = out.object.externalTag;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case complex::METAOUTBOUND_BALANCER:
|
case complex::METAOUTBOUND_BALANCER:
|
||||||
{
|
{
|
||||||
|
tag = getTag(out.realOutbound);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// In case the tag is duplicated:
|
||||||
|
while (outbounds.contains(tag))
|
||||||
|
{
|
||||||
|
tag += "_" + GenerateRandomString(5);
|
||||||
|
// It's ok to set them directly without checking.
|
||||||
|
out.object.externalTag = tag;
|
||||||
|
out.realOutbound["tag"] = tag;
|
||||||
|
}
|
||||||
|
outbounds[tag] = out;
|
||||||
|
emit OnOutboundCreated(std::make_shared<OutboundObjectMeta>(outbounds.last()));
|
||||||
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString NodeDispatcher::CreateRule(RuleObject rule)
|
QString NodeDispatcher::CreateRule(RuleObject rule)
|
||||||
{
|
{
|
||||||
|
auto &tag = rule.QV2RAY_RULE_TAG;
|
||||||
|
while (rules.contains(tag))
|
||||||
|
{
|
||||||
|
tag += "_" + GenerateRandomString(5);
|
||||||
|
}
|
||||||
|
rules[tag] = rule;
|
||||||
|
emit OnRuleCreated(std::make_shared<RuleObject>(rules.last()));
|
||||||
|
return tag;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user