1
0
mirror of https://github.com/coturn/coturn.git synced 2025-10-29 05:51:10 +01:00

working on bandwidth draft

This commit is contained in:
mom040267 2014-05-27 07:48:11 +00:00
parent 9218a1fc43
commit f9608553fb
4 changed files with 38 additions and 4 deletions

View File

@ -77,6 +77,32 @@ static void barrier_wait_func(const char* func, int line)
#define barrier_wait() barrier_wait_func(__FUNCTION__,__LINE__)
/////////////// Bandwidth //////////////////
static pthread_mutex_t mutex_bps;
static band_limit_t allocate_bps(band_limit_t bps)
{
band_limit_t ret = 0;
if(bps>0) {
pthread_mutex_lock(&mutex_bps);
if(turn_params.bps_capacity_allocated < turn_params.bps_capacity) {
band_limit_t reserve = turn_params.bps_capacity - turn_params.bps_capacity_allocated;
if(reserve <= bps) {
ret = reserve;
turn_params.bps_capacity_allocated = turn_params.bps_capacity;
} else {
ret = bps;
turn_params.bps_capacity_allocated -= ret;
}
}
pthread_mutex_unlock(&mutex_bps);
}
return ret;
}
/////////////// AUX SERVERS ////////////////
static void add_aux_server_list(const char *saddr, turn_server_addrs_list_t *list)
@ -1382,7 +1408,7 @@ static void setup_relay_server(struct relay_server *rs, ioa_engine_handle e, int
&turn_params.secure_stun, turn_params.shatype, &turn_params.mobility,
turn_params.server_relay,
send_turn_session_info,
turn_params.max_bps);
turn_params.max_bps, allocate_bps);
if(to_set_rfc5780) {
set_rfc5780(&(rs->server), get_alt_addr, send_message_from_listener_to_client);
@ -1527,6 +1553,8 @@ void setup_server(void)
{
evthread_use_pthreads();
pthread_mutex_init(&mutex_bps, NULL);
#if !defined(TURN_NO_THREAD_BARRIERS)
/* relay threads plus auth thread plus main listener thread */

View File

@ -4349,7 +4349,7 @@ void init_turn_server(turn_turnserver* server,
send_socket_to_relay_cb send_socket_to_relay,
vintp secure_stun, SHATYPE shatype, vintp mobility, int server_relay,
send_turn_session_info_cb send_turn_session_info,
band_limit_t max_bps) {
band_limit_t max_bps, allocate_bps_cb allocate_bps_func) {
if (!server)
return;
@ -4407,6 +4407,7 @@ void init_turn_server(turn_turnserver* server,
server->send_socket_to_relay = send_socket_to_relay;
server->max_bps = max_bps;
server->allocate_bps_func = allocate_bps_func;
set_ioa_timer(server->e, 1, 0, timer_timeout_handler, server, 1, "timer_timeout_handler");
}

View File

@ -92,7 +92,7 @@ typedef void (*release_allocation_quota_cb)(u08bits *username, u08bits *realm);
typedef int (*send_socket_to_relay_cb)(turnserver_id id, u64bits cid, stun_tid *tid, ioa_socket_handle s, int message_integrity, MESSAGE_TO_RELAY_TYPE rmt, ioa_net_data *nd);
typedef int (*send_turn_session_info_cb)(struct turn_session_info *tsi);
typedef vint band_limit_t;
typedef band_limit_t (*allocate_bps_cb)(band_limit_t bps);
struct _turn_turnserver {
@ -154,6 +154,7 @@ struct _turn_turnserver {
/* Bandwidth draft: */
band_limit_t max_bps;
allocate_bps_cb allocate_bps_func;
};
///////////////////////////////////////////
@ -188,7 +189,8 @@ void init_turn_server(turn_turnserver* server,
vintp mobility,
int server_relay,
send_turn_session_info_cb send_turn_session_info,
band_limit_t max_bps);
band_limit_t max_bps,
allocate_bps_cb allocate_bps_func);
ioa_engine_handle turn_server_get_engine(turn_turnserver *s);

View File

@ -60,6 +60,7 @@ struct _realm_options_t {
//////////////// session info //////////////////////
typedef u64bits turnsession_id;
typedef unsigned int band_limit_t;
#define NONCE_MAX_SIZE (NONCE_LENGTH_32BITS*4+1)
@ -103,6 +104,8 @@ struct _ts_ur_super_session {
realm_options_t realm_options;
int realm_set;
s08bits origin[STUN_MAX_ORIGIN_SIZE + 1];
/* Bandwidth */
band_limit_t bps;
};
////// Session info for statistics //////