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