Skip to content

Commit d23314a

Browse files
committed
REFAC: Use dedicated struct for packet stats
1 parent e146860 commit d23314a

File tree

8 files changed

+61
-60
lines changed

8 files changed

+61
-60
lines changed

src/crypto/CryptState.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
#include "Timer.h"
1010
#include <string>
1111

12+
struct PacketStats {
13+
unsigned int good = 0;
14+
unsigned int late = 0;
15+
unsigned int lost = 0;
16+
unsigned int resync = 0;
17+
};
18+
1219
class CryptState {
1320
private:
1421
Q_DISABLE_COPY(CryptState)
1522
public:
16-
unsigned int uiGood = 0;
17-
unsigned int uiLate = 0;
18-
unsigned int uiLost = 0;
19-
unsigned int uiResync = 0;
20-
21-
unsigned int uiRemoteGood = 0;
22-
unsigned int uiRemoteLate = 0;
23-
unsigned int uiRemoteLost = 0;
24-
unsigned int uiRemoteResync = 0;
23+
PacketStats m_statsLocal = {};
24+
PacketStats m_statsRemote = {};
2525

2626
Timer tLastGood;
2727
Timer tLastRequest;

src/crypto/CryptStateOCB2.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,18 +206,18 @@ bool CryptStateOCB2::decrypt(const unsigned char *source, unsigned char *dst, un
206206
if (restore)
207207
memcpy(decrypt_iv, saveiv, AES_BLOCK_SIZE);
208208

209-
uiGood++;
210-
// uiLate += late, but we have to make sure we don't cause wrap-arounds on the unsigned lhs
209+
m_statsLocal.good++;
210+
// m_statsLocal.late += late, but we have to make sure we don't cause wrap-arounds on the unsigned lhs
211211
if (late > 0) {
212-
uiLate += static_cast< unsigned int >(late);
213-
} else if (static_cast< int >(uiLate) > std::abs(late)) {
214-
uiLate -= static_cast< unsigned int >(std::abs(late));
212+
m_statsLocal.late += static_cast< unsigned int >(late);
213+
} else if (static_cast< int >(m_statsLocal.late) > std::abs(late)) {
214+
m_statsLocal.late -= static_cast< unsigned int >(std::abs(late));
215215
}
216-
// uiLost += lost, but we have to make sure we don't cause wrap-arounds on the unsigned lhs
216+
// m_statsLocal.lost += lost, but we have to make sure we don't cause wrap-arounds on the unsigned lhs
217217
if (lost > 0) {
218-
uiLost += static_cast< unsigned int >(lost);
219-
} else if (static_cast< int >(uiLost) > std::abs(lost)) {
220-
uiLost -= static_cast< unsigned int >(std::abs(lost));
218+
m_statsLocal.lost += static_cast< unsigned int >(lost);
219+
} else if (static_cast< int >(m_statsLocal.lost) > std::abs(lost)) {
220+
m_statsLocal.lost -= static_cast< unsigned int >(std::abs(lost));
221221
}
222222

223223
tLastGood.restart();

src/mumble/Messages.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ void MainWindow::msgCryptSetup(const MumbleProto::CryptSetup &msg) {
10831083
} else if (msg.has_server_nonce()) {
10841084
const std::string &server_nonce = msg.server_nonce();
10851085
if (server_nonce.size() == AES_BLOCK_SIZE) {
1086-
c->csCrypt->uiResync++;
1086+
c->csCrypt->m_statsLocal.resync++;
10871087
if (!c->csCrypt->setDecryptIV(server_nonce)) {
10881088
qWarning("Messages: Cipher resync failed: Invalid nonce from the server!");
10891089
}

src/mumble/ServerHandler.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -591,10 +591,10 @@ void ServerHandler::sendPingInternal() {
591591
MumbleProto::Ping mpp;
592592

593593
mpp.set_timestamp(t);
594-
mpp.set_good(connection->csCrypt->uiGood);
595-
mpp.set_late(connection->csCrypt->uiLate);
596-
mpp.set_lost(connection->csCrypt->uiLost);
597-
mpp.set_resync(connection->csCrypt->uiResync);
594+
mpp.set_good(connection->csCrypt->m_statsLocal.good);
595+
mpp.set_late(connection->csCrypt->m_statsLocal.late);
596+
mpp.set_lost(connection->csCrypt->m_statsLocal.lost);
597+
mpp.set_resync(connection->csCrypt->m_statsLocal.resync);
598598

599599

600600
if (boost::accumulators::count(accUDP)) {
@@ -639,20 +639,20 @@ void ServerHandler::message(Mumble::Protocol::TCPMessageType type, const QByteAr
639639
// connection is still OK.
640640
iInFlightTCPPings = 0;
641641

642-
connection->csCrypt->uiRemoteGood = msg.good();
643-
connection->csCrypt->uiRemoteLate = msg.late();
644-
connection->csCrypt->uiRemoteLost = msg.lost();
645-
connection->csCrypt->uiRemoteResync = msg.resync();
642+
connection->csCrypt->m_statsRemote.good = msg.good();
643+
connection->csCrypt->m_statsRemote.late = msg.late();
644+
connection->csCrypt->m_statsRemote.lost = msg.lost();
645+
connection->csCrypt->m_statsRemote.resync = msg.resync();
646646
accTCP(static_cast< double >(tTimestamp.elapsed() - msg.timestamp()) / 1000.0);
647647

648-
if (((connection->csCrypt->uiRemoteGood == 0) || (connection->csCrypt->uiGood == 0)) && bUdp
649-
&& (tTimestamp.elapsed() > 20000000ULL)) {
648+
if (((connection->csCrypt->m_statsRemote.good == 0) || (connection->csCrypt->m_statsLocal.good == 0))
649+
&& bUdp && (tTimestamp.elapsed() > 20000000ULL)) {
650650
bUdp = false;
651651
if (!NetworkConfig::TcpModeEnabled()) {
652-
if ((connection->csCrypt->uiRemoteGood == 0) && (connection->csCrypt->uiGood == 0))
652+
if ((connection->csCrypt->m_statsRemote.good == 0) && (connection->csCrypt->m_statsLocal.good == 0))
653653
Global::get().mw->msgBox(
654654
tr("UDP packets cannot be sent to or received from the server. Switching to TCP mode."));
655-
else if (connection->csCrypt->uiRemoteGood == 0)
655+
else if (connection->csCrypt->m_statsRemote.good == 0)
656656
Global::get().mw->msgBox(
657657
tr("UDP packets cannot be sent to the server. Switching to TCP mode."));
658658
else
@@ -661,7 +661,8 @@ void ServerHandler::message(Mumble::Protocol::TCPMessageType type, const QByteAr
661661

662662
database->setUdp(qbaDigest, false);
663663
}
664-
} else if (!bUdp && (connection->csCrypt->uiRemoteGood > 3) && (connection->csCrypt->uiGood > 3)) {
664+
} else if (!bUdp && (connection->csCrypt->m_statsRemote.good > 3)
665+
&& (connection->csCrypt->m_statsLocal.good > 3)) {
665666
bUdp = true;
666667
if (!NetworkConfig::TcpModeEnabled()) {
667668
Global::get().mw->msgBox(

src/mumble/ServerInformation.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,14 @@ void ServerInformation::populateUDPStatistics(const Connection &connection) {
164164
constexpr int LOST_ROW = 2;
165165
constexpr int RESYNC_ROW = 3;
166166

167-
QTableWidgetItem *toGoodItem = new QTableWidgetItem(QString::number(connection.csCrypt->uiRemoteGood));
168-
QTableWidgetItem *fromGoodItem = new QTableWidgetItem(QString::number(connection.csCrypt->uiGood));
169-
QTableWidgetItem *toLateItem = new QTableWidgetItem(QString::number(connection.csCrypt->uiRemoteLate));
170-
QTableWidgetItem *fromLateItem = new QTableWidgetItem(QString::number(connection.csCrypt->uiLate));
171-
QTableWidgetItem *toLostItem = new QTableWidgetItem(QString::number(connection.csCrypt->uiRemoteLost));
172-
QTableWidgetItem *fromLostItem = new QTableWidgetItem(QString::number(connection.csCrypt->uiLost));
173-
QTableWidgetItem *toResyncItem = new QTableWidgetItem(QString::number(connection.csCrypt->uiRemoteResync));
174-
QTableWidgetItem *fromResyncItem = new QTableWidgetItem(QString::number(connection.csCrypt->uiResync));
167+
QTableWidgetItem *toGoodItem = new QTableWidgetItem(QString::number(connection.csCrypt->m_statsRemote.good));
168+
QTableWidgetItem *fromGoodItem = new QTableWidgetItem(QString::number(connection.csCrypt->m_statsLocal.good));
169+
QTableWidgetItem *toLateItem = new QTableWidgetItem(QString::number(connection.csCrypt->m_statsRemote.late));
170+
QTableWidgetItem *fromLateItem = new QTableWidgetItem(QString::number(connection.csCrypt->m_statsLocal.late));
171+
QTableWidgetItem *toLostItem = new QTableWidgetItem(QString::number(connection.csCrypt->m_statsRemote.lost));
172+
QTableWidgetItem *fromLostItem = new QTableWidgetItem(QString::number(connection.csCrypt->m_statsLocal.lost));
173+
QTableWidgetItem *toResyncItem = new QTableWidgetItem(QString::number(connection.csCrypt->m_statsRemote.resync));
174+
QTableWidgetItem *fromResyncItem = new QTableWidgetItem(QString::number(connection.csCrypt->m_statsLocal.resync));
175175

176176
connection_udp_statisticsTable->setItem(GOOD_ROW, TO_SERVER_COL, toGoodItem);
177177
connection_udp_statisticsTable->setItem(GOOD_ROW, FROM_SERVER_COL, fromGoodItem);

src/murmur/Messages.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,10 +1997,10 @@ void Server::msgPing(ServerUser *uSource, MumbleProto::Ping &msg) {
19971997

19981998
QMutexLocker l(&uSource->qmCrypt);
19991999

2000-
uSource->csCrypt->uiRemoteGood = msg.good();
2001-
uSource->csCrypt->uiRemoteLate = msg.late();
2002-
uSource->csCrypt->uiRemoteLost = msg.lost();
2003-
uSource->csCrypt->uiRemoteResync = msg.resync();
2000+
uSource->csCrypt->m_statsRemote.good = msg.good();
2001+
uSource->csCrypt->m_statsRemote.late = msg.late();
2002+
uSource->csCrypt->m_statsRemote.lost = msg.lost();
2003+
uSource->csCrypt->m_statsRemote.resync = msg.resync();
20042004

20052005
uSource->dUDPPingAvg = msg.udp_ping_avg();
20062006
uSource->dUDPPingVar = msg.udp_ping_var();
@@ -2013,10 +2013,10 @@ void Server::msgPing(ServerUser *uSource, MumbleProto::Ping &msg) {
20132013

20142014
msg.Clear();
20152015
msg.set_timestamp(ts);
2016-
msg.set_good(uSource->csCrypt->uiGood);
2017-
msg.set_late(uSource->csCrypt->uiLate);
2018-
msg.set_lost(uSource->csCrypt->uiLost);
2019-
msg.set_resync(uSource->csCrypt->uiResync);
2016+
msg.set_good(uSource->csCrypt->m_statsLocal.good);
2017+
msg.set_late(uSource->csCrypt->m_statsLocal.late);
2018+
msg.set_lost(uSource->csCrypt->m_statsLocal.lost);
2019+
msg.set_resync(uSource->csCrypt->m_statsLocal.resync);
20202020

20212021
sendMessage(uSource, msg);
20222022
}
@@ -2034,7 +2034,7 @@ void Server::msgCryptSetup(ServerUser *uSource, MumbleProto::CryptSetup &msg) {
20342034
sendMessage(uSource, msg);
20352035
} else {
20362036
const std::string &str = msg.client_nonce();
2037-
uSource->csCrypt->uiResync++;
2037+
uSource->csCrypt->m_statsLocal.resync++;
20382038
if (!uSource->csCrypt->setDecryptIV(str)) {
20392039
qWarning("Messages: Cipher resync failed: Invalid nonce from the client!");
20402040
}
@@ -2275,16 +2275,16 @@ void Server::msgUserStats(ServerUser *uSource, MumbleProto::UserStats &msg) {
22752275
QMutexLocker l(&pDstServerUser->qmCrypt);
22762276

22772277
mpusss = msg.mutable_from_client();
2278-
mpusss->set_good(pDstServerUser->csCrypt->uiGood);
2279-
mpusss->set_late(pDstServerUser->csCrypt->uiLate);
2280-
mpusss->set_lost(pDstServerUser->csCrypt->uiLost);
2281-
mpusss->set_resync(pDstServerUser->csCrypt->uiResync);
2278+
mpusss->set_good(pDstServerUser->csCrypt->m_statsLocal.good);
2279+
mpusss->set_late(pDstServerUser->csCrypt->m_statsLocal.late);
2280+
mpusss->set_lost(pDstServerUser->csCrypt->m_statsLocal.lost);
2281+
mpusss->set_resync(pDstServerUser->csCrypt->m_statsLocal.resync);
22822282

22832283
mpusss = msg.mutable_from_server();
2284-
mpusss->set_good(pDstServerUser->csCrypt->uiRemoteGood);
2285-
mpusss->set_late(pDstServerUser->csCrypt->uiRemoteLate);
2286-
mpusss->set_lost(pDstServerUser->csCrypt->uiRemoteLost);
2287-
mpusss->set_resync(pDstServerUser->csCrypt->uiRemoteResync);
2284+
mpusss->set_good(pDstServerUser->csCrypt->m_statsRemote.good);
2285+
mpusss->set_late(pDstServerUser->csCrypt->m_statsRemote.late);
2286+
mpusss->set_lost(pDstServerUser->csCrypt->m_statsRemote.lost);
2287+
mpusss->set_resync(pDstServerUser->csCrypt->m_statsRemote.resync);
22882288
}
22892289

22902290
msg.set_udp_packets(pDstServerUser->uiUDPPackets);

src/tests/Benchmark.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ void Client::readyRead() {
233233
} else if (msg.has_server_nonce()) {
234234
const std::string &server_nonce = msg.server_nonce();
235235
if (server_nonce.size() == AES_BLOCK_SIZE) {
236-
crypt.uiResync++;
236+
crypt.m_statsLocal.resync++;
237237
crypt.setDecryptIV(server_nonce);
238238
}
239239
} else {

src/tests/TestCrypt/TestCrypt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ void TestCrypt::ivrecovery() {
122122

123123
// Wraparound.
124124
for (int i = 0; i < 128; i++) {
125-
dec.uiLost = 0;
125+
dec.m_statsLocal.lost = 0;
126126
for (int j = 0; j < 15; j++)
127127
enc.encrypt(secret, crypted, 10);
128128
QVERIFY(dec.decrypt(crypted, decr, 14));
129-
QCOMPARE(dec.uiLost, 14U);
129+
QCOMPARE(dec.m_statsLocal.lost, 14U);
130130
}
131131

132132
QVERIFY(enc.getEncryptIV() == dec.getDecryptIV());

0 commit comments

Comments
 (0)