示例#1
0
static void
kms_connection_ext_get_connection_attrs (KmsISdpMediaExtension * ext,
    const GstSDPMedia * media, GArray * conns)
{
  guint i, len;

  len = gst_sdp_media_connections_len (media);

  for (i = 0; i < len; i++) {
    const GstSDPConnection *conn;

    conn = gst_sdp_media_get_connection (media, i);

    add_address_to_list (conns, conn);
  }
}
示例#2
0
/*
 * \fn hip_dht_resolve_hi()
 *
 * \param hi	pointer to host identity whose name, LSI, or HIT can be used
 *              for lookups, and the HIT and address may be updated
 * \param retry if TRUE, we'll spawn a new thread an retry multiple times
 *              without blocking
 *
 * \return	returns -1 if there is a problem, 0 otherwise
 *
 * \brief Given a Host Identity, perform a DHT lookup using its HIT and store
 * any resulting address in the hi_node. If the HIT is missing, perform a HIT
 * lookup in the DHT using the name and/or LSI.
 */
int hip_dht_resolve_hi(hi_node *hi, int retry)
{
  int err;
  struct sockaddr_storage ss_addr;
  struct sockaddr *addr = (struct sockaddr*) &ss_addr;
  sockaddr_list *list;
  char hit_str[INET6_ADDRSTRLEN];
#ifndef __WIN32__
  pthread_attr_t attr;
  pthread_t thr;
#endif
  if (hip_dht_select_server(addr) < 0)
    {
      return(0);           /* prevents unneccessary thread creation */

    }
  /* When retry is turned on, a separate thread will be forked that
   * will perform the DHT lookup(s), retry a certain number of times,
   * and exit */
  if (retry == TRUE)
    {
#ifdef __WIN32__
      _beginthread(hip_dht_resolve_hi_thread, 0, (void *)hi);
#else
      pthread_attr_init(&attr);
      pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
      pthread_create(&thr, &attr, hip_dht_resolve_hi_thread, hi);
#endif
      return(0);
      /* We have been recursively called from a thread */
    }
  else if (retry == 2)
    {
      retry = TRUE;           /* used for calls below... */
    }

  /*
   * First locate the HIT using the peer's name if this HIT is missing.
   */
  if (hits_equal(hi->hit, zero_hit))
    {
      if (hi->name_len == 0)
        {
          log_(NORM,
               "HIT and name not present, unable to perform"
               " DHT lookup.\n");
          return(-1);
        }
      log_(NORM,
           "HIT not present for peer %s, performing DHT lookup "
           "using the name '%s'.\n",
           logaddr(SA(&hi->lsi)),
           hi->name);
      if ((err = hip_dht_lookup_hit_by_name(hi->name, &hi->hit,
                                            retry)) < 0)
        {
          /* no HIT from name, so we cannot do address lookup */
          log_(WARN, "Unable to find HIT for %s in the DHT.\n",
               logaddr(SA(&hi->lsi)));
          return(err);
        }
      else
        {
          hit_to_str(hit_str, hi->hit);
          log_(NORM, "Discovered HIT for peer %s using the DHT: "
               "%s\n", hi->name, hit_str);
        }
    }

  /*
   * Look up current IP address using HIT as key
   */
  memset(addr, 0, sizeof(struct sockaddr_storage));
  addr->sa_family = AF_INET;
  if ((err = hip_dht_lookup_address(&hi->hit, addr, retry)) < 0)
    {
      return(err);
    }

  /* add address to list, checking if first item is empty */
  pthread_mutex_lock(&hi->addrs_mutex);
  if ((hi->addrs.status == DELETED) || !VALID_FAM(&hi->addrs.addr))
    {
      memcpy(&hi->addrs.addr, addr, SALEN(addr));
      hi->addrs.if_index = 0;
      hi->addrs.lifetime = 0;
      hi->addrs.status = UNVERIFIED;
      hi->addrs.nonce = 0;
      gettimeofday(&hi->addrs.creation_time, NULL);
    }
  else
    {
      list = &hi->addrs;
      add_address_to_list(&list, addr, 0);
    }
  pthread_mutex_unlock(&hi->addrs_mutex);

  return(0);
}