-
Notifications
You must be signed in to change notification settings - Fork 6
/
NetworkEngine.h
68 lines (50 loc) · 1.43 KB
/
NetworkEngine.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
#ifndef NETWORKENGINE_H
#define NETWORKENGINE_H
#include <QTcpServer>
#include <QList>
#include <QVector>
#include "SocketWorker.h"
#include "NetworkTaskQueue.h"
#include <QHostAddress>
#include <QSet>
#include <QTimer>
#include "Transaction.h"
class Bingot;
class Peer
{
private:
QHostAddress m_address;
unsigned short m_port;
public:
Peer(const QHostAddress &address = QHostAddress::Any, unsigned int port = 0);
const QHostAddress &getAddress() const;
unsigned short getPort() const;
void operator=(const Peer &in);
bool operator==(const Peer &in);
friend bool operator==(const Peer &a, const Peer &b);
friend uint qhash(const Peer &in);
friend uint qHash(const Peer &key, uint seed);
};
bool operator==(const Peer &a, const Peer &b);
inline uint qhash(const Peer &in);
inline uint qHash(const Peer &key, uint seed);
class NetworkEngine : public QTcpServer
{
Q_OBJECT
public:
NetworkEngine();
void incomingConnection(qintptr socketId);
void initialize(Bingot *bingot);
~NetworkEngine();
void addPeer(const Peer& in);
void sendMessage(const QByteArray &msg);
private:
QVector<SocketWorker*> m_socketWorkerList;
NetworkTaskQueue *m_taskQueue;
QMutex m_peerAddressesMutex;
QSet<Peer> m_peerAddresses;
QTimer m_peerTimer;
private slots:
void onPeerTimerTimeout();
};
#endif // NETWORKENGINE_H