Qt remote objects IPC
This commit is contained in:
parent
c4df9c004b
commit
048a673d31
18 changed files with 340 additions and 25 deletions
|
|
@ -10,9 +10,11 @@ include("3rd/QtSsh/src/ssh/ssh.pri")
|
|||
include("3rd/QtSsh/src/botan/botan.pri")
|
||||
|
||||
HEADERS += \
|
||||
../ipc/ipc.h \
|
||||
communicator.h \
|
||||
core/defs.h \
|
||||
core/errorstrings.h \
|
||||
core/ipcclient.h \
|
||||
core/openvpnconfigurator.h \
|
||||
core/servercontroller.h \
|
||||
debug.h \
|
||||
|
|
@ -32,6 +34,7 @@ HEADERS += \
|
|||
|
||||
SOURCES += \
|
||||
communicator.cpp \
|
||||
core/ipcclient.cpp \
|
||||
core/openvpnconfigurator.cpp \
|
||||
core/servercontroller.cpp \
|
||||
debug.cpp \
|
||||
|
|
@ -101,5 +104,5 @@ macx {
|
|||
LIBS += -framework Cocoa -framework ApplicationServices -framework CoreServices -framework Foundation -framework AppKit
|
||||
}
|
||||
|
||||
REPC_REPLICA += ../communicator/communicator.rep
|
||||
REPC_REPLICA += ../ipc/ipcinterface.rep
|
||||
|
||||
|
|
|
|||
51
client/core/ipcclient.cpp
Normal file
51
client/core/ipcclient.cpp
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
#include "ipcclient.h"
|
||||
#include <QRemoteObjectNode>
|
||||
|
||||
IpcClient &IpcClient::Instance()
|
||||
{
|
||||
static IpcClient s;
|
||||
return s;
|
||||
}
|
||||
|
||||
QSharedPointer<IpcProcessInterfaceReplica> IpcClient::createPrivilegedProcess()
|
||||
{
|
||||
if (! Instance().m_ipcClient->isReplicaValid()) return nullptr;
|
||||
|
||||
QRemoteObjectPendingReply<int> futureResult = Instance().m_ipcClient->createPrivilegedProcess();
|
||||
futureResult.waitForFinished(1000);
|
||||
|
||||
int pid = futureResult.returnValue();
|
||||
QSharedPointer<QRemoteObjectNode> replica(new QRemoteObjectNode);
|
||||
//Instance().m_processNodes.insert(pid, replica);
|
||||
|
||||
replica->connectToNode(QUrl(amnezia::getIpcProcessUrl(pid)));
|
||||
auto ptr = QSharedPointer<IpcProcessInterfaceReplica>(replica->acquire<IpcProcessInterfaceReplica>());
|
||||
connect(ptr.data(), &IpcProcessInterfaceReplica::destroyed, replica.data(), [replica](){
|
||||
replica->deleteLater();
|
||||
});
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
IpcClient::IpcClient(QObject *parent) : QObject(parent)
|
||||
{
|
||||
m_ClientNode.connectToNode(QUrl(QStringLiteral(IPC_SERVICE_URL)));
|
||||
m_ipcClient.reset(m_ClientNode.acquire<IpcInterfaceReplica>());
|
||||
m_ipcClient->waitForSource(1000);
|
||||
|
||||
|
||||
|
||||
// connect(m_ipcClient.data(), &IpcInterfaceReplica::stateChanged, [&](QRemoteObjectReplica::State state, QRemoteObjectReplica::State oldState){
|
||||
|
||||
//// qDebug() << "state" << state;
|
||||
//// for (int i = 0; i < 10; ++i) {
|
||||
//// QRemoteObjectPendingReply<qint64> future = m_ipcClient->createPrivilegedProcess("", QStringList());
|
||||
|
||||
//// future.waitForFinished();
|
||||
//// qDebug() << "QRemoteObjectPendingReply" << QDateTime::currentMSecsSinceEpoch() - future.returnValue();
|
||||
|
||||
//// }
|
||||
// });
|
||||
|
||||
|
||||
}
|
||||
30
client/core/ipcclient.h
Normal file
30
client/core/ipcclient.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#ifndef IPCCLIENT_H
|
||||
#define IPCCLIENT_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "ipc.h"
|
||||
#include "rep_ipcinterface_replica.h"
|
||||
|
||||
class IpcClient : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static IpcClient &Instance();
|
||||
|
||||
static QSharedPointer<IpcProcessInterfaceReplica> createPrivilegedProcess();
|
||||
|
||||
static QSharedPointer<IpcInterfaceReplica> ipcClient() { return Instance().m_ipcClient; }
|
||||
|
||||
signals:
|
||||
|
||||
private:
|
||||
explicit IpcClient(QObject *parent = nullptr);
|
||||
|
||||
QRemoteObjectNode m_ClientNode; // create remote object node
|
||||
QSharedPointer<IpcInterfaceReplica> m_ipcClient;
|
||||
|
||||
//QMap<int, QSharedPointer<QRemoteObjectNode>> m_processNodes;
|
||||
};
|
||||
|
||||
#endif // IPCCLIENT_H
|
||||
|
|
@ -11,8 +11,8 @@
|
|||
|
||||
|
||||
OpenVpnProtocol::OpenVpnProtocol(const QString& args, QObject* parent) :
|
||||
VpnProtocol(args, parent),
|
||||
m_requestFromUserToStop(false)
|
||||
VpnProtocol(args, parent)
|
||||
//m_requestFromUserToStop(false)
|
||||
{
|
||||
setConfigFile(args);
|
||||
connect(m_communicator, &Communicator::messageReceived, this, &OpenVpnProtocol::onMessageReceived);
|
||||
|
|
@ -130,14 +130,14 @@ ErrorCode OpenVpnProtocol::start()
|
|||
{
|
||||
qDebug() << "Start OpenVPN connection";
|
||||
|
||||
m_requestFromUserToStop = false;
|
||||
//m_requestFromUserToStop = false;
|
||||
m_openVpnStateSigTermHandlerTimer.stop();
|
||||
OpenVpnProtocol::stop();
|
||||
|
||||
if (communicator() && !communicator()->isConnected()) {
|
||||
setLastError(ErrorCode::AmneziaServiceConnectionFailed);
|
||||
return lastError();
|
||||
}
|
||||
// if (communicator() && !communicator()->isConnected()) {
|
||||
// setLastError(ErrorCode::AmneziaServiceConnectionFailed);
|
||||
// return lastError();
|
||||
// }
|
||||
|
||||
if (!QFileInfo::exists(openVpnExecPath())) {
|
||||
setLastError(ErrorCode::OpenVpnExecutableMissing);
|
||||
|
|
@ -165,7 +165,20 @@ ErrorCode OpenVpnProtocol::start()
|
|||
}
|
||||
|
||||
setConnectionState(ConnectionState::Connecting);
|
||||
m_communicator->sendMessage(Message(Message::State::StartRequest, args));
|
||||
|
||||
QSharedPointer<IpcProcessInterfaceReplica> process = IpcClient::createPrivilegedProcess();
|
||||
process->waitForSource(1000);
|
||||
if (!process->isInitialized()) {
|
||||
return ErrorCode::AmneziaServiceConnectionFailed;
|
||||
}
|
||||
process->setProgram(openVpnExecPath());
|
||||
process->setArguments(QStringList() << "--config" << configPath()<<
|
||||
"--management"<< m_managementHost<< QString::number(m_managementPort)<<
|
||||
"--management-client"<<
|
||||
"--log-append"<< vpnLogFileNamePath);
|
||||
process->start();
|
||||
|
||||
//m_communicator->sendMessage(Message(Message::State::StartRequest, args));
|
||||
startTimeoutTimer();
|
||||
|
||||
return ErrorCode::NoError;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@
|
|||
#include "message.h"
|
||||
#include "vpnprotocol.h"
|
||||
|
||||
#include "core/ipcclient.h"
|
||||
|
||||
class OpenVpnProtocol : public VpnProtocol
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
@ -45,7 +47,7 @@ protected:
|
|||
ManagementServer m_managementServer;
|
||||
QString m_configFileName;
|
||||
QTimer m_openVpnStateSigTermHandlerTimer;
|
||||
bool m_requestFromUserToStop;
|
||||
//bool m_requestFromUserToStop;
|
||||
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <core/openvpnconfigurator.h>
|
||||
#include <core/servercontroller.h>
|
||||
|
||||
#include "ipc.h"
|
||||
#include "protocols/openvpnprotocol.h"
|
||||
#include "protocols/shadowsocksvpnprotocol.h"
|
||||
#include "utils.h"
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QScopedPointer>
|
||||
#include <QRemoteObjectNode>
|
||||
|
||||
#include "protocols/vpnprotocol.h"
|
||||
#include "core/defs.h"
|
||||
|
|
@ -45,6 +46,7 @@ protected:
|
|||
|
||||
private:
|
||||
Settings m_settings;
|
||||
|
||||
};
|
||||
|
||||
#endif // VPNCONNECTION_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue