Skip to content
Permalink
Browse files

Merge pull request #2622 from mkrautz/max-in-flight-tcp-pings

ServerHandler: reconnect to the server if it is not responding to TCP pings
  • Loading branch information...
Kissaki committed Nov 7, 2016
2 parents dd874cc + 9fc379a commit 012cde52d5e5579e8af24634682990604262a54b
Showing with 31 additions and 0 deletions.
  1. +15 −0 src/mumble/ServerHandler.cpp
  2. +1 −0 src/mumble/ServerHandler.h
  3. +3 −0 src/mumble/Settings.cpp
  4. +12 −0 src/mumble/Settings.h
@@ -69,6 +69,7 @@ ServerHandler::ServerHandler() {
bUdp = true;
tConnectionTimeoutTimer = NULL;
uiVersion = 0;
iInFlightTCPPings = 0;

// Historically, the qWarning line below initialized OpenSSL for us.
// It used to have this comment:
@@ -392,6 +393,11 @@ void ServerHandler::sendPing() {
if (!connection)
return;

if (g.s.iMaxInFlightTCPPings >= 0 && iInFlightTCPPings >= g.s.iMaxInFlightTCPPings) {
serverConnectionClosed(QAbstractSocket::UnknownSocketError, tr("Server is not responding to TCP pings"));
return;
}

CryptState &cs = connection->csCrypt;

quint64 t = tTimestamp.elapsed();
@@ -426,6 +432,8 @@ void ServerHandler::sendPing() {
mpp.set_tcp_packets(static_cast<int>(boost::accumulators::count(accTCP)));

sendMessage(mpp);

iInFlightTCPPings += 1;
}

void ServerHandler::message(unsigned int msgType, const QByteArray &qbaMsg) {
@@ -454,6 +462,11 @@ void ServerHandler::message(unsigned int msgType, const QByteArray &qbaMsg) {
ConnectionPtr connection(cConnection);
if (!connection) return;

// Reset in-flight TCP ping counter to 0.
// We've received a ping. That means the
// connection is still OK.
iInFlightTCPPings = 0;

CryptState &cs = connection->csCrypt;
cs.uiRemoteGood = msg.good();
cs.uiRemoteLate = msg.late();
@@ -532,6 +545,8 @@ void ServerHandler::serverConnectionConnected() {
ConnectionPtr connection(cConnection);
if (!connection) return;

iInFlightTCPPings = 0;

tConnectionTimeoutTimer->stop();

if (g.s.bQoS)
@@ -73,6 +73,7 @@ class ServerHandler : public QThread {
void handleVoicePacket(unsigned int msgFlags, PacketDataStream &pds, MessageHandler::UDPMessageType type);
public:
Timer tTimestamp;
int iInFlightTCPPings;
QTimer *tConnectionTimeoutTimer;
QList<QSslError> qlErrors;
QList<QSslCertificate> qscCert;
@@ -344,6 +344,7 @@ Settings::Settings() {
bAutoConnect = false;
ptProxyType = NoProxy;
usProxyPort = 0;
iMaxInFlightTCPPings = 2;

iMaxImageSize = ciDefaultMaxImageSize;
iMaxImageWidth = 1024; // Allow 1024x1024 resolution
@@ -644,6 +645,7 @@ void Settings::load(QSettings* settings_ptr) {
SAVELOAD(iMaxImageWidth, "net/maximagewidth");
SAVELOAD(iMaxImageHeight, "net/maximageheight");
SAVELOAD(qsServicePrefix, "net/serviceprefix");
SAVELOAD(iMaxInFlightTCPPings, "net/maxinflighttcppings");

// Network settings - SSL
SAVELOAD(qsSslCiphers, "net/sslciphers");
@@ -956,6 +958,7 @@ void Settings::save() {
SAVELOAD(iMaxImageWidth, "net/maximagewidth");
SAVELOAD(iMaxImageHeight, "net/maximageheight");
SAVELOAD(qsServicePrefix, "net/serviceprefix");
SAVELOAD(iMaxInFlightTCPPings, "net/maxinflighttcppings");

// Network settings - SSL
SAVELOAD(qsSslCiphers, "net/sslciphers");
@@ -290,6 +290,18 @@ struct Settings {
QString qsProxyHost, qsProxyUsername, qsProxyPassword;
unsigned short usProxyPort;

/// iMaxInFlightTCPPings specifies the maximum
/// number of ping messages that the client has
/// sent, but not yet recieved a response for
/// from the server. This value is checked when
/// the client sends its next ping message. If
/// the maximum is reached, the connection will
/// be closed.
/// If this setting is assigned a value of 0 or
/// a negative number, the TCP ping check is
/// disabled.
int iMaxInFlightTCPPings;

/// The service prefix that the WebFetch class will use
/// when it constructs its fully-qualified URL. If this
/// is empty, no prefix is used.

0 comments on commit 012cde5

Please sign in to comment.
You can’t perform that action at this time.