Skip to content

Commit

Permalink
FEAT(server): Add setting for rolling stats time window
Browse files Browse the repository at this point in the history
  • Loading branch information
Hartmnt committed Jan 11, 2025
1 parent 0a911a2 commit 38c9e27
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions auxiliary_files/mumble-server.ini
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,12 @@ allowping=true
;
; allowRecording=true

; The time frame in seconds the server will keep rolling packet stats for each client.
; The default is 5 minutes = 300 seconds. Set to 0 to disable rolling packet stats.
; This opetion has been introduced with 1.6.0
;
; rollingStatsSeconds=300

; The amount of allowed listener proxies in a single channel. It defaults to -1
; meaning that there is no limit. Set to 0 to disable Channel Listeners altogether.
; This option has been introduced with 1.4.0.
Expand Down
4 changes: 4 additions & 0 deletions src/crypto/CryptState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include "CryptState.h"

void CryptState::handleRollingStats() {
if (!m_rollingStatsEnabled) {
return;
}

std::chrono::time_point< std::chrono::steady_clock > now = std::chrono::steady_clock::now();

// Update no more than every few seconds
Expand Down
1 change: 1 addition & 0 deletions src/crypto/CryptState.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class CryptState {
PacketStats m_statsLocalRolling = {};
PacketStats m_statsRemoteRolling = {};

bool m_rollingStatsEnabled = false;
/// This is the packet statistics sliding time window size in seconds
std::chrono::duration< uint32_t, std::ratio< 1 > > m_rollingWindow = std::chrono::seconds(60 * 5);

Expand Down
4 changes: 4 additions & 0 deletions src/murmur/Meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ MetaParams::MetaParams() {

allowRecording = true;

rollingStatsSeconds = 300;

qsSettings = nullptr;
}

Expand Down Expand Up @@ -329,6 +331,8 @@ void MetaParams::read(QString fname) {

allowRecording = typeCheckedFromSettings("allowRecording", allowRecording);

rollingStatsSeconds = typeCheckedFromSettings("rollingStatsSeconds", rollingStatsSeconds);

iOpusThreshold = typeCheckedFromSettings("opusthreshold", iOpusThreshold);

iChannelNestingLimit = typeCheckedFromSettings("channelnestinglimit", iChannelNestingLimit);
Expand Down
3 changes: 3 additions & 0 deletions src/murmur/Meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ class MetaParams {
/// A flag indicating whether recording is allowed on this server
bool allowRecording;

/// The number of seconds to keep rolling stats for per client
uint32_t rollingStatsSeconds;

/// qsAbsSettingsFilePath is the absolute path to
/// the murmur.ini used by this Meta instance.
QString qsAbsSettingsFilePath;
Expand Down
10 changes: 10 additions & 0 deletions src/murmur/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

#include <algorithm>
#include <cassert>
#include <chrono>
#include <vector>

#ifdef Q_OS_WIN
Expand Down Expand Up @@ -346,6 +347,7 @@ void Server::readParams() {
bBonjour = Meta::mp.bBonjour;
bAllowPing = Meta::mp.bAllowPing;
allowRecording = Meta::mp.allowRecording;
rollingStatsSeconds = Meta::mp.rollingStatsSeconds;
bCertRequired = Meta::mp.bCertRequired;
bForceExternalAuth = Meta::mp.bForceExternalAuth;
qrUserName = Meta::mp.qrUserName;
Expand Down Expand Up @@ -445,6 +447,7 @@ void Server::readParams() {

iChannelNestingLimit = getConf("channelnestinglimit", iChannelNestingLimit).toInt();
iChannelCountLimit = getConf("channelcountlimit", iChannelCountLimit).toInt();
rollingStatsSeconds = getConf("rollingStatsSeconds", rollingStatsSeconds).toUInt();

qrUserName =
decltype(qrUserName)(QRegularExpression::anchoredPattern(getConf("username", qrUserName.pattern()).toString()));
Expand Down Expand Up @@ -577,6 +580,8 @@ void Server::setLiveConf(const QString &key, const QString &value) {
bAllowPing = !v.isNull() ? QVariant(v).toBool() : Meta::mp.bAllowPing;
else if (key == "allowrecording")
allowRecording = !v.isNull() ? QVariant(v).toBool() : Meta::mp.allowRecording;
else if (key == "rollingStatsSeconds")
rollingStatsSeconds = i ? static_cast< unsigned int >(i) : Meta::mp.rollingStatsSeconds;
else if (key == "username")
qrUserName = !v.isNull() ? QRegularExpression(v) : Meta::mp.qrUserName;
else if (key == "channelname")
Expand Down Expand Up @@ -1437,6 +1442,11 @@ void Server::newClient() {
u->haAddress = ha;
HostAddress(sock->localAddress()).toSockaddr(&u->saiTcpLocalAddress);

if (rollingStatsSeconds > 0) {
u->csCrypt->m_rollingStatsEnabled = true;
u->csCrypt->m_rollingWindow = std::chrono::seconds(std::max(10U, rollingStatsSeconds));
}

connect(u, &ServerUser::connectionClosed, this, &Server::connectionClosed);
connect(u, SIGNAL(message(Mumble::Protocol::TCPMessageType, const QByteArray &)), this,
SLOT(message(Mumble::Protocol::TCPMessageType, const QByteArray &)));
Expand Down
1 change: 1 addition & 0 deletions src/murmur/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class Server : public QThread {
bool bBonjour;
bool bAllowPing;
bool allowRecording;
uint32_t rollingStatsSeconds;

QRegularExpression qrUserName;
QRegularExpression qrChannelName;
Expand Down

0 comments on commit 38c9e27

Please sign in to comment.