Skip to content

Commit

Permalink
Merge PR #2623: Use same source address for UDP packets that is used …
Browse files Browse the repository at this point in the history
…for TCP packets
  • Loading branch information
mkrautz committed Nov 13, 2016
2 parents 380cd6b + 2b1c6b4 commit b2e37e6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ quint16 Connection::peerPort() const {
return qtsSocket->peerPort();
}

QHostAddress Connection::localAddress() const {
return qtsSocket->localAddress();
}

quint16 Connection::localPort() const {
return qtsSocket->localPort();
}

QList<QSslCertificate> Connection::peerCertificateChain() const {
const QSslCertificate cert = qtsSocket->peerCertificate();
if (cert.isNull())
Expand Down
4 changes: 4 additions & 0 deletions src/Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ class Connection : public QObject {
QString sessionProtocolString() const;
QHostAddress peerAddress() const;
quint16 peerPort() const;
/// Look up the local address of this Connection.
QHostAddress localAddress() const;
/// Look up the local port of this Connection.
quint16 localPort() const;
bool bDisconnectedEmitted;

void setToS();
Expand Down
17 changes: 13 additions & 4 deletions src/mumble/ServerHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,12 +600,21 @@ void ServerHandler::serverConnectionConnected() {
QMutexLocker qml(&qmUdp);

qhaRemote = connection->peerAddress();
qhaLocal = connection->localAddress();
if (qhaLocal.isNull()) {
qFatal("ServerHandler: qhaLocal is unexpectedly a null addr");
}

qusUdp = new QUdpSocket(this);
if (qhaRemote.protocol() == QAbstractSocket::IPv6Protocol)
qusUdp->bind(QHostAddress(QHostAddress::AnyIPv6), 0);
else
qusUdp->bind(QHostAddress(QHostAddress::Any), 0);
if (g.s.bUdpForceTcpAddr) {
qusUdp->bind(qhaLocal);
} else {
if (qhaRemote.protocol() == QAbstractSocket::IPv6Protocol) {
qusUdp->bind(QHostAddress(QHostAddress::AnyIPv6), 0);
} else {
qusUdp->bind(QHostAddress(QHostAddress::Any), 0);
}
}

connect(qusUdp, SIGNAL(readyRead()), this, SLOT(udpReady()));

Expand Down
1 change: 1 addition & 0 deletions src/mumble/ServerHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class ServerHandler : public QThread {
#endif

QHostAddress qhaRemote;
QHostAddress qhaLocal;
QUdpSocket *qusUdp;
QMutex qmUdp;

Expand Down
3 changes: 3 additions & 0 deletions src/mumble/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ Settings::Settings() {
ptProxyType = NoProxy;
usProxyPort = 0;
iMaxInFlightTCPPings = 2;
bUdpForceTcpAddr = true;

iMaxImageSize = ciDefaultMaxImageSize;
iMaxImageWidth = 1024; // Allow 1024x1024 resolution
Expand Down Expand Up @@ -646,6 +647,7 @@ void Settings::load(QSettings* settings_ptr) {
SAVELOAD(iMaxImageHeight, "net/maximageheight");
SAVELOAD(qsServicePrefix, "net/serviceprefix");
SAVELOAD(iMaxInFlightTCPPings, "net/maxinflighttcppings");
SAVELOAD(bUdpForceTcpAddr, "net/udpforcetcpaddr");

// Network settings - SSL
SAVELOAD(qsSslCiphers, "net/sslciphers");
Expand Down Expand Up @@ -959,6 +961,7 @@ void Settings::save() {
SAVELOAD(iMaxImageHeight, "net/maximageheight");
SAVELOAD(qsServicePrefix, "net/serviceprefix");
SAVELOAD(iMaxInFlightTCPPings, "net/maxinflighttcppings");
SAVELOAD(bUdpForceTcpAddr, "net/udpforcetcpaddr");

// Network settings - SSL
SAVELOAD(qsSslCiphers, "net/sslciphers");
Expand Down
4 changes: 4 additions & 0 deletions src/mumble/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ struct Settings {
ProxyType ptProxyType;
QString qsProxyHost, qsProxyUsername, qsProxyPassword;
unsigned short usProxyPort;
/// bUdpForceTcpAddr forces Mumble to bind its UDP
/// socket to the same address as its TCP
/// connection is using.
bool bUdpForceTcpAddr;

/// iMaxInFlightTCPPings specifies the maximum
/// number of ping messages that the client has
Expand Down

0 comments on commit b2e37e6

Please sign in to comment.