6 #include <QNetworkDatagram>
11 using namespace swift::config;
13 using namespace swift::core::afv::crypto;
15 namespace swift::core::afv::connection
17 CClientConnection::CClientConnection(
const QString &apiServer,
QObject *parent)
30 &CClientConnection::voiceServerHeartbeat);
49 userName, password, client, m_networkVersion,
51 this, [=](
bool authenticated) {
53 if (!myself) {
return; }
62 this->connectToVoiceServer();
65 CLogMessage(
this).
info(u
"Connected: '%1' to voice server, socket open: %2")
66 << cs << boolToYesNo(m_udpSocket->
isOpen());
68 else { m_connection.
reset(); }
74 if (callback) { callback(authenticated); }
96 disconnectFromVoiceServer();
115 if (!m_apiServerConnection) {
return false; }
116 return m_apiServerConnection->
setUrl(url);
122 if (!m_apiServerConnection) {
return e; }
123 return m_apiServerConnection->
getUrl();
126 void CClientConnection::connectToVoiceServer()
129 m_udpSocket->
bind(localAddress);
130 m_voiceServerTimer->
start(3000);
135 void CClientConnection::disconnectFromVoiceServer()
137 m_voiceServerTimer->
stop();
142 void CClientConnection::readPendingDatagrams()
147 this->processMessage(datagram.
data());
151 void CClientConnection::processMessage(
const QByteArray &messageDdata,
bool loopback)
155 SWIFT_VERIFY_X(
false, Q_FUNC_INFO,
"processMessage used without crypto channel");
165 const AudioRxOnTransceiversDto audioOnTransceiverDto = deserializer.
getDto<AudioRxOnTransceiversDto>();
174 if (CBuildConfig::isLocalDeveloperDebugBuild())
192 void CClientConnection::voiceServerHeartbeat()
196 SWIFT_VERIFY_X(
false, Q_FUNC_INFO,
"voiceServerHeartbeat used without crypto channel or socket");
201 if (CBuildConfig::isLocalDeveloperDebugBuild())
203 CLogMessage(
this).
debug(u
"Sending voice server heartbeat to '%1'") << voiceServerUrl.host();
205 HeartbeatDto keepAlive;
208 CryptoDtoMode::AEAD_ChaCha20Poly1305, keepAlive);
210 static_cast<quint16
>(voiceServerUrl.port()));
void removeCallsign(const QString &callsign)
Remove callsign from network.
PostCallsignResponseDto addCallsign(const QString &callsign)
Add callsign to network.
void forceDisconnect()
Force disconnect from network.
QVector< StationDto > getAllAliasedStations()
All aliased stations.
void connectTo(const QString &username, const QString &password, const QString &client, const QUuid &networkVersion, ConnectionCallback callback)
Connect to network.
void updateTransceivers(const QString &callsign, const QVector< TransceiverDto > &transceivers)
Update transceivers.
const QString & getUrl() const
Get the URL.
bool setUrl(const QString &url)
Set the URL.
const PostCallsignResponseDto & getTokens() const
Tokens.
bool isReceivingAudio() const
Receiving audio?
void setTsAuthenticatedToNow()
Timestamps.
void createCryptoChannels()
Crypto channels for voice and data.
bool isConnected() const
Is connected?
void setCallsign(const QString &callsign)
Callsign.
void setTokens(const PostCallsignResponseDto &dto)
Tokens.
const QString & getCallsign() const
Callsign.
void setConnected(bool connected)
Is connected?
void setTsHeartbeatToNow()
Timestamps.
void setUserName(const QString &un)
Uername.
QScopedPointer< crypto::CCryptoDtoChannel > m_voiceCryptoChannel
used crypto channel
void reset()
Reset all login related data.
void updateTransceivers(const QString &callsign, const QVector< TransceiverDto > &transceivers)
Update transceivers.
bool updateVoiceServerUrl(const QString &url)
Update the voice server URL.
void disconnectFrom(const QString &reason={})
Disconnect.
void audioReceived(const AudioRxOnTransceiversDto &dto)
Audio has been received.
QVector< StationDto > getAllAliasedStations()
All aliased stations.
const QString & getVoiceServerUrl() const
Get the voice server URL.
void connectTo(const QString &userName, const QString &password, const QString &callsign, const QString &client, ConnectionCallback callback)
Connect.
Class for emitting a log message.
Derived & warning(const char16_t(&format)[N])
Set the severity to warning, providing a format string.
Derived & debug()
Set the severity to debug.
Derived & info(const char16_t(&format)[N])
Set the severity to info, providing a format string.
Callable wrapper for a member function with function signature F.
Free functions in swift::misc.
bool bind(QHostAddress::SpecialAddress addr, quint16 port, QAbstractSocket::BindMode mode)
virtual void disconnectFromHost()
void errorOccurred(QAbstractSocket::SocketError socketError)
QString errorString() const const
bool isOpen() const const
QByteArray data() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool isEmpty() const const
std::string toStdString() const const
bool hasPendingDatagrams() const const
QNetworkDatagram receiveDatagram(qint64 maxSize)
qint64 writeDatagram(const QByteArray &datagram, const QHostAddress &host, quint16 port)
static QByteArray getShortDtoName()
Names.
static QByteArray getShortDtoName()
Name.
VoiceServerConnectionDataDto VoiceServer
Properties.
QString addressIpV4
Properties.
quint16 m_dataLength
Data.
QByteArray m_dtoNameBuffer
Name data.
#define SWIFT_VERIFY_X(COND, WHERE, WHAT)
A weaker kind of assert.