-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconnectionhandler.h
61 lines (45 loc) · 1.29 KB
/
connectionhandler.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef CONNECTIONHANDLER_H
#define CONNECTIONHANDLER_H
#include <QSslCertificate>
#include <QSslKey>
#include <QUdpSocket>
#include <QTimer>
#include <QTcpServer>
#include "host.h"
#include "mousebutton.h"
class Connection;
class QTcpServer;
class ConnectionHandler : public QTcpServer
{
Q_OBJECT
static constexpr int maxConnections = 20;
public:
ConnectionHandler(QObject *parent);
~ConnectionHandler();
void trustHost(const Host &host);
const QSslCertificate &ourCertificate() const;
const QList<QSslCertificate> trustedCertificates() const;
const Host hostWithCert(const QSslCertificate &cert) const;
bool isTrusted(const Host &host) const;
protected:
void incomingConnection(qintptr handle) override;
signals:
void pingFromHost(const Host &host);
void mouseMoveRequested(const QPoint &position);
void mouseClickRequested(const QPoint &position, const MouseButton button);
private slots:
void sendPing();
void onDatagram();
void onClientError();
void onClientDisconnected();
private:
void generateKey();
QSslCertificate m_certificate;
QSslKey m_key;
QUdpSocket m_pingSocket;
QTimer m_pingTimer;
QByteArray m_digest;
QList<Host> m_trustedHosts;
int m_activeConnections = 0;
};
#endif // CONNECTIONHANDLER_H