diff --git a/Build.Counter b/Build.Counter index 0f3c80e3..64b0edc1 100644 --- a/Build.Counter +++ b/Build.Counter @@ -1 +1 @@ -3005 +3011 diff --git a/src/Qv2rayBase.hpp b/src/Qv2rayBase.hpp index 34d4ab0d..3628558d 100644 --- a/src/Qv2rayBase.hpp +++ b/src/Qv2rayBase.hpp @@ -9,7 +9,7 @@ #include "QvTinyLog.hpp" #include "QvCoreConfigObjects.hpp" -const int QV2RAY_CONFIG_VERSION = 6; +const int QV2RAY_CONFIG_VERSION = 7; // Linux users and DEs should handle the darkMode UI themselves. #ifndef QV2RAY_USE_BUILTIN_DARKTHEME @@ -189,11 +189,17 @@ namespace Qv2ray bool enableProxy; bool withLocalDNS; QList dnsList; - int statsPort; Qv2rayForwardProxyConfig forwardProxyConfig; - Qv2rayConnectionConfig() : bypassCN(true), enableProxy(true), withLocalDNS(false), dnsList(QStringList() << "8.8.4.4" << "1.1.1.1"), statsPort(15490) { } - XTOSTRUCT(O(bypassCN, enableProxy, withLocalDNS, dnsList, statsPort, forwardProxyConfig)) + Qv2rayConnectionConfig() : bypassCN(true), enableProxy(true), withLocalDNS(false), dnsList(QStringList() << "8.8.4.4" << "1.1.1.1") { } + XTOSTRUCT(O(bypassCN, enableProxy, withLocalDNS, dnsList, forwardProxyConfig)) + }; + + struct Qv2rayAPIConfig { + bool enableAPI; + int statsPort; + Qv2rayAPIConfig(): enableAPI(true), statsPort(15490) { } + XTOSTRUCT(O(enableAPI, statsPort)) }; struct Qv2rayConfig { @@ -210,6 +216,7 @@ namespace Qv2ray QMap subscriptions; // Qv2rayUIConfig uiConfig; + Qv2rayAPIConfig apiConfig; Qv2rayInboundsConfig inboundConfig; Qv2rayConnectionConfig connectionConfig; Qv2rayToolBarConfig toolBarConfig; diff --git a/src/QvConfigUpgrade.cpp b/src/QvConfigUpgrade.cpp index 592f25f5..6327f2ce 100644 --- a/src/QvConfigUpgrade.cpp +++ b/src/QvConfigUpgrade.cpp @@ -123,6 +123,16 @@ namespace Qv2ray root["subscriptions"] = newSubscriptions; break; } + + // Qv2ray version 2, RC 4 + case 6: { + // Moved API Stats port from connectionConfig to apiConfig + QJsonObject apiConfig; + apiConfig["enableAPI"] = true; + apiConfig["statsPort"] = root["connectionConfig"].toObject()["statsPort"].toInt(); + root["apiConfig"] = apiConfig; + break; + } } root["config_version"] = root["config_version"].toInt() + 1; diff --git a/src/QvCoreConfigOperations_Generation.cpp b/src/QvCoreConfigOperations_Generation.cpp index 5fa187f2..46f9b25f 100644 --- a/src/QvCoreConfigOperations_Generation.cpp +++ b/src/QvCoreConfigOperations_Generation.cpp @@ -408,7 +408,7 @@ namespace Qv2ray INBOUNDS inbounds = INBOUNDS(root["inbounds"].toArray()); INBOUNDSETTING fakeDocodemoDoor; fakeDocodemoDoor["address"] = "127.0.0.1"; - QJsonObject apiInboundsRoot = GenerateInboundEntry("127.0.0.1", gConf.connectionConfig.statsPort, "dokodemo-door", fakeDocodemoDoor, API_TAG_INBOUND); + QJsonObject apiInboundsRoot = GenerateInboundEntry("127.0.0.1", gConf.apiConfig.statsPort, "dokodemo-door", fakeDocodemoDoor, API_TAG_INBOUND); inbounds.push_front(apiInboundsRoot); root["inbounds"] = inbounds; // diff --git a/src/components/QvKernelInteractions.cpp b/src/components/QvKernelInteractions.cpp index 0739bd07..c9da19a0 100644 --- a/src/components/QvKernelInteractions.cpp +++ b/src/components/QvKernelInteractions.cpp @@ -63,22 +63,18 @@ namespace Qv2ray // Check if V2ray core returns a version number correctly. QProcess proc; proc.start(vCorePath + " -version"); + proc.waitForFinished(); + auto exitCode = proc.exitCode(); - if (!proc.waitForFinished(1000) || proc.exitCode() != 0) { - DEBUG(MODULE_VCORE, "V2ray core not exited within 1 sec, or it failed with an exit code: " + QSTRN(proc.exitCode())) - - if (proc.exitCode() != 0) { - *message = tr("V2ray core failed with an exit code: ") + QSTRN(proc.exitCode()); - } else { - *message = tr("V2ray core not responsed within 1 secs."); - } - + if (exitCode != 0) { + DEBUG(MODULE_VCORE, "VCore failed with an exit code: " + QSTRN(exitCode)) + *message = tr("V2ray core failed with an exit code: ") + QSTRN(exitCode); return false; } QString output = QString(proc.readAllStandardOutput()); LOG(MODULE_VCORE, "V2ray output: " + SplitLines(output).join(";")) - *message = SplitLines(output).first(); + *message = SplitLines(output).first(); return true; } @@ -134,7 +130,7 @@ namespace Qv2ray KernelStarted = false; } - bool V2rayKernelInstance::StartConnection(CONFIGROOT root, int apiPort) + bool V2rayKernelInstance::StartConnection(CONFIGROOT root) { if (KernelStarted) { LOG(MODULE_VCORE, "Status is invalid, expect STOPPED when calling StartConnection") @@ -169,15 +165,18 @@ namespace Qv2ray vProcess->waitForStarted(); DEBUG(MODULE_VCORE, "V2ray core started.") KernelStarted = true; + auto conf = GetGlobalConfig(); if (StartupOption.noAPI) { LOG(MODULE_VCORE, "API has been disabled by the command line argument \"-noAPI\"") + } else if (!conf.apiConfig.enableAPI) { + LOG(MODULE_VCORE, "API has been disabled by the global config option") } else if (inboundTags.isEmpty()) { LOG(MODULE_VCORE, "API is disabled since no inbound tags configured. This is probably caused by a bad complex config.") } else { // Config API apiFailedCounter = 0; - this->apiPort = apiPort; + this->apiPort = conf.apiConfig.statsPort; Channel = grpc::CreateChannel("127.0.0.1:" + to_string(apiPort), grpc::InsecureChannelCredentials()); StatsService service; Stub = service.NewStub(Channel); diff --git a/src/components/QvKernelInteractions.hpp b/src/components/QvKernelInteractions.hpp index f5a47555..51e3d217 100644 --- a/src/components/QvKernelInteractions.hpp +++ b/src/components/QvKernelInteractions.hpp @@ -27,7 +27,7 @@ namespace Qv2ray long getAllSpeedUp(); long getAllSpeedDown(); // - bool StartConnection(CONFIGROOT root, int apiPort); + bool StartConnection(CONFIGROOT root); void StopConnection(); bool KernelStarted = false; // diff --git a/src/ui/w_MainWindow_extra.cpp b/src/ui/w_MainWindow_extra.cpp index 4900287e..4809f60b 100644 --- a/src/ui/w_MainWindow_extra.cpp +++ b/src/ui/w_MainWindow_extra.cpp @@ -130,7 +130,7 @@ bool MainWindow::MWtryStartConnection() { auto connectionRoot = connections[CurrentConnectionIdentifier].config; currentFullConfig = GenerateRuntimeConfig(connectionRoot); - bool startFlag = this->vinstance->StartConnection(currentFullConfig, currentConfig.connectionConfig.statsPort); + bool startFlag = this->vinstance->StartConnection(currentFullConfig); if (startFlag) { bool usePAC = currentConfig.inboundConfig.pacConfig.enablePAC; diff --git a/src/ui/w_PreferencesWindow.cpp b/src/ui/w_PreferencesWindow.cpp index dd88149d..4ccea048 100644 --- a/src/ui/w_PreferencesWindow.cpp +++ b/src/ui/w_PreferencesWindow.cpp @@ -100,7 +100,7 @@ PreferencesWindow::PreferencesWindow(QWidget *parent) : QDialog(parent), // vCorePathTxt->setText(CurrentConfig.v2CorePath); vCoreAssetsPathTxt->setText(CurrentConfig.v2AssetsPath); - statsPortBox->setValue(CurrentConfig.connectionConfig.statsPort); + statsPortBox->setValue(CurrentConfig.apiConfig.statsPort); // // bypassCNCb->setChecked(CurrentConfig.connectionConfig.bypassCN); @@ -203,7 +203,7 @@ void PreferencesWindow::on_buttonBox_accepted() if (!StartupOption.noAPI) { size ++; - ports << CurrentConfig.connectionConfig.statsPort; + ports << CurrentConfig.apiConfig.statsPort; } if (ports.size() != size) { @@ -466,7 +466,7 @@ void PreferencesWindow::on_bypassCNCb_stateChanged(int arg1) void PreferencesWindow::on_statsPortBox_valueChanged(int arg1) { NEEDRESTART - CurrentConfig.connectionConfig.statsPort = arg1; + CurrentConfig.apiConfig.statsPort = arg1; } void PreferencesWindow::on_socksPortLE_valueChanged(int arg1) @@ -1021,3 +1021,10 @@ void PreferencesWindow::on_maxLogLinesSB_valueChanged(int arg1) NEEDRESTART CurrentConfig.uiConfig.maximumLogLines = arg1; } + +void PreferencesWindow::on_enableAPI_stateChanged(int arg1) +{ + LOADINGCHECK + NEEDRESTART + CurrentConfig.apiConfig.enableAPI = arg1 == Qt::Checked; +} diff --git a/src/ui/w_PreferencesWindow.hpp b/src/ui/w_PreferencesWindow.hpp index 30cf02c8..3902628f 100644 --- a/src/ui/w_PreferencesWindow.hpp +++ b/src/ui/w_PreferencesWindow.hpp @@ -160,6 +160,8 @@ class PreferencesWindow : public QDialog, private Ui::PreferencesWindow void on_maxLogLinesSB_valueChanged(int arg1); + void on_enableAPI_stateChanged(int arg1); + private: void SetAutoStartButtonsState(bool isAutoStart); // Set ui parameters for a line; diff --git a/src/ui/w_PreferencesWindow.ui b/src/ui/w_PreferencesWindow.ui index 53084af3..28005871 100644 --- a/src/ui/w_PreferencesWindow.ui +++ b/src/ui/w_PreferencesWindow.ui @@ -44,7 +44,7 @@ 0 0 647 - 476 + 547 @@ -248,13 +248,107 @@ + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + API Subsystem + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + API Port + + + + + + + Enabled + + + + + + + + 100 + 0 + + + + 1024 + + + 65535 + + + 15934 + + + + + + + Enabled + + + + + + + QFrame::Plain + + + 2 + + + Qt::Vertical + + + + + + Log Level - + @@ -295,7 +389,7 @@ - + @@ -332,7 +426,7 @@ - + @@ -381,21 +475,21 @@ - + Transparent Proxy - + Enabled - + @@ -432,7 +526,7 @@ - + @@ -494,7 +588,7 @@ - + Qt::Vertical @@ -995,53 +1089,27 @@ - - - API Port - - - - - - - - 100 - 0 - - - - 1024 - - - 65535 - - - 15934 - - - - Use Local DNS - + Enabled - + Custom DNS List - + @@ -1879,7 +1947,6 @@ p, li { white-space: pre-wrap; } pushButton proxyDefaultCb bypassCNCb - statsPortBox localDNSCb DNSListTxt fpGroupBox diff --git a/tools/grpc_gen.bat b/tools/grpc_gen.bat index 18be7be5..cfb042c1 100644 --- a/tools/grpc_gen.bat +++ b/tools/grpc_gen.bat @@ -1,21 +1,21 @@ @echo off cd tools echo Extracting files. -%~dp0\7z.exe -y e %~dp0gRPC-win32.tar.gz -o%~dp0 && %~dp0\7z.exe -y x %~dp0gRPC-win32.tar -o%~dp0\..\libs\gRPC-win32 +"%~dp0\7z.exe" -y e "%~dp0gRPC-win32.tar.gz" -o"%~dp0 && %~dp0\7z.exe" -y x "%~dp0gRPC-win32.tar" -o"%~dp0\..\libs\gRPC-win32" if errorlevel 1 goto errored -del %~dp0gRPC-win32.tar +del "%~dp0gRPC-win32.tar" -mkdir %~dp0..\libs\gen +mkdir "%~dp0..\libs\gen" echo. echo Generate grpc.pb.h using gRPC and protocol buffer echo. ---^> Generating gRPC file. -%~dp0\..\libs\gRPC-win32\bin\protoc.exe v2ray_api_commands.proto --grpc_out=%~dp0..\libs\gen --plugin=protoc-gen-grpc="%~dp0..\libs\gRPC-win32\bin\grpc_cpp_plugin.exe" +"%~dp0\..\libs\gRPC-win32\bin\protoc.exe" v2ray_api_commands.proto --grpc_out="%~dp0..\libs\gen" --plugin=protoc-gen-grpc="%~dp0..\libs\gRPC-win32\bin\grpc_cpp_plugin.exe" if errorlevel 1 goto errored echo. ---^> Generating proto file. -%~dp0\..\libs\gRPC-win32\bin\protoc.exe v2ray_api_commands.proto --cpp_out=%~dp0..\libs\gen +"%~dp0\..\libs\gRPC-win32\bin\protoc.exe" v2ray_api_commands.proto --cpp_out="%~dp0..\libs\gen" if errorlevel 1 goto errored echo DONE @@ -24,4 +24,4 @@ exit 0 :errored echo %errorlevel% echo SOME PROCESS FAILED! -exit 1 \ No newline at end of file +exit 1