summaryrefslogtreecommitdiffstats
path: root/src/client/net/serverdiscovery.cpp
diff options
context:
space:
mode:
authorChristian Klinger2016-09-29 15:40:18 +0200
committerChristian Klinger2016-09-29 15:40:18 +0200
commit3d82bfc698165bb20f3c38d42f2b77ab855c1edf (patch)
tree2c170bcdd5c89259bb0b530fa11fdfe701c99850 /src/client/net/serverdiscovery.cpp
parentadded an information dialog that displays ip and hostname. (diff)
downloadpvs2-3d82bfc698165bb20f3c38d42f2b77ab855c1edf.tar.gz
pvs2-3d82bfc698165bb20f3c38d42f2b77ab855c1edf.tar.xz
pvs2-3d82bfc698165bb20f3c38d42f2b77ab855c1edf.zip
astyle.
Diffstat (limited to 'src/client/net/serverdiscovery.cpp')
-rw-r--r--src/client/net/serverdiscovery.cpp35
1 files changed, 13 insertions, 22 deletions
diff --git a/src/client/net/serverdiscovery.cpp b/src/client/net/serverdiscovery.cpp
index 1d1e891..4a69e91 100644
--- a/src/client/net/serverdiscovery.cpp
+++ b/src/client/net/serverdiscovery.cpp
@@ -12,16 +12,15 @@
*/
ServerDiscovery::ServerDiscovery(QObject *parent)
: QObject(parent),
- _minDiscoveryInterval(500),
- _maxDiscoveryInterval(5000)
+ _minDiscoveryInterval(500),
+ _maxDiscoveryInterval(5000)
{
_hashErrorCount = 0;
_ipErrorCount = 0;
/* Try to get a UDP port for server discovery */
int tries = 10;
- while (tries-- != 0)
- {
+ while (tries-- != 0) {
const quint16 port = (quint16)(qrand() % 10000) + 10000;
if (_discoverySocket.bind(QHostAddress::Any, port))
break;
@@ -109,19 +108,14 @@ void ServerDiscovery::doDiscovery()
_packet.setField(_IPLIST, iplist);
// Check if specifig manager IP is given. If not broadcast in whole network.
- if (_mgrIP != QHostAddress::Null)
- {
+ if (_mgrIP != QHostAddress::Null) {
qDebug() << "Broadcasting to " << _mgrIP.toString();
if (!_packet.writeMessage(&_discoverySocket, _mgrIP, SERVICE_DISCOVERY_PORT))
qDebug("Failed");
- } else
- {
- foreach (QNetworkInterface interface, QNetworkInterface::allInterfaces())
- {
- foreach (QNetworkAddressEntry entry, interface.addressEntries())
- {
- if (!entry.broadcast().isNull() && entry.ip() != QHostAddress::LocalHost && entry.ip() != QHostAddress::LocalHostIPv6)
- {
+ } else {
+ foreach (QNetworkInterface interface, QNetworkInterface::allInterfaces()) {
+ foreach (QNetworkAddressEntry entry, interface.addressEntries()) {
+ if (!entry.broadcast().isNull() && entry.ip() != QHostAddress::LocalHost && entry.ip() != QHostAddress::LocalHostIPv6) {
qDebug() << "Broadcasting to " << entry.broadcast().toString();
if (!_packet.writeMessage(&_discoverySocket, entry.broadcast(), SERVICE_DISCOVERY_PORT))
qDebug("FAILED");
@@ -148,10 +142,9 @@ void ServerDiscovery::onUdpReadyRead()
char data[UDPBUFSIZ];
QHostAddress addr;
quint16 port;
- while (_discoverySocket.hasPendingDatagrams())
- {
+ while (_discoverySocket.hasPendingDatagrams()) {
// Discard any packets if discovery is stopped
- if (!this->isActive()){
+ if (!this->isActive()) {
_discoverySocket.readDatagram(NULL, 0);
continue;
}
@@ -171,16 +164,14 @@ void ServerDiscovery::onUdpReadyRead()
const QByteArray cert(_packet.getFieldBytes(_CERT));
// Check if the source IP of the packet matches any of the addresses given in the IP list
- if (!Network::isAddressInList(QString::fromUtf8(iplist), addr.toString()))
- {
+ if (!Network::isAddressInList(QString::fromUtf8(iplist), addr.toString())) {
++_ipErrorCount;
emit error(ErrorType::InvalidIpList, _hashErrorCount);
continue;
}
// If so, check if the submitted hash seems valid
- if (genSha1(&_nameBytes, &_salt2, &iplist, &port, &cert) != hash && _mgrIP != addr)
- {
+ if (genSha1(&_nameBytes, &_salt2, &iplist, &port, &cert) != hash && _mgrIP != addr) {
// did not match local session name, or other data was spoofed
++_hashErrorCount;
emit error(ErrorType::InvalidHash, _ipErrorCount);
@@ -189,7 +180,7 @@ void ServerDiscovery::onUdpReadyRead()
/* Otherwise it's a valid reply */
qDebug() << "Server detected:"
- << addr.toString() + ":" + QString::fromUtf8(port) + "/" + _nameBytes;
+ << addr.toString() + ":" + QString::fromUtf8(port) + "/" + _nameBytes;
// Tell that a server hs been found
emit serverDetected(addr.toString(), (quint16)QString::fromUtf8(port).toInt(), _nameBytes, cert, (_mgrIP == addr));