blob: d7d6010cd913063e86fdc745c8fa8a638e617e82 (
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 = 0);
~ServerDiscovery();
void start(const QByteArray& sessionName, 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
|