mirror of
				https://github.com/coturn/coturn.git
				synced 2025-11-04 00:41:02 +01:00 
			
		
		
		
	working on rtcp sockets
This commit is contained in:
		
							parent
							
								
									3955c8a020
								
							
						
					
					
						commit
						55c8e19424
					
				@ -681,10 +681,10 @@ static int ioa_socket_check_bandwidth(ioa_socket_handle s, size_t sz, int read)
 | 
				
			|||||||
	return 1;
 | 
						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) {
 | 
					  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) {
 | 
					    if (*s) {
 | 
				
			||||||
      return 0;
 | 
					      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) {
 | 
					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;
 | 
							return AF_INET;
 | 
				
			||||||
	} else if(s->done) {
 | 
						} else if(first_time && s->parent_s && (s != s->parent_s)) {
 | 
				
			||||||
		return s->family;
 | 
							first_time = 0;
 | 
				
			||||||
	} else if(s->parent_s && (s != s->parent_s)) {
 | 
							s = s->parent_s;
 | 
				
			||||||
		return get_ioa_socket_address_family(s->parent_s);
 | 
							goto beg;
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		return s->family;
 | 
							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);
 | 
					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);
 | 
					int get_ioa_socket_address_family(ioa_socket_handle s);
 | 
				
			||||||
SOCKET_TYPE get_ioa_socket_type(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;
 | 
					  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) {
 | 
					static void rtcp_map_timeout_handler(ioa_engine_handle e, void* arg) {
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  UNUSED_ARG(e);
 | 
					  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 - success
 | 
				
			||||||
 * <0 - not found
 | 
					 * <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;
 | 
						ioa_socket_handle s = NULL;
 | 
				
			||||||
	if (rtcp_map_valid(map)) {
 | 
						if (rtcp_map_valid(map)) {
 | 
				
			||||||
		ur_map_value_type value;
 | 
							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;
 | 
								rtcp_alloc_type* rval = (rtcp_alloc_type*) value;
 | 
				
			||||||
			if (rval) {
 | 
								if (rval) {
 | 
				
			||||||
				s = rval->s;
 | 
									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);
 | 
							TURN_MUTEX_UNLOCK(&map->mutex);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return s;
 | 
						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) {
 | 
					void rtcp_map_free(rtcp_map** map) {
 | 
				
			||||||
  if(map && rtcp_map_valid(*map)) {
 | 
					  if(map && rtcp_map_valid(*map)) {
 | 
				
			||||||
    TURN_MUTEX_LOCK(&((*map)->mutex));
 | 
					    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 - success
 | 
				
			||||||
 * <0 - not found
 | 
					 * <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);
 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * @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);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @ret:
 | 
					 * @ret:
 | 
				
			||||||
 | 
				
			|||||||
@ -4261,7 +4261,7 @@ static int create_relay_connection(turn_turnserver* server,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			ioa_socket_handle s = NULL;
 | 
								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 ||
 | 
									!s ||
 | 
				
			||||||
				ioa_socket_tobeclosed(s)) {
 | 
									ioa_socket_tobeclosed(s)) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -4275,16 +4275,12 @@ static int create_relay_connection(turn_turnserver* server,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			newelem = get_relay_session_ss(ss,family);
 | 
								newelem = get_relay_session_ss(ss,family);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			IOA_CLOSE_SOCKET(newelem->s);
 | 
								if(newelem->s != s) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			ns_bzero(newelem, sizeof(relay_endpoint_session));
 | 
					 | 
				
			||||||
			newelem->s = s;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if(!check_realm_hash(newelem->s,(u08bits*)ss->realm_options.name)) {
 | 
					 | 
				
			||||||
				IOA_CLOSE_SOCKET(newelem->s);
 | 
									IOA_CLOSE_SOCKET(newelem->s);
 | 
				
			||||||
				*err_code = 508;
 | 
					
 | 
				
			||||||
				*reason = (const u08bits *)"Cannot find a valid reserved socket for this realm";
 | 
									ns_bzero(newelem, sizeof(relay_endpoint_session));
 | 
				
			||||||
				return -1;
 | 
									newelem->s = s;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			addr_debug_print(server->verbose, get_local_addr_from_ioa_socket(newelem->s), "Local relay addr (RTCP)");
 | 
								addr_debug_print(server->verbose, get_local_addr_from_ioa_socket(newelem->s), "Local relay addr (RTCP)");
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user