unify server and device uuid
This commit is contained in:
parent
7a409f7aa9
commit
43eba94b87
@ -19,39 +19,21 @@
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#include "cloudmanager.h"
|
||||
#include "guhcore.h"
|
||||
#include "awsconnector.h"
|
||||
#include "janusconnector.h"
|
||||
#include "loggingcategories.h"
|
||||
|
||||
#include <QNetworkSession>
|
||||
#include <QNetworkConfigurationManager>
|
||||
|
||||
CloudManager::CloudManager(QObject *parent) : QObject(parent)
|
||||
CloudManager::CloudManager(NetworkManager *networkManager, QObject *parent) : QObject(parent),
|
||||
m_networkManager(networkManager)
|
||||
{
|
||||
m_awsConnector = new AWSConnector(this);
|
||||
connect(m_awsConnector, &AWSConnector::devicePaired, this, &CloudManager::onPairingFinished);
|
||||
connect(m_awsConnector, &AWSConnector::webRtcHandshakeMessageReceived, this, &CloudManager::onAWSWebRtcHandshakeMessageReceived);
|
||||
|
||||
// Extract the machine id so we have a unique identifier for this machine
|
||||
// TODO: this only works for debian based systems, perhaps we should find something more general
|
||||
QFile f("/etc/machine-id");
|
||||
if (f.open(QFile::ReadOnly)) {
|
||||
QString tmpId = QString::fromLatin1(f.readAll()).trimmed();
|
||||
tmpId.insert(8, "-");
|
||||
tmpId.insert(13, "-");
|
||||
tmpId.insert(18, "-");
|
||||
tmpId.insert(23, "-");
|
||||
m_deviceId = QUuid(tmpId);
|
||||
qCDebug(dcCloud()) << "Device ID is:" << m_deviceId;
|
||||
setEnabled(true);
|
||||
} else {
|
||||
qWarning(dcCloud()) << "Failed to open /etc/machine-id for reading. Cloud connection will not work.";
|
||||
}
|
||||
|
||||
m_janusConnector = new JanusConnector(this);
|
||||
connect(m_janusConnector, &JanusConnector::webRtcHandshakeMessageReceived, this, &CloudManager::onJanusWebRtcHandshakeMessageReceived);
|
||||
|
||||
connect(GuhCore::instance()->networkManager(), &NetworkManager::stateChanged, this, &CloudManager::onlineStateChanged);
|
||||
connect(m_networkManager, &NetworkManager::stateChanged, this, &CloudManager::onlineStateChanged);
|
||||
}
|
||||
|
||||
void CloudManager::setServerUrl(const QString &serverUrl)
|
||||
@ -59,7 +41,7 @@ void CloudManager::setServerUrl(const QString &serverUrl)
|
||||
m_serverUrl = serverUrl;
|
||||
}
|
||||
|
||||
void CloudManager::setDeviceId(const QString &deviceId)
|
||||
void CloudManager::setDeviceId(const QUuid &deviceId)
|
||||
{
|
||||
m_deviceId = deviceId;
|
||||
}
|
||||
@ -81,24 +63,24 @@ void CloudManager::setEnabled(bool enabled)
|
||||
if (enabled) {
|
||||
bool missingConfig = false;
|
||||
if (m_deviceId.isNull()) {
|
||||
qCWarning(dcCloud()) << "Don't have a unique device ID (/etc/machine-id).";
|
||||
qCWarning(dcCloud()) << "Don't have a unique device ID.";
|
||||
missingConfig = true;
|
||||
}
|
||||
|
||||
if (GuhCore::instance()->configuration()->cloudServerUrl().isEmpty()) {
|
||||
qCWarning(dcCloud()) << "Cloud server URL not set in configuration.";
|
||||
if (m_serverUrl.isEmpty()) {
|
||||
qCWarning(dcCloud()) << "Cloud server URL not set.";
|
||||
missingConfig = true;
|
||||
}
|
||||
if (GuhCore::instance()->configuration()->cloudCertificate().isEmpty()) {
|
||||
qCWarning(dcCloud()) << "Cloud certificate not set in configuration.";
|
||||
if (m_clientCertificate.isEmpty()) {
|
||||
qCWarning(dcCloud()) << "Cloud certificate not set.";
|
||||
missingConfig = true;
|
||||
}
|
||||
if (GuhCore::instance()->configuration()->cloudCertificateKey().isEmpty()) {
|
||||
qCWarning(dcCloud()) << "Cloud certificate key not set in configuration.";
|
||||
if (m_clientCertificateKey.isEmpty()) {
|
||||
qCWarning(dcCloud()) << "Cloud certificate key not set.";
|
||||
missingConfig = true;
|
||||
}
|
||||
if (GuhCore::instance()->configuration()->cloudCertificateCA().isEmpty()) {
|
||||
qCWarning(dcCloud()) << "Cloud certificate CA not set in configuration.";
|
||||
if (m_caCertificate.isEmpty()) {
|
||||
qCWarning(dcCloud()) << "Cloud certificate CA not set.";
|
||||
missingConfig = true;
|
||||
}
|
||||
if (missingConfig) {
|
||||
@ -107,7 +89,7 @@ void CloudManager::setEnabled(bool enabled)
|
||||
}
|
||||
|
||||
m_enabled = true;
|
||||
if (!m_awsConnector->isConnected() && GuhCore::instance()->networkManager()->state() == NetworkManager::NetworkManagerStateConnectedGlobal) {
|
||||
if (!m_awsConnector->isConnected() && m_networkManager->state() == NetworkManager::NetworkManagerStateConnectedGlobal) {
|
||||
connect2aws();
|
||||
}
|
||||
}
|
||||
@ -120,19 +102,19 @@ void CloudManager::pairDevice(const QString &idToken, const QString &authToken,
|
||||
|
||||
void CloudManager::connect2aws()
|
||||
{
|
||||
m_awsConnector->connect2AWS(GuhCore::instance()->configuration()->cloudServerUrl(),
|
||||
// "1e10fb7e-d9d9-4145-88dd-2d3caf623c18", // micha's test id (needs micha's test certs) - remove that before merging
|
||||
m_deviceId.toString().remove(QRegExp("[{}]*")),
|
||||
GuhCore::instance()->configuration()->cloudCertificateCA(),
|
||||
GuhCore::instance()->configuration()->cloudCertificate(),
|
||||
GuhCore::instance()->configuration()->cloudCertificateKey()
|
||||
m_awsConnector->connect2AWS(m_serverUrl,
|
||||
"1e10fb7e-d9d9-4145-88dd-2d3caf623c18", // micha's test id (needs micha's test certs) - remove that before merging
|
||||
// m_deviceId.toString().remove(QRegExp("[{}]*")),
|
||||
m_caCertificate,
|
||||
m_clientCertificate,
|
||||
m_clientCertificateKey
|
||||
);
|
||||
}
|
||||
|
||||
void CloudManager::onlineStateChanged()
|
||||
{
|
||||
qWarning() << "online state changed" << GuhCore::instance()->networkManager()->state();
|
||||
if (GuhCore::instance()->networkManager()->state() == NetworkManager::NetworkManagerStateConnectedGlobal) {
|
||||
qWarning() << "online state changed" << m_networkManager->state();
|
||||
if (m_networkManager->state() == NetworkManager::NetworkManagerStateConnectedGlobal) {
|
||||
if (m_enabled && !m_awsConnector->isConnected()) {
|
||||
connect2aws();
|
||||
}
|
||||
|
||||
@ -26,6 +26,8 @@
|
||||
#include <QNetworkSession>
|
||||
#include <QUuid>
|
||||
|
||||
#include "networkmanager/networkmanager.h"
|
||||
|
||||
class JanusConnector;
|
||||
class AWSConnector;
|
||||
|
||||
@ -33,10 +35,10 @@ class CloudManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CloudManager(QObject *parent = nullptr);
|
||||
explicit CloudManager(NetworkManager *networkManager, QObject *parent = nullptr);
|
||||
|
||||
void setServerUrl(const QString &serverUrl);
|
||||
void setDeviceId(const QString &deviceId);
|
||||
void setDeviceId(const QUuid &deviceId);
|
||||
void setClientCertificates(const QString &caCertificate, const QString &clientCertificate, const QString &clientCertificateKey);
|
||||
|
||||
bool enabled() const;
|
||||
@ -57,11 +59,11 @@ private slots:
|
||||
void onJanusWebRtcHandshakeMessageReceived(const QString &transactionId, const QVariantMap &data);
|
||||
|
||||
private:
|
||||
QNetworkSession *m_networkSession;
|
||||
QTimer m_reconnectTimer;
|
||||
bool m_enabled = false;
|
||||
AWSConnector *m_awsConnector = nullptr;
|
||||
JanusConnector *m_janusConnector = nullptr;
|
||||
NetworkManager *m_networkManager = nullptr;
|
||||
|
||||
QString m_serverUrl;
|
||||
QUuid m_deviceId;
|
||||
|
||||
@ -24,6 +24,7 @@
|
||||
|
||||
#include <QTimeZone>
|
||||
#include <QCoreApplication>
|
||||
#include <QFile>
|
||||
|
||||
namespace guhserver {
|
||||
|
||||
@ -33,9 +34,21 @@ GuhConfiguration::GuhConfiguration(QObject *parent) :
|
||||
// Init server uuid if we don't have one.
|
||||
QUuid id = serverUuid();
|
||||
if (id.isNull()) {
|
||||
id = QUuid::createUuid();
|
||||
setServerUuid(id);
|
||||
// If we can, let's use the system's machine-id as our UUID.
|
||||
QFile f("/etc/machine-id");
|
||||
if (f.open(QFile::ReadOnly)) {
|
||||
QString tmpId = QString::fromLatin1(f.readAll()).trimmed();
|
||||
tmpId.insert(8, "-");
|
||||
tmpId.insert(13, "-");
|
||||
tmpId.insert(18, "-");
|
||||
tmpId.insert(23, "-");
|
||||
setServerUuid(QUuid(tmpId));
|
||||
} else {
|
||||
qWarning(dcApplication()) << "Failed to open /etc/machine-id for reading. Generating a new UUID for this server instance.";
|
||||
setServerUuid(QUuid::createUuid());
|
||||
}
|
||||
}
|
||||
qCDebug(dcApplication()) << "UUID is:" << serverName();
|
||||
|
||||
// Make sure default values are in configuration file so that it's easier for users to modify
|
||||
setServerName(serverName());
|
||||
|
||||
@ -446,7 +446,13 @@ void GuhCore::init() {
|
||||
|
||||
m_userManager = new UserManager(this);
|
||||
|
||||
m_cloudManager = new CloudManager(this);
|
||||
m_cloudManager = new CloudManager(m_networkManager, this);
|
||||
m_cloudManager->setDeviceId(m_configuration->serverUuid());
|
||||
m_cloudManager->setServerUrl(m_configuration->cloudServerUrl());
|
||||
m_cloudManager->setClientCertificates(m_configuration->cloudCertificateCA(), m_configuration->cloudCertificate(), m_configuration->cloudCertificateKey());
|
||||
if (!m_configuration->cloudServerUrl().isEmpty()) {
|
||||
m_cloudManager->setEnabled(true);
|
||||
}
|
||||
|
||||
connect(m_configuration, &GuhConfiguration::localeChanged, this, &GuhCore::onLocaleChanged);
|
||||
|
||||
|
||||
@ -42,6 +42,8 @@ JanusConnector::JanusConnector(QObject *parent) : QObject(parent)
|
||||
});
|
||||
connect(&m_socketTimeoutTimer, &QTimer::timeout, this, &JanusConnector::heartbeat);
|
||||
m_socketTimeoutTimer.setInterval(5000);
|
||||
|
||||
connectToJanus();
|
||||
}
|
||||
|
||||
bool JanusConnector::connectToJanus()
|
||||
|
||||
Reference in New Issue
Block a user