diff --git a/src/crypto/CryptState.h b/src/crypto/CryptState.h index ce85205d370..6a9dc66ae7d 100644 --- a/src/crypto/CryptState.h +++ b/src/crypto/CryptState.h @@ -9,19 +9,19 @@ #include "Timer.h" #include +struct PacketStats { + unsigned int good = 0; + unsigned int late = 0; + unsigned int lost = 0; + unsigned int rsync = 0; +}; + class CryptState { private: Q_DISABLE_COPY(CryptState) public: - unsigned int uiGood = 0; - unsigned int uiLate = 0; - unsigned int uiLost = 0; - unsigned int uiResync = 0; - - unsigned int uiRemoteGood = 0; - unsigned int uiRemoteLate = 0; - unsigned int uiRemoteLost = 0; - unsigned int uiRemoteResync = 0; + PacketStats m_statsLocal = {}; + PacketStats m_statsRemote = {}; Timer tLastGood; Timer tLastRequest; diff --git a/src/crypto/CryptStateOCB2.cpp b/src/crypto/CryptStateOCB2.cpp index fae8061063a..733ee12a4da 100644 --- a/src/crypto/CryptStateOCB2.cpp +++ b/src/crypto/CryptStateOCB2.cpp @@ -206,18 +206,18 @@ bool CryptStateOCB2::decrypt(const unsigned char *source, unsigned char *dst, un if (restore) memcpy(decrypt_iv, saveiv, AES_BLOCK_SIZE); - uiGood++; - // uiLate += late, but we have to make sure we don't cause wrap-arounds on the unsigned lhs + m_statsLocal.good++; + // m_statsLocal.late += late, but we have to make sure we don't cause wrap-arounds on the unsigned lhs if (late > 0) { - uiLate += static_cast< unsigned int >(late); - } else if (static_cast< int >(uiLate) > std::abs(late)) { - uiLate -= static_cast< unsigned int >(std::abs(late)); + m_statsLocal.late += static_cast< unsigned int >(late); + } else if (static_cast< int >(m_statsLocal.late) > std::abs(late)) { + m_statsLocal.late -= static_cast< unsigned int >(std::abs(late)); } - // uiLost += lost, but we have to make sure we don't cause wrap-arounds on the unsigned lhs + // m_statsLocal.lost += lost, but we have to make sure we don't cause wrap-arounds on the unsigned lhs if (lost > 0) { - uiLost += static_cast< unsigned int >(lost); - } else if (static_cast< int >(uiLost) > std::abs(lost)) { - uiLost -= static_cast< unsigned int >(std::abs(lost)); + m_statsLocal.lost += static_cast< unsigned int >(lost); + } else if (static_cast< int >(m_statsLocal.lost) > std::abs(lost)) { + m_statsLocal.lost -= static_cast< unsigned int >(std::abs(lost)); } tLastGood.restart(); diff --git a/src/mumble/Messages.cpp b/src/mumble/Messages.cpp index 661ed43bf73..716075a92d6 100644 --- a/src/mumble/Messages.cpp +++ b/src/mumble/Messages.cpp @@ -1083,7 +1083,7 @@ void MainWindow::msgCryptSetup(const MumbleProto::CryptSetup &msg) { } else if (msg.has_server_nonce()) { const std::string &server_nonce = msg.server_nonce(); if (server_nonce.size() == AES_BLOCK_SIZE) { - c->csCrypt->uiResync++; + c->csCrypt->m_statsLocal.resync++; if (!c->csCrypt->setDecryptIV(server_nonce)) { qWarning("Messages: Cipher resync failed: Invalid nonce from the server!"); } diff --git a/src/mumble/ServerHandler.cpp b/src/mumble/ServerHandler.cpp index 3a98b0a44b7..abf7e524bd3 100644 --- a/src/mumble/ServerHandler.cpp +++ b/src/mumble/ServerHandler.cpp @@ -591,10 +591,10 @@ void ServerHandler::sendPingInternal() { MumbleProto::Ping mpp; mpp.set_timestamp(t); - mpp.set_good(connection->csCrypt->uiGood); - mpp.set_late(connection->csCrypt->uiLate); - mpp.set_lost(connection->csCrypt->uiLost); - mpp.set_resync(connection->csCrypt->uiResync); + mpp.set_good(connection->csCrypt->m_statsLocal.good); + mpp.set_late(connection->csCrypt->m_statsLocal.late); + mpp.set_lost(connection->csCrypt->m_statsLocal.lost); + mpp.set_resync(connection->csCrypt->m_statsLocal.resync); if (boost::accumulators::count(accUDP)) { @@ -639,20 +639,20 @@ void ServerHandler::message(Mumble::Protocol::TCPMessageType type, const QByteAr // connection is still OK. iInFlightTCPPings = 0; - connection->csCrypt->uiRemoteGood = msg.good(); - connection->csCrypt->uiRemoteLate = msg.late(); - connection->csCrypt->uiRemoteLost = msg.lost(); - connection->csCrypt->uiRemoteResync = msg.resync(); + connection->csCrypt->m_statsRemote.good = msg.good(); + connection->csCrypt->m_statsRemote.late = msg.late(); + connection->csCrypt->m_statsRemote.lost = msg.lost(); + connection->csCrypt->m_statsRemote.resync = msg.resync(); accTCP(static_cast< double >(tTimestamp.elapsed() - msg.timestamp()) / 1000.0); - if (((connection->csCrypt->uiRemoteGood == 0) || (connection->csCrypt->uiGood == 0)) && bUdp - && (tTimestamp.elapsed() > 20000000ULL)) { + if (((connection->csCrypt->m_statsRemote.good == 0) || (connection->csCrypt->m_statsLocal.good == 0)) + && bUdp && (tTimestamp.elapsed() > 20000000ULL)) { bUdp = false; if (!NetworkConfig::TcpModeEnabled()) { - if ((connection->csCrypt->uiRemoteGood == 0) && (connection->csCrypt->uiGood == 0)) + if ((connection->csCrypt->m_statsRemote.good == 0) && (connection->csCrypt->m_statsLocal.good == 0)) Global::get().mw->msgBox( tr("UDP packets cannot be sent to or received from the server. Switching to TCP mode.")); - else if (connection->csCrypt->uiRemoteGood == 0) + else if (connection->csCrypt->m_statsRemote.good == 0) Global::get().mw->msgBox( tr("UDP packets cannot be sent to the server. Switching to TCP mode.")); else @@ -661,7 +661,8 @@ void ServerHandler::message(Mumble::Protocol::TCPMessageType type, const QByteAr database->setUdp(qbaDigest, false); } - } else if (!bUdp && (connection->csCrypt->uiRemoteGood > 3) && (connection->csCrypt->uiGood > 3)) { + } else if (!bUdp && (connection->csCrypt->m_statsRemote.good > 3) + && (connection->csCrypt->m_statsLocal.good > 3)) { bUdp = true; if (!NetworkConfig::TcpModeEnabled()) { Global::get().mw->msgBox( diff --git a/src/mumble/ServerInformation.cpp b/src/mumble/ServerInformation.cpp index 0912047812d..7df371b5cac 100644 --- a/src/mumble/ServerInformation.cpp +++ b/src/mumble/ServerInformation.cpp @@ -164,14 +164,14 @@ void ServerInformation::populateUDPStatistics(const Connection &connection) { constexpr int LOST_ROW = 2; constexpr int RESYNC_ROW = 3; - QTableWidgetItem *toGoodItem = new QTableWidgetItem(QString::number(connection.csCrypt->uiRemoteGood)); - QTableWidgetItem *fromGoodItem = new QTableWidgetItem(QString::number(connection.csCrypt->uiGood)); - QTableWidgetItem *toLateItem = new QTableWidgetItem(QString::number(connection.csCrypt->uiRemoteLate)); - QTableWidgetItem *fromLateItem = new QTableWidgetItem(QString::number(connection.csCrypt->uiLate)); - QTableWidgetItem *toLostItem = new QTableWidgetItem(QString::number(connection.csCrypt->uiRemoteLost)); - QTableWidgetItem *fromLostItem = new QTableWidgetItem(QString::number(connection.csCrypt->uiLost)); - QTableWidgetItem *toResyncItem = new QTableWidgetItem(QString::number(connection.csCrypt->uiRemoteResync)); - QTableWidgetItem *fromResyncItem = new QTableWidgetItem(QString::number(connection.csCrypt->uiResync)); + QTableWidgetItem *toGoodItem = new QTableWidgetItem(QString::number(connection.csCrypt->m_statsRemote.good)); + QTableWidgetItem *fromGoodItem = new QTableWidgetItem(QString::number(connection.csCrypt->m_statsLocal.good)); + QTableWidgetItem *toLateItem = new QTableWidgetItem(QString::number(connection.csCrypt->m_statsRemote.late)); + QTableWidgetItem *fromLateItem = new QTableWidgetItem(QString::number(connection.csCrypt->m_statsLocal.late)); + QTableWidgetItem *toLostItem = new QTableWidgetItem(QString::number(connection.csCrypt->m_statsRemote.lost)); + QTableWidgetItem *fromLostItem = new QTableWidgetItem(QString::number(connection.csCrypt->m_statsLocal.lost)); + QTableWidgetItem *toResyncItem = new QTableWidgetItem(QString::number(connection.csCrypt->m_statsRemote.resync)); + QTableWidgetItem *fromResyncItem = new QTableWidgetItem(QString::number(connection.csCrypt->m_statsLocal.resync)); connection_udp_statisticsTable->setItem(GOOD_ROW, TO_SERVER_COL, toGoodItem); connection_udp_statisticsTable->setItem(GOOD_ROW, FROM_SERVER_COL, fromGoodItem); diff --git a/src/murmur/Messages.cpp b/src/murmur/Messages.cpp index ae4f7eb64a4..8d0dc3abd2a 100644 --- a/src/murmur/Messages.cpp +++ b/src/murmur/Messages.cpp @@ -1997,10 +1997,10 @@ void Server::msgPing(ServerUser *uSource, MumbleProto::Ping &msg) { QMutexLocker l(&uSource->qmCrypt); - uSource->csCrypt->uiRemoteGood = msg.good(); - uSource->csCrypt->uiRemoteLate = msg.late(); - uSource->csCrypt->uiRemoteLost = msg.lost(); - uSource->csCrypt->uiRemoteResync = msg.resync(); + uSource->csCrypt->m_statsRemote.good = msg.good(); + uSource->csCrypt->m_statsRemote.late = msg.late(); + uSource->csCrypt->m_statsRemote.lost = msg.lost(); + uSource->csCrypt->m_statsRemote.resync = msg.resync(); uSource->dUDPPingAvg = msg.udp_ping_avg(); uSource->dUDPPingVar = msg.udp_ping_var(); @@ -2013,10 +2013,10 @@ void Server::msgPing(ServerUser *uSource, MumbleProto::Ping &msg) { msg.Clear(); msg.set_timestamp(ts); - msg.set_good(uSource->csCrypt->uiGood); - msg.set_late(uSource->csCrypt->uiLate); - msg.set_lost(uSource->csCrypt->uiLost); - msg.set_resync(uSource->csCrypt->uiResync); + msg.set_good(uSource->csCrypt->m_statsLocal.good); + msg.set_late(uSource->csCrypt->m_statsLocal.late); + msg.set_lost(uSource->csCrypt->m_statsLocal.lost); + msg.set_resync(uSource->csCrypt->m_statsLocal.resync); sendMessage(uSource, msg); } @@ -2034,7 +2034,7 @@ void Server::msgCryptSetup(ServerUser *uSource, MumbleProto::CryptSetup &msg) { sendMessage(uSource, msg); } else { const std::string &str = msg.client_nonce(); - uSource->csCrypt->uiResync++; + uSource->csCrypt->m_statsLocal.resync++; if (!uSource->csCrypt->setDecryptIV(str)) { qWarning("Messages: Cipher resync failed: Invalid nonce from the client!"); } @@ -2275,16 +2275,16 @@ void Server::msgUserStats(ServerUser *uSource, MumbleProto::UserStats &msg) { QMutexLocker l(&pDstServerUser->qmCrypt); mpusss = msg.mutable_from_client(); - mpusss->set_good(pDstServerUser->csCrypt->uiGood); - mpusss->set_late(pDstServerUser->csCrypt->uiLate); - mpusss->set_lost(pDstServerUser->csCrypt->uiLost); - mpusss->set_resync(pDstServerUser->csCrypt->uiResync); + mpusss->set_good(pDstServerUser->csCrypt->m_statsLocal.good); + mpusss->set_late(pDstServerUser->csCrypt->m_statsLocal.late); + mpusss->set_lost(pDstServerUser->csCrypt->m_statsLocal.lost); + mpusss->set_resync(pDstServerUser->csCrypt->m_statsLocal.resync); mpusss = msg.mutable_from_server(); - mpusss->set_good(pDstServerUser->csCrypt->uiRemoteGood); - mpusss->set_late(pDstServerUser->csCrypt->uiRemoteLate); - mpusss->set_lost(pDstServerUser->csCrypt->uiRemoteLost); - mpusss->set_resync(pDstServerUser->csCrypt->uiRemoteResync); + mpusss->set_good(pDstServerUser->csCrypt->m_statsRemote.good); + mpusss->set_late(pDstServerUser->csCrypt->m_statsRemote.late); + mpusss->set_lost(pDstServerUser->csCrypt->m_statsRemote.lost); + mpusss->set_resync(pDstServerUser->csCrypt->m_statsRemote.resync); } msg.set_udp_packets(pDstServerUser->uiUDPPackets); diff --git a/src/tests/Benchmark.cpp b/src/tests/Benchmark.cpp index 9f7f3926521..c2e08010753 100644 --- a/src/tests/Benchmark.cpp +++ b/src/tests/Benchmark.cpp @@ -233,7 +233,7 @@ void Client::readyRead() { } else if (msg.has_server_nonce()) { const std::string &server_nonce = msg.server_nonce(); if (server_nonce.size() == AES_BLOCK_SIZE) { - crypt.uiResync++; + crypt.m_statsLocal.resync++; crypt.setDecryptIV(server_nonce); } } else { diff --git a/src/tests/TestCrypt/TestCrypt.cpp b/src/tests/TestCrypt/TestCrypt.cpp index 9e2c37ac714..0aecd24d71d 100644 --- a/src/tests/TestCrypt/TestCrypt.cpp +++ b/src/tests/TestCrypt/TestCrypt.cpp @@ -122,11 +122,11 @@ void TestCrypt::ivrecovery() { // Wraparound. for (int i = 0; i < 128; i++) { - dec.uiLost = 0; + dec.m_statsLocal.lost = 0; for (int j = 0; j < 15; j++) enc.encrypt(secret, crypted, 10); QVERIFY(dec.decrypt(crypted, decr, 14)); - QCOMPARE(dec.uiLost, 14U); + QCOMPARE(dec.m_statsLocal.lost, 14U); } QVERIFY(enc.getEncryptIV() == dec.getDecryptIV());