minor refactor

This commit is contained in:
arm64v8a
2023-05-22 11:07:14 +09:00
parent 1b050dd3fb
commit c5122b77e4
98 changed files with 1173 additions and 1142 deletions

View File

@@ -8,12 +8,12 @@
#include <QFile>
#include <QFileInfo>
#define BOX_UNDERLYING_DNS NekoRay::dataStore->core_box_underlying_dns.isEmpty() ? "underlying://0.0.0.0" : NekoRay::dataStore->core_box_underlying_dns
#define BOX_UNDERLYING_DNS_EXPORT NekoRay::dataStore->core_box_underlying_dns.isEmpty() ? (status->forExport ? "local" : "underlying://0.0.0.0") : NekoRay::dataStore->core_box_underlying_dns
#define BOX_UNDERLYING_DNS dataStore->core_box_underlying_dns.isEmpty() ? "underlying://0.0.0.0" : dataStore->core_box_underlying_dns
#define BOX_UNDERLYING_DNS_EXPORT dataStore->core_box_underlying_dns.isEmpty() ? (status->forExport ? "local" : "underlying://0.0.0.0") : dataStore->core_box_underlying_dns
namespace NekoRay {
namespace NekoGui {
QStringList getAutoBypassExternalProcessPaths(const QSharedPointer<BuildConfigResult> &result) {
QStringList getAutoBypassExternalProcessPaths(const std::shared_ptr<BuildConfigResult> &result) {
QStringList paths;
for (const auto &extR: result->extRs) {
auto path = extR->program;
@@ -54,15 +54,15 @@ namespace NekoRay {
// Common
QSharedPointer<BuildConfigResult> BuildConfig(const QSharedPointer<ProxyEntity> &ent, bool forTest, bool forExport) {
auto result = QSharedPointer<BuildConfigResult>(new BuildConfigResult);
auto status = QSharedPointer<BuildConfigStatus>(new BuildConfigStatus);
std::shared_ptr<BuildConfigResult> BuildConfig(const std::shared_ptr<ProxyEntity> &ent, bool forTest, bool forExport) {
auto result = std::make_shared<BuildConfigResult>();
auto status = std::make_shared<BuildConfigStatus>();
status->ent = ent;
status->result = result;
status->forTest = forTest;
status->forExport = forExport;
auto customBean = dynamic_cast<fmt::CustomBean *>(ent->bean.get());
auto customBean = dynamic_cast<NekoGui_fmt::CustomBean *>(ent->bean.get());
if (customBean != nullptr && customBean->core == "internal-full") {
result->coreConfig = QString2QJsonObject(customBean->config_simple);
} else {
@@ -92,9 +92,9 @@ namespace NekoRay {
return result;
}
QString BuildChain(int chainId, const QSharedPointer<BuildConfigStatus> &status) {
QString BuildChain(int chainId, const std::shared_ptr<BuildConfigStatus> &status) {
// Make list
QList<QSharedPointer<ProxyEntity>> ents;
QList<std::shared_ptr<ProxyEntity>> ents;
auto ent = status->ent;
auto result = status->result;
@@ -155,7 +155,7 @@ namespace NekoRay {
// V2Ray
void BuildConfigV2Ray(const QSharedPointer<BuildConfigStatus> &status) {
void BuildConfigV2Ray(const std::shared_ptr<BuildConfigStatus> &status) {
// Log
auto logObj = QJsonObject{{"loglevel", dataStore->log_level}};
status->result->coreConfig.insert("log", logObj);
@@ -397,8 +397,8 @@ namespace NekoRay {
status->result->coreConfig.insert("stats", QJsonObject());
}
QString BuildChainInternal(int chainId, const QList<QSharedPointer<ProxyEntity>> &ents,
const QSharedPointer<BuildConfigStatus> &status) {
QString BuildChainInternal(int chainId, const QList<std::shared_ptr<ProxyEntity>> &ents,
const std::shared_ptr<BuildConfigStatus> &status) {
QString chainTag = "c-" + Int2String(chainId);
QString chainTagOut;
bool muxApplied = false;
@@ -550,7 +550,7 @@ namespace NekoRay {
// Outbound
QJsonObject outbound;
auto stream = GetStreamSettings(ent->bean.data());
auto stream = GetStreamSettings(ent->bean.get());
if (thisExternalStat > 0) {
auto extR = ent->bean->BuildExternal(ext_mapping_port, ext_socks_port, thisExternalStat);
@@ -563,7 +563,7 @@ namespace NekoRay {
return {};
}
extR.tag = ent->bean->DisplayType();
status->result->extRs.emplace_back(std::make_shared<fmt::ExternalBuildResult>(extR));
status->result->extRs.emplace_back(std::make_shared<NekoGui_fmt::ExternalBuildResult>(extR));
// SOCKS OUTBOUND
if (IS_NEKO_BOX) {
@@ -664,7 +664,7 @@ namespace NekoRay {
// Bypass Lookup for the first profile
auto serverAddress = ent->bean->serverAddress;
auto customBean = dynamic_cast<fmt::CustomBean *>(ent->bean.get());
auto customBean = dynamic_cast<NekoGui_fmt::CustomBean *>(ent->bean.get());
if (customBean != nullptr && customBean->core == "internal") {
auto server = QString2QJsonObject(customBean->config_simple)["server"].toString();
if (!server.isEmpty()) serverAddress = server;
@@ -685,7 +685,7 @@ namespace NekoRay {
// SingBox
void BuildConfigSingBox(const QSharedPointer<BuildConfigStatus> &status) {
void BuildConfigSingBox(const std::shared_ptr<BuildConfigStatus> &status) {
// Log
status->result->coreConfig["log"] = QJsonObject{{"level", dataStore->log_level}};
@@ -921,7 +921,7 @@ namespace NekoRay {
// tun user rule
if (IS_NEKO_BOX_INTERNAL_TUN && dataStore->spmode_vpn) {
auto match_out = NekoRay::dataStore->vpn_rule_white ? "proxy" : "bypass";
auto match_out = dataStore->vpn_rule_white ? "proxy" : "bypass";
QString process_name_rule = dataStore->vpn_rule_process.trimmed();
if (!process_name_rule.isEmpty()) {
@@ -984,10 +984,10 @@ namespace NekoRay {
// experimental
QJsonObject experimentalObj;
if (!status->forTest && NekoRay::dataStore->core_box_clash_api > 0) {
if (!status->forTest && dataStore->core_box_clash_api > 0) {
QJsonObject clash_api = {
{"external_controller", "127.0.0.1:" + Int2String(NekoRay::dataStore->core_box_clash_api)},
{"secret", NekoRay::dataStore->core_box_clash_api_secret},
{"external_controller", "127.0.0.1:" + Int2String(dataStore->core_box_clash_api)},
{"secret", dataStore->core_box_clash_api_secret},
{"external_ui", "dashboard"},
};
experimentalObj["clash_api"] = clash_api;
@@ -998,8 +998,8 @@ namespace NekoRay {
QString WriteVPNSingBoxConfig() {
// tun user rule
auto match_out = NekoRay::dataStore->vpn_rule_white ? "nekoray-socks" : "direct";
auto no_match_out = NekoRay::dataStore->vpn_rule_white ? "direct" : "nekoray-socks";
auto match_out = dataStore->vpn_rule_white ? "nekoray-socks" : "direct";
auto no_match_out = dataStore->vpn_rule_white ? "direct" : "nekoray-socks";
QString process_name_rule = dataStore->vpn_rule_process.trimmed();
if (!process_name_rule.isEmpty()) {
@@ -1090,4 +1090,4 @@ namespace NekoRay {
return QFileInfo(file2).absoluteFilePath();
}
} // namespace NekoRay
} // namespace NekoGui

View File

@@ -3,23 +3,23 @@
#include "ProxyEntity.hpp"
#include "sys/ExternalProcess.hpp"
namespace NekoRay {
namespace NekoGui {
class BuildConfigResult {
public:
QString error;
QJsonObject coreConfig;
QList<QSharedPointer<traffic::TrafficData>> outboundStats; // all, but not including "bypass" "block"
QSharedPointer<traffic::TrafficData> outboundStat; // main
QList<std::shared_ptr<NekoGui_traffic::TrafficData>> outboundStats; // all, but not including "bypass" "block"
std::shared_ptr<NekoGui_traffic::TrafficData> outboundStat; // main
QStringList ignoreConnTag;
std::list<std::shared_ptr<NekoRay::fmt::ExternalBuildResult>> extRs;
std::list<std::shared_ptr<NekoGui_fmt::ExternalBuildResult>> extRs;
};
class BuildConfigStatus {
public:
QSharedPointer<BuildConfigResult> result;
QSharedPointer<ProxyEntity> ent;
std::shared_ptr<BuildConfigResult> result;
std::shared_ptr<ProxyEntity> ent;
bool forTest;
bool forExport;
@@ -44,18 +44,18 @@ namespace NekoRay {
QJsonArray outbounds;
};
QSharedPointer<BuildConfigResult> BuildConfig(const QSharedPointer<ProxyEntity> &ent, bool forTest, bool forExport);
std::shared_ptr<BuildConfigResult> BuildConfig(const std::shared_ptr<ProxyEntity> &ent, bool forTest, bool forExport);
void BuildConfigV2Ray(const QSharedPointer<BuildConfigStatus> &status);
void BuildConfigV2Ray(const std::shared_ptr<BuildConfigStatus> &status);
void BuildConfigSingBox(const QSharedPointer<BuildConfigStatus> &status);
void BuildConfigSingBox(const std::shared_ptr<BuildConfigStatus> &status);
QString BuildChain(int chainId, const QSharedPointer<BuildConfigStatus> &status);
QString BuildChain(int chainId, const std::shared_ptr<BuildConfigStatus> &status);
QString BuildChainInternal(int chainId, const QList<QSharedPointer<ProxyEntity>> &ents,
const QSharedPointer<BuildConfigStatus> &status);
QString BuildChainInternal(int chainId, const QList<std::shared_ptr<ProxyEntity>> &ents,
const std::shared_ptr<BuildConfigStatus> &status);
QString WriteVPNSingBoxConfig();
QString WriteVPNLinuxScript(const QString &protectPath, const QString &configPath);
} // namespace NekoRay
} // namespace NekoGui

View File

@@ -5,7 +5,7 @@
#include <QFile>
#include <QColor>
namespace NekoRay {
namespace NekoGui {
ProfileManager *profileManager = new ProfileManager();
@@ -40,7 +40,7 @@ namespace NekoRay {
void ProfileManager::SaveManager() {
}
QSharedPointer<ProxyEntity> ProfileManager::LoadProxyEntity(const QString &jsonPath) {
std::shared_ptr<ProxyEntity> ProfileManager::LoadProxyEntity(const QString &jsonPath) {
// Load type
ProxyEntity ent0(nullptr, nullptr);
ent0.fn = jsonPath;
@@ -48,7 +48,7 @@ namespace NekoRay {
auto type = ent0.type;
// Load content
QSharedPointer<ProxyEntity> ent;
std::shared_ptr<ProxyEntity> ent;
bool validType = validJson;
if (validType) {
@@ -66,45 +66,45 @@ namespace NekoRay {
// 新建的不给 fn 和 id
QSharedPointer<ProxyEntity> ProfileManager::NewProxyEntity(const QString &type) {
fmt::AbstractBean *bean;
std::shared_ptr<ProxyEntity> ProfileManager::NewProxyEntity(const QString &type) {
NekoGui_fmt::AbstractBean *bean;
if (type == "socks") {
bean = new fmt::SocksHttpBean(NekoRay::fmt::SocksHttpBean::type_Socks5);
bean = new NekoGui_fmt::SocksHttpBean(NekoGui_fmt::SocksHttpBean::type_Socks5);
} else if (type == "http") {
bean = new fmt::SocksHttpBean(NekoRay::fmt::SocksHttpBean::type_HTTP);
bean = new NekoGui_fmt::SocksHttpBean(NekoGui_fmt::SocksHttpBean::type_HTTP);
} else if (type == "shadowsocks") {
bean = new fmt::ShadowSocksBean();
bean = new NekoGui_fmt::ShadowSocksBean();
} else if (type == "chain") {
bean = new fmt::ChainBean();
bean = new NekoGui_fmt::ChainBean();
} else if (type == "vmess") {
bean = new fmt::VMessBean();
bean = new NekoGui_fmt::VMessBean();
} else if (type == "trojan") {
bean = new fmt::TrojanVLESSBean(fmt::TrojanVLESSBean::proxy_Trojan);
bean = new NekoGui_fmt::TrojanVLESSBean(NekoGui_fmt::TrojanVLESSBean::proxy_Trojan);
} else if (type == "vless") {
bean = new fmt::TrojanVLESSBean(fmt::TrojanVLESSBean::proxy_VLESS);
bean = new NekoGui_fmt::TrojanVLESSBean(NekoGui_fmt::TrojanVLESSBean::proxy_VLESS);
} else if (type == "naive") {
bean = new fmt::NaiveBean();
bean = new NekoGui_fmt::NaiveBean();
} else if (type == "hysteria") {
bean = new fmt::HysteriaBean();
bean = new NekoGui_fmt::HysteriaBean();
} else if (type == "custom") {
bean = new fmt::CustomBean();
bean = new NekoGui_fmt::CustomBean();
} else {
bean = new fmt::AbstractBean(-114514);
bean = new NekoGui_fmt::AbstractBean(-114514);
}
auto ent = QSharedPointer<ProxyEntity>(new ProxyEntity(bean, type));
auto ent = std::make_shared<ProxyEntity>(bean, type);
return ent;
}
QSharedPointer<Group> ProfileManager::NewGroup() {
auto ent = QSharedPointer<Group>(new Group());
std::shared_ptr<Group> ProfileManager::NewGroup() {
auto ent = std::make_shared<Group>();
return ent;
}
// ProxyEntity
ProxyEntity::ProxyEntity(fmt::AbstractBean *bean, const QString &type_) {
ProxyEntity::ProxyEntity(NekoGui_fmt::AbstractBean *bean, const QString &type_) {
if (type_ != nullptr) this->type = type_;
_add(new configItem("type", &type, itemType::string));
@@ -115,7 +115,7 @@ namespace NekoRay {
// 可以不关联 bean只加载 ProxyEntity 的信息
if (bean != nullptr) {
this->bean = QSharedPointer<fmt::AbstractBean>(bean);
this->bean = std::shared_ptr<NekoGui_fmt::AbstractBean>(bean);
// 有虚函数就要在这里 dynamic_cast
_add(new configItem("bean", dynamic_cast<JsonStore *>(bean), itemType::jsonStore));
_add(new configItem("traffic", dynamic_cast<JsonStore *>(traffic_data.get()), itemType::jsonStore));
@@ -158,7 +158,7 @@ namespace NekoRay {
}
}
bool ProfileManager::AddProfile(const QSharedPointer<ProxyEntity> &ent, int gid) {
bool ProfileManager::AddProfile(const std::shared_ptr<ProxyEntity> &ent, int gid) {
if (ent->id >= 0) {
return false;
}
@@ -183,7 +183,7 @@ namespace NekoRay {
QFile(QString("profiles/%1.json").arg(id)).remove();
}
void ProfileManager::MoveProfile(const QSharedPointer<ProxyEntity> &ent, int gid) {
void ProfileManager::MoveProfile(const std::shared_ptr<ProxyEntity> &ent, int gid) {
if (gid == ent->gid || gid < 0) return;
auto oldGroup = GetGroup(ent->gid);
if (oldGroup != nullptr && !oldGroup->order.isEmpty()) {
@@ -199,7 +199,7 @@ namespace NekoRay {
ent->Save();
}
QSharedPointer<ProxyEntity> ProfileManager::GetProfile(int id) {
std::shared_ptr<ProxyEntity> ProfileManager::GetProfile(int id) {
return profiles.value(id, nullptr);
}
@@ -212,13 +212,13 @@ namespace NekoRay {
_add(new configItem("order", &order, itemType::integerList));
_add(new configItem("url", &url, itemType::string));
_add(new configItem("info", &info, itemType::string));
_add(new configItem("lastup", &last_update, itemType::integer64));
_add(new configItem("lastup", &sub_last_update, itemType::integer64));
_add(new configItem("manually_column_width", &manually_column_width, itemType::boolean));
_add(new configItem("column_width", &column_width, itemType::integerList));
}
QSharedPointer<Group> ProfileManager::LoadGroup(const QString &jsonPath) {
QSharedPointer<Group> ent = QSharedPointer<Group>(new Group());
std::shared_ptr<Group> ProfileManager::LoadGroup(const QString &jsonPath) {
auto ent = std::make_shared<Group>();
ent->fn = jsonPath;
ent->Load();
return ent;
@@ -232,7 +232,7 @@ namespace NekoRay {
}
}
bool ProfileManager::AddGroup(const QSharedPointer<Group> &ent) {
bool ProfileManager::AddGroup(const std::shared_ptr<Group> &ent) {
if (ent->id >= 0) {
return false;
}
@@ -262,27 +262,27 @@ namespace NekoRay {
QFile(QString("groups/%1.json").arg(gid)).remove();
}
QSharedPointer<Group> ProfileManager::GetGroup(int id) {
std::shared_ptr<Group> ProfileManager::GetGroup(int id) {
return groups.value(id, nullptr);
}
QSharedPointer<Group> ProfileManager::CurrentGroup() {
return GetGroup(NekoRay::dataStore->current_group);
std::shared_ptr<Group> ProfileManager::CurrentGroup() {
return GetGroup(dataStore->current_group);
}
QList<QSharedPointer<ProxyEntity>> Group::Profiles() const {
QList<QSharedPointer<ProxyEntity>> ret;
QList<std::shared_ptr<ProxyEntity>> Group::Profiles() const {
QList<std::shared_ptr<ProxyEntity>> ret;
for (const auto &ent: profileManager->profiles) {
if (id == ent->gid) ret += ent;
}
return ret;
}
QList<QSharedPointer<ProxyEntity>> Group::ProfilesWithOrder() const {
QList<std::shared_ptr<ProxyEntity>> Group::ProfilesWithOrder() const {
if (order.isEmpty()) {
return Profiles();
} else {
QList<QSharedPointer<ProxyEntity>> ret;
QList<std::shared_ptr<ProxyEntity>> ret;
for (auto _id: order) {
auto ent = profileManager->GetProfile(_id);
if (ent != nullptr) ret += ent;
@@ -291,4 +291,4 @@ namespace NekoRay {
}
}
} // namespace NekoRay
} // namespace NekoGui

View File

@@ -1,15 +1,15 @@
#pragma once
#include "main/NekoRay.hpp"
#include "main/NekoGui.hpp"
#include "ProxyEntity.hpp"
#include "Group.hpp"
namespace NekoRay {
namespace NekoGui {
class ProfileManager : public JsonStore {
public:
// Manager
QMap<int, QSharedPointer<ProxyEntity>> profiles;
QMap<int, QSharedPointer<Group>> groups;
QMap<int, std::shared_ptr<ProxyEntity>> profiles;
QMap<int, std::shared_ptr<Group>> groups;
// JSON
QList<int> _profiles;
@@ -17,25 +17,25 @@ namespace NekoRay {
ProfileManager();
[[nodiscard]] static QSharedPointer<ProxyEntity> NewProxyEntity(const QString &type);
[[nodiscard]] static std::shared_ptr<ProxyEntity> NewProxyEntity(const QString &type);
[[nodiscard]] static QSharedPointer<Group> NewGroup();
[[nodiscard]] static std::shared_ptr<Group> NewGroup();
bool AddProfile(const QSharedPointer<ProxyEntity> &ent, int gid = -1);
bool AddProfile(const std::shared_ptr<ProxyEntity> &ent, int gid = -1);
void DeleteProfile(int id);
void MoveProfile(const QSharedPointer<ProxyEntity> &ent, int gid);
void MoveProfile(const std::shared_ptr<ProxyEntity> &ent, int gid);
QSharedPointer<ProxyEntity> GetProfile(int id);
std::shared_ptr<ProxyEntity> GetProfile(int id);
bool AddGroup(const QSharedPointer<Group> &ent);
bool AddGroup(const std::shared_ptr<Group> &ent);
void DeleteGroup(int gid);
QSharedPointer<Group> GetGroup(int id);
std::shared_ptr<Group> GetGroup(int id);
QSharedPointer<Group> CurrentGroup();
std::shared_ptr<Group> CurrentGroup();
private:
void LoadManager();
@@ -46,10 +46,10 @@ namespace NekoRay {
[[nodiscard]] int NewGroupID() const;
static QSharedPointer<ProxyEntity> LoadProxyEntity(const QString &jsonPath);
static std::shared_ptr<ProxyEntity> LoadProxyEntity(const QString &jsonPath);
static QSharedPointer<Group> LoadGroup(const QString &jsonPath);
static std::shared_ptr<Group> LoadGroup(const QString &jsonPath);
};
extern ProfileManager *profileManager;
} // namespace NekoRay
} // namespace NekoGui

View File

@@ -1,9 +1,9 @@
#pragma once
#include "main/NekoRay.hpp"
#include "main/NekoGui.hpp"
#include "ProxyEntity.hpp"
namespace NekoRay {
namespace NekoGui {
class Group : public JsonStore {
public:
int id = -1;
@@ -11,7 +11,7 @@ namespace NekoRay {
QString name = "";
QString url = "";
QString info = "";
qint64 last_update = 0;
qint64 sub_last_update = 0;
// list ui
bool manually_column_width = false;
@@ -21,9 +21,9 @@ namespace NekoRay {
Group();
// 按 id 顺序
[[nodiscard]] QList<QSharedPointer<ProxyEntity>> Profiles() const;
[[nodiscard]] QList<std::shared_ptr<ProxyEntity>> Profiles() const;
// 按 显示 顺序
[[nodiscard]] QList<QSharedPointer<ProxyEntity>> ProfilesWithOrder() const;
[[nodiscard]] QList<std::shared_ptr<ProxyEntity>> ProfilesWithOrder() const;
};
} // namespace NekoRay
} // namespace NekoGui

View File

@@ -1,10 +1,10 @@
#include "ProfileFilter.hpp"
namespace NekoRay {
void ProfileFilter::Uniq(const QList<QSharedPointer<ProxyEntity>> &in,
QList<QSharedPointer<ProxyEntity>> &out,
namespace NekoGui {
void ProfileFilter::Uniq(const QList<std::shared_ptr<ProxyEntity>> &in,
QList<std::shared_ptr<ProxyEntity>> &out,
bool by_address, bool keep_last) {
QMap<QString, QSharedPointer<ProxyEntity>> hashMap;
QMap<QString, std::shared_ptr<ProxyEntity>> hashMap;
for (const auto &ent: in) {
QString key = by_address ? (ent->bean->DisplayAddress() + ent->bean->DisplayType())
@@ -22,11 +22,11 @@ namespace NekoRay {
}
}
void ProfileFilter::Common(const QList<QSharedPointer<ProxyEntity>> &src,
const QList<QSharedPointer<ProxyEntity>> &dst,
QList<QSharedPointer<ProxyEntity>> &out,
void ProfileFilter::Common(const QList<std::shared_ptr<ProxyEntity>> &src,
const QList<std::shared_ptr<ProxyEntity>> &dst,
QList<std::shared_ptr<ProxyEntity>> &out,
bool by_address, bool keep_last) {
QMap<QString, QSharedPointer<ProxyEntity>> hashMap;
QMap<QString, std::shared_ptr<ProxyEntity>> hashMap;
for (const auto &ent: src) {
QString key = by_address ? (ent->bean->DisplayAddress() + ent->bean->DisplayType())
@@ -46,9 +46,9 @@ namespace NekoRay {
}
}
void ProfileFilter::OnlyInSrc(const QList<QSharedPointer<ProxyEntity>> &src,
const QList<QSharedPointer<ProxyEntity>> &dst,
QList<QSharedPointer<ProxyEntity>> &out,
void ProfileFilter::OnlyInSrc(const QList<std::shared_ptr<ProxyEntity>> &src,
const QList<std::shared_ptr<ProxyEntity>> &dst,
QList<std::shared_ptr<ProxyEntity>> &out,
bool by_address) {
QMap<QString, bool> hashMap;
@@ -64,12 +64,12 @@ namespace NekoRay {
}
}
void ProfileFilter::OnlyInSrc_ByPointer(const QList<QSharedPointer<ProxyEntity>> &src,
const QList<QSharedPointer<ProxyEntity>> &dst,
QList<QSharedPointer<ProxyEntity>> &out) {
void ProfileFilter::OnlyInSrc_ByPointer(const QList<std::shared_ptr<ProxyEntity>> &src,
const QList<std::shared_ptr<ProxyEntity>> &dst,
QList<std::shared_ptr<ProxyEntity>> &out) {
for (const auto &ent: src) {
if (!dst.contains(ent)) out += ent;
}
}
} // namespace NekoRay
} // namespace NekoGui

View File

@@ -2,34 +2,34 @@
#include "ProxyEntity.hpp"
namespace NekoRay {
namespace NekoGui {
class ProfileFilter {
public:
static void Uniq(
const QList<QSharedPointer<ProxyEntity>> &in,
QList<QSharedPointer<ProxyEntity>> &out,
const QList<std::shared_ptr<ProxyEntity>> &in,
QList<std::shared_ptr<ProxyEntity>> &out,
bool by_address = false, // def by bean
bool keep_last = false // def keep first
);
static void Common(
const QList<QSharedPointer<ProxyEntity>> &src,
const QList<QSharedPointer<ProxyEntity>> &dst,
QList<QSharedPointer<ProxyEntity>> &out,
const QList<std::shared_ptr<ProxyEntity>> &src,
const QList<std::shared_ptr<ProxyEntity>> &dst,
QList<std::shared_ptr<ProxyEntity>> &out,
bool by_address = false, // def by bean
bool keep_last = false // def keep first
);
static void OnlyInSrc(
const QList<QSharedPointer<ProxyEntity>> &src,
const QList<QSharedPointer<ProxyEntity>> &dst,
QList<QSharedPointer<NekoRay::ProxyEntity>> &out,
const QList<std::shared_ptr<ProxyEntity>> &src,
const QList<std::shared_ptr<ProxyEntity>> &dst,
QList<std::shared_ptr<ProxyEntity>> &out,
bool by_address = false // def by bean
);
static void OnlyInSrc_ByPointer(
const QList<QSharedPointer<ProxyEntity>> &src,
const QList<QSharedPointer<ProxyEntity>> &dst,
QList<QSharedPointer<ProxyEntity>> &out);
const QList<std::shared_ptr<ProxyEntity>> &src,
const QList<std::shared_ptr<ProxyEntity>> &dst,
QList<std::shared_ptr<ProxyEntity>> &out);
};
} // namespace NekoRay
} // namespace NekoGui

View File

@@ -1,28 +1,28 @@
#pragma once
#include "main/NekoRay.hpp"
#include "TrafficData.hpp"
#include "main/NekoGui.hpp"
#include "db/traffic/TrafficData.hpp"
#include "fmt/AbstractBean.hpp"
namespace NekoRay {
namespace fmt {
class SocksHttpBean;
namespace NekoGui_fmt {
class SocksHttpBean;
class ShadowSocksBean;
class ShadowSocksBean;
class VMessBean;
class VMessBean;
class TrojanVLESSBean;
class TrojanVLESSBean;
class NaiveBean;
class NaiveBean;
class HysteriaBean;
class HysteriaBean;
class CustomBean;
class CustomBean;
class ChainBean;
}; // namespace fmt
class ChainBean;
}; // namespace NekoGui_fmt
namespace NekoGui {
class ProxyEntity : public JsonStore {
public:
QString type;
@@ -30,47 +30,47 @@ namespace NekoRay {
int id = -1;
int gid = 0;
int latency = 0;
QSharedPointer<fmt::AbstractBean> bean;
QSharedPointer<traffic::TrafficData> traffic_data = QSharedPointer<traffic::TrafficData>(new traffic::TrafficData(""));
std::shared_ptr<NekoGui_fmt::AbstractBean> bean;
std::shared_ptr<NekoGui_traffic::TrafficData> traffic_data = std::make_shared<NekoGui_traffic::TrafficData>("");
QString full_test_report;
ProxyEntity(fmt::AbstractBean *bean, const QString &type_);
ProxyEntity(NekoGui_fmt::AbstractBean *bean, const QString &type_);
[[nodiscard]] QString DisplayLatency() const;
[[nodiscard]] QColor DisplayLatencyColor() const;
[[nodiscard]] fmt::ChainBean *ChainBean() const {
return (fmt::ChainBean *) bean.get();
[[nodiscard]] NekoGui_fmt::ChainBean *ChainBean() const {
return (NekoGui_fmt::ChainBean *) bean.get();
};
[[nodiscard]] fmt::SocksHttpBean *SocksHTTPBean() const {
return (fmt::SocksHttpBean *) bean.get();
[[nodiscard]] NekoGui_fmt::SocksHttpBean *SocksHTTPBean() const {
return (NekoGui_fmt::SocksHttpBean *) bean.get();
};
[[nodiscard]] fmt::ShadowSocksBean *ShadowSocksBean() const {
return (fmt::ShadowSocksBean *) bean.get();
[[nodiscard]] NekoGui_fmt::ShadowSocksBean *ShadowSocksBean() const {
return (NekoGui_fmt::ShadowSocksBean *) bean.get();
};
[[nodiscard]] fmt::VMessBean *VMessBean() const {
return (fmt::VMessBean *) bean.get();
[[nodiscard]] NekoGui_fmt::VMessBean *VMessBean() const {
return (NekoGui_fmt::VMessBean *) bean.get();
};
[[nodiscard]] fmt::TrojanVLESSBean *TrojanVLESSBean() const {
return (fmt::TrojanVLESSBean *) bean.get();
[[nodiscard]] NekoGui_fmt::TrojanVLESSBean *TrojanVLESSBean() const {
return (NekoGui_fmt::TrojanVLESSBean *) bean.get();
};
[[nodiscard]] fmt::NaiveBean *NaiveBean() const {
return (fmt::NaiveBean *) bean.get();
[[nodiscard]] NekoGui_fmt::NaiveBean *NaiveBean() const {
return (NekoGui_fmt::NaiveBean *) bean.get();
};
[[nodiscard]] fmt::HysteriaBean *HysteriaBean() const {
return (fmt::HysteriaBean *) bean.get();
[[nodiscard]] NekoGui_fmt::HysteriaBean *HysteriaBean() const {
return (NekoGui_fmt::HysteriaBean *) bean.get();
};
[[nodiscard]] fmt::CustomBean *CustomBean() const {
return (fmt::CustomBean *) bean.get();
[[nodiscard]] NekoGui_fmt::CustomBean *CustomBean() const {
return (NekoGui_fmt::CustomBean *) bean.get();
};
};
} // namespace NekoRay
} // namespace NekoGui

View File

@@ -1,8 +1,8 @@
#pragma once
#include "main/NekoRay.hpp"
#include "main/NekoGui.hpp"
namespace NekoRay::traffic {
namespace NekoGui_traffic {
class TrafficData : public JsonStore {
public:
int id = -1; // ent id
@@ -37,4 +37,4 @@ namespace NekoRay::traffic {
return UNICODE_LRO + QString("%1↑ %2↓").arg(ReadableSize(uplink), ReadableSize(downlink));
}
};
} // namespace NekoRay::traffic
} // namespace NekoGui_traffic

View File

@@ -9,7 +9,7 @@
#include <QJsonDocument>
#include <QElapsedTimer>
namespace NekoRay::traffic {
namespace NekoGui_traffic {
TrafficLooper *trafficLooper = new TrafficLooper;
QElapsedTimer elapsedTimer;
@@ -23,8 +23,8 @@ namespace NekoRay::traffic {
if (interval <= 0) return nullptr;
// query
auto uplink = NekoRay::rpc::defaultClient->QueryStats(item->tag, "uplink");
auto downlink = NekoRay::rpc::defaultClient->QueryStats(item->tag, "downlink");
auto uplink = NekoGui_rpc::defaultClient->QueryStats(item->tag, "uplink");
auto downlink = NekoGui_rpc::defaultClient->QueryStats(item->tag, "downlink");
// add diff
item->downlink += downlink;
@@ -45,7 +45,7 @@ namespace NekoRay::traffic {
QJsonArray TrafficLooper::get_connection_list() {
#ifndef NKR_NO_GRPC
auto str = NekoRay::rpc::defaultClient->ListConnections();
auto str = NekoGui_rpc::defaultClient->ListConnections();
QJsonDocument jsonDocument = QJsonDocument::fromJson(str.c_str());
return jsonDocument.array();
#else
@@ -79,10 +79,10 @@ namespace NekoRay::traffic {
void TrafficLooper::Loop() {
elapsedTimer.start();
while (true) {
auto sleep_ms = dataStore->traffic_loop_interval;
auto sleep_ms = NekoGui::dataStore->traffic_loop_interval;
if (sleep_ms < 500 || sleep_ms > 5000) sleep_ms = 1000;
QThread::msleep(sleep_ms);
if (dataStore->traffic_loop_interval == 0) continue; // user disabled
if (NekoGui::dataStore->traffic_loop_interval == 0) continue; // user disabled
// profile start and stop
if (!loop_enabled) {
@@ -109,7 +109,7 @@ namespace NekoRay::traffic {
// do conn list update
QJsonArray conn_list;
if (dataStore->connection_statistics) {
if (NekoGui::dataStore->connection_statistics) {
conn_list = get_connection_list();
}
@@ -125,11 +125,11 @@ namespace NekoRay::traffic {
if (item->id < 0) continue;
m->refresh_proxy_list(item->id);
}
if (dataStore->connection_statistics) {
if (NekoGui::dataStore->connection_statistics) {
m->refresh_connection_list(conn_list);
}
});
}
}
} // namespace NekoRay::traffic
} // namespace NekoGui_traffic

View File

@@ -1,20 +1,19 @@
#pragma once
#include <QSharedPointer>
#include <QString>
#include <QList>
#include <QMutex>
#include "TrafficData.hpp"
namespace NekoRay::traffic {
namespace NekoGui_traffic {
class TrafficLooper {
public:
bool loop_enabled = false;
bool looping = false;
QMutex loop_mutex;
QList<QSharedPointer<TrafficData>> items;
QList<std::shared_ptr<TrafficData>> items;
TrafficData *proxy = nullptr;
void UpdateAll();
@@ -30,4 +29,4 @@ namespace NekoRay::traffic {
};
extern TrafficLooper *trafficLooper;
} // namespace NekoRay::traffic
} // namespace NekoGui_traffic