blob: 21f9bf933ab1f3a27bd285d2bf7ba47f8261ee8e (
plain) (
tree)
|
|
#ifndef SERVERDISCOVERY_H
#define SERVERDISCOVERY_H
#include <QObject>
#include <QUdpSocket>
#include <QTimer>
#include "../../shared/networkmessage.h"
class ServerDiscovery : public QObject
{
Q_OBJECT
public:
enum class ErrorType
{
InvalidIpList,
InvalidHash
};
explicit ServerDiscovery(QObject *parent = nullptr);
~ServerDiscovery() override;
void start(const QByteArray& sessionName, const QString& mgrIP);
void stop();
inline bool isActive() { return _discoveryTimer.isActive(); }
private:
QTimer _discoveryTimer;
const int _minDiscoveryInterval;
const int _maxDiscoveryInterval;
int _hashErrorCount;
int _ipErrorCount;
QByteArray _nameBytes;
QByteArray _salt2;
QUdpSocket _discoverySocket;
NetworkMessage _packet;
QHostAddress _mgrIP;
static const int UDPBUFSIZ = 9000;
static const int SALT_LEN = 18;
signals:
void serverDetected(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect);
void error(ErrorType e, int count);
public slots:
private slots:
void doDiscovery();
void onUdpReadyRead();
};
#endif // SERVERDISCOVERY_H
|