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

Commit

Permalink
BREAKING: Updated Plugin Interface, supported proxychains
Browse files Browse the repository at this point in the history
  • Loading branch information
QxQ authored and QxQ committed Oct 12, 2020
1 parent e1ba5be commit f55ea39
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 11 deletions.
21 changes: 18 additions & 3 deletions core/Kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@ bool NaiveProxyKernel::StartKernel()
url.setUserName(username);
url.setPassword(password);
}
url.setHost(host);
if (!sni.isEmpty())
{
// ### Hack : SNI is used for proxychains
url.setHost(sni);
arguments << QString("--host-resolver-rules=MAP %1 127.0.0.1").arg(sni);
}
else
{
url.setHost(host);
}
url.setPort(port);
arguments << QString("--proxy=%1").arg(url.url());
}
Expand Down Expand Up @@ -70,6 +79,7 @@ bool NaiveProxyKernel::StartKernel()

void NaiveProxyKernel::SetConnectionSettings(const QMap<Qv2rayPlugin::KernelOptionFlags, QVariant> &options, const QJsonObject &settings)
{
sni.clear();
this->listenIp = options[KERNEL_LISTEN_ADDRESS].toString();
this->socksPort = options[KERNEL_SOCKS_ENABLED].toBool() ? options[KERNEL_SOCKS_PORT].toInt() : 0;
this->httpPort = options[KERNEL_HTTP_ENABLED].toBool() ? options[KERNEL_HTTP_PORT].toInt() : 0;
Expand All @@ -79,16 +89,21 @@ void NaiveProxyKernel::SetConnectionSettings(const QMap<Qv2rayPlugin::KernelOpti
this->password = settings["password"].toString();
this->protocol = settings["protocol"].toString();
this->padding = settings["padding"].toBool();
//
// Special SNI option
if (settings.contains("sni"))
sni = settings["sni"].toString();
//

if (this->protocol != "https" && this->protocol != "quic")
{
emit OnKernelLogAvailable(QString("warning: outbound protocol %1 is falled back to https"));
emit OnKernelLogAvailable("warning: outbound protocol falled back to https");
this->protocol = "https";
}

if (this->port <= 0 || this->port >= 65536)
{
emit OnKernelLogAvailable(QString("warning: outbound port %1 is falled back to 443"));
emit OnKernelLogAvailable("warning: outbound port falled back to 443");
this->port = 443;
}
}
Expand Down
2 changes: 2 additions & 0 deletions core/Kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class NaiveProxyKernel : public Qv2rayPlugin::PluginKernel
bool padding;
int port;
QProcess process;
//
QString sni;

private:
bool isStarted = false;
Expand Down
20 changes: 17 additions & 3 deletions core/Serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#include <QUrlQuery>

const QString NaiveProxyOutboundHandler::SerializeOutbound(const QString &, const QString &alias, const QString &,
const QJsonObject &object) const
const QString NaiveProxyOutboundHandler::SerializeOutbound(const QString &, const QString &alias, const QString &, const QJsonObject &object,
const QJsonObject &) const
{
QUrl url;
if (const auto protocol = object["protocol"].toString(); protocol != "https" && protocol != "quic")
Expand Down Expand Up @@ -32,6 +32,19 @@ const QString NaiveProxyOutboundHandler::SerializeOutbound(const QString &, cons
return url.toString();
}

const void NaiveProxyOutboundHandler::SetOutboundInfo(const QString &protocol, const Qv2rayPlugin::OutboundInfoObject &info,
QJsonObject &outbound) const
{
if (protocol != "naive")
return;
if (info.contains(Qv2rayPlugin::INFO_SERVER))
outbound["host"] = info[Qv2rayPlugin::INFO_SERVER].toString();
if (info.contains(Qv2rayPlugin::INFO_SERVER))
outbound["port"] = info[Qv2rayPlugin::INFO_PORT].toInt();
if (info.contains(Qv2rayPlugin::INFO_SNI))
outbound["sni"] = info[Qv2rayPlugin::INFO_SNI].toString();
}

const QPair<QString, QJsonObject> NaiveProxyOutboundHandler::DeserializeOutbound(const QString &link, QString *alias,
QString *errorMessage) const
{
Expand Down Expand Up @@ -66,6 +79,7 @@ const Qv2rayPlugin::OutboundInfoObject NaiveProxyOutboundHandler::GetOutboundInf
return { //
{ Qv2rayPlugin::INFO_PROTOCOL, protocol },
{ Qv2rayPlugin::INFO_SERVER, outbound["host"].toString() },
{ Qv2rayPlugin::INFO_PORT, outbound["port"].toInt() }
{ Qv2rayPlugin::INFO_PORT, outbound["port"].toInt() },
{ Qv2rayPlugin::INFO_SNI, outbound["sni"].toString() }
};
}
10 changes: 6 additions & 4 deletions core/Serializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ class NaiveProxyOutboundHandler : public Qv2rayPlugin::PluginOutboundHandler
{
public:
explicit NaiveProxyOutboundHandler() : Qv2rayPlugin::PluginOutboundHandler(){};
const QString SerializeOutbound(const QString &protocol, //
const QString &alias, //
const QString &groupName, //
const QJsonObject &object) const override;
const QString SerializeOutbound(const QString &protocol, //
const QString &alias, //
const QString &groupName, //
const QJsonObject &object, //
const QJsonObject &) const override;
const QPair<QString, QJsonObject> DeserializeOutbound(const QString &link, //
QString *alias, //
QString *errorMessage) const override;
const Qv2rayPlugin::OutboundInfoObject GetOutboundInfo(const QString &protocol, const QJsonObject &outbound) const override;
const void SetOutboundInfo(const QString &protocol, const Qv2rayPlugin::OutboundInfoObject &info, QJsonObject &outbound) const override;
const QList<QString> SupportedProtocols() const override
{
return { "naive" };
Expand Down
2 changes: 1 addition & 1 deletion interface

0 comments on commit f55ea39

Please sign in to comment.