diff --git a/.gitmodules b/.gitmodules index c39a32b..5a8b873 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "interface"] path = interface - url = https://github.com/Qv2ray/QvPlugin-Host/ + url = https://github.com/Qv2ray/QvPlugin-Interface [submodule "3rdparty/shadowsocksr-uvw"] path = 3rdparty/shadowsocksr-uvw url = https://github.com/Qv2ray/shadowsocksr-uvw diff --git a/3rdparty/shadowsocksr-uvw b/3rdparty/shadowsocksr-uvw index 857fe00..6c2f5e2 160000 --- a/3rdparty/shadowsocksr-uvw +++ b/3rdparty/shadowsocksr-uvw @@ -1 +1 @@ -Subproject commit 857fe00910854c9a74d8d5446e9e30af6149a411 +Subproject commit 6c2f5e2bb758382a489ed3f9f444684c23c195e9 diff --git a/CMakeLists.txt b/CMakeLists.txt index 1281188..c77699b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,3 +49,5 @@ target_link_libraries(${PROJECT_NAME} Qt5::Widgets Qt5::Network ${SHADOWSOCKSR_UVW_LIBRARY}) + +install(TARGETS ${PROJECT_NAME} DESTINATION share/qv2ray/plugins) 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..beaf59c 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 + 100; 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 8ec8004..24d6cde 160000 --- a/interface +++ b/interface @@ -1 +1 @@ -Subproject commit 8ec800431c7ca133e3d6fa1270a263b0e0f836c1 +Subproject commit 24d6cdeabb50cf753e23efea225f66c59f23c06e