Skip to content

Commit 7321aa8

Browse files
fchevassu-antidotetr
authored andcommitted
Split bans_and_allowances_mutex in two distinct mutexes
1 parent 81067ef commit 7321aa8

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/httpserver/webserver.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,10 @@ class webserver {
184184
std::map<details::http_endpoint, http_resource*> registered_resources;
185185
std::map<std::string, http_resource*> registered_resources_str;
186186

187-
std::shared_mutex bans_and_allowances_mutex;
187+
std::shared_mutex bans_mutex;
188188
std::set<http::ip_representation> bans;
189+
190+
std::shared_mutex allowances_mutex;
189191
std::set<http::ip_representation> allowances;
190192

191193
struct MHD_Daemon* daemon;

src/webserver.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ void webserver::unregister_resource(const string& resource) {
379379
}
380380

381381
void webserver::ban_ip(const string& ip) {
382-
std::unique_lock bans_and_allowances_lock(bans_and_allowances_mutex);
382+
std::unique_lock bans_lock(bans_mutex);
383383
ip_representation t_ip(ip);
384384
set<ip_representation>::iterator it = bans.find(t_ip);
385385
if (it != bans.end() && (t_ip.weight() < (*it).weight())) {
@@ -391,7 +391,7 @@ void webserver::ban_ip(const string& ip) {
391391
}
392392

393393
void webserver::allow_ip(const string& ip) {
394-
std::unique_lock bans_and_allowances_lock(bans_and_allowances_mutex);
394+
std::unique_lock allowances_lock(allowances_mutex);
395395
ip_representation t_ip(ip);
396396
set<ip_representation>::iterator it = allowances.find(t_ip);
397397
if (it != allowances.end() && (t_ip.weight() < (*it).weight())) {
@@ -403,12 +403,12 @@ void webserver::allow_ip(const string& ip) {
403403
}
404404

405405
void webserver::unban_ip(const string& ip) {
406-
std::unique_lock bans_and_allowances_lock(bans_and_allowances_mutex);
406+
std::unique_lock bans_lock(bans_mutex);
407407
bans.erase(ip_representation(ip));
408408
}
409409

410410
void webserver::disallow_ip(const string& ip) {
411-
std::unique_lock bans_and_allowances_lock(bans_and_allowances_mutex);
411+
std::unique_lock allowances_lock(allowances_mutex);
412412
allowances.erase(ip_representation(ip));
413413
}
414414

@@ -455,7 +455,8 @@ MHD_Result policy_callback(void *cls, const struct sockaddr* addr, socklen_t add
455455

456456
if (!(static_cast<webserver*>(cls))->ban_system_enabled) return MHD_YES;
457457

458-
std::shared_lock bans_and_allowances_lock((static_cast<webserver*>(cls))->bans_and_allowances_mutex);
458+
std::shared_lock bans_lock(bans_mutex);
459+
std::shared_lock allowances_lock(allowances_mutex);
459460
if ((((static_cast<webserver*>(cls))->default_policy == http_utils::ACCEPT) &&
460461
((static_cast<webserver*>(cls))->bans.count(ip_representation(addr))) &&
461462
(!(static_cast<webserver*>(cls))->allowances.count(ip_representation(addr)))) ||

0 commit comments

Comments
 (0)