working on rtcp sockets

libevent.rpm
mom040267 11 years ago
parent 3955c8a020
commit 55c8e19424
  1. 17
      src/apps/relay/ns_ioalib_engine_impl.c
  2. 2
      src/server/ns_turn_ioalib.h
  3. 103
      src/server/ns_turn_maps_rtcp.c
  4. 10
      src/server/ns_turn_maps_rtcp.h
  5. 14
      src/server/ns_turn_server.c

@ -681,10 +681,10 @@ static int ioa_socket_check_bandwidth(ioa_socket_handle s, size_t sz, int read)
return 1;
}
int get_ioa_socket_from_reservation(ioa_engine_handle e, u64bits in_reservation_token, ioa_socket_handle *s)
int get_ioa_socket_from_reservation(ioa_engine_handle e, u64bits in_reservation_token, ioa_socket_handle *s, u08bits *realm)
{
if (e && in_reservation_token && s) {
*s = rtcp_map_get(e->map_rtcp, in_reservation_token);
*s = rtcp_map_get(e->map_rtcp, in_reservation_token, realm);
if (*s) {
return 0;
}
@ -1823,12 +1823,15 @@ void set_ioa_socket_sub_session(ioa_socket_handle s, tcp_connection *tc)
}
int get_ioa_socket_address_family(ioa_socket_handle s) {
if(!s) {
int first_time = 1;
beg:
if (!(s && (s->magic == SOCKET_MAGIC) && !(s->done))) {
return AF_INET;
} else if(s->done) {
return s->family;
} else if(s->parent_s && (s != s->parent_s)) {
return get_ioa_socket_address_family(s->parent_s);
} else if(first_time && s->parent_s && (s != s->parent_s)) {
first_time = 0;
s = s->parent_s;
goto beg;
} else {
return s->family;
}

@ -215,7 +215,7 @@ int create_relay_ioa_sockets(ioa_engine_handle e, ioa_socket_handle client_s,
ioa_socket_handle ioa_create_connecting_tcp_relay_socket(ioa_socket_handle s, ioa_addr *peer_addr, connect_cb cb, void *arg);
int get_ioa_socket_from_reservation(ioa_engine_handle e, u64bits in_reservation_token, ioa_socket_handle *s);
int get_ioa_socket_from_reservation(ioa_engine_handle e, u64bits in_reservation_token, ioa_socket_handle *s, u08bits *realm);
int get_ioa_socket_address_family(ioa_socket_handle s);
SOCKET_TYPE get_ioa_socket_type(ioa_socket_handle s);

@ -85,6 +85,54 @@ static int timeout_check(ur_map_key_type key,
return 0;
}
static void rtcp_alloc_free(ur_map_value_type value)
{
rtcp_alloc_type *at = (rtcp_alloc_type *)value;
if (at) {
IOA_CLOSE_SOCKET(at->s);
turn_free(at,sizeof(rtcp_alloc_type));
}
}
static void rtcp_alloc_free_savefd(ur_map_value_type value)
{
rtcp_alloc_type *at = (rtcp_alloc_type *) value;
if (at) {
turn_free(at,sizeof(rtcp_alloc_type));
}
}
static int foreachcb_free(ur_map_key_type key, ur_map_value_type value) {
UNUSED_ARG(key);
if(value) {
rtcp_alloc_free(value);
}
return 0;
}
/**
* @ret:
* 1 - success
* 0 - not found
*/
static int rtcp_map_del(rtcp_map* map, rtcp_token_type token) {
if(!rtcp_map_valid(map)) return 0;
else {
TURN_MUTEX_LOCK(&map->mutex);
int ret = ur_map_del(map->map,token,rtcp_alloc_free);
TURN_MUTEX_UNLOCK(&map->mutex);
return ret;
}
}
static int rtcp_map_del_savefd(rtcp_map* map, rtcp_token_type token) {
if(!rtcp_map_valid(map)) return 0;
else {
int ret = ur_map_del(map->map,token,rtcp_alloc_free_savefd);
return ret;
}
}
static void rtcp_map_timeout_handler(ioa_engine_handle e, void* arg) {
UNUSED_ARG(e);
@ -166,7 +214,7 @@ int rtcp_map_put(rtcp_map* map, rtcp_token_type token, ioa_socket_handle s) {
* >=0 - success
* <0 - not found
*/
ioa_socket_handle rtcp_map_get(rtcp_map* map, rtcp_token_type token) {
ioa_socket_handle rtcp_map_get(rtcp_map* map, rtcp_token_type token, u08bits *realm) {
ioa_socket_handle s = NULL;
if (rtcp_map_valid(map)) {
ur_map_value_type value;
@ -176,61 +224,18 @@ ioa_socket_handle rtcp_map_get(rtcp_map* map, rtcp_token_type token) {
rtcp_alloc_type* rval = (rtcp_alloc_type*) value;
if (rval) {
s = rval->s;
if(!check_realm_hash(s,realm)) {
s = NULL;
} else {
rtcp_map_del_savefd(map, token);
}
}
}
rtcp_map_del_savefd(map, token);
TURN_MUTEX_UNLOCK(&map->mutex);
}
return s;
}
static void rtcp_alloc_free(ur_map_value_type value)
{
rtcp_alloc_type *at = (rtcp_alloc_type *)value;
if (at) {
IOA_CLOSE_SOCKET(at->s);
turn_free(at,sizeof(rtcp_alloc_type));
}
}
static void rtcp_alloc_free_savefd(ur_map_value_type value)
{
rtcp_alloc_type *at = (rtcp_alloc_type *) value;
if (at) {
turn_free(at,sizeof(rtcp_alloc_type));
}
}
static int foreachcb_free(ur_map_key_type key, ur_map_value_type value) {
UNUSED_ARG(key);
if(value) {
rtcp_alloc_free(value);
}
return 0;
}
/**
* @ret:
* 1 - success
* 0 - not found
*/
int rtcp_map_del(rtcp_map* map, rtcp_token_type token) {
if(!rtcp_map_valid(map)) return 0;
else {
TURN_MUTEX_LOCK(&map->mutex);
int ret = ur_map_del(map->map,token,rtcp_alloc_free);
TURN_MUTEX_UNLOCK(&map->mutex);
return ret;
}
}
int rtcp_map_del_savefd(rtcp_map* map, rtcp_token_type token) {
if(!rtcp_map_valid(map)) return 0;
else {
int ret = ur_map_del(map->map,token,rtcp_alloc_free_savefd);
return ret;
}
}
void rtcp_map_free(rtcp_map** map) {
if(map && rtcp_map_valid(*map)) {
TURN_MUTEX_LOCK(&((*map)->mutex));

@ -61,15 +61,7 @@ int rtcp_map_put(rtcp_map* map, rtcp_token_type key, ioa_socket_handle s);
* >=0 - success
* <0 - not found
*/
ioa_socket_handle rtcp_map_get(rtcp_map* map, rtcp_token_type token);
/**
* @ret:
* 1 - success
* 0 - not found
*/
int rtcp_map_del(rtcp_map* map, rtcp_token_type token);
int rtcp_map_del_savefd(rtcp_map* map, rtcp_token_type token);
ioa_socket_handle rtcp_map_get(rtcp_map* map, rtcp_token_type token, u08bits *realm);
/**
* @ret:

@ -4261,7 +4261,7 @@ static int create_relay_connection(turn_turnserver* server,
ioa_socket_handle s = NULL;
if ((get_ioa_socket_from_reservation(server->e, in_reservation_token,&s) < 0)||
if ((get_ioa_socket_from_reservation(server->e, in_reservation_token,&s,(u08bits*)ss->realm_options.name) < 0)||
!s ||
ioa_socket_tobeclosed(s)) {
@ -4275,16 +4275,12 @@ static int create_relay_connection(turn_turnserver* server,
newelem = get_relay_session_ss(ss,family);
IOA_CLOSE_SOCKET(newelem->s);
ns_bzero(newelem, sizeof(relay_endpoint_session));
newelem->s = s;
if(newelem->s != s) {
if(!check_realm_hash(newelem->s,(u08bits*)ss->realm_options.name)) {
IOA_CLOSE_SOCKET(newelem->s);
*err_code = 508;
*reason = (const u08bits *)"Cannot find a valid reserved socket for this realm";
return -1;
ns_bzero(newelem, sizeof(relay_endpoint_session));
newelem->s = s;
}
addr_debug_print(server->verbose, get_local_addr_from_ioa_socket(newelem->s), "Local relay addr (RTCP)");

Loading…
Cancel
Save