-
Notifications
You must be signed in to change notification settings - Fork 14
/
discovery.h
46 lines (42 loc) · 1.27 KB
/
discovery.h
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
#ifndef LAFDUP_DISCOVERY_H
#define LAFDUP_DISCOVERY_H
#include "lafrpc.h"
class LafdupDiscovery;
class LafdupKcpSocket : public qtng::KcpSocket
{
public:
LafdupKcpSocket(LafdupDiscovery *parent);
virtual bool filter(char *data, qint32 *len, qtng::HostAddress *addr, quint16 *port) override;
private:
LafdupDiscovery *parent;
};
class LafdupPeer;
class LafdupDiscovery
{
public:
LafdupDiscovery(const QByteArray &uuid, quint16 port, LafdupPeer *parent);
~LafdupDiscovery();
public:
bool start();
void stop();
void setExtraKnownPeers(const QSet<QPair<qtng::HostAddress, quint16>> &extraKnownPeers);
QSet<QPair<qtng::HostAddress, quint16>> getExtraKnownPeers();
QStringList getAllBoundAddresses();
quint16 getPort();
QByteArray getUuid();
static quint16 getDefaultPort();
private:
void serve();
void discovery();
void handleDiscoveryRequest(const QByteArray &packet, qtng::HostAddress addr, quint16 port);
private:
QSharedPointer<LafdupKcpSocket> kcpSocket;
qtng::CoroutineGroup *operations;
QHash<QString, QPair<qtng::HostAddress, quint16>> knownPeers;
QSet<QPair<qtng::HostAddress, quint16>> extraKnownPeers;
QByteArray uuid;
LafdupPeer *parent;
quint16 port;
friend class LafdupKcpSocket;
};
#endif