Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

Commit

Permalink
Merge pull request #8 from Qv2ray/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
QxQ authored Jul 9, 2020
2 parents 1b04545 + 115dc9f commit 172f253
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ target_link_libraries(${PROJECT_NAME}
Qt5::Widgets
Qt5::Network
${SHADOWSOCKSR_UVW_LIBRARY})

install(TARGETS ${PROJECT_NAME} DESTINATION share/qv2ray/plugins)
5 changes: 2 additions & 3 deletions SSRPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include <QMetaEnum>
namespace SSRPlugin
{
std::shared_ptr<QvPluginKernel> QvSSRPlugin::GetKernel()
std::unique_ptr<QvPluginKernel> QvSSRPlugin::CreateKernel()
{
return kernel;
return std::make_unique<SSRKernelInstance>();
}

std::shared_ptr<QvPluginSerializer> QvSSRPlugin::GetSerializer()
Expand All @@ -29,7 +29,6 @@ namespace SSRPlugin
emit PluginLog("Initialize plugin.");
this->settings = settings;
eventHandler = std::make_shared<SSRPluginEventHandler>(this);
kernel = std::make_shared<SSRKernelInstance>(this);
serializer = std::make_shared<SSRSerializer>(this);
return true;
}
Expand Down
7 changes: 4 additions & 3 deletions SSRPlugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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", //
Expand All @@ -34,11 +34,13 @@ namespace SSRPlugin
{ SPECIAL_TYPE_KERNEL, //
SPECIAL_TYPE_SERIALIZOR } //
};
x.KernelOutboundCapabilities = { { "ShadowSocksR", "shadowsocksr" } };
return x;
}
//
std::unique_ptr<QWidget> GetSettingsWidget() override;
std::unique_ptr<QvPluginEditor> GetEditorWidget(UI_TYPE) override;
std::shared_ptr<QvPluginKernel> GetKernel() override;
std::unique_ptr<QvPluginKernel> CreateKernel() override;
std::shared_ptr<QvPluginSerializer> GetSerializer() override;
std::shared_ptr<QvPluginEventHandler> GetEventHandler() override;
//
Expand All @@ -54,6 +56,5 @@ namespace SSRPlugin
QJsonObject settings;
std::shared_ptr<SSRPluginEventHandler> eventHandler;
std::shared_ptr<SSRSerializer> serializer;
std::shared_ptr<SSRKernelInstance> kernel;
};
} // namespace SSRPlugin
24 changes: 15 additions & 9 deletions core/kernel/SSRInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,25 @@ namespace SSRPlugin
{
}

void SSRKernelInstance::SetConnectionSettings(const QString &listenAddress, const QMap<QString, int> &inbound, const QJsonObject &settings)
void SSRKernelInstance::SetConnectionSettings(const QMap<KernelSetting, QVariant> &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();
Expand All @@ -36,9 +44,7 @@ namespace SSRPlugin
auto mode = static_cast<SSRThread::SSR_WORK_MODE>(enable_udp);
ssrThread = std::make_unique<SSRThread>(socks_local_port, //
remotePort, //
60000,
1500,
mode,
60000, 1500, mode, //
listen_address.toStdString(), //
remote_host, //
method, //
Expand All @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions core/kernel/SSRInstance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QString, int> &inbound, const QJsonObject &settings) override;
const QList<Qv2rayPlugin::QvPluginOutboundProtocolObject> KernelOutboundCapabilities() const override
{
return { { "ShadowSocksR", "shadowsocksr" } };
}
void SetConnectionSettings(const QMap<KernelSetting, QVariant> &options, const QJsonObject &settings) override;

private:
int socks_local_port;
Expand Down

0 comments on commit 172f253

Please sign in to comment.