Add Qt6 support
This commit is contained in:
parent
9f60a76d14
commit
fad0bc1e62
@ -68,7 +68,11 @@ QByteArray SlipDataProcessor::deserializeData(const QByteArray &data)
|
|||||||
QByteArray SlipDataProcessor::serializeData(const QByteArray &data)
|
QByteArray SlipDataProcessor::serializeData(const QByteArray &data)
|
||||||
{
|
{
|
||||||
QByteArray serializedData;
|
QByteArray serializedData;
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
|
QDataStream stream(&serializedData, QDataStream::WriteOnly);
|
||||||
|
#else
|
||||||
QDataStream stream(&serializedData, QIODevice::WriteOnly);
|
QDataStream stream(&serializedData, QIODevice::WriteOnly);
|
||||||
|
#endif
|
||||||
// stream << static_cast<quint8>(ProtocolByteEnd);
|
// stream << static_cast<quint8>(ProtocolByteEnd);
|
||||||
|
|
||||||
for (int i = 0; i < data.length(); i++) {
|
for (int i = 0; i < data.length(); i++) {
|
||||||
@ -110,7 +114,11 @@ SlipDataProcessor::Frame SlipDataProcessor::parseFrame(const QByteArray &data)
|
|||||||
QByteArray SlipDataProcessor::buildFrame(const Frame &frame)
|
QByteArray SlipDataProcessor::buildFrame(const Frame &frame)
|
||||||
{
|
{
|
||||||
QByteArray data;
|
QByteArray data;
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
|
QDataStream stream(&data, QDataStream::WriteOnly);
|
||||||
|
#else
|
||||||
QDataStream stream(&data, QIODevice::WriteOnly);
|
QDataStream stream(&data, QIODevice::WriteOnly);
|
||||||
|
#endif
|
||||||
stream << frame.socketAddress;
|
stream << frame.socketAddress;
|
||||||
for (int i = 0; i < frame.data.size(); i++) {
|
for (int i = 0; i < frame.data.size(); i++) {
|
||||||
stream << static_cast<quint8>(frame.data.at(i));
|
stream << static_cast<quint8>(frame.data.at(i));
|
||||||
|
|||||||
@ -28,7 +28,7 @@
|
|||||||
#include "jsonhandler.h"
|
#include "jsonhandler.h"
|
||||||
#include <QMetaMethod>
|
#include <QMetaMethod>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QRegExp>
|
#include <QRegularExpression>
|
||||||
|
|
||||||
#include "jsonreply.h"
|
#include "jsonreply.h"
|
||||||
#include "jsontypes.h"
|
#include "jsontypes.h"
|
||||||
@ -67,7 +67,7 @@ QVariantMap JsonHandler::introspect(const QMetaMethod::MethodType &type)
|
|||||||
if (!m_descriptions.contains(method.name()) || !m_params.contains(method.name())) {
|
if (!m_descriptions.contains(method.name()) || !m_params.contains(method.name())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (QString(method.name()).contains(QRegExp("^[A-Z]"))) {
|
if (QString(method.name()).contains(QRegularExpression("^[A-Z]"))) {
|
||||||
QVariantMap methodData;
|
QVariantMap methodData;
|
||||||
methodData.insert("description", m_descriptions.value(method.name()));
|
methodData.insert("description", m_descriptions.value(method.name()));
|
||||||
methodData.insert("params", m_params.value(method.name()));
|
methodData.insert("params", m_params.value(method.name()));
|
||||||
|
|||||||
@ -39,6 +39,7 @@ namespace remoteproxy {
|
|||||||
class JsonReply: public QObject
|
class JsonReply: public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum Type {
|
enum Type {
|
||||||
TypeSync,
|
TypeSync,
|
||||||
|
|||||||
@ -29,6 +29,7 @@
|
|||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
#include "loggingcategories.h"
|
#include "loggingcategories.h"
|
||||||
|
|
||||||
@ -72,7 +73,7 @@ QPair<bool, QString> JsonTypes::validateMap(const QVariantMap &templateMap, cons
|
|||||||
// Make sure all values defined in the template are around
|
// Make sure all values defined in the template are around
|
||||||
foreach (const QString &key, templateMap.keys()) {
|
foreach (const QString &key, templateMap.keys()) {
|
||||||
QString strippedKey = key;
|
QString strippedKey = key;
|
||||||
strippedKey.remove(QRegExp("^o:"));
|
strippedKey.remove(QRegularExpression("^o:"));
|
||||||
if (!key.startsWith("o:") && !map.contains(strippedKey)) {
|
if (!key.startsWith("o:") && !map.contains(strippedKey)) {
|
||||||
qCWarning(dcJsonRpc()) << "*** missing key" << key;
|
qCWarning(dcJsonRpc()) << "*** missing key" << key;
|
||||||
qCWarning(dcJsonRpc()) << "Expected: " << templateMap;
|
qCWarning(dcJsonRpc()) << "Expected: " << templateMap;
|
||||||
@ -274,7 +275,7 @@ QString JsonTypes::basicTypeToString(const QVariant::Type &type)
|
|||||||
|
|
||||||
QPair<bool, QString> JsonTypes::report(bool status, const QString &message)
|
QPair<bool, QString> JsonTypes::report(bool status, const QString &message)
|
||||||
{
|
{
|
||||||
return qMakePair<bool, QString>(status, message);
|
return QPair<bool, QString>(status, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantList JsonTypes::enumToStrings(const QMetaObject &metaObject, const QString &enumName)
|
QVariantList JsonTypes::enumToStrings(const QMetaObject &metaObject, const QString &enumName)
|
||||||
|
|||||||
@ -70,7 +70,6 @@ namespace remoteproxy {
|
|||||||
class JsonTypes
|
class JsonTypes
|
||||||
{
|
{
|
||||||
Q_GADGET
|
Q_GADGET
|
||||||
Q_ENUMS(BasicType)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum BasicType {
|
enum BasicType {
|
||||||
|
|||||||
@ -45,6 +45,15 @@ public:
|
|||||||
|
|
||||||
QString name() const override;
|
QString name() const override;
|
||||||
|
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
|
// Server
|
||||||
|
Q_INVOKABLE remoteproxy::JsonReply *RegisterServer(const QVariantMap ¶ms, TransportClient *transportClient);
|
||||||
|
Q_INVOKABLE remoteproxy::JsonReply *DisconnectClient(const QVariantMap ¶ms, TransportClient *transportClient);
|
||||||
|
Q_INVOKABLE remoteproxy::JsonReply *Ping(const QVariantMap ¶ms, TransportClient *transportClient);
|
||||||
|
|
||||||
|
// Client
|
||||||
|
Q_INVOKABLE remoteproxy::JsonReply *RegisterClient(const QVariantMap ¶ms, TransportClient *transportClient);
|
||||||
|
#else
|
||||||
// Server
|
// Server
|
||||||
Q_INVOKABLE JsonReply *RegisterServer(const QVariantMap ¶ms, TransportClient *transportClient);
|
Q_INVOKABLE JsonReply *RegisterServer(const QVariantMap ¶ms, TransportClient *transportClient);
|
||||||
Q_INVOKABLE JsonReply *DisconnectClient(const QVariantMap ¶ms, TransportClient *transportClient);
|
Q_INVOKABLE JsonReply *DisconnectClient(const QVariantMap ¶ms, TransportClient *transportClient);
|
||||||
@ -52,7 +61,7 @@ public:
|
|||||||
|
|
||||||
// Client
|
// Client
|
||||||
Q_INVOKABLE JsonReply *RegisterClient(const QVariantMap ¶ms, TransportClient *transportClient);
|
Q_INVOKABLE JsonReply *RegisterClient(const QVariantMap ¶ms, TransportClient *transportClient);
|
||||||
|
#endif
|
||||||
signals:
|
signals:
|
||||||
void ClientConnected(const QVariantMap ¶ms, TransportClient *transportClient);
|
void ClientConnected(const QVariantMap ¶ms, TransportClient *transportClient);
|
||||||
void ClientDisconnected(const QVariantMap ¶ms, TransportClient *transportClient);
|
void ClientDisconnected(const QVariantMap ¶ms, TransportClient *transportClient);
|
||||||
|
|||||||
@ -29,6 +29,7 @@
|
|||||||
#include "loggingcategories.h"
|
#include "loggingcategories.h"
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
namespace remoteproxy {
|
namespace remoteproxy {
|
||||||
|
|
||||||
@ -101,7 +102,7 @@ void LogEngine::rotateLogs()
|
|||||||
|
|
||||||
QString LogEngine::createTimestamp()
|
QString LogEngine::createTimestamp()
|
||||||
{
|
{
|
||||||
return QString::number(QDateTime::currentDateTimeUtc().toTime_t());
|
return QString::number(QDateTime::currentDateTimeUtc().toSecsSinceEpoch());
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogEngine::enable()
|
void LogEngine::enable()
|
||||||
|
|||||||
@ -331,7 +331,7 @@ QDebug operator<<(QDebug debug, ProxyConfiguration *configuration)
|
|||||||
debug.nospace() << " Locality name:" << configuration->sslConfiguration().localCertificate().issuerInfo(QSslCertificate::LocalityName) << "\n";
|
debug.nospace() << " Locality name:" << configuration->sslConfiguration().localCertificate().issuerInfo(QSslCertificate::LocalityName) << "\n";
|
||||||
debug.nospace() << " State/Province:" << configuration->sslConfiguration().localCertificate().issuerInfo(QSslCertificate::StateOrProvinceName) << "\n";
|
debug.nospace() << " State/Province:" << configuration->sslConfiguration().localCertificate().issuerInfo(QSslCertificate::StateOrProvinceName) << "\n";
|
||||||
debug.nospace() << " Email address:" << configuration->sslConfiguration().localCertificate().issuerInfo(QSslCertificate::EmailAddress) << "\n";
|
debug.nospace() << " Email address:" << configuration->sslConfiguration().localCertificate().issuerInfo(QSslCertificate::EmailAddress) << "\n";
|
||||||
debug.nospace() << "UnixSocketServer Proxy" << endl;
|
debug.nospace() << "UnixSocketServer Proxy" << "\n";
|
||||||
debug.nospace() << " - Filename:" << configuration->unixSocketFileName() << "\n";
|
debug.nospace() << " - Filename:" << configuration->unixSocketFileName() << "\n";
|
||||||
debug.nospace() << "WebSocketServer TunnelProxy" << "\n";
|
debug.nospace() << "WebSocketServer TunnelProxy" << "\n";
|
||||||
debug.nospace() << " - Host:" << configuration->webSocketServerTunnelProxyHost().toString() << "\n";
|
debug.nospace() << " - Host:" << configuration->webSocketServerTunnelProxyHost().toString() << "\n";
|
||||||
|
|||||||
@ -42,6 +42,9 @@ namespace remoteproxy {
|
|||||||
JsonRpcServer::JsonRpcServer(QObject *parent) :
|
JsonRpcServer::JsonRpcServer(QObject *parent) :
|
||||||
JsonHandler(parent)
|
JsonHandler(parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//qRegisterMetaType<JsonReply*>();
|
||||||
|
|
||||||
// Methods
|
// Methods
|
||||||
QVariantMap params; QVariantMap returns;
|
QVariantMap params; QVariantMap returns;
|
||||||
|
|
||||||
@ -66,9 +69,9 @@ JsonRpcServer::JsonRpcServer(QObject *parent) :
|
|||||||
// Notifications
|
// Notifications
|
||||||
params.clear(); returns.clear();
|
params.clear(); returns.clear();
|
||||||
setDescription("TunnelEstablished", "Emitted whenever the tunnel has been established successfully. "
|
setDescription("TunnelEstablished", "Emitted whenever the tunnel has been established successfully. "
|
||||||
"This is the last message from the remote proxy server! Any following data will be from "
|
"This is the last message from the remote proxy server! Any following data will be from "
|
||||||
"the other tunnel client until the connection will be closed. The parameter contain some information "
|
"the other tunnel client until the connection will be closed. The parameter contain some information "
|
||||||
"about the other tunnel client.");
|
"about the other tunnel client.");
|
||||||
params.insert("uuid", JsonTypes::basicTypeToString(JsonTypes::String));
|
params.insert("uuid", JsonTypes::basicTypeToString(JsonTypes::String));
|
||||||
params.insert("name", JsonTypes::basicTypeToString(JsonTypes::String));
|
params.insert("name", JsonTypes::basicTypeToString(JsonTypes::String));
|
||||||
setParams("TunnelEstablished", params);
|
setParams("TunnelEstablished", params);
|
||||||
@ -114,14 +117,20 @@ JsonReply *JsonRpcServer::Introspect(const QVariantMap ¶ms, TransportClient
|
|||||||
|
|
||||||
QVariantMap methods;
|
QVariantMap methods;
|
||||||
foreach (JsonHandler *handler, m_handlers) {
|
foreach (JsonHandler *handler, m_handlers) {
|
||||||
methods.unite(handler->introspect(QMetaMethod::Method));
|
QVariantMap handlerMethods = handler->introspect(QMetaMethod::Method);
|
||||||
|
foreach (const QString &method, handlerMethods.keys()) {
|
||||||
|
methods.insert(method, handlerMethods.value(method));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data.insert("methods", methods);
|
data.insert("methods", methods);
|
||||||
|
|
||||||
QVariantMap signalsMap;
|
QVariantMap signalsMap;
|
||||||
foreach (JsonHandler *handler, m_handlers) {
|
foreach (JsonHandler *handler, m_handlers) {
|
||||||
signalsMap.unite(handler->introspect(QMetaMethod::Signal));
|
QVariantMap handlerSignals = handler->introspect(QMetaMethod::Signal);
|
||||||
|
foreach (const QString &signalName, handlerSignals.keys()) {
|
||||||
|
signalsMap.insert(signalName, handlerSignals.value(signalName));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data.insert("notifications", signalsMap);
|
data.insert("notifications", signalsMap);
|
||||||
@ -141,10 +150,10 @@ void JsonRpcServer::sendResponse(TransportClient *client, int commandId, const Q
|
|||||||
if (client->slipEnabled()) {
|
if (client->slipEnabled()) {
|
||||||
SlipDataProcessor::Frame frame;
|
SlipDataProcessor::Frame frame;
|
||||||
frame.socketAddress = 0x0000;
|
frame.socketAddress = 0x0000;
|
||||||
frame.data = data + '\n';
|
frame.data = data + "\n";
|
||||||
client->sendData(SlipDataProcessor::serializeData(SlipDataProcessor::buildFrame(frame)));
|
client->sendData(SlipDataProcessor::serializeData(SlipDataProcessor::buildFrame(frame)));
|
||||||
} else {
|
} else {
|
||||||
client->sendData(data + '\n');
|
client->sendData(data + "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,10 +169,10 @@ void JsonRpcServer::sendErrorResponse(TransportClient *client, int commandId, co
|
|||||||
if (client->slipEnabled()) {
|
if (client->slipEnabled()) {
|
||||||
SlipDataProcessor::Frame frame;
|
SlipDataProcessor::Frame frame;
|
||||||
frame.socketAddress = 0x0000;
|
frame.socketAddress = 0x0000;
|
||||||
frame.data = data + '\n';
|
frame.data = data + "\n";
|
||||||
client->sendData(SlipDataProcessor::serializeData(SlipDataProcessor::buildFrame(frame)));
|
client->sendData(SlipDataProcessor::serializeData(SlipDataProcessor::buildFrame(frame)));
|
||||||
} else {
|
} else {
|
||||||
client->sendData(data + '\n');
|
client->sendData(data + "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,9 +181,9 @@ QString JsonRpcServer::formatAssertion(const QString &targetNamespace, const QSt
|
|||||||
QJsonDocument doc = QJsonDocument::fromVariant(handler->introspect(QMetaMethod::Method).value(targetNamespace + "." + method));
|
QJsonDocument doc = QJsonDocument::fromVariant(handler->introspect(QMetaMethod::Method).value(targetNamespace + "." + method));
|
||||||
QJsonDocument doc2 = QJsonDocument::fromVariant(data);
|
QJsonDocument doc2 = QJsonDocument::fromVariant(data);
|
||||||
return QString("\nMethod: %1\nTemplate: %2\nValue: %3")
|
return QString("\nMethod: %1\nTemplate: %2\nValue: %3")
|
||||||
.arg(targetNamespace + "." + method)
|
.arg(targetNamespace + "." + method)
|
||||||
.arg(QString(doc.toJson(QJsonDocument::Indented)))
|
.arg(QString(doc.toJson(QJsonDocument::Indented)))
|
||||||
.arg(QString(doc2.toJson(QJsonDocument::Indented)));
|
.arg(QString(doc2.toJson(QJsonDocument::Indented)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonRpcServer::registerHandler(JsonHandler *handler)
|
void JsonRpcServer::registerHandler(JsonHandler *handler)
|
||||||
@ -248,14 +257,38 @@ void JsonRpcServer::processDataPacket(TransportClient *transportClient, const QB
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonReply *reply;
|
|
||||||
QMetaObject::invokeMethod(handler, method.toLatin1().data(), Q_RETURN_ARG(JsonReply*, reply), Q_ARG(QVariantMap, params), Q_ARG(TransportClient*, transportClient));
|
JsonReply *reply = nullptr;
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
|
bool invokedSuccessfully = QMetaObject::invokeMethod(handler, method.toLatin1().constData(),
|
||||||
|
Qt::DirectConnection,
|
||||||
|
qReturnArg(reply),
|
||||||
|
params, transportClient);
|
||||||
|
|
||||||
|
if (!invokedSuccessfully) {
|
||||||
|
qCWarning(dcJsonRpc()) << "Failed to invoke method" << handler << method;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
QMetaObject::invokeMethod(handler, method.toLatin1().constData(),
|
||||||
|
Qt::DirectConnection,
|
||||||
|
Q_RETURN_ARG(JsonReply *, reply),
|
||||||
|
Q_ARG(QVariantMap, params),
|
||||||
|
Q_ARG(TransportClient *, transportClient));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
if (!reply) {
|
||||||
|
qCWarning(dcJsonRpc()) << "Internal error. No reply, could not invoke method.";
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (reply->type() == JsonReply::TypeAsync) {
|
if (reply->type() == JsonReply::TypeAsync) {
|
||||||
m_asyncReplies.insert(reply, transportClient);
|
m_asyncReplies.insert(reply, transportClient);
|
||||||
reply->setClientId(transportClient->clientId());
|
reply->setClientId(transportClient->clientId());
|
||||||
reply->setCommandId(commandId);
|
reply->setCommandId(commandId);
|
||||||
|
|
||||||
connect(reply, &JsonReply::finished, this, &JsonRpcServer::asyncReplyFinished);
|
connect(reply, &remoteproxy::JsonReply::finished, this, &JsonRpcServer::asyncReplyFinished);
|
||||||
reply->startWait();
|
reply->startWait();
|
||||||
} else {
|
} else {
|
||||||
Q_ASSERT_X((targetNamespace == "RemoteProxy" && method == "Introspect") || handler->validateReturns(method, reply->data()).first
|
Q_ASSERT_X((targetNamespace == "RemoteProxy" && method == "Introspect") || handler->validateReturns(method, reply->data()).first
|
||||||
@ -295,7 +328,7 @@ void JsonRpcServer::asyncReplyFinished()
|
|||||||
if (!reply->timedOut()) {
|
if (!reply->timedOut()) {
|
||||||
Q_ASSERT_X(reply->handler()->validateReturns(reply->method(), reply->data()).first
|
Q_ASSERT_X(reply->handler()->validateReturns(reply->method(), reply->data()).first
|
||||||
,"validating return value", formatAssertion(reply->handler()->name(),
|
,"validating return value", formatAssertion(reply->handler()->name(),
|
||||||
reply->method(), reply->handler(), reply->data()).toLatin1().data());
|
reply->method(), reply->handler(), reply->data()).toLatin1().data());
|
||||||
|
|
||||||
QPair<bool, QString> returnValidation = reply->handler()->validateReturns(reply->method(), reply->data());
|
QPair<bool, QString> returnValidation = reply->handler()->validateReturns(reply->method(), reply->data());
|
||||||
if (!returnValidation.first) {
|
if (!returnValidation.first) {
|
||||||
@ -385,12 +418,12 @@ void JsonRpcServer::sendNotification(const QString &nameSpace, const QString &me
|
|||||||
if (transportClient->slipEnabled()) {
|
if (transportClient->slipEnabled()) {
|
||||||
SlipDataProcessor::Frame frame;
|
SlipDataProcessor::Frame frame;
|
||||||
frame.socketAddress = 0x0000;
|
frame.socketAddress = 0x0000;
|
||||||
frame.data = data + '\n';
|
frame.data = data + "\n";
|
||||||
qCDebug(dcJsonRpcTraffic()) << "Sending notification frame:" <<frame.socketAddress << qUtf8Printable(frame.data);
|
qCDebug(dcJsonRpcTraffic()) << "Sending notification frame:" <<frame.socketAddress << qUtf8Printable(frame.data);
|
||||||
transportClient->sendData(SlipDataProcessor::serializeData(SlipDataProcessor::buildFrame(frame)));
|
transportClient->sendData(SlipDataProcessor::serializeData(SlipDataProcessor::buildFrame(frame)));
|
||||||
} else {
|
} else {
|
||||||
qCDebug(dcJsonRpcTraffic()) << "Sending notification:" << data;
|
qCDebug(dcJsonRpcTraffic()) << "Sending notification:" << data;
|
||||||
transportClient->sendData(data + '\n');
|
transportClient->sendData(data + "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -56,7 +56,7 @@ bool MonitorServer::running() const
|
|||||||
|
|
||||||
void MonitorServer::sendMonitorData(QLocalSocket *clientConnection, const QVariantMap &dataMap)
|
void MonitorServer::sendMonitorData(QLocalSocket *clientConnection, const QVariantMap &dataMap)
|
||||||
{
|
{
|
||||||
QByteArray data = QJsonDocument::fromVariant(dataMap).toJson(QJsonDocument::Compact) + '\n';
|
QByteArray data = QJsonDocument::fromVariant(dataMap).toJson(QJsonDocument::Compact) + "\n";
|
||||||
qCDebug(dcMonitorServer()) << "Sending monitor data" << qUtf8Printable(data);
|
qCDebug(dcMonitorServer()) << "Sending monitor data" << qUtf8Printable(data);
|
||||||
clientConnection->write(data);
|
clientConnection->write(data);
|
||||||
clientConnection->flush();
|
clientConnection->flush();
|
||||||
|
|||||||
@ -45,7 +45,7 @@ TcpSocketServer::~TcpSocketServer()
|
|||||||
|
|
||||||
void TcpSocketServer::sendData(const QUuid &clientId, const QByteArray &data)
|
void TcpSocketServer::sendData(const QUuid &clientId, const QByteArray &data)
|
||||||
{
|
{
|
||||||
QTcpSocket *client = m_clientList.value(clientId);
|
QSslSocket *client = m_clientList.value(clientId);
|
||||||
if (!client) {
|
if (!client) {
|
||||||
qCWarning(dcTcpSocketServer()) << "Client" << clientId << "unknown to this transport";
|
qCWarning(dcTcpSocketServer()) << "Client" << clientId << "unknown to this transport";
|
||||||
return;
|
return;
|
||||||
@ -59,7 +59,7 @@ void TcpSocketServer::sendData(const QUuid &clientId, const QByteArray &data)
|
|||||||
|
|
||||||
void TcpSocketServer::killClientConnection(const QUuid &clientId, const QString &killReason)
|
void TcpSocketServer::killClientConnection(const QUuid &clientId, const QString &killReason)
|
||||||
{
|
{
|
||||||
QTcpSocket *client = m_clientList.value(clientId);
|
QSslSocket *client = m_clientList.value(clientId);
|
||||||
if (!client) {
|
if (!client) {
|
||||||
qCWarning(dcTcpSocketServer()) << "Could not kill connection with id" << clientId.toString() << "with reason" << killReason << "because there is no socket with this id.";
|
qCWarning(dcTcpSocketServer()) << "Could not kill connection with id" << clientId.toString() << "with reason" << killReason << "because there is no socket with this id.";
|
||||||
return;
|
return;
|
||||||
@ -193,10 +193,17 @@ void SslServer::incomingConnection(qintptr socketDescriptor)
|
|||||||
qCDebug(dcTcpSocketServer()) << "Client socket disconnected:" << sslSocket << sslSocket->peerAddress().toString();;
|
qCDebug(dcTcpSocketServer()) << "Client socket disconnected:" << sslSocket << sslSocket->peerAddress().toString();;
|
||||||
|
|
||||||
if (m_sslEnabled) {
|
if (m_sslEnabled) {
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
|
// FIXME: the SSL socket behavior seems to have changed in Qt6,
|
||||||
|
// we need to emit this signal in any case, otherwise the upper layer assumes the
|
||||||
|
// socket object still exists, even if we only hand over to upper layers on encypted.
|
||||||
|
emit socketDisconnected(sslSocket);
|
||||||
|
#else
|
||||||
// Only tell the upper layer the client has disconnecred if it was encrypted
|
// Only tell the upper layer the client has disconnecred if it was encrypted
|
||||||
if (sslSocket->isEncrypted()) {
|
if (sslSocket->isEncrypted()) {
|
||||||
emit socketDisconnected(sslSocket);
|
emit socketDisconnected(sslSocket);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
emit socketDisconnected(sslSocket);
|
emit socketDisconnected(sslSocket);
|
||||||
}
|
}
|
||||||
@ -221,6 +228,19 @@ void SslServer::incomingConnection(qintptr socketDescriptor)
|
|||||||
emit socketConnected(sslSocket);
|
emit socketConnected(sslSocket);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
|
connect(sslSocket, &QSslSocket::errorOccurred, this, [sslSocket](QAbstractSocket::SocketError error){
|
||||||
|
qCWarning(dcTcpSocketServer()) << "Socket error occurred on" << sslSocket << error << sslSocket->errorString() << "Explicitly closing the client connection.";
|
||||||
|
sslSocket->close();
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(sslSocket, &QSslSocket::sslErrors, this, [sslSocket](const QList<QSslError> &errors) {
|
||||||
|
qCWarning(dcTcpSocketServer()) << "SSL error occurred in the client connection" << sslSocket;
|
||||||
|
foreach (const QSslError &error, errors) {
|
||||||
|
qCWarning(dcTcpSocketServer()) << "--> SSL error:" << error.error() << error.errorString();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
#else
|
||||||
typedef void (QAbstractSocket:: *errorSignal)(QAbstractSocket::SocketError);
|
typedef void (QAbstractSocket:: *errorSignal)(QAbstractSocket::SocketError);
|
||||||
connect(sslSocket, static_cast<errorSignal>(&QAbstractSocket::error), this, [sslSocket](QAbstractSocket::SocketError error){
|
connect(sslSocket, static_cast<errorSignal>(&QAbstractSocket::error), this, [sslSocket](QAbstractSocket::SocketError error){
|
||||||
qCWarning(dcTcpSocketServer()) << "Socket error occurred on" << sslSocket << error << sslSocket->errorString() << "Explicitly closing the client connection.";
|
qCWarning(dcTcpSocketServer()) << "Socket error occurred on" << sslSocket << error << sslSocket->errorString() << "Explicitly closing the client connection.";
|
||||||
@ -235,6 +255,8 @@ void SslServer::incomingConnection(qintptr socketDescriptor)
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
if (m_sslEnabled) {
|
if (m_sslEnabled) {
|
||||||
qCDebug(dcTcpSocketServer()) << "Starting SSL encryption for" << sslSocket;
|
qCDebug(dcTcpSocketServer()) << "Starting SSL encryption for" << sslSocket;
|
||||||
sslSocket->setSslConfiguration(m_config);
|
sslSocket->setSslConfiguration(m_config);
|
||||||
|
|||||||
@ -38,7 +38,7 @@ TransportClient::TransportClient(TransportInterface *interface, const QUuid &cli
|
|||||||
m_clientId(clientId),
|
m_clientId(clientId),
|
||||||
m_peerAddress(address)
|
m_peerAddress(address)
|
||||||
{
|
{
|
||||||
m_creationTimeStamp = QDateTime::currentDateTime().toMSecsSinceEpoch() / 1000;
|
m_creationTimeStamp = QDateTime::currentDateTime().toSecsSinceEpoch();
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid TransportClient::clientId() const
|
QUuid TransportClient::clientId() const
|
||||||
|
|||||||
@ -134,14 +134,14 @@ void UnixSocketServer::onClientConnected()
|
|||||||
qCDebug(dcUnixSocketServer()) << "New client connected" << clientId.toString();
|
qCDebug(dcUnixSocketServer()) << "New client connected" << clientId.toString();
|
||||||
m_clientList.insert(clientId, client);
|
m_clientList.insert(clientId, client);
|
||||||
|
|
||||||
connect(client, &QLocalSocket::disconnected, this, [=](){
|
connect(client, &QLocalSocket::disconnected, this, [this, client](){
|
||||||
QUuid clientId = m_clientList.key(client);
|
QUuid clientId = m_clientList.key(client);
|
||||||
qCDebug(dcUnixSocketServer()) << "Client disconnected:" << clientId.toString();
|
qCDebug(dcUnixSocketServer()) << "Client disconnected:" << clientId.toString();
|
||||||
if (m_clientList.take(clientId)) {
|
if (m_clientList.take(clientId)) {
|
||||||
emit clientDisconnected(clientId);
|
emit clientDisconnected(clientId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
connect(client, &QLocalSocket::readyRead, this, [=](){
|
connect(client, &QLocalSocket::readyRead, this, [this, client, clientId](){
|
||||||
QByteArray data = client->readAll();
|
QByteArray data = client->readAll();
|
||||||
qCDebug(dcUnixSocketServerTraffic()) << "Incomming data from" << clientId.toString() << data;
|
qCDebug(dcUnixSocketServerTraffic()) << "Incomming data from" << clientId.toString() << data;
|
||||||
emit dataAvailable(clientId, data);
|
emit dataAvailable(clientId, data);
|
||||||
|
|||||||
@ -105,7 +105,7 @@ JsonReply *JsonRpcClient::callPing(uint timestamp)
|
|||||||
|
|
||||||
void JsonRpcClient::sendRequest(const QVariantMap &request, bool slipEnabled)
|
void JsonRpcClient::sendRequest(const QVariantMap &request, bool slipEnabled)
|
||||||
{
|
{
|
||||||
QByteArray data = QJsonDocument::fromVariant(request).toJson(QJsonDocument::Compact) + '\n';
|
QByteArray data = QJsonDocument::fromVariant(request).toJson(QJsonDocument::Compact) + "\n";
|
||||||
|
|
||||||
if (slipEnabled) {
|
if (slipEnabled) {
|
||||||
SlipDataProcessor::Frame frame;
|
SlipDataProcessor::Frame frame;
|
||||||
|
|||||||
@ -41,11 +41,17 @@ TcpSocketConnection::TcpSocketConnection(QObject *parent) :
|
|||||||
QObject::connect(m_tcpSocket, &QSslSocket::readyRead, this, &TcpSocketConnection::onReadyRead);
|
QObject::connect(m_tcpSocket, &QSslSocket::readyRead, this, &TcpSocketConnection::onReadyRead);
|
||||||
QObject::connect(m_tcpSocket, &QSslSocket::stateChanged, this, &TcpSocketConnection::onStateChanged);
|
QObject::connect(m_tcpSocket, &QSslSocket::stateChanged, this, &TcpSocketConnection::onStateChanged);
|
||||||
|
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
|
connect(m_tcpSocket, &QSslSocket::errorOccurred, this, &TcpSocketConnection::onError);
|
||||||
|
connect(m_tcpSocket, &QSslSocket::sslErrors, this, &TcpSocketConnection::sslErrors);
|
||||||
|
#else
|
||||||
typedef void (QSslSocket:: *errorSignal)(QAbstractSocket::SocketError);
|
typedef void (QSslSocket:: *errorSignal)(QAbstractSocket::SocketError);
|
||||||
QObject::connect(m_tcpSocket, static_cast<errorSignal>(&QSslSocket::error), this, &TcpSocketConnection::onError);
|
QObject::connect(m_tcpSocket, static_cast<errorSignal>(&QSslSocket::error), this, &TcpSocketConnection::onError);
|
||||||
|
|
||||||
typedef void (QSslSocket:: *sslErrorsSignal)(const QList<QSslError> &);
|
typedef void (QSslSocket:: *sslErrorsSignal)(const QList<QSslError> &);
|
||||||
QObject::connect(m_tcpSocket, static_cast<sslErrorsSignal>(&QSslSocket::sslErrors), this, &TcpSocketConnection::sslErrors);
|
QObject::connect(m_tcpSocket, static_cast<sslErrorsSignal>(&QSslSocket::sslErrors), this, &TcpSocketConnection::sslErrors);
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TcpSocketConnection::~TcpSocketConnection()
|
TcpSocketConnection::~TcpSocketConnection()
|
||||||
|
|||||||
@ -87,7 +87,7 @@ void MonitorClient::onDisconnected()
|
|||||||
|
|
||||||
void MonitorClient::onReadyRead()
|
void MonitorClient::onReadyRead()
|
||||||
{
|
{
|
||||||
// Note: the server sends the data compact with '\n' at the end
|
// Note: the server sends the data compact with "\n" at the end
|
||||||
QByteArray data = m_socket->readAll();
|
QByteArray data = m_socket->readAll();
|
||||||
|
|
||||||
int index = data.indexOf("}\n");
|
int index = data.indexOf("}\n");
|
||||||
|
|||||||
@ -69,7 +69,7 @@ void NonInteractiveMonitor::onConnected()
|
|||||||
QVariantList clientList = serverMap.value("clientConnections").toList();
|
QVariantList clientList = serverMap.value("clientConnections").toList();
|
||||||
|
|
||||||
// Server line
|
// Server line
|
||||||
QString serverConnectionTime = QDateTime::fromTime_t(serverMap.value("timestamp").toUInt()).toString("dd.MM.yyyy hh:mm:ss");
|
QString serverConnectionTime = QDateTime::fromMSecsSinceEpoch(serverMap.value("timestamp").toLongLong() * 1000).toString("dd.MM.yyyy hh:mm:ss");
|
||||||
QString serverLinePrint;
|
QString serverLinePrint;
|
||||||
if (clientList.isEmpty()) {
|
if (clientList.isEmpty()) {
|
||||||
serverLinePrint.prepend("├──");
|
serverLinePrint.prepend("├──");
|
||||||
@ -97,7 +97,7 @@ void NonInteractiveMonitor::onConnected()
|
|||||||
}
|
}
|
||||||
|
|
||||||
clientLinePrint += QString("%1 | %2 | %3 RX: %4 TX: %5 | %6")
|
clientLinePrint += QString("%1 | %2 | %3 RX: %4 TX: %5 | %6")
|
||||||
.arg(QDateTime::fromTime_t(clientMap.value("timestamp").toUInt()).toString("dd.MM.yyyy hh:mm:ss"))
|
.arg(QDateTime::fromMSecsSinceEpoch(clientMap.value("timestamp").toLongLong() * 1000).toString("dd.MM.yyyy hh:mm:ss"))
|
||||||
.arg(clientMap.value("clientUuid").toString())
|
.arg(clientMap.value("clientUuid").toString())
|
||||||
.arg(clientMap.value("address").toString(), - 15)
|
.arg(clientMap.value("address").toString(), - 15)
|
||||||
.arg(Utils::humanReadableTraffic(serverMap.value("rxDataCount").toInt()), - 9)
|
.arg(Utils::humanReadableTraffic(serverMap.value("rxDataCount").toInt()), - 9)
|
||||||
|
|||||||
@ -195,7 +195,7 @@ void TerminalWindow::paintContentClients()
|
|||||||
QVariantMap clientMap = clientVariant.toMap();
|
QVariantMap clientMap = clientVariant.toMap();
|
||||||
|
|
||||||
uint timeStamp = clientMap.value("timestamp").toUInt();
|
uint timeStamp = clientMap.value("timestamp").toUInt();
|
||||||
QString clientConnectionTime = QDateTime::fromTime_t(timeStamp).toString("dd.MM.yyyy hh:mm:ss");
|
QString clientConnectionTime = QDateTime::fromMSecsSinceEpoch(timeStamp * 1000).toString("dd.MM.yyyy hh:mm:ss");
|
||||||
|
|
||||||
int rxDataCountBytes = clientMap.value("rxDataCount").toInt();
|
int rxDataCountBytes = clientMap.value("rxDataCount").toInt();
|
||||||
int txDataCountBytes = clientMap.value("txDataCount").toInt();
|
int txDataCountBytes = clientMap.value("txDataCount").toInt();
|
||||||
@ -226,7 +226,7 @@ void TerminalWindow::paintContentTunnels()
|
|||||||
|
|
||||||
// Tunnel time
|
// Tunnel time
|
||||||
uint timeStamp = tunnelMap.value("timestamp").toUInt();
|
uint timeStamp = tunnelMap.value("timestamp").toUInt();
|
||||||
QString tunnelConnectionTime = QDateTime::fromTime_t(timeStamp).toString("dd.MM.yyyy hh:mm:ss");
|
QString tunnelConnectionTime = QDateTime::fromMSecsSinceEpoch(timeStamp * 1000).toString("dd.MM.yyyy hh:mm:ss");
|
||||||
|
|
||||||
QString tunnelPrint = QString("%1 | %2 | %3 | %4 | %5 (%6) <---> %7 (%8)")
|
QString tunnelPrint = QString("%1 | %2 | %3 | %4 | %5 (%6) <---> %7 (%8)")
|
||||||
.arg(tunnelConnectionTime)
|
.arg(tunnelConnectionTime)
|
||||||
@ -252,7 +252,7 @@ void TerminalWindow::paintContentTunnelProxy()
|
|||||||
foreach (const QVariant &serverVariant, tunnelProxyMap.value("tunnelConnections").toList()) {
|
foreach (const QVariant &serverVariant, tunnelProxyMap.value("tunnelConnections").toList()) {
|
||||||
QVariantMap serverMap = serverVariant.toMap();
|
QVariantMap serverMap = serverVariant.toMap();
|
||||||
uint timeStamp = serverMap.value("timestamp").toUInt();
|
uint timeStamp = serverMap.value("timestamp").toUInt();
|
||||||
QString serverConnectionTime = QDateTime::fromTime_t(timeStamp).toString("dd.MM.yyyy hh:mm:ss");
|
QString serverConnectionTime = QDateTime::fromMSecsSinceEpoch(timeStamp * 1000).toString("dd.MM.yyyy hh:mm:ss");
|
||||||
int rxDataCountBytes = serverMap.value("rxDataCount").toInt();
|
int rxDataCountBytes = serverMap.value("rxDataCount").toInt();
|
||||||
int txDataCountBytes = serverMap.value("txDataCount").toInt();
|
int txDataCountBytes = serverMap.value("txDataCount").toInt();
|
||||||
QString serverLinePrint = QString("%1 | %2 | RX: %3 | TX: %4 | %5")
|
QString serverLinePrint = QString("%1 | %2 | RX: %3 | TX: %4 | %5")
|
||||||
@ -287,7 +287,7 @@ void TerminalWindow::paintContentTunnelProxy()
|
|||||||
mvwaddch(m_contentWindow, i, 5, ACS_HLINE);
|
mvwaddch(m_contentWindow, i, 5, ACS_HLINE);
|
||||||
|
|
||||||
QString clientLinePrint = QString("%1 | %2 | RX: %3 | TX: %4 | %5")
|
QString clientLinePrint = QString("%1 | %2 | RX: %3 | TX: %4 | %5")
|
||||||
.arg(QDateTime::fromTime_t(clientMap.value("timestamp").toUInt()).toString("dd.MM.yyyy hh:mm:ss"))
|
.arg(QDateTime::fromMSecsSinceEpoch(clientMap.value("timestamp").toULongLong() * 1000).toString("dd.MM.yyyy hh:mm:ss"))
|
||||||
.arg(clientMap.value("address").toString(), - 16)
|
.arg(clientMap.value("address").toString(), - 16)
|
||||||
.arg(Utils::humanReadableTraffic(clientMap.value("rxDataCount").toInt()), - 10)
|
.arg(Utils::humanReadableTraffic(clientMap.value("rxDataCount").toInt()), - 10)
|
||||||
.arg(Utils::humanReadableTraffic(clientMap.value("txDataCount").toInt()), - 10)
|
.arg(Utils::humanReadableTraffic(clientMap.value("txDataCount").toInt()), - 10)
|
||||||
|
|||||||
@ -43,7 +43,7 @@ public:
|
|||||||
Utils() = default;
|
Utils() = default;
|
||||||
|
|
||||||
inline static QString getDurationString(uint timestamp) {
|
inline static QString getDurationString(uint timestamp) {
|
||||||
uint duration = QDateTime::currentDateTimeUtc().toTime_t() - timestamp;
|
uint duration = QDateTime::currentDateTimeUtc().toSecsSinceEpoch() - timestamp;
|
||||||
int seconds = static_cast<int>(duration % 60);
|
int seconds = static_cast<int>(duration % 60);
|
||||||
duration /= 60;
|
duration /= 60;
|
||||||
int minutes = static_cast<int>(duration % 60);
|
int minutes = static_cast<int>(duration % 60);
|
||||||
|
|||||||
@ -1,10 +1,22 @@
|
|||||||
QT *= network websockets
|
QT *= network websockets
|
||||||
QT -= gui
|
QT -= gui
|
||||||
|
|
||||||
CONFIG += c++11 console
|
CONFIG += console
|
||||||
|
|
||||||
QMAKE_CXXFLAGS *= -Werror -std=c++11 -g -Wno-deprecated-declarations
|
greaterThan(QT_MAJOR_VERSION, 5) {
|
||||||
QMAKE_LFLAGS *= -std=c++11
|
message("Building using Qt6 support")
|
||||||
|
CONFIG *= c++17
|
||||||
|
QMAKE_LFLAGS *= -std=c++17
|
||||||
|
QMAKE_CXXFLAGS *= -std=c++17
|
||||||
|
} else {
|
||||||
|
message("Building using Qt5 support")
|
||||||
|
CONFIG *= c++11
|
||||||
|
QMAKE_LFLAGS *= -std=c++11
|
||||||
|
QMAKE_CXXFLAGS *= -std=c++11
|
||||||
|
DEFINES += QT_DISABLE_DEPRECATED_UP_TO=0x050F00
|
||||||
|
}
|
||||||
|
|
||||||
|
QMAKE_CXXFLAGS *= -Werror -g -Wno-deprecated-declarations
|
||||||
|
|
||||||
top_srcdir=$$PWD
|
top_srcdir=$$PWD
|
||||||
top_builddir=$$shadowed($$PWD)
|
top_builddir=$$shadowed($$PWD)
|
||||||
@ -19,6 +31,7 @@ coverage {
|
|||||||
MOC_DIR =
|
MOC_DIR =
|
||||||
|
|
||||||
LIBS += -lgcov
|
LIBS += -lgcov
|
||||||
|
|
||||||
QMAKE_CXXFLAGS += --coverage
|
QMAKE_CXXFLAGS += --coverage
|
||||||
QMAKE_LDFLAGS += --coverage
|
QMAKE_LDFLAGS += --coverage
|
||||||
|
|
||||||
|
|||||||
@ -171,11 +171,9 @@ void RemoteProxyTestsTunnelProxy::getHello()
|
|||||||
|
|
||||||
void RemoteProxyTestsTunnelProxy::monitorServer()
|
void RemoteProxyTestsTunnelProxy::monitorServer()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Start the server
|
// Start the server
|
||||||
startServer();
|
startServer();
|
||||||
|
|
||||||
|
|
||||||
// ** Create the server **
|
// ** Create the server **
|
||||||
QString serverName = "nymea server";
|
QString serverName = "nymea server";
|
||||||
QUuid serverUuid = QUuid::createUuid();
|
QUuid serverUuid = QUuid::createUuid();
|
||||||
@ -188,7 +186,9 @@ void RemoteProxyTestsTunnelProxy::monitorServer()
|
|||||||
tunnelProxyServer->startServer(m_serverUrlTunnelProxyTcp);
|
tunnelProxyServer->startServer(m_serverUrlTunnelProxyTcp);
|
||||||
|
|
||||||
QSignalSpy serverRunningSpy(tunnelProxyServer, &TunnelProxySocketServer::runningChanged);
|
QSignalSpy serverRunningSpy(tunnelProxyServer, &TunnelProxySocketServer::runningChanged);
|
||||||
serverRunningSpy.wait();
|
if (serverRunningSpy.isEmpty())
|
||||||
|
serverRunningSpy.wait();
|
||||||
|
|
||||||
QVERIFY(serverRunningSpy.count() == 1);
|
QVERIFY(serverRunningSpy.count() == 1);
|
||||||
QList<QVariant> arguments = serverRunningSpy.takeFirst();
|
QList<QVariant> arguments = serverRunningSpy.takeFirst();
|
||||||
QVERIFY(arguments.at(0).toBool() == true);
|
QVERIFY(arguments.at(0).toBool() == true);
|
||||||
|
|||||||
@ -241,7 +241,7 @@ QVariant BaseTest::invokeTcpSocketTunnelProxyApiCall(const QString &method, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
QSignalSpy dataSpy(socket, &QSslSocket::readyRead);
|
QSignalSpy dataSpy(socket, &QSslSocket::readyRead);
|
||||||
socket->write(jsonDoc.toJson(QJsonDocument::Compact) + '\n');
|
socket->write(jsonDoc.toJson(QJsonDocument::Compact) + "\n");
|
||||||
dataSpy.wait();
|
dataSpy.wait();
|
||||||
if (dataSpy.count() != 1) {
|
if (dataSpy.count() != 1) {
|
||||||
qWarning() << "No data received";
|
qWarning() << "No data received";
|
||||||
@ -292,7 +292,7 @@ QVariant BaseTest::injectTcpSocketTunnelProxyData(const QByteArray &data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QSignalSpy dataSpy(socket, &QSslSocket::readyRead);
|
QSignalSpy dataSpy(socket, &QSslSocket::readyRead);
|
||||||
socket->write(data + '\n');
|
socket->write(data + "\n");
|
||||||
dataSpy.wait();
|
dataSpy.wait();
|
||||||
if (dataSpy.count() != 1) {
|
if (dataSpy.count() != 1) {
|
||||||
qWarning() << "No data received";
|
qWarning() << "No data received";
|
||||||
@ -345,7 +345,7 @@ QPair<QVariant, QSslSocket *> BaseTest::invokeTcpSocketTunnelProxyApiCallPersist
|
|||||||
request.insert("method", method);
|
request.insert("method", method);
|
||||||
request.insert("params", params);
|
request.insert("params", params);
|
||||||
QJsonDocument jsonDoc = QJsonDocument::fromVariant(request);
|
QJsonDocument jsonDoc = QJsonDocument::fromVariant(request);
|
||||||
QByteArray payload = jsonDoc.toJson(QJsonDocument::Compact) + '\n';
|
QByteArray payload = jsonDoc.toJson(QJsonDocument::Compact) + "\n";
|
||||||
|
|
||||||
QSignalSpy dataSpy(socket, &QSslSocket::readyRead);
|
QSignalSpy dataSpy(socket, &QSslSocket::readyRead);
|
||||||
|
|
||||||
@ -439,7 +439,7 @@ QPair<QVariant, QWebSocket *> BaseTest::invokeWebSocketTunnelProxyApiCallPersist
|
|||||||
request.insert("method", method);
|
request.insert("method", method);
|
||||||
request.insert("params", params);
|
request.insert("params", params);
|
||||||
QJsonDocument jsonDoc = QJsonDocument::fromVariant(request);
|
QJsonDocument jsonDoc = QJsonDocument::fromVariant(request);
|
||||||
QByteArray payload = jsonDoc.toJson(QJsonDocument::Compact) + '\n';
|
QByteArray payload = jsonDoc.toJson(QJsonDocument::Compact) + "\n";
|
||||||
|
|
||||||
|
|
||||||
if (socket->state() != QAbstractSocket::ConnectedState) {
|
if (socket->state() != QAbstractSocket::ConnectedState) {
|
||||||
|
|||||||
@ -11,7 +11,7 @@ ClientConnection::ClientConnection(const QUrl &serverUrl, const QString &name, c
|
|||||||
{
|
{
|
||||||
m_remoteConnection = new TunnelProxyRemoteConnection(m_uuid, m_name);
|
m_remoteConnection = new TunnelProxyRemoteConnection(m_uuid, m_name);
|
||||||
m_timer.setSingleShot(true);
|
m_timer.setSingleShot(true);
|
||||||
connect(&m_timer, &QTimer::timeout, this, [=](){
|
connect(&m_timer, &QTimer::timeout, this, [this](){
|
||||||
if (m_remoteConnection->remoteConnected()) {
|
if (m_remoteConnection->remoteConnected()) {
|
||||||
m_remoteConnection->sendData(generateRandomString(100).toUtf8());
|
m_remoteConnection->sendData(generateRandomString(100).toUtf8());
|
||||||
m_timer.start(1000);
|
m_timer.start(1000);
|
||||||
@ -45,7 +45,7 @@ ClientConnection::ClientConnection(const QUrl &serverUrl, const QString &name, c
|
|||||||
qWarning() << "Socket error occurred" << error;
|
qWarning() << "Socket error occurred" << error;
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_remoteConnection, &TunnelProxyRemoteConnection::sslErrors, this, [=](const QList<QSslError> &errors){
|
connect(m_remoteConnection, &TunnelProxyRemoteConnection::sslErrors, this, [this](const QList<QSslError> &errors){
|
||||||
if (m_insecure) {
|
if (m_insecure) {
|
||||||
m_remoteConnection->ignoreSslErrors(errors);
|
m_remoteConnection->ignoreSslErrors(errors);
|
||||||
} else {
|
} else {
|
||||||
@ -67,7 +67,7 @@ QString ClientConnection::generateRandomString(uint length) const
|
|||||||
const QString possibleCharacters("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
|
const QString possibleCharacters("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
|
||||||
QString randomString;
|
QString randomString;
|
||||||
for(uint i = 0; i < length; i++) {
|
for(uint i = 0; i < length; i++) {
|
||||||
randomString.append(possibleCharacters.at(qrand() % possibleCharacters.length()));
|
randomString.append(possibleCharacters.at(std::rand() % possibleCharacters.length()));
|
||||||
}
|
}
|
||||||
return randomString;
|
return randomString;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,7 @@ ServerConnection::ServerConnection(const QUrl &serverUrl, const QString &name, c
|
|||||||
|
|
||||||
m_socketServer = new TunnelProxySocketServer(m_uuid, m_name, this);
|
m_socketServer = new TunnelProxySocketServer(m_uuid, m_name, this);
|
||||||
|
|
||||||
connect(m_socketServer, &TunnelProxySocketServer::clientConnected, this, [=](TunnelProxySocket *tunnelProxySocket){
|
connect(m_socketServer, &TunnelProxySocketServer::clientConnected, this, [this](TunnelProxySocket *tunnelProxySocket){
|
||||||
qDebug() << "[+] Client connected" << tunnelProxySocket;
|
qDebug() << "[+] Client connected" << tunnelProxySocket;
|
||||||
if (m_echo) {
|
if (m_echo) {
|
||||||
connect(tunnelProxySocket, &TunnelProxySocket::dataReceived, m_socketServer, [tunnelProxySocket](const QByteArray &data){
|
connect(tunnelProxySocket, &TunnelProxySocket::dataReceived, m_socketServer, [tunnelProxySocket](const QByteArray &data){
|
||||||
@ -20,18 +20,18 @@ ServerConnection::ServerConnection(const QUrl &serverUrl, const QString &name, c
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_socketServer, &TunnelProxySocketServer::clientDisconnected, this, [=](TunnelProxySocket *tunnelProxySocket){
|
connect(m_socketServer, &TunnelProxySocketServer::clientDisconnected, this, [](TunnelProxySocket *tunnelProxySocket){
|
||||||
qDebug() << "[-] Client disconnected" << tunnelProxySocket;
|
qDebug() << "[-] Client disconnected" << tunnelProxySocket;
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_socketServer, &TunnelProxySocketServer::runningChanged, this, [=](bool running){
|
connect(m_socketServer, &TunnelProxySocketServer::runningChanged, this, [this](bool running){
|
||||||
if (running) {
|
if (running) {
|
||||||
qDebug() << "Connected with" << m_socketServer->remoteProxyServer() << m_socketServer->remoteProxyServerName() << m_socketServer->remoteProxyServerVersion() << m_socketServer->remoteProxyApiVersion();
|
qDebug() << "Connected with" << m_socketServer->remoteProxyServer() << m_socketServer->remoteProxyServerName() << m_socketServer->remoteProxyServerVersion() << m_socketServer->remoteProxyApiVersion();
|
||||||
}
|
}
|
||||||
qDebug() << "--> The tunnel proxy server is" << (running ? "running and listening for incoming connections" : "not running any more");
|
qDebug() << "--> The tunnel proxy server is" << (running ? "running and listening for incoming connections" : "not running any more");
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_socketServer, &TunnelProxySocketServer::sslErrors, this, [=](const QList<QSslError> &errors){
|
connect(m_socketServer, &TunnelProxySocketServer::sslErrors, this, [this](const QList<QSslError> &errors){
|
||||||
if (m_insecure) {
|
if (m_insecure) {
|
||||||
m_socketServer->ignoreSslErrors(errors);
|
m_socketServer->ignoreSslErrors(errors);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user