added handshake for dos protection
All checks were successful
Blockstorage/repertory/pipeline/head This commit looks good
BlockStorage/repertory/pipeline/head This commit looks good

This commit is contained in:
2025-09-21 11:13:52 -05:00
parent beff363507
commit 067a1d26b3
2 changed files with 17 additions and 3 deletions

View File

@@ -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);

View File

@@ -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();
} }