added handshake for dos protection
This commit is contained in:
@@ -57,6 +57,7 @@ private:
|
||||
resolve_results_;
|
||||
std::mutex clients_mutex_;
|
||||
std::vector<std::shared_ptr<client>> clients_;
|
||||
std::vector<std::thread> service_threads_;
|
||||
|
||||
private:
|
||||
static void close(client &cli);
|
||||
|
@@ -33,14 +33,25 @@ using namespace repertory::comm;
|
||||
|
||||
namespace repertory {
|
||||
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() {
|
||||
allow_connections_ = false;
|
||||
close_all();
|
||||
|
||||
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) {
|
||||
try {
|
||||
cli.socket.shutdown(boost::asio::socket_base::shutdown_both);
|
||||
@@ -58,7 +69,9 @@ void packet_client::close_all() {
|
||||
}
|
||||
|
||||
clients_.clear();
|
||||
for (std::size_t idx = 0U; idx < service_threads_.size(); ++idx) {
|
||||
io_context_.restart();
|
||||
}
|
||||
resolve_results_ = {};
|
||||
unique_id_ = utils::create_uuid_string();
|
||||
}
|
||||
|
Reference in New Issue
Block a user