-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathatomengineserver.h
76 lines (66 loc) · 2.13 KB
/
atomengineserver.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
// Copyright 2018 AtomicSwap Solutions Ltd. All rights reserved.
// Use of this source code is governed by Microsoft Reference Source
// License (MS-RSL) that can be found in the LICENSE file.
#ifndef ATOMENGINESERVER_H
#define ATOMENGINESERVER_H
#include <QObject>
#include <QTcpServer>
#include <QTcpSocket>
#include <QJsonDocument>
#include <QJsonObject>
#include <QFile>
#include <map>
#include <memory>
#include <set>
#include <QSettings>
struct OrderInfo;
using OrderInfoPtr = std::shared_ptr<OrderInfo>;
using Orders = std::map<long long, OrderInfoPtr>;
struct TradeInfo;
using TradeInfoPtr = std::shared_ptr<TradeInfo>;
using Trades = std::map<long long, TradeInfoPtr>;
using Connections = std::map<qintptr, QTcpSocket*>;
using Buffers = std::map<qintptr, QByteArray>;
using ActiveAddrs = std::map<QString, qintptr>;
using Addrs = std::set<QString>;
using BlackList = std::set<QString>;
using RequestCheckingTime = std::map<QString, long long>;
using RequestCheckingCount = std::map<QString, long long>;
class AtomEngineServer : public QObject
{
Q_OBJECT
public:
AtomEngineServer();
~AtomEngineServer();
bool run();
private:
bool load();
OrderInfoPtr createOrder(const QString& key, const QJsonObject& orderJson);
bool deleteOrder(const QString& key, long long id);
TradeInfoPtr createTrade(const QString& key, long long orderId, const QString& initiatorAddress);
TradeInfoPtr updateTrade(const QString& key, const QJsonObject& tradeJson);
void sendDisconnectedAddrs(const Addrs& addrs);
void sendConnectedAddrs(qintptr curDescr);
private slots:
void onNewConnection();
void onClientDisconnected();
void onReadyRead();
private:
QTcpServer* server_;
Connections connections_;
Orders orders_;
Trades trades_;
ActiveAddrs addrs_;
long long curOrderId_;
long long curTradeId_;
QFile backupFile_;
Buffers buffers_;
QSettings* settings_;
BlackList blackList_;
long long maxRequestSize_;
long long requestCheckingInterval_;
long long requestsCount_;
RequestCheckingTime checkingTime_;
RequestCheckingCount checkingCount_;
};
#endif // ATOMENGINESERVER_H