-
Notifications
You must be signed in to change notification settings - Fork 0
/
connectioninitiator.h
86 lines (72 loc) · 2.13 KB
/
connectioninitiator.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef CONNECTIONINITIATOR_H
#define CONNECTIONINITIATOR_H
#include <QObject>
#include <QMutex>
#include <QThread>
#include "user.h"
class DatabaseHandler;
class ControlPlaneConnection;
class DataPlaneConnection;
class DataPlaneServer;
class DataPlaneClient;
class ControlPlaneClient;
class ControlPlaneServer;
/**
* @brief The ConnectionInitiator class singleton class that is responsible to initialize
* the control and data plane connections.
*/
class ConnectionInitiator : public QObject
{
Q_OBJECT
private:
DatabaseHandler* qSql;
QSslCertificate cert;
QSslKey key;
ControlPlaneServer* server;
QThread dpServerThread;
DataPlaneServer* dpServer;
QList<ControlPlaneClient*> clients;
QList<ControlPlaneConnection*> connections;
QList<DataPlaneClient*> dpclients;
QList<DataPlaneConnection*> dpConnections;
static ConnectionInitiator* instance;
/**
* @brief startServer iniate an SSL server to receive connections from friends
*/
void startServer();
/**
* @brief startClients initiate an SSL connection with each friend
*/
void startClients();
explicit ConnectionInitiator(QObject *parent = 0);
public:
static ConnectionInitiator* getInstance();
/**
* @brief run runs the ConnectionInitiator, may be used to launch it in a QThread.
*/
void run();
/**
* @brief getConnection will return the control planeconnection with uid "uid"
* and will create one if one did not exist
* Is protected with a Mutex
* @param uid
* @return the connection that has uid "uid"
*/
ControlPlaneConnection* getConnection(QString uid);
/**
* @brief getDpConnection same as @see getConnection but for the dataplane
* @param uid
* @return
*/
DataPlaneConnection* getDpConnection(QString uid);
void removeConnection(ControlPlaneConnection* con);
void removeConnection(DataPlaneConnection* con);
/**
* @brief getMyUid
* @return the user's local uid
*/
QString getMyUid();
QSslKey getPrivateKey();
QSslCertificate getLocalCertificate();
};
#endif // CONNECTIONINITIATOR_H