[AFV] Guard against "missing" crypto channel (=> ASSERT)

This commit is contained in:
Klaus Basan
2020-01-27 15:26:56 +01:00
committed by Mat Sutcliffe
parent 481833b003
commit 34817a83d5
3 changed files with 21 additions and 2 deletions

View File

@@ -58,7 +58,6 @@ namespace BlackCore
{
// callback when connection has been established
if (!myself) { return; }
m_connection.setConnected(authenticated);
if (authenticated)
{
@@ -72,6 +71,9 @@ namespace BlackCore
CLogMessage(this).info(u"Connected: '%1' to voice server, socket open: %2") << callsign << boolToYesNo(m_udpSocket->isOpen());
}
// Make sure crypto channels etc. are created
m_connection.setConnected(authenticated);
// callback of the calling parent
if (callback) { callback(authenticated); }
}
@@ -146,6 +148,12 @@ namespace BlackCore
void CClientConnection::processMessage(const QByteArray &messageDdata, bool loopback)
{
if (!m_connection.m_voiceCryptoChannel)
{
BLACK_VERIFY_X(false, Q_FUNC_INFO, "processMessage used without crypto channel");
return;
}
CryptoDtoSerializer::Deserializer deserializer = CryptoDtoSerializer::deserialize(*m_connection.m_voiceCryptoChannel, messageDdata, loopback);
if (deserializer.dtoNameBuffer == AudioRxOnTransceiversDto::getShortDtoName())
@@ -176,6 +184,12 @@ namespace BlackCore
void CClientConnection::voiceServerHeartbeat()
{
if (!m_connection.m_voiceCryptoChannel || !m_udpSocket)
{
BLACK_VERIFY_X(false, Q_FUNC_INFO, "voiceServerHeartbeat used without crypto channel or socket");
return;
}
const QUrl voiceServerUrl("udp://" + m_connection.getTokens().VoiceServer.addressIpV4);
if (CBuildConfig::isLocalDeveloperDebugBuild()) { CLogMessage(this).debug(u"Sending voice server heartbeat to '%1'") << voiceServerUrl.host(); }
HeartbeatDto keepAlive;

View File

@@ -15,6 +15,7 @@
#include "blackcore/afv/connection/clientconnectiondata.h"
#include "blackcore/afv/connection/apiserverconnection.h"
#include "blackcore/afv/dto.h"
#include "blackmisc/verify.h"
#include <QObject>
#include <QString>
@@ -69,6 +70,11 @@ namespace BlackCore
template<typename T>
void sendToVoiceServer(const T &dto)
{
if (!m_connection.m_voiceCryptoChannel || !m_udpSocket)
{
BLACK_VERIFY_X(false, Q_FUNC_INFO, "sendVoice used without crypto channel or socket");
return;
}
const QUrl voiceServerUrl("udp://" + m_connection.getTokens().VoiceServer.addressIpV4);
const QByteArray dataBytes = Crypto::CryptoDtoSerializer::serialize(*m_connection.m_voiceCryptoChannel, Crypto::CryptoDtoMode::AEAD_ChaCha20Poly1305, dto);
m_udpSocket->writeDatagram(dataBytes, QHostAddress(voiceServerUrl.host()), static_cast<quint16>(voiceServerUrl.port()));

View File

@@ -43,7 +43,6 @@ namespace BlackCore
return;
}
m_voiceCryptoChannel.reset(new CCryptoDtoChannel(m_tokens.VoiceServer.channelConfig));
// dataCryptoChannel.reset(new CryptoDtoChannel(m_tokens.DataServer.channelConfig));
}
void CClientConnectionData::setTsAuthenticatedToNow()