From f525c40f487ddbf4d471c3b8106e84a60fda9c94 Mon Sep 17 00:00:00 2001 From: Qv2ray-dev <59914293+Qv2ray-dev@users.noreply.github.com> Date: Sun, 17 May 2020 08:54:33 +0800 Subject: [PATCH 1/4] add: adapt plugin interface V2 --- SSRPlugin.cpp | 5 ++--- SSRPlugin.hpp | 7 ++++--- core/kernel/SSRInstance.cpp | 24 +++++++++++++++--------- core/kernel/SSRInstance.hpp | 6 +----- interface | 2 +- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/SSRPlugin.cpp b/SSRPlugin.cpp index 5e6524c..4d1fa3d 100644 --- a/SSRPlugin.cpp +++ b/SSRPlugin.cpp @@ -8,9 +8,9 @@ #include namespace SSRPlugin { - std::shared_ptr QvSSRPlugin::GetKernel() + std::unique_ptr QvSSRPlugin::CreateKernel() { - return kernel; + return std::make_unique(); } std::shared_ptr QvSSRPlugin::GetSerializer() @@ -29,7 +29,6 @@ namespace SSRPlugin emit PluginLog("Initialize plugin."); this->settings = settings; eventHandler = std::make_shared(this); - kernel = std::make_shared(this); serializer = std::make_shared(this); return true; } diff --git a/SSRPlugin.hpp b/SSRPlugin.hpp index 82da74e..4b1862b 100644 --- a/SSRPlugin.hpp +++ b/SSRPlugin.hpp @@ -24,7 +24,7 @@ namespace SSRPlugin // Basic metainfo of this plugin const QvPluginMetadata GetMetadata() const override { - return QvPluginMetadata{ + auto x = QvPluginMetadata{ "SSR Plugin", // "Qv2ray Development Group", // "qvplugin_ssr", // @@ -34,11 +34,13 @@ namespace SSRPlugin { SPECIAL_TYPE_KERNEL, // SPECIAL_TYPE_SERIALIZOR } // }; + x.KernelOutboundCapabilities = { { "ShadowSocksR", "shadowsocksr" } }; + return x; } // std::unique_ptr GetSettingsWidget() override; std::unique_ptr GetEditorWidget(UI_TYPE) override; - std::shared_ptr GetKernel() override; + std::unique_ptr CreateKernel() override; std::shared_ptr GetSerializer() override; std::shared_ptr GetEventHandler() override; // @@ -54,6 +56,5 @@ namespace SSRPlugin QJsonObject settings; std::shared_ptr eventHandler; std::shared_ptr serializer; - std::shared_ptr kernel; }; } // namespace SSRPlugin diff --git a/core/kernel/SSRInstance.cpp b/core/kernel/SSRInstance.cpp index e40900c..b279719 100644 --- a/core/kernel/SSRInstance.cpp +++ b/core/kernel/SSRInstance.cpp @@ -14,17 +14,25 @@ namespace SSRPlugin { } - void SSRKernelInstance::SetConnectionSettings(const QString &listenAddress, const QMap &inbound, const QJsonObject &settings) + void SSRKernelInstance::SetConnectionSettings(const QMap &options, const QJsonObject &settings) { - this->listen_address = listenAddress; - socks_local_port = inbound["socks"]; - http_local_port = inbound["http"]; - enable_udp = inbound["enable_udp"]; + this->listen_address = options[KERNEL_LISTEN_ADDRESS].toString(); + socks_local_port = options[KERNEL_SOCKS_ENABLED].toBool() ? options[KERNEL_SOCKS_PORT].toInt() : 0; + http_local_port = options[KERNEL_HTTP_ENABLED].toBool() ? options[KERNEL_HTTP_PORT].toInt() : 0; + enable_udp = options[KERNEL_SOCKS_UDP_ENABLED].toBool(); outbound.loadJson(settings); } bool SSRKernelInstance::StartKernel() { + if (socks_local_port == 0 && http_local_port == 0) + { + emit OnKernelCrashed("Both HTTP and SOCKS are not enabled"); + return false; + } + // If the socks has been disabled + if (socks_local_port == 0) + socks_local_port = http_local_port + 1; auto remotePort = outbound.port; auto remote_host = outbound.address.toStdString(); auto method = outbound.method.toStdString(); @@ -36,9 +44,7 @@ namespace SSRPlugin auto mode = static_cast(enable_udp); ssrThread = std::make_unique(socks_local_port, // remotePort, // - 60000, - 1500, - mode, + 60000, 1500, mode, // listen_address.toStdString(), // remote_host, // method, // @@ -47,7 +53,7 @@ namespace SSRPlugin obfs_param, // protocol, // protocol_param); - ssrThread->connect(ssrThread.get(), &SSRThread::onSSRThreadLog, this, &SSRKernelInstance::OnKernelLogAvaliable); + ssrThread->connect(ssrThread.get(), &SSRThread::onSSRThreadLog, this, &SSRKernelInstance::OnKernelLogAvailable); ssrThread->connect(ssrThread.get(), &SSRThread::OnDataReady, this, &SSRKernelInstance::OnKernelStatsAvailable); ssrThread->start(); if (http_local_port != 0) diff --git a/core/kernel/SSRInstance.hpp b/core/kernel/SSRInstance.hpp index 25c1fc7..6e4dda0 100644 --- a/core/kernel/SSRInstance.hpp +++ b/core/kernel/SSRInstance.hpp @@ -11,11 +11,7 @@ namespace SSRPlugin explicit SSRKernelInstance(QObject *parent = nullptr); bool StartKernel() override; bool StopKernel() override; - void SetConnectionSettings(const QString &listen_address, const QMap &inbound, const QJsonObject &settings) override; - const QList KernelOutboundCapabilities() const override - { - return { { "ShadowSocksR", "shadowsocksr" } }; - } + void SetConnectionSettings(const QMap &options, const QJsonObject &settings) override; private: int socks_local_port; diff --git a/interface b/interface index d37c7ea..4dc6f64 160000 --- a/interface +++ b/interface @@ -1 +1 @@ -Subproject commit d37c7ea9459956dc459610e98b821d4a790cb6e8 +Subproject commit 4dc6f64ecee55729f017e0b2dd82170476aa6886 From 1cba7de252d7e59be594de439a503a4b0979facf Mon Sep 17 00:00:00 2001 From: Qv2ray-dev <59914293+Qv2ray-dev@users.noreply.github.com> Date: Sun, 17 May 2020 09:16:14 +0800 Subject: [PATCH 2/4] add: adapt plugin interface V2 - 1 --- core/kernel/SSRInstance.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/kernel/SSRInstance.cpp b/core/kernel/SSRInstance.cpp index b279719..beaf59c 100644 --- a/core/kernel/SSRInstance.cpp +++ b/core/kernel/SSRInstance.cpp @@ -32,7 +32,7 @@ namespace SSRPlugin } // If the socks has been disabled if (socks_local_port == 0) - socks_local_port = http_local_port + 1; + socks_local_port = http_local_port + 100; auto remotePort = outbound.port; auto remote_host = outbound.address.toStdString(); auto method = outbound.method.toStdString(); From 816ae3fed99fa2579c86ccaa116f3abecbfc4887 Mon Sep 17 00:00:00 2001 From: DuckVador Date: Tue, 26 May 2020 15:42:49 +0800 Subject: [PATCH 3/4] submodule: updated submodule --- 3rdparty/shadowsocksr-uvw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdparty/shadowsocksr-uvw b/3rdparty/shadowsocksr-uvw index 5587fe9..951bbeb 160000 --- a/3rdparty/shadowsocksr-uvw +++ b/3rdparty/shadowsocksr-uvw @@ -1 +1 @@ -Subproject commit 5587fe911ad041eb953b7f4d3bab73c693a332ef +Subproject commit 951bbebeec5a90a0d3e1fa4bfc3784ddb68bd922 From 46ff8710de8f7504a774d9193a942faf8b733e8a Mon Sep 17 00:00:00 2001 From: ymshenyu Date: Wed, 27 May 2020 22:49:47 +0800 Subject: [PATCH 4/4] mac: use xcode 10.3 --- .github/workflows/build-simpleplugin.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-simpleplugin.yml b/.github/workflows/build-simpleplugin.yml index 6156b45..83986dd 100644 --- a/.github/workflows/build-simpleplugin.yml +++ b/.github/workflows/build-simpleplugin.yml @@ -104,6 +104,7 @@ jobs: shell: bash if: matrix.platform == 'macos-latest' run: | + sudo xcode-select -s "/Applications/Xcode_10.3.app" mkdir build cd build cmake .. -DCMAKE_BUILD_TYPE=Release -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl@1.1 -DOPENSSL_LIBRARIES=/usr/local/opt/openssl@1.1/lib -DOPENSSL_USE_STATIC_LIBS=ON -DMACOSX_DEPLOYMENT_TARGET=10.13