blob: 21f9bf933ab1f3a27bd285d2bf7ba47f8261ee8e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#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
|