-
Notifications
You must be signed in to change notification settings - Fork 192
Fix webserver thread safety #330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
2ff6e31
ba2234d
d4a89d8
2f7b4ff
145e9aa
589ff8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -370,6 +370,7 @@ void webserver::unregister_resource(const string& resource) { | |
| } | ||
|
|
||
| void webserver::ban_ip(const string& ip) { | ||
| std::unique_lock bans_and_allowances_lock(bans_and_allowances_mutex); | ||
| ip_representation t_ip(ip); | ||
| set<ip_representation>::iterator it = bans.find(t_ip); | ||
| if (it != bans.end() && (t_ip.weight() < (*it).weight())) { | ||
|
|
@@ -381,6 +382,7 @@ void webserver::ban_ip(const string& ip) { | |
| } | ||
|
|
||
| void webserver::allow_ip(const string& ip) { | ||
| std::unique_lock bans_and_allowances_lock(bans_and_allowances_mutex); | ||
| ip_representation t_ip(ip); | ||
| set<ip_representation>::iterator it = allowances.find(t_ip); | ||
| if (it != allowances.end() && (t_ip.weight() < (*it).weight())) { | ||
|
|
@@ -392,10 +394,12 @@ void webserver::allow_ip(const string& ip) { | |
| } | ||
|
|
||
| void webserver::unban_ip(const string& ip) { | ||
| std::unique_lock bans_and_allowances_lock(bans_and_allowances_mutex); | ||
| bans.erase(ip_representation(ip)); | ||
| } | ||
|
|
||
| void webserver::disallow_ip(const string& ip) { | ||
| std::unique_lock bans_and_allowances_lock(bans_and_allowances_mutex); | ||
| allowances.erase(ip_representation(ip)); | ||
| } | ||
|
|
||
|
|
@@ -405,6 +409,7 @@ MHD_Result policy_callback(void *cls, const struct sockaddr* addr, socklen_t add | |
|
|
||
| if (!(static_cast<webserver*>(cls))->ban_system_enabled) return MHD_YES; | ||
|
|
||
| std::shared_lock bans_and_allowances_lock((static_cast<webserver*>(cls))->bans_and_allowances_mutex); | ||
|
||
| if ((((static_cast<webserver*>(cls))->default_policy == http_utils::ACCEPT) && | ||
| ((static_cast<webserver*>(cls))->bans.count(ip_representation(addr))) && | ||
| (!(static_cast<webserver*>(cls))->allowances.count(ip_representation(addr)))) || | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth splitting this into two, given the writing use-cases are isolated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done