swift
Loading...
Searching...
No Matches
clientconnectiondata.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2019 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#include "misc/logmessage.h"
7
8using namespace swift::misc;
9using namespace swift::core::afv::crypto;
10
11namespace swift::core::afv::connection
12{
18
20 {
21 return m_authenticatedDateTimeUtc.secsTo(QDateTime::currentDateTimeUtc());
22 }
23
25 {
26 if (!m_lastVoiceServerHeartbeatAckUtc.isValid())
27 {
28 return false;
29 }
30 const qint64 d = qAbs(m_lastVoiceServerHeartbeatAckUtc.secsTo(QDateTime::currentDateTimeUtc()));
31 return d < ServerTimeoutSecs;
32 }
33
35 {
36 if (!m_lastDataServerHeartbeatAckUtc.isValid())
37 {
38 return false;
39 }
40 const qint64 d = qAbs(m_lastDataServerHeartbeatAckUtc.secsTo(QDateTime::currentDateTimeUtc()));
41 return d < ServerTimeoutSecs;
42 }
43
45 {
46 if (!m_tokens.isValid)
47 {
48 CLogMessage(this).warning(u"Tokens not set");
49 return;
50 }
51 try
52 {
53 m_voiceCryptoChannel.reset(new CCryptoDtoChannel(m_tokens.VoiceServer.channelConfig));
54 }
55 catch (const std::invalid_argument &)
56 {
58 }
59 }
60
62 {
63 m_authenticatedDateTimeUtc = QDateTime::currentDateTimeUtc();
64 }
65
67 {
69 m_lastVoiceServerHeartbeatAckUtc = now;
70 m_lastDataServerHeartbeatAckUtc = now;
71 }
72
74 {
75 m_userName.clear();
76 m_callsign.clear();
77 m_authenticatedDateTimeUtc = QDateTime();
78 m_lastVoiceServerHeartbeatAckUtc = QDateTime();
79 this->setTokens({});
80 }
81
82 bool CClientConnectionData::voiceServerAlive() const
83 {
84 return (m_authenticatedDateTimeUtc.isValid() && timeSinceAuthenticationSecs() < ServerTimeoutSecs) ||
85 (m_lastVoiceServerHeartbeatAckUtc.isValid() &&
86 m_lastVoiceServerHeartbeatAckUtc.secsTo(QDateTime::currentDateTimeUtc()) < ServerTimeoutSecs);
87 }
88} // namespace swift::core::afv::connection
void createCryptoChannels()
Crypto channels for voice and data.
void setTokens(const PostCallsignResponseDto &dto)
Tokens.
static const QStringList & getLogCategories()
Categories.
qint64 secondsSinceAuthentication() const
Time since authentication.
QScopedPointer< crypto::CCryptoDtoChannel > m_voiceCryptoChannel
used crypto channel
static const QString & vatsimSpecific()
VATSIM specific.
static const QString & audio()
Audio related.
Class for emitting a log message.
Definition logmessage.h:27
Derived & warning(const char16_t(&format)[N])
Set the severity to warning, providing a format string.
Free functions in swift::misc.
QDateTime currentDateTimeUtc()
bool isValid() const const
qint64 secsTo(const QDateTime &other) const const