Add option for disableing proxy server functionality
This commit is contained in:
parent
0c5da0213a
commit
1694a43098
@ -69,38 +69,43 @@ void Engine::start(ProxyConfiguration *configuration)
|
|||||||
m_configuration = configuration;
|
m_configuration = configuration;
|
||||||
qCDebug(dcEngine()) << "Using configuration" << m_configuration;
|
qCDebug(dcEngine()) << "Using configuration" << m_configuration;
|
||||||
|
|
||||||
// Make sure an authenticator was registered
|
// TODO: the old proxy server is deprecated. Will be removed in future releases
|
||||||
Q_ASSERT_X(m_authenticator != nullptr, "Engine", "There is no authenticator registerd.");
|
if (configuration->proxyEnabled()) {
|
||||||
|
// Make sure an authenticator was registered
|
||||||
|
Q_ASSERT_X(m_authenticator != nullptr, "Engine", "There is no authenticator registerd.");
|
||||||
|
|
||||||
// Proxy
|
// Proxy
|
||||||
// -------------------------------------
|
// -------------------------------------
|
||||||
m_proxyServer = new ProxyServer(this);
|
m_proxyServer = new ProxyServer(this);
|
||||||
m_webSocketServerProxy = new WebSocketServer(m_configuration->sslEnabled(), m_configuration->sslConfiguration(), this);
|
m_webSocketServerProxy = new WebSocketServer(m_configuration->sslEnabled(), m_configuration->sslConfiguration(), this);
|
||||||
m_tcpSocketServerProxy = new TcpSocketServer(m_configuration->sslEnabled(), m_configuration->sslConfiguration(), this);
|
m_tcpSocketServerProxy = new TcpSocketServer(m_configuration->sslEnabled(), m_configuration->sslConfiguration(), this);
|
||||||
m_unixSocketServerProxy = new UnixSocketServer(m_configuration->unixSocketFileName(), this);
|
m_unixSocketServerProxy = new UnixSocketServer(m_configuration->unixSocketFileName(), this);
|
||||||
|
|
||||||
// Configure websocket server
|
// Configure websocket server
|
||||||
QUrl websocketServerUrl;
|
QUrl websocketServerUrl;
|
||||||
websocketServerUrl.setScheme(m_configuration->sslEnabled() ? "wss" : "ws");
|
websocketServerUrl.setScheme(m_configuration->sslEnabled() ? "wss" : "ws");
|
||||||
websocketServerUrl.setHost(m_configuration->webSocketServerProxyHost().toString());
|
websocketServerUrl.setHost(m_configuration->webSocketServerProxyHost().toString());
|
||||||
websocketServerUrl.setPort(m_configuration->webSocketServerProxyPort());
|
websocketServerUrl.setPort(m_configuration->webSocketServerProxyPort());
|
||||||
m_webSocketServerProxy->setServerUrl(websocketServerUrl);
|
m_webSocketServerProxy->setServerUrl(websocketServerUrl);
|
||||||
|
|
||||||
// Configure tcp socket server
|
// Configure tcp socket server
|
||||||
QUrl tcpSocketServerProxyUrl;
|
QUrl tcpSocketServerProxyUrl;
|
||||||
tcpSocketServerProxyUrl.setScheme(m_configuration->sslEnabled() ? "ssl" : "tcp");
|
tcpSocketServerProxyUrl.setScheme(m_configuration->sslEnabled() ? "ssl" : "tcp");
|
||||||
tcpSocketServerProxyUrl.setHost(m_configuration->tcpServerHost().toString());
|
tcpSocketServerProxyUrl.setHost(m_configuration->tcpServerHost().toString());
|
||||||
tcpSocketServerProxyUrl.setPort(m_configuration->tcpServerPort());
|
tcpSocketServerProxyUrl.setPort(m_configuration->tcpServerPort());
|
||||||
m_tcpSocketServerProxy->setServerUrl(tcpSocketServerProxyUrl);
|
m_tcpSocketServerProxy->setServerUrl(tcpSocketServerProxyUrl);
|
||||||
|
|
||||||
// Register the transport interfaces in the proxy server
|
// Register the transport interfaces in the proxy server
|
||||||
m_proxyServer->registerTransportInterface(m_webSocketServerProxy);
|
m_proxyServer->registerTransportInterface(m_webSocketServerProxy);
|
||||||
m_proxyServer->registerTransportInterface(m_tcpSocketServerProxy);
|
m_proxyServer->registerTransportInterface(m_tcpSocketServerProxy);
|
||||||
m_proxyServer->registerTransportInterface(m_unixSocketServerProxy);
|
m_proxyServer->registerTransportInterface(m_unixSocketServerProxy);
|
||||||
|
|
||||||
// Start the server
|
// Start the server
|
||||||
qCDebug(dcEngine()) << "Starting the proxy servers...";
|
qCDebug(dcEngine()) << "Starting the proxy servers...";
|
||||||
m_proxyServer->startServer();
|
m_proxyServer->startServer();
|
||||||
|
} else {
|
||||||
|
qCDebug(dcEngine()) << "Proxy server disabled. Not starting proxy server.";
|
||||||
|
}
|
||||||
|
|
||||||
// Tunnel proxy
|
// Tunnel proxy
|
||||||
// -------------------------------------
|
// -------------------------------------
|
||||||
@ -263,7 +268,9 @@ QVariantMap Engine::createServerStatistic()
|
|||||||
monitorData.insert("serverName", m_configuration->serverName());
|
monitorData.insert("serverName", m_configuration->serverName());
|
||||||
monitorData.insert("serverVersion", SERVER_VERSION_STRING);
|
monitorData.insert("serverVersion", SERVER_VERSION_STRING);
|
||||||
monitorData.insert("apiVersion", API_VERSION_STRING);
|
monitorData.insert("apiVersion", API_VERSION_STRING);
|
||||||
monitorData.insert("proxyStatistic", proxyServer()->currentStatistics());
|
if (m_proxyServer) {
|
||||||
|
monitorData.insert("proxyStatistic", m_proxyServer->currentStatistics());
|
||||||
|
}
|
||||||
monitorData.insert("tunnelProxyStatistic", tunnelProxyServer()->currentStatistics());
|
monitorData.insert("tunnelProxyStatistic", tunnelProxyServer()->currentStatistics());
|
||||||
return monitorData;
|
return monitorData;
|
||||||
}
|
}
|
||||||
@ -277,7 +284,8 @@ void Engine::onTimerTick()
|
|||||||
m_currentTimeCounter += deltaTime;
|
m_currentTimeCounter += deltaTime;
|
||||||
if (m_currentTimeCounter >= 1000) {
|
if (m_currentTimeCounter >= 1000) {
|
||||||
// One second passed, do second tick
|
// One second passed, do second tick
|
||||||
m_proxyServer->tick();
|
if (m_proxyServer)
|
||||||
|
m_proxyServer->tick();
|
||||||
|
|
||||||
QVariantMap serverStatistics = createServerStatistic();
|
QVariantMap serverStatistics = createServerStatistic();
|
||||||
m_monitorServer->updateClients(serverStatistics);
|
m_monitorServer->updateClients(serverStatistics);
|
||||||
|
|||||||
@ -54,6 +54,7 @@ bool ProxyConfiguration::loadConfiguration(const QString &fileName)
|
|||||||
|
|
||||||
settings.beginGroup("ProxyServer");
|
settings.beginGroup("ProxyServer");
|
||||||
setServerName(settings.value("name", "nymea-remoteproxy").toString());
|
setServerName(settings.value("name", "nymea-remoteproxy").toString());
|
||||||
|
setProxyEnabled(settings.value("proxyEnabled", true).toBool());
|
||||||
setWriteLogFile(settings.value("writeLogs", false).toBool());
|
setWriteLogFile(settings.value("writeLogs", false).toBool());
|
||||||
setLogFileName(settings.value("logFile", "/var/log/nymea-remoteproxy.log").toString());
|
setLogFileName(settings.value("logFile", "/var/log/nymea-remoteproxy.log").toString());
|
||||||
setLogEngineEnabled(settings.value("logEngineEnabled", false).toBool());
|
setLogEngineEnabled(settings.value("logEngineEnabled", false).toBool());
|
||||||
@ -241,6 +242,16 @@ void ProxyConfiguration::setAloneTimeout(int timeout)
|
|||||||
m_aloneTimeout = timeout;
|
m_aloneTimeout = timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ProxyConfiguration::proxyEnabled() const
|
||||||
|
{
|
||||||
|
return m_proxyEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProxyConfiguration::setProxyEnabled(bool proxyEnabled)
|
||||||
|
{
|
||||||
|
m_proxyEnabled = proxyEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
QString ProxyConfiguration::awsRegion() const
|
QString ProxyConfiguration::awsRegion() const
|
||||||
{
|
{
|
||||||
return m_awsRegion;
|
return m_awsRegion;
|
||||||
@ -419,10 +430,6 @@ QDebug operator<<(QDebug debug, ProxyConfiguration *configuration)
|
|||||||
debug.nospace() << " - Authentication timeout:" << configuration->authenticationTimeout() << " [ms]" << endl;
|
debug.nospace() << " - Authentication timeout:" << configuration->authenticationTimeout() << " [ms]" << endl;
|
||||||
debug.nospace() << " - Inactive timeout:" << configuration->inactiveTimeout() << " [ms]" << endl;
|
debug.nospace() << " - Inactive timeout:" << configuration->inactiveTimeout() << " [ms]" << endl;
|
||||||
debug.nospace() << " - Alone timeout:" << configuration->aloneTimeout() << " [ms]" << endl;
|
debug.nospace() << " - Alone timeout:" << configuration->aloneTimeout() << " [ms]" << endl;
|
||||||
debug.nospace() << "AWS configuration" << endl;
|
|
||||||
debug.nospace() << " - Region:" << configuration->awsRegion() << endl;
|
|
||||||
debug.nospace() << " - Authorizer lambda function:" << configuration->awsAuthorizerLambdaFunctionName() << endl;
|
|
||||||
debug.nospace() << " - Credentials URL:" << configuration->awsCredentialsUrl().toString() << endl;
|
|
||||||
debug.nospace() << "SSL configuration" << endl;
|
debug.nospace() << "SSL configuration" << endl;
|
||||||
debug.nospace() << " - Enabled:" << configuration->sslEnabled() << endl;
|
debug.nospace() << " - Enabled:" << configuration->sslEnabled() << endl;
|
||||||
debug.nospace() << " - Certificate:" << configuration->sslCertificateFileName() << endl;
|
debug.nospace() << " - Certificate:" << configuration->sslCertificateFileName() << endl;
|
||||||
@ -444,14 +451,22 @@ QDebug operator<<(QDebug debug, ProxyConfiguration *configuration)
|
|||||||
debug.nospace() << " Locality name:" << configuration->sslConfiguration().localCertificate().issuerInfo(QSslCertificate::LocalityName) << endl;
|
debug.nospace() << " Locality name:" << configuration->sslConfiguration().localCertificate().issuerInfo(QSslCertificate::LocalityName) << endl;
|
||||||
debug.nospace() << " State/Province:" << configuration->sslConfiguration().localCertificate().issuerInfo(QSslCertificate::StateOrProvinceName) << endl;
|
debug.nospace() << " State/Province:" << configuration->sslConfiguration().localCertificate().issuerInfo(QSslCertificate::StateOrProvinceName) << endl;
|
||||||
debug.nospace() << " Email address:" << configuration->sslConfiguration().localCertificate().issuerInfo(QSslCertificate::EmailAddress) << endl;
|
debug.nospace() << " Email address:" << configuration->sslConfiguration().localCertificate().issuerInfo(QSslCertificate::EmailAddress) << endl;
|
||||||
debug.nospace() << "WebSocketServer Proxy" << endl;
|
if (configuration->proxyEnabled()) {
|
||||||
debug.nospace() << " - Host:" << configuration->webSocketServerProxyHost().toString() << endl;
|
debug.nospace() << "AWS configuration" << endl;
|
||||||
debug.nospace() << " - Port:" << configuration->webSocketServerProxyPort() << endl;
|
debug.nospace() << " - Region:" << configuration->awsRegion() << endl;
|
||||||
debug.nospace() << "TcpServer Proxy" << endl;
|
debug.nospace() << " - Authorizer lambda function:" << configuration->awsAuthorizerLambdaFunctionName() << endl;
|
||||||
debug.nospace() << " - Host:" << configuration->tcpServerHost().toString() << endl;
|
debug.nospace() << " - Credentials URL:" << configuration->awsCredentialsUrl().toString() << endl;
|
||||||
debug.nospace() << " - Port:" << configuration->tcpServerPort() << endl;
|
debug.nospace() << "WebSocketServer Proxy" << endl;
|
||||||
debug.nospace() << "UnixSocketServer Proxy" << endl;
|
debug.nospace() << " - Host:" << configuration->webSocketServerProxyHost().toString() << endl;
|
||||||
debug.nospace() << " - Filename:" << configuration->unixSocketFileName() << endl;
|
debug.nospace() << " - Port:" << configuration->webSocketServerProxyPort() << endl;
|
||||||
|
debug.nospace() << "TcpServer Proxy" << endl;
|
||||||
|
debug.nospace() << " - Host:" << configuration->tcpServerHost().toString() << endl;
|
||||||
|
debug.nospace() << " - Port:" << configuration->tcpServerPort() << endl;
|
||||||
|
debug.nospace() << "UnixSocketServer Proxy" << endl;
|
||||||
|
debug.nospace() << " - Filename:" << configuration->unixSocketFileName() << endl;
|
||||||
|
} else {
|
||||||
|
debug.nospace() << "Proxy Server: disabled" << endl;
|
||||||
|
}
|
||||||
debug.nospace() << "WebSocketServer TunnelProxy" << endl;
|
debug.nospace() << "WebSocketServer TunnelProxy" << endl;
|
||||||
debug.nospace() << " - Host:" << configuration->webSocketServerTunnelProxyHost().toString() << endl;
|
debug.nospace() << " - Host:" << configuration->webSocketServerTunnelProxyHost().toString() << endl;
|
||||||
debug.nospace() << " - Port:" << configuration->webSocketServerTunnelProxyPort() << endl;
|
debug.nospace() << " - Port:" << configuration->webSocketServerTunnelProxyPort() << endl;
|
||||||
|
|||||||
@ -74,6 +74,9 @@ public:
|
|||||||
int aloneTimeout() const;
|
int aloneTimeout() const;
|
||||||
void setAloneTimeout(int timeout);
|
void setAloneTimeout(int timeout);
|
||||||
|
|
||||||
|
bool proxyEnabled() const;
|
||||||
|
void setProxyEnabled(bool proxyEnabled);
|
||||||
|
|
||||||
// AWS
|
// AWS
|
||||||
QString awsRegion() const;
|
QString awsRegion() const;
|
||||||
void setAwsRegion(const QString ®ion);
|
void setAwsRegion(const QString ®ion);
|
||||||
@ -145,6 +148,8 @@ private:
|
|||||||
int m_inactiveTimeout = 8000;
|
int m_inactiveTimeout = 8000;
|
||||||
int m_aloneTimeout = 8000;
|
int m_aloneTimeout = 8000;
|
||||||
|
|
||||||
|
bool m_proxyEnabled = true;
|
||||||
|
|
||||||
// AWS
|
// AWS
|
||||||
QString m_awsRegion;
|
QString m_awsRegion;
|
||||||
QString m_awsAuthorizerLambdaFunctionName;
|
QString m_awsAuthorizerLambdaFunctionName;
|
||||||
|
|||||||
@ -64,10 +64,8 @@ void TcpSocketServer::killClientConnection(const QUuid &clientId, const QString
|
|||||||
if (!client)
|
if (!client)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (client->state() == QAbstractSocket::ConnectedState) {
|
qCDebug(dcTcpSocketServer()) << "Killing client connection" << clientId.toString() << "Reason:" << killReason;
|
||||||
qCWarning(dcTcpSocketServer()) << "Killing client connection" << clientId.toString() << "Reason:" << killReason;
|
client->close();
|
||||||
client->close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TcpSocketServer::running() const
|
bool TcpSocketServer::running() const
|
||||||
|
|||||||
@ -207,13 +207,14 @@ int main(int argc, char *argv[])
|
|||||||
if (s_loggingEnabled)
|
if (s_loggingEnabled)
|
||||||
qCDebug(dcApplication()) << "Logging enabled. Writing logs to" << s_logFile.fileName();
|
qCDebug(dcApplication()) << "Logging enabled. Writing logs to" << s_logFile.fileName();
|
||||||
|
|
||||||
|
|
||||||
Authenticator *authenticator = nullptr;
|
Authenticator *authenticator = nullptr;
|
||||||
if (parser.isSet(mockAuthenticatorOption)) {
|
if (parser.isSet(mockAuthenticatorOption)) {
|
||||||
authenticator = qobject_cast<Authenticator *>(new DummyAuthenticator(nullptr));
|
authenticator = qobject_cast<Authenticator *>(new DummyAuthenticator(nullptr));
|
||||||
} else {
|
} else {
|
||||||
// Create default authenticator
|
if (configuration->proxyEnabled()) {
|
||||||
authenticator = qobject_cast<Authenticator *>(new AwsAuthenticator(configuration->awsCredentialsUrl(), nullptr));
|
// Create default authenticator
|
||||||
|
authenticator = qobject_cast<Authenticator *>(new AwsAuthenticator(configuration->awsCredentialsUrl(), nullptr));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure and start the engines
|
// Configure and start the engines
|
||||||
|
|||||||
Reference in New Issue
Block a user