Some XRay improvements (#1075)
This commit is contained in:
parent
862e83ddf5
commit
a22a9448ca
16 changed files with 252 additions and 122 deletions
|
@ -7,7 +7,6 @@
|
|||
class IpcInterface
|
||||
{
|
||||
SLOT( int createPrivilegedProcess() ); // return local pid
|
||||
//SIGNAL(sendMessage(const QByteArray &message));
|
||||
|
||||
// Route functions
|
||||
SLOT( int routeAddList(const QString &gw, const QStringList &ips) );
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
class IpcProcessInterface
|
||||
{
|
||||
//SLOT( start(const QString &program, const QStringList &args) );
|
||||
SLOT( start() );
|
||||
SLOT( close() );
|
||||
|
||||
|
|
11
ipc/ipc_process_tun2socks.rep
Normal file
11
ipc/ipc_process_tun2socks.rep
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include <QtCore>
|
||||
#include <QString>
|
||||
|
||||
class IpcProcessTun2Socks
|
||||
{
|
||||
SLOT( start() );
|
||||
SLOT( stop() );
|
||||
|
||||
SIGNAL( setConnectionState(int state) );
|
||||
SIGNAL( stateChanged(QProcess::ProcessState newState) );
|
||||
};
|
|
@ -8,6 +8,7 @@
|
|||
#include "logger.h"
|
||||
#include "router.h"
|
||||
|
||||
#include "../core/networkUtilities.h"
|
||||
#include "../client/protocols/protocols_defs.h"
|
||||
#ifdef Q_OS_WIN
|
||||
#include "../client/platforms/windows/daemon/windowsdaemon.h"
|
||||
|
@ -209,7 +210,7 @@ bool IpcServer::enableKillSwitch(const QJsonObject &configStr, int vpnAdapterInd
|
|||
if (splitTunnelType == 0) {
|
||||
blockAll = true;
|
||||
allowNets = true;
|
||||
allownets.append(configStr.value(amnezia::config_key::hostName).toString());
|
||||
allownets.append(configStr.value("vpnServer").toString());
|
||||
} else if (splitTunnelType == 1) {
|
||||
blockNets = true;
|
||||
for (auto v : splitTunnelSites) {
|
||||
|
@ -218,7 +219,7 @@ bool IpcServer::enableKillSwitch(const QJsonObject &configStr, int vpnAdapterInd
|
|||
} else if (splitTunnelType == 2) {
|
||||
blockAll = true;
|
||||
allowNets = true;
|
||||
allownets.append(configStr.value(amnezia::config_key::hostName).toString());
|
||||
allownets.append(configStr.value("vpnServer").toString());
|
||||
for (auto v : splitTunnelSites) {
|
||||
allownets.append(v.toString());
|
||||
}
|
||||
|
@ -329,7 +330,7 @@ bool IpcServer::enablePeerTraffic(const QJsonObject &configStr)
|
|||
}
|
||||
}
|
||||
|
||||
config.m_excludedAddresses.append(configStr.value(amnezia::config_key::hostName).toString());
|
||||
config.m_excludedAddresses.append(configStr.value("vpnServer").toString());
|
||||
if (splitTunnelType == 2) {
|
||||
for (auto v : splitTunnelSites) {
|
||||
QString ipRange = v.toString();
|
||||
|
@ -351,7 +352,6 @@ bool IpcServer::enablePeerTraffic(const QJsonObject &configStr)
|
|||
|
||||
WindowsDaemon::instance()->prepareActivation(config, inetAdapterIndex);
|
||||
WindowsDaemon::instance()->activateSplitTunnel(config, vpnAdapterIndex);
|
||||
return true;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -9,8 +9,10 @@
|
|||
|
||||
#include "ipc.h"
|
||||
#include "ipcserverprocess.h"
|
||||
#include "ipctun2socksprocess.h"
|
||||
|
||||
#include "rep_ipc_interface_source.h"
|
||||
#include "rep_ipc_process_tun2socks_source.h"
|
||||
|
||||
class IpcServer : public IpcInterfaceSource
|
||||
{
|
||||
|
@ -44,10 +46,12 @@ private:
|
|||
ProcessDescriptor (QObject *parent = nullptr) {
|
||||
serverNode = QSharedPointer<QRemoteObjectHost>(new QRemoteObjectHost(parent));
|
||||
ipcProcess = QSharedPointer<IpcServerProcess>(new IpcServerProcess(parent));
|
||||
tun2socksProcess = QSharedPointer<IpcProcessTun2Socks>(new IpcProcessTun2Socks(parent));
|
||||
localServer = QSharedPointer<QLocalServer>(new QLocalServer(parent));
|
||||
}
|
||||
|
||||
QSharedPointer<IpcServerProcess> ipcProcess;
|
||||
QSharedPointer<IpcProcessTun2Socks> tun2socksProcess;
|
||||
QSharedPointer<QRemoteObjectHost> serverNode;
|
||||
QSharedPointer<QLocalServer> localServer;
|
||||
};
|
||||
|
|
74
ipc/ipctun2socksprocess.cpp
Normal file
74
ipc/ipctun2socksprocess.cpp
Normal file
|
@ -0,0 +1,74 @@
|
|||
#include "ipctun2socksprocess.h"
|
||||
#include "ipc.h"
|
||||
#include <QProcess>
|
||||
#include <QString>
|
||||
|
||||
#include "../protocols/protocols_defs.h"
|
||||
|
||||
#ifndef Q_OS_IOS
|
||||
|
||||
IpcProcessTun2Socks::IpcProcessTun2Socks(QObject *parent) :
|
||||
IpcProcessTun2SocksSource(parent),
|
||||
m_t2sProcess(QSharedPointer<QProcess>(new QProcess()))
|
||||
{
|
||||
connect(m_t2sProcess.data(), &QProcess::stateChanged, this, &IpcProcessTun2Socks::stateChanged);
|
||||
qDebug() << "IpcProcessTun2Socks::IpcProcessTun2Socks()";
|
||||
|
||||
}
|
||||
|
||||
IpcProcessTun2Socks::~IpcProcessTun2Socks()
|
||||
{
|
||||
qDebug() << "IpcProcessTun2Socks::~IpcProcessTun2Socks()";
|
||||
}
|
||||
|
||||
void IpcProcessTun2Socks::start()
|
||||
{
|
||||
qDebug() << "IpcProcessTun2Socks::start()";
|
||||
m_t2sProcess->setProgram(amnezia::permittedProcessPath(static_cast<amnezia::PermittedProcess>(amnezia::PermittedProcess::Tun2Socks)));
|
||||
QString XrayConStr = "socks5://127.0.0.1:10808";
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
QStringList arguments({"-device", "tun://tun2", "-proxy", XrayConStr, "-tun-post-up",
|
||||
QString("cmd /c netsh interface ip set address name=\"tun2\" static %1 255.255.255.255")
|
||||
.arg(amnezia::protocols::xray::defaultLocalAddr)});
|
||||
#endif
|
||||
#ifdef Q_OS_LINUX
|
||||
QStringList arguments({"-device", "tun://tun2", "-proxy", XrayConStr});
|
||||
#endif
|
||||
#ifdef Q_OS_MAC
|
||||
QStringList arguments({"-device", "utun22", "-proxy", XrayConStr});
|
||||
#endif
|
||||
|
||||
m_t2sProcess->setArguments(arguments);
|
||||
|
||||
Utils::killProcessByName(m_t2sProcess->program());
|
||||
m_t2sProcess->start();
|
||||
|
||||
connect(m_t2sProcess.data(), &QProcess::readyReadStandardOutput, this, [this]() {
|
||||
QString line = m_t2sProcess.data()->readAllStandardOutput();
|
||||
if (line.contains("[STACK] tun://") && line.contains("<-> socks5://127.0.0.1")) {
|
||||
emit setConnectionState(Vpn::ConnectionState::Connected);
|
||||
}
|
||||
});
|
||||
|
||||
connect(m_t2sProcess.data(), QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, [this](int exitCode, QProcess::ExitStatus exitStatus) {
|
||||
qDebug().noquote() << "tun2socks finished, exitCode, exiStatus" << exitCode << exitStatus;
|
||||
emit setConnectionState(Vpn::ConnectionState::Disconnected);
|
||||
if (exitStatus != QProcess::NormalExit){
|
||||
stop();
|
||||
}
|
||||
if (exitCode !=0 ){
|
||||
stop();
|
||||
}
|
||||
});
|
||||
|
||||
m_t2sProcess->start();
|
||||
m_t2sProcess->waitForStarted();
|
||||
}
|
||||
|
||||
void IpcProcessTun2Socks::stop()
|
||||
{
|
||||
qDebug() << "IpcProcessTun2Socks::stop()";
|
||||
m_t2sProcess->close();
|
||||
}
|
||||
#endif
|
52
ipc/ipctun2socksprocess.h
Normal file
52
ipc/ipctun2socksprocess.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
#ifndef IPCTUN2SOCKSPROCESS_H
|
||||
#define IPCTUN2SOCKSPROCESS_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#ifndef Q_OS_IOS
|
||||
#include "rep_ipc_process_tun2socks_source.h"
|
||||
|
||||
namespace Vpn
|
||||
{
|
||||
Q_NAMESPACE
|
||||
enum ConnectionState {
|
||||
Unknown,
|
||||
Disconnected,
|
||||
Preparing,
|
||||
Connecting,
|
||||
Connected,
|
||||
Disconnecting,
|
||||
Reconnecting,
|
||||
Error
|
||||
};
|
||||
Q_ENUM_NS(ConnectionState)
|
||||
}
|
||||
|
||||
|
||||
class IpcProcessTun2Socks : public IpcProcessTun2SocksSource
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit IpcProcessTun2Socks(QObject *parent = nullptr);
|
||||
virtual ~IpcProcessTun2Socks();
|
||||
|
||||
void start() override;
|
||||
void stop() override;
|
||||
|
||||
signals:
|
||||
|
||||
private:
|
||||
QSharedPointer<QProcess> m_t2sProcess;
|
||||
};
|
||||
|
||||
#else
|
||||
class IpcProcessTun2Socks : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit IpcProcessTun2Socks(QObject *parent = nullptr);
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif // IPCTUN2SOCKSPROCESS_H
|
Loading…
Add table
Add a link
Reference in a new issue