mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 12:34:37 +03:00
refactor mux
This commit is contained in:
@@ -546,6 +546,7 @@ namespace NekoRay {
|
|||||||
// Outbound
|
// Outbound
|
||||||
|
|
||||||
QJsonObject outbound;
|
QJsonObject outbound;
|
||||||
|
auto stream = GetStreamSettings(ent->bean.data());
|
||||||
|
|
||||||
if (thisExternalStat > 0) {
|
if (thisExternalStat > 0) {
|
||||||
const auto extR = ent->bean->BuildExternal(ext_mapping_port, ext_socks_port, thisExternalStat);
|
const auto extR = ent->bean->BuildExternal(ext_mapping_port, ext_socks_port, thisExternalStat);
|
||||||
@@ -601,33 +602,52 @@ namespace NekoRay {
|
|||||||
ent->traffic_data->tag = tagOut.toStdString();
|
ent->traffic_data->tag = tagOut.toStdString();
|
||||||
status->result->outboundStats += ent->traffic_data;
|
status->result->outboundStats += ent->traffic_data;
|
||||||
|
|
||||||
|
// mux common
|
||||||
|
auto needMux = ent->type == "vmess" || ent->type == "trojan" || ent->type == "vless";
|
||||||
|
needMux &= !dataStore->mux_protocol.isEmpty() && dataStore->mux_concurrency > 0;
|
||||||
|
|
||||||
|
if (stream != nullptr) {
|
||||||
|
if (IS_NEKO_BOX) {
|
||||||
|
if (stream->network == "grpc" || stream->network == "quic" || (stream->network == "http" && stream->security == "tls")) {
|
||||||
|
needMux = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (stream->network == "grpc" || stream->network == "quic") {
|
||||||
|
needMux = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// common
|
||||||
if (IS_NEKO_BOX) {
|
if (IS_NEKO_BOX) {
|
||||||
// apply domain_strategy
|
// apply domain_strategy
|
||||||
outbound["domain_strategy"] = dataStore->outbound_domain_strategy;
|
outbound["domain_strategy"] = dataStore->outbound_domain_strategy;
|
||||||
// TODO apply mux
|
|
||||||
} else {
|
|
||||||
if (!status->forTest) outbound["domainStrategy"] = dataStore->outbound_domain_strategy;
|
|
||||||
// apply mux
|
// apply mux
|
||||||
if (dataStore->mux_cool > 0 && !muxApplied) {
|
if (!muxApplied && needMux) {
|
||||||
// TODO refactor mux settings
|
|
||||||
if (ent->type == "vmess" || ent->type == "trojan" || ent->type == "vless") {
|
|
||||||
auto muxObj = QJsonObject{
|
auto muxObj = QJsonObject{
|
||||||
{"enabled", true},
|
{"enabled", true},
|
||||||
{"concurrency", dataStore->mux_cool},
|
{"protocol", dataStore->mux_protocol},
|
||||||
|
{"max_streams", dataStore->mux_concurrency},
|
||||||
|
};
|
||||||
|
outbound["multiplex"] = muxObj;
|
||||||
|
muxApplied = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// apply domain_strategy
|
||||||
|
if (!status->forTest) outbound["domainStrategy"] = dataStore->outbound_domain_strategy;
|
||||||
|
// apply mux
|
||||||
|
if (!muxApplied && needMux) {
|
||||||
|
auto muxObj = QJsonObject{
|
||||||
|
{"enabled", true},
|
||||||
|
{"concurrency", dataStore->mux_concurrency},
|
||||||
};
|
};
|
||||||
auto stream = GetStreamSettings(ent->bean.data());
|
|
||||||
if (stream != nullptr && !stream->packet_encoding.isEmpty()) {
|
if (stream != nullptr && !stream->packet_encoding.isEmpty()) {
|
||||||
muxObj["packetEncoding"] = stream->packet_encoding;
|
muxObj["packetEncoding"] = stream->packet_encoding;
|
||||||
}
|
}
|
||||||
if (stream != nullptr && stream->network == "grpc") {
|
|
||||||
// ignore mux.cool for gRPC
|
|
||||||
} else {
|
|
||||||
outbound["mux"] = muxObj;
|
outbound["mux"] = muxObj;
|
||||||
muxApplied = true;
|
muxApplied = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// apply custom outbound settings
|
// apply custom outbound settings
|
||||||
MergeJson(QString2QJsonObject(ent->bean->custom_outbound), outbound);
|
MergeJson(QString2QJsonObject(ent->bean->custom_outbound), outbound);
|
||||||
|
|||||||
@@ -36,8 +36,10 @@
|
|||||||
ui->a->setText(Int2String(NekoRay::dataStore->a)); \
|
ui->a->setText(Int2String(NekoRay::dataStore->a)); \
|
||||||
ui->a->setValidator(QRegExpValidator_Number);
|
ui->a->setValidator(QRegExpValidator_Number);
|
||||||
#define D_SAVE_INT(a) NekoRay::dataStore->a = ui->a->text().toInt();
|
#define D_SAVE_INT(a) NekoRay::dataStore->a = ui->a->text().toInt();
|
||||||
#define P_LOAD_COMBO_STR(a) ui->a->setCurrentText(bean->a);
|
#define P_LOAD_COMBO_STRING(a) ui->a->setCurrentText(bean->a);
|
||||||
#define P_SAVE_COMBO_STR(a) bean->a = ui->a->currentText();
|
#define P_SAVE_COMBO_STRING(a) bean->a = ui->a->currentText();
|
||||||
|
#define D_LOAD_COMBO_STRING(a) ui->a->setCurrentText(NekoRay::dataStore->a);
|
||||||
|
#define D_SAVE_COMBO_STRING(a) NekoRay::dataStore->a = ui->a->currentText();
|
||||||
#define P_LOAD_COMBO_INT(a) ui->a->setCurrentIndex(bean->a);
|
#define P_LOAD_COMBO_INT(a) ui->a->setCurrentIndex(bean->a);
|
||||||
#define P_SAVE_COMBO_INT(a) bean->a = ui->a->currentIndex();
|
#define P_SAVE_COMBO_INT(a) bean->a = ui->a->currentIndex();
|
||||||
#define D_LOAD_BOOL(a) ui->a->setChecked(NekoRay::dataStore->a);
|
#define D_LOAD_BOOL(a) ui->a->setChecked(NekoRay::dataStore->a);
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ namespace NekoRay {
|
|||||||
_add(new configItem("domain_strategy", &domain_strategy, itemType::string));
|
_add(new configItem("domain_strategy", &domain_strategy, itemType::string));
|
||||||
_add(new configItem("outbound_domain_strategy", &outbound_domain_strategy, itemType::string));
|
_add(new configItem("outbound_domain_strategy", &outbound_domain_strategy, itemType::string));
|
||||||
_add(new configItem("sniffing_mode", &sniffing_mode, itemType::integer));
|
_add(new configItem("sniffing_mode", &sniffing_mode, itemType::integer));
|
||||||
_add(new configItem("mux_cool", &mux_cool, itemType::integer));
|
_add(new configItem("mux_protocol", &mux_protocol, itemType::string));
|
||||||
|
_add(new configItem("mux_concurrency", &mux_concurrency, itemType::integer));
|
||||||
_add(new configItem("traffic_loop_interval", &traffic_loop_interval, itemType::integer));
|
_add(new configItem("traffic_loop_interval", &traffic_loop_interval, itemType::integer));
|
||||||
_add(new configItem("dns_routing", &dns_routing, itemType::boolean));
|
_add(new configItem("dns_routing", &dns_routing, itemType::boolean));
|
||||||
_add(new configItem("test_concurrent", &test_concurrent, itemType::integer));
|
_add(new configItem("test_concurrent", &test_concurrent, itemType::integer));
|
||||||
|
|||||||
@@ -82,7 +82,8 @@ namespace NekoRay {
|
|||||||
int traffic_loop_interval = 500;
|
int traffic_loop_interval = 500;
|
||||||
bool connection_statistics = false;
|
bool connection_statistics = false;
|
||||||
int current_group = 0; // group id
|
int current_group = 0; // group id
|
||||||
int mux_cool = -8;
|
QString mux_protocol = "";
|
||||||
|
int mux_concurrency = 8;
|
||||||
QString theme = "0";
|
QString theme = "0";
|
||||||
QString v2ray_asset_dir = "";
|
QString v2ray_asset_dir = "";
|
||||||
int language = 0;
|
int language = 0;
|
||||||
|
|||||||
@@ -59,23 +59,25 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
|
|||||||
// Common
|
// Common
|
||||||
|
|
||||||
if (IS_NEKO_BOX) {
|
if (IS_NEKO_BOX) {
|
||||||
ui->groupBox_mux->hide();
|
|
||||||
ui->groupBox_http->hide();
|
ui->groupBox_http->hide();
|
||||||
ui->inbound_socks_port_l->setText(ui->inbound_socks_port_l->text().replace("Socks", "Mixed"));
|
ui->inbound_socks_port_l->setText(ui->inbound_socks_port_l->text().replace("Socks", "Mixed"));
|
||||||
ui->hlayout_l2->addWidget(ui->groupBox_log);
|
ui->hlayout_l2->addWidget(ui->groupbox_custom_inbound);
|
||||||
ui->log_level->addItems(QString("trace debug info warn error fatal panic").split(" "));
|
ui->log_level->addItems(QString("trace debug info warn error fatal panic").split(" "));
|
||||||
|
ui->mux_protocol->addItems({"", "h2mux", "smux", "yamux"});
|
||||||
} else {
|
} else {
|
||||||
ui->log_level->addItems({"debug", "info", "warning", "none"});
|
ui->log_level->addItems({"debug", "info", "warning", "none"});
|
||||||
|
ui->mux_protocol->addItems({"", "mux.cool"});
|
||||||
}
|
}
|
||||||
|
|
||||||
refresh_auth();
|
refresh_auth();
|
||||||
|
|
||||||
ui->socks_ip->setText(NekoRay::dataStore->inbound_address);
|
D_LOAD_STRING(inbound_address)
|
||||||
ui->log_level->setCurrentText(NekoRay::dataStore->log_level);
|
D_LOAD_COMBO_STRING(log_level)
|
||||||
CACHE.custom_inbound = NekoRay::dataStore->custom_inbound;
|
CACHE.custom_inbound = NekoRay::dataStore->custom_inbound;
|
||||||
D_LOAD_INT(inbound_socks_port)
|
D_LOAD_INT(inbound_socks_port)
|
||||||
D_LOAD_INT_ENABLE(inbound_http_port, http_enable)
|
D_LOAD_INT_ENABLE(inbound_http_port, http_enable)
|
||||||
D_LOAD_INT_ENABLE(mux_cool, mux_cool_enable)
|
D_LOAD_INT(mux_concurrency)
|
||||||
|
D_LOAD_COMBO_STRING(mux_protocol)
|
||||||
D_LOAD_INT(test_concurrent)
|
D_LOAD_INT(test_concurrent)
|
||||||
D_LOAD_STRING(test_url)
|
D_LOAD_STRING(test_url)
|
||||||
|
|
||||||
@@ -260,12 +262,13 @@ DialogBasicSettings::~DialogBasicSettings() {
|
|||||||
void DialogBasicSettings::accept() {
|
void DialogBasicSettings::accept() {
|
||||||
// Common
|
// Common
|
||||||
|
|
||||||
NekoRay::dataStore->inbound_address = ui->socks_ip->text();
|
D_SAVE_STRING(inbound_address)
|
||||||
NekoRay::dataStore->log_level = ui->log_level->currentText();
|
D_SAVE_COMBO_STRING(log_level)
|
||||||
NekoRay::dataStore->custom_inbound = CACHE.custom_inbound;
|
NekoRay::dataStore->custom_inbound = CACHE.custom_inbound;
|
||||||
D_SAVE_INT(inbound_socks_port)
|
D_SAVE_INT(inbound_socks_port)
|
||||||
D_SAVE_INT_ENABLE(inbound_http_port, http_enable)
|
D_SAVE_INT_ENABLE(inbound_http_port, http_enable)
|
||||||
D_SAVE_INT_ENABLE(mux_cool, mux_cool_enable)
|
D_SAVE_INT(mux_concurrency)
|
||||||
|
D_SAVE_COMBO_STRING(mux_protocol)
|
||||||
D_SAVE_INT(test_concurrent)
|
D_SAVE_INT(test_concurrent)
|
||||||
D_SAVE_STRING(test_url)
|
D_SAVE_STRING(test_url)
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_8">
|
<layout class="QHBoxLayout" name="hlayout_l1">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="horizontalGroupBox_3">
|
<widget class="QGroupBox" name="horizontalGroupBox_3">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_19">
|
<layout class="QHBoxLayout" name="horizontalLayout_19">
|
||||||
@@ -43,7 +43,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="socks_ip"/>
|
<widget class="QLineEdit" name="inbound_address"/>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="inbound_auth">
|
<widget class="QPushButton" name="inbound_auth">
|
||||||
@@ -56,7 +56,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="horizontalGroupBox_4">
|
<widget class="QGroupBox" name="groupbox_custom_inbound">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_10">
|
<layout class="QHBoxLayout" name="horizontalLayout_10">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_11">
|
<widget class="QLabel" name="label_11">
|
||||||
@@ -147,7 +147,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_11">
|
<layout class="QHBoxLayout" name="hlayout_l4">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="groupBox_log">
|
<widget class="QGroupBox" name="groupBox_log">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
@@ -170,16 +170,12 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_6">
|
<widget class="QLabel" name="label_6">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string notr="true">mux.cool</string>
|
<string notr="true">Mux</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="mux_cool_enable">
|
<widget class="QComboBox" name="mux_protocol"/>
|
||||||
<property name="text">
|
|
||||||
<string>Enable</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_7">
|
<widget class="QLabel" name="label_7">
|
||||||
@@ -189,7 +185,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="mux_cool"/>
|
<widget class="QLineEdit" name="mux_concurrency"/>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
|||||||
@@ -26,10 +26,10 @@ EditCustom::~EditCustom() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define SAVE_CUSTOM_BEAN \
|
#define SAVE_CUSTOM_BEAN \
|
||||||
P_SAVE_COMBO_STR(core) \
|
P_SAVE_COMBO_STRING(core) \
|
||||||
bean->command = ui->command->text().split(" "); \
|
bean->command = ui->command->text().split(" "); \
|
||||||
P_SAVE_STRING_QTEXTEDIT(config_simple) \
|
P_SAVE_STRING_QTEXTEDIT(config_simple) \
|
||||||
P_SAVE_COMBO_STR(config_suffix) \
|
P_SAVE_COMBO_STRING(config_suffix) \
|
||||||
P_SAVE_INT(mapping_port) \
|
P_SAVE_INT(mapping_port) \
|
||||||
P_SAVE_INT(socks_port)
|
P_SAVE_INT(socks_port)
|
||||||
|
|
||||||
@@ -60,10 +60,10 @@ void EditCustom::onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// load core ui
|
// load core ui
|
||||||
P_LOAD_COMBO_STR(core)
|
P_LOAD_COMBO_STRING(core)
|
||||||
ui->command->setText(bean->command.join(" "));
|
ui->command->setText(bean->command.join(" "));
|
||||||
P_LOAD_STRING(config_simple)
|
P_LOAD_STRING(config_simple)
|
||||||
P_LOAD_COMBO_STR(config_suffix)
|
P_LOAD_COMBO_STRING(config_suffix)
|
||||||
P_LOAD_INT(mapping_port)
|
P_LOAD_INT(mapping_port)
|
||||||
P_LOAD_INT(socks_port)
|
P_LOAD_INT(socks_port)
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ void EditNaive::onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) {
|
|||||||
|
|
||||||
P_LOAD_STRING(username);
|
P_LOAD_STRING(username);
|
||||||
P_LOAD_STRING(password);
|
P_LOAD_STRING(password);
|
||||||
P_LOAD_COMBO_STR(protocol);
|
P_LOAD_COMBO_STRING(protocol);
|
||||||
P_C_LOAD_STRING(extra_headers);
|
P_C_LOAD_STRING(extra_headers);
|
||||||
P_LOAD_STRING(sni);
|
P_LOAD_STRING(sni);
|
||||||
P_C_LOAD_STRING(certificate);
|
P_C_LOAD_STRING(certificate);
|
||||||
@@ -31,7 +31,7 @@ bool EditNaive::onEnd() {
|
|||||||
|
|
||||||
P_SAVE_STRING(username);
|
P_SAVE_STRING(username);
|
||||||
P_SAVE_STRING(password);
|
P_SAVE_STRING(password);
|
||||||
P_SAVE_COMBO_STR(protocol);
|
P_SAVE_COMBO_STRING(protocol);
|
||||||
P_C_SAVE_STRING(extra_headers);
|
P_C_SAVE_STRING(extra_headers);
|
||||||
P_SAVE_STRING(sni);
|
P_SAVE_STRING(sni);
|
||||||
P_C_SAVE_STRING(certificate);
|
P_C_SAVE_STRING(certificate);
|
||||||
|
|||||||
Reference in New Issue
Block a user