35 lines
776 B
C++
35 lines
776 B
C++
#pragma once
|
|
#include <string>
|
|
#include <thread>
|
|
#include <mutex>
|
|
#include <vector>
|
|
#include <openssl/ssl.h>
|
|
#include "Protocol.hpp"
|
|
|
|
class ShardServer {
|
|
public:
|
|
ShardServer(const std::string& shard_id, int max_capacity, const std::string& master_ip, int master_port);
|
|
~ShardServer();
|
|
void run();
|
|
void stop();
|
|
|
|
private:
|
|
void connectToMaster();
|
|
void registerShard();
|
|
void sendHeartbeat();
|
|
void heartbeatLoop();
|
|
void sendPacket(uint16_t opcode, const std::vector<char>& payload);
|
|
|
|
std::string shard_id_;
|
|
int max_capacity_;
|
|
int current_load_;
|
|
std::string master_ip_;
|
|
int master_port_;
|
|
int master_fd_;
|
|
SSL_CTX* ssl_ctx_;
|
|
SSL* ssl_;
|
|
bool running_;
|
|
std::thread heartbeat_thread_;
|
|
std::mutex mutex_;
|
|
};
|