added handshake for dos protection
This commit is contained in:
@@ -57,6 +57,7 @@ private:
|
|||||||
resolve_results_;
|
resolve_results_;
|
||||||
std::mutex clients_mutex_;
|
std::mutex clients_mutex_;
|
||||||
std::vector<std::shared_ptr<client>> clients_;
|
std::vector<std::shared_ptr<client>> clients_;
|
||||||
|
std::vector<std::thread> service_threads_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void close(client &cli);
|
static void close(client &cli);
|
||||||
|
@@ -33,12 +33,23 @@ using namespace repertory::comm;
|
|||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
packet_client::packet_client(remote::remote_config cfg)
|
packet_client::packet_client(remote::remote_config cfg)
|
||||||
: cfg_(std::move(cfg)), unique_id_(utils::create_uuid_string()) {}
|
: cfg_(std::move(cfg)), unique_id_(utils::create_uuid_string()) {
|
||||||
|
for (std::uint8_t idx = 0U; idx < cfg.max_connections; ++idx) {
|
||||||
|
service_threads_.emplace_back([this]() { io_context_.run(); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
packet_client::~packet_client() {
|
packet_client::~packet_client() {
|
||||||
allow_connections_ = false;
|
allow_connections_ = false;
|
||||||
close_all();
|
close_all();
|
||||||
io_context_.stop();
|
|
||||||
|
for (std::size_t idx = 0U; idx < service_threads_.size(); ++idx) {
|
||||||
|
io_context_.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &thread : service_threads_) {
|
||||||
|
thread.join();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void packet_client::close(client &cli) {
|
void packet_client::close(client &cli) {
|
||||||
@@ -58,7 +69,9 @@ void packet_client::close_all() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
clients_.clear();
|
clients_.clear();
|
||||||
io_context_.restart();
|
for (std::size_t idx = 0U; idx < service_threads_.size(); ++idx) {
|
||||||
|
io_context_.restart();
|
||||||
|
}
|
||||||
resolve_results_ = {};
|
resolve_results_ = {};
|
||||||
unique_id_ = utils::create_uuid_string();
|
unique_id_ = utils::create_uuid_string();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user