Skip to content

Commit 145e9aa

Browse files
Split bans_and_allowances_mutex in two distinct mutexes
1 parent 2f7b4ff commit 145e9aa

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
@@ -179,8 +179,10 @@ class webserver {
179179
std::map<details::http_endpoint, http_resource*> registered_resources;
180180
std::map<std::string, http_resource*> registered_resources_str;
181181

182-
std::shared_mutex bans_and_allowances_mutex;
182+
std::shared_mutex bans_mutex;
183183
std::set<http::ip_representation> bans;
184+
185+
std::shared_mutex allowances_mutex;
184186
std::set<http::ip_representation> allowances;
185187

186188
struct MHD_Daemon* daemon;

src/webserver.cpp

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

372372
void webserver::ban_ip(const string& ip) {
373-
std::unique_lock bans_and_allowances_lock(bans_and_allowances_mutex);
373+
std::unique_lock bans_lock(bans_mutex);
374374
ip_representation t_ip(ip);
375375
set<ip_representation>::iterator it = bans.find(t_ip);
376376
if (it != bans.end() && (t_ip.weight() < (*it).weight())) {
@@ -382,7 +382,7 @@ void webserver::ban_ip(const string& ip) {
382382
}
383383

384384
void webserver::allow_ip(const string& ip) {
385-
std::unique_lock bans_and_allowances_lock(bans_and_allowances_mutex);
385+
std::unique_lock allowances_lock(allowances_mutex);
386386
ip_representation t_ip(ip);
387387
set<ip_representation>::iterator it = allowances.find(t_ip);
388388
if (it != allowances.end() && (t_ip.weight() < (*it).weight())) {
@@ -394,12 +394,12 @@ void webserver::allow_ip(const string& ip) {
394394
}
395395

396396
void webserver::unban_ip(const string& ip) {
397-
std::unique_lock bans_and_allowances_lock(bans_and_allowances_mutex);
397+
std::unique_lock bans_lock(bans_mutex);
398398
bans.erase(ip_representation(ip));
399399
}
400400

401401
void webserver::disallow_ip(const string& ip) {
402-
std::unique_lock bans_and_allowances_lock(bans_and_allowances_mutex);
402+
std::unique_lock allowances_lock(allowances_mutex);
403403
allowances.erase(ip_representation(ip));
404404
}
405405

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

410410
if (!(static_cast<webserver*>(cls))->ban_system_enabled) return MHD_YES;
411411

412-
std::shared_lock bans_and_allowances_lock((static_cast<webserver*>(cls))->bans_and_allowances_mutex);
412+
std::shared_lock bans_lock(bans_mutex);
413+
std::shared_lock allowances_lock(allowances_mutex);
413414
if ((((static_cast<webserver*>(cls))->default_policy == http_utils::ACCEPT) &&
414415
((static_cast<webserver*>(cls))->bans.count(ip_representation(addr))) &&
415416
(!(static_cast<webserver*>(cls))->allowances.count(ip_representation(addr)))) ||

0 commit comments

Comments
 (0)