2 #include <QNetworkInterface>
3 #include "../../shared/settings.h"
4 #include "../../shared/network.h"
5 #include "../../shared/util.h"
7 #include "../util/util.h"
14 _minDiscoveryInterval(500),
15 _maxDiscoveryInterval(5000)
22 while (tries-- != 0) {
23 quint16 port = quint16(16384 +
slxrand() % 32768);
27 qFatal(
"Could not bind to any UDP port for server discovery.");
49 if (!mgrIP.isEmpty()) {
52 _mgrIP = QHostAddress::Null;
61 this->blockSignals(
false);
79 this->blockSignals(
true);
98 salt1[i] = char(
slxrand() & 0xff);
108 if (
_mgrIP != QHostAddress::Null) {
109 qDebug() <<
"Sending discovery to " <<
_mgrIP.toString();
113 foreach (QNetworkInterface interface, QNetworkInterface::allInterfaces()) {
114 foreach (QNetworkAddressEntry entry, interface.addressEntries()) {
115 if (!entry.broadcast().isNull() && entry.ip() != QHostAddress::LocalHost && entry.ip() != QHostAddress::LocalHostIPv6) {
116 qDebug() <<
"Broadcasting to " << entry.broadcast().toString();
122 qDebug(
"Broadcasting to 255.255.255.255");
155 qDebug() <<
"Corrupt discovery reply from" << addr.toString();
167 qDebug() <<
"Received bogus discovery reply from" << addr.toString() <<
"... Not in" << iplist;
176 qDebug() <<
"Received bogus session name in discovery reply from" << addr.toString();
183 qDebug() <<
"Server detected:"
184 << addr.toString() +
":" + QString::fromUtf8(port) +
"/" +
_nameBytes;
188 const ushort iport = QString::fromUtf8(port).toUShort(&ok);
192 qDebug() <<
"... but server advertises unparsable port" << port;
QUdpSocket _discoverySocket
ServerDiscovery(QObject *parent=nullptr)
Ctor.
void error(ErrorType e, int count)
bool writeMessage(QAbstractSocket *socket)
#define SERVICE_DISCOVERY_PORT
static quint16 hash(const QHostAddress &host)
hash
const int _minDiscoveryInterval
void start(const QByteArray &sessionName, const QString &mgrIP)
start
QByteArray genSha1(const QByteArray *a, const QByteArray *b, const QByteArray *c, const QByteArray *d, const QByteArray *e)
const int _maxDiscoveryInterval
~ServerDiscovery() override
Dtor.
void onUdpReadyRead()
Handle incoming service discovery packets.
bool isAddressInList(const QString &list, const QString &address)
int readMessage(QAbstractSocket *socket)
static const int SALT_LEN
QString interfaceAddressesToString()
Returns list of all addresses assigned to the interfaces of this machine.
static const int UDPBUFSIZ
void serverDetected(const QString &host, const quint16 port, const QByteArray &sessionName, const QByteArray &certHash, bool autoConnect)
QByteArray getFieldBytes(const QByteArray &key) const
void setField(const QByteArray &key, const QByteArray &value)
void doDiscovery()
ConnectWindow::doDiscovery.