-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathServer.hpp
69 lines (57 loc) · 1.51 KB
/
Server.hpp
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
#pragma once
#include <openssl/ssl.h>
#include <assert.h>
#include <openssl/ossl_typ.h>
#include <memory>
#include <mutex>
#include <string>
#include "Forward.hpp"
#include "KVStore.hpp"
#include "Worker.hpp"
#include "metrics/Types.hpp"
#include "EventLoop.hpp"
#include "Redis.hpp"
namespace eventhub {
class Server final {
public:
Server(Config& cfg);
~Server();
void start();
void stop();
void reload();
Config& config() { return _config; }
int getServerSocket() { return _server_socket; };
Worker* getWorker();
void publish(const std::string& topicName, const std::string& data);
Redis& getRedis() { return _redis; }
KVStore* getKVStore() { return _kv_store.get(); }
metrics::AggregatedMetrics getAggregatedMetrics();
int getSSLServerSocket() { return _server_socket_ssl; };
bool isSSL() { return _ssl_enabled; }
SSL_CTX* getSSLContext() {
assert(isSSL());
assert(_ssl_ctx != nullptr);
return _ssl_ctx;
}
private:
Config& _config;
int _server_socket;
int _server_socket_ssl;
bool _ssl_enabled;
SSL_CTX* _ssl_ctx;
std::string _ssl_cert_md5_hash;
std::string _ssl_priv_key_md5_hash;
WorkerGroup<Worker> _connection_workers;
WorkerGroup<Worker>::iterator _cur_worker;
std::mutex _connection_workers_lock;
Redis _redis;
std::unique_ptr<KVStore> _kv_store;
metrics::ServerMetrics _metrics;
EventLoop _ev;
void _listenerInit();
void _sslListenerInit();
void _initSSL();
void _loadSSLCertificates();
void _checkSSLCertUpdated();
};
} // namespace eventhub