Skip to content
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

WPB-15070 - Make calls to ur_addr_map_get thread safe by introducing locks #29

Open
wants to merge 2 commits into
base: wireapp/4.6.2-federation
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ns_turn_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#ifndef __IOADEFS__
#define __IOADEFS__

#define TURN_SERVER_VERSION "wireapp/4.6.2h"
#define TURN_SERVER_VERSION "wireapp/4.6.2j"
#define TURN_SERVER_VERSION_NAME "Gorst"
#ifndef TURN_SERVER_BUILD_INFO
#define TURN_SERVER_BUILD_INFO ""
Expand Down
8 changes: 8 additions & 0 deletions src/server/ns_turn_ratelimit.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ int ratelimit_is_address_limited(ioa_addr *address, int max_requests, int window
*address_new = *address;
addr_set_port(address_new, 0);

/* Set global lock for `ur_addr_map_get` */
TURN_MUTEX_LOCK(&rate_limit_main_mutex);
if (ur_addr_map_get(rate_limit_map, address_new, &ratelimit_ptr)) {
/* Unlock global lock from `ur_addr_map_get` */
TURN_MUTEX_UNLOCK(&rate_limit_main_mutex);

free(address_new);
ratelimit_entry *rateLimitEntry = (ratelimit_entry *)(void *)(ur_map_value_type)ratelimit_ptr;
TURN_MUTEX_LOCK(&(rateLimitEntry->mutex));
Expand All @@ -105,6 +110,9 @@ int ratelimit_is_address_limited(ioa_addr *address, int max_requests, int window
TURN_MUTEX_UNLOCK(&(rateLimitEntry->mutex));
return 0;
} else {
/* Unlock global lock from `ur_addr_map_get` */
TURN_MUTEX_UNLOCK(&rate_limit_main_mutex);

/* Request is outside of defined window and count, request is ratelimited */
if (rateLimitEntry->request_count < UINT32_MAX)
rateLimitEntry->request_count++;
Expand Down