Ejemplo n.º 1
0
u16bits turnports_size(turnports* tp) {
  if(!tp) return 0;
  else {
    TURN_MUTEX_LOCK(&tp->mutex);
    u16bits ret = (u16bits)((tp->high-tp->low));
    TURN_MUTEX_UNLOCK(&tp->mutex);
    return ret;
  }
}
Ejemplo n.º 2
0
int turnports_is_allocated(turnports* tp, u16bits port) {
  if(!tp) return 0;
  else {
    TURN_MUTEX_LOCK(&tp->mutex);
    int ret = is_taken(tp->status[port]);
    TURN_MUTEX_UNLOCK(&tp->mutex);
    return ret;
  }
}
Ejemplo n.º 3
0
int turnipports_allocate(turnipports* tp, u08bits transport, const ioa_addr *backend_addr)
{
	int ret = -1;
	if (tp && backend_addr) {
		TURN_MUTEX_LOCK((const turn_mutex*)&(tp->mutex));
		turnports *t = turnipports_add(tp, transport, backend_addr);
		ret = turnports_allocate(t);
		TURN_MUTEX_UNLOCK((const turn_mutex*)&(tp->mutex));
	}
	return ret;
}
Ejemplo n.º 4
0
void turnipports_remove(turnipports* tp, u08bits transport, const ioa_addr *backend_addr)
{
	if (tp && backend_addr) {
		ioa_addr ba;
		addr_cpy(&ba, backend_addr);
		addr_set_port(&ba, 0);
		TURN_MUTEX_LOCK((const turn_mutex*)&(tp->mutex));
		ur_addr_map_del(get_map(tp, transport), &ba, turnipports_del_func);
		TURN_MUTEX_UNLOCK((const turn_mutex*)&(tp->mutex));
	}
}
Ejemplo n.º 5
0
int turnipports_allocate_even(turnipports* tp, const ioa_addr *backend_addr, int allocate_rtcp,
				u64bits *reservation_token)
{
	int ret = -1;
	if (tp && backend_addr) {
		TURN_MUTEX_LOCK((const turn_mutex*)&(tp->mutex));
		turnports *t = turnipports_add(tp, STUN_ATTRIBUTE_TRANSPORT_UDP_VALUE, backend_addr);
		ret = turnports_allocate_even(t, allocate_rtcp, reservation_token);
		TURN_MUTEX_UNLOCK((const turn_mutex*)&(tp->mutex));
	}
	return ret;
}
Ejemplo n.º 6
0
void turnports_release(turnports* tp, u16bits port) {
  TURN_MUTEX_LOCK(&tp->mutex);
  if(tp && port>=tp->range_start && port<=tp->range_stop) {
    u16bits position=(u16bits)(tp->high & 0x0000FFFF);
    if(is_taken(tp->status[port])) {
      tp->status[port]=tp->high;
      tp->ports[position]=port;
      ++(tp->high);
    }
  }
  TURN_MUTEX_UNLOCK(&tp->mutex);
}
Ejemplo n.º 7
0
void turnipports_release(turnipports* tp, u08bits transport, const ioa_addr *socket_addr)
{
	if (tp && socket_addr) {
		ioa_addr ba;
		ur_addr_map_value_type t;
		addr_cpy(&ba, socket_addr);
		addr_set_port(&ba, 0);
		TURN_MUTEX_LOCK((const turn_mutex*)&(tp->mutex));
		if (ur_addr_map_get(get_map(tp, transport), &ba, &t)) {
			turnports_release((turnports*) t, addr_get_port(socket_addr));
		}
		TURN_MUTEX_UNLOCK((const turn_mutex*)&(tp->mutex));
	}
}
Ejemplo n.º 8
0
int turnports_is_available(turnports* tp, u16bits port) {
  if(tp) {
    TURN_MUTEX_LOCK(&tp->mutex);
    u64bits status = tp->status[port];
    if((status!=TPS_OUT_OF_RANGE) && !is_taken(status)) {
      u16bits position=(u16bits)(status & 0x0000FFFF);
      if((int)(tp->ports[position])==(int)port) {
	TURN_MUTEX_UNLOCK(&tp->mutex);
	return 1;
      }
    }
    TURN_MUTEX_UNLOCK(&tp->mutex);
  }
  return 0;
}
Ejemplo n.º 9
0
int turnipports_is_allocated(turnipports* tp, u08bits transport, const ioa_addr *backend_addr, u16bits port)
{
	int ret = 0;
	if (tp && backend_addr) {
		ioa_addr ba;
		ur_addr_map_value_type t;
		addr_cpy(&ba, backend_addr);
		addr_set_port(&ba, 0);
		TURN_MUTEX_LOCK((const turn_mutex*)&(tp->mutex));
		if (ur_addr_map_get(get_map(tp,transport), &ba, &t)) {
			ret = turnports_is_allocated((turnports*) t, port);
		}
		TURN_MUTEX_UNLOCK((const turn_mutex*)&(tp->mutex));
	}
	return ret;
}
Ejemplo n.º 10
0
static turnports* turnipports_add(turnipports* tp, u08bits transport, const ioa_addr *backend_addr)
{
	ur_addr_map_value_type t = 0;
	if (tp && backend_addr) {
		ioa_addr ba;
		addr_cpy(&ba, backend_addr);
		addr_set_port(&ba, 0);
		TURN_MUTEX_LOCK((const turn_mutex*)&(tp->mutex));
		if (!ur_addr_map_get(get_map(tp, transport), &ba, &t)) {
			t = (ur_addr_map_value_type) turnports_create(tp->start, tp->end);
			ur_addr_map_put(get_map(tp, transport), &ba, t);
		}
		TURN_MUTEX_UNLOCK((const turn_mutex*)&(tp->mutex));
	}
	return (turnports*) t;
}
Ejemplo n.º 11
0
int get_realm_options_by_origin(char *origin, realm_options_t* ro)
{
	ur_string_map_value_type value = 0;
	TURN_MUTEX_LOCK(&o_to_realm_mutex);
	if (ur_string_map_get(o_to_realm, (ur_string_map_key_type) origin, &value) && value) {
		char *realm = turn_strdup((char*)value);
		TURN_MUTEX_UNLOCK(&o_to_realm_mutex);
		realm_params_t rp;
		get_realm_data(realm, &rp);
		ns_bcopy(&(rp.options),ro,sizeof(realm_options_t));
		turn_free(realm,strlen(realm)+1);
		return 1;
	} else {
		TURN_MUTEX_UNLOCK(&o_to_realm_mutex);
		get_default_realm_options(ro);
		return 0;
	}
}
Ejemplo n.º 12
0
int turnports_allocate_even(turnports* tp, int allocate_rtcp, u64bits *reservation_token) {
  if(tp) {
    TURN_MUTEX_LOCK(&tp->mutex);
    u16bits size = turnports_size(tp);
    if(size>1) {
      u16bits i=0;
      for(i=0;i<size;i++) {
	int port=turnports_allocate(tp);
	if(port & 0x00000001) {
	  turnports_release(tp,port);
	} else {
	  if(!allocate_rtcp) {
	    TURN_MUTEX_UNLOCK(&tp->mutex);
	    return port;
	  } else {
	    int rtcp_port=port+1;
	    if(rtcp_port>tp->range_stop) {
	      turnports_release(tp,port);
	    } else if(!turnports_is_available(tp,rtcp_port)) {
	      turnports_release(tp,port);
	    } else {
	      tp->status[port]=TPS_TAKEN_EVEN;
	      tp->status[rtcp_port]=TPS_TAKEN_ODD;
	      if(reservation_token) {
		u16bits *v16=(u16bits*)reservation_token;
		u32bits *v32=(u32bits*)reservation_token;
		v16[0]=(u16bits)(tp->ports[(u16bits)(tp->low & 0x0000FFFF)]);
		v16[1]=(u16bits)(tp->ports[(u16bits)(tp->high & 0x0000FFFF)]);
		v32[1]=(u32bits)random();
	      }
	      TURN_MUTEX_UNLOCK(&tp->mutex);
	      return port;
	    }
	  }
	}
      }
    }
    TURN_MUTEX_UNLOCK(&tp->mutex);
  }
  return -1;
}
Ejemplo n.º 13
0
int turnports_allocate(turnports* tp) {

  int port=-1;

  TURN_MUTEX_LOCK(&tp->mutex);

  if(tp) {

    while(1) {
      
      if(tp->high <= tp->low) {
	TURN_MUTEX_UNLOCK(&tp->mutex);
	return -1;
      }
      
      int position=(u16bits)(tp->low & 0x0000FFFF);
      
      port=tp->ports[position];
      if(port<(int)(tp->range_start) || port>((int)(tp->range_stop))) {
	TURN_MUTEX_UNLOCK(&tp->mutex);
	return -1;
      }
      if(is_taken(tp->status[port])) {
	++(tp->low);
	continue;
      } 
      if(tp->status[port]!=tp->low) {
	++(tp->low);
	continue;
      }
      tp->status[port]=TPS_TAKEN_SINGLE;
      ++(tp->low);
      break;
    }
  }

  TURN_MUTEX_UNLOCK(&tp->mutex);

  return port;
}
Ejemplo n.º 14
0
void update_o_to_realm(ur_string_map * o_to_realm_new) {
  TURN_MUTEX_LOCK(&o_to_realm_mutex);
  ur_string_map_free(&o_to_realm);
  o_to_realm = o_to_realm_new;
  TURN_MUTEX_UNLOCK(&o_to_realm_mutex);
}