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

Commit d47772e

Browse files
authored
Merge pull request #5 from Qv2ray/dev
Forwarding to Interface V2
2 parents dead710 + 46ff871 commit d47772e

File tree

6 files changed

+24
-21
lines changed

6 files changed

+24
-21
lines changed

.github/workflows/build-simpleplugin.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ jobs:
104104
shell: bash
105105
if: matrix.platform == 'macos-latest'
106106
run: |
107+
sudo xcode-select -s "/Applications/Xcode_10.3.app"
107108
mkdir build
108109
cd build
109110
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

SSRPlugin.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
#include <QMetaEnum>
99
namespace SSRPlugin
1010
{
11-
std::shared_ptr<QvPluginKernel> QvSSRPlugin::GetKernel()
11+
std::unique_ptr<QvPluginKernel> QvSSRPlugin::CreateKernel()
1212
{
13-
return kernel;
13+
return std::make_unique<SSRKernelInstance>();
1414
}
1515

1616
std::shared_ptr<QvPluginSerializer> QvSSRPlugin::GetSerializer()
@@ -29,7 +29,6 @@ namespace SSRPlugin
2929
emit PluginLog("Initialize plugin.");
3030
this->settings = settings;
3131
eventHandler = std::make_shared<SSRPluginEventHandler>(this);
32-
kernel = std::make_shared<SSRKernelInstance>(this);
3332
serializer = std::make_shared<SSRSerializer>(this);
3433
return true;
3534
}

SSRPlugin.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace SSRPlugin
2424
// Basic metainfo of this plugin
2525
const QvPluginMetadata GetMetadata() const override
2626
{
27-
return QvPluginMetadata{
27+
auto x = QvPluginMetadata{
2828
"SSR Plugin", //
2929
"Qv2ray Development Group", //
3030
"qvplugin_ssr", //
@@ -34,11 +34,13 @@ namespace SSRPlugin
3434
{ SPECIAL_TYPE_KERNEL, //
3535
SPECIAL_TYPE_SERIALIZOR } //
3636
};
37+
x.KernelOutboundCapabilities = { { "ShadowSocksR", "shadowsocksr" } };
38+
return x;
3739
}
3840
//
3941
std::unique_ptr<QWidget> GetSettingsWidget() override;
4042
std::unique_ptr<QvPluginEditor> GetEditorWidget(UI_TYPE) override;
41-
std::shared_ptr<QvPluginKernel> GetKernel() override;
43+
std::unique_ptr<QvPluginKernel> CreateKernel() override;
4244
std::shared_ptr<QvPluginSerializer> GetSerializer() override;
4345
std::shared_ptr<QvPluginEventHandler> GetEventHandler() override;
4446
//
@@ -54,6 +56,5 @@ namespace SSRPlugin
5456
QJsonObject settings;
5557
std::shared_ptr<SSRPluginEventHandler> eventHandler;
5658
std::shared_ptr<SSRSerializer> serializer;
57-
std::shared_ptr<SSRKernelInstance> kernel;
5859
};
5960
} // namespace SSRPlugin

core/kernel/SSRInstance.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,25 @@ namespace SSRPlugin
1414
{
1515
}
1616

17-
void SSRKernelInstance::SetConnectionSettings(const QString &listenAddress, const QMap<QString, int> &inbound, const QJsonObject &settings)
17+
void SSRKernelInstance::SetConnectionSettings(const QMap<KernelSetting, QVariant> &options, const QJsonObject &settings)
1818
{
19-
this->listen_address = listenAddress;
20-
socks_local_port = inbound["socks"];
21-
http_local_port = inbound["http"];
22-
enable_udp = inbound["enable_udp"];
19+
this->listen_address = options[KERNEL_LISTEN_ADDRESS].toString();
20+
socks_local_port = options[KERNEL_SOCKS_ENABLED].toBool() ? options[KERNEL_SOCKS_PORT].toInt() : 0;
21+
http_local_port = options[KERNEL_HTTP_ENABLED].toBool() ? options[KERNEL_HTTP_PORT].toInt() : 0;
22+
enable_udp = options[KERNEL_SOCKS_UDP_ENABLED].toBool();
2323
outbound.loadJson(settings);
2424
}
2525

2626
bool SSRKernelInstance::StartKernel()
2727
{
28+
if (socks_local_port == 0 && http_local_port == 0)
29+
{
30+
emit OnKernelCrashed("Both HTTP and SOCKS are not enabled");
31+
return false;
32+
}
33+
// If the socks has been disabled
34+
if (socks_local_port == 0)
35+
socks_local_port = http_local_port + 100;
2836
auto remotePort = outbound.port;
2937
auto remote_host = outbound.address.toStdString();
3038
auto method = outbound.method.toStdString();
@@ -36,9 +44,7 @@ namespace SSRPlugin
3644
auto mode = static_cast<SSRThread::SSR_WORK_MODE>(enable_udp);
3745
ssrThread = std::make_unique<SSRThread>(socks_local_port, //
3846
remotePort, //
39-
60000,
40-
1500,
41-
mode,
47+
60000, 1500, mode, //
4248
listen_address.toStdString(), //
4349
remote_host, //
4450
method, //
@@ -47,7 +53,7 @@ namespace SSRPlugin
4753
obfs_param, //
4854
protocol, //
4955
protocol_param);
50-
ssrThread->connect(ssrThread.get(), &SSRThread::onSSRThreadLog, this, &SSRKernelInstance::OnKernelLogAvaliable);
56+
ssrThread->connect(ssrThread.get(), &SSRThread::onSSRThreadLog, this, &SSRKernelInstance::OnKernelLogAvailable);
5157
ssrThread->connect(ssrThread.get(), &SSRThread::OnDataReady, this, &SSRKernelInstance::OnKernelStatsAvailable);
5258
ssrThread->start();
5359
if (http_local_port != 0)

core/kernel/SSRInstance.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ namespace SSRPlugin
1111
explicit SSRKernelInstance(QObject *parent = nullptr);
1212
bool StartKernel() override;
1313
bool StopKernel() override;
14-
void SetConnectionSettings(const QString &listen_address, const QMap<QString, int> &inbound, const QJsonObject &settings) override;
15-
const QList<Qv2rayPlugin::QvPluginOutboundProtocolObject> KernelOutboundCapabilities() const override
16-
{
17-
return { { "ShadowSocksR", "shadowsocksr" } };
18-
}
14+
void SetConnectionSettings(const QMap<KernelSetting, QVariant> &options, const QJsonObject &settings) override;
1915

2016
private:
2117
int socks_local_port;

interface

0 commit comments

Comments
 (0)