Exemplo n.º 1
0
bool NiceConnection::setRemoteCandidates(
    std::vector<CandidateInfo> &candidates) {

    ELOG_DEBUG("Setting remote candidates %d", candidates.size());


    for (unsigned int compId = 1; compId <= iceComponents_; compId++) {

        GSList* candList = NULL;

        for (unsigned int it = 0; it < candidates.size(); it++) {
            NiceCandidateType nice_cand_type;
            CandidateInfo cinfo = candidates[it];
            if (cinfo.mediaType != this->mediaType
                    || this->transportName->compare(cinfo.transProtocol)
                    || cinfo.componentId != compId)
                continue;

            switch (cinfo.hostType) {
            case HOST:
                nice_cand_type = NICE_CANDIDATE_TYPE_HOST;
                break;
            case SRLFX:
                nice_cand_type = NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE;
                break;
            case PRFLX:
                nice_cand_type = NICE_CANDIDATE_TYPE_PEER_REFLEXIVE;
                break;
            case RELAY:
                nice_cand_type = NICE_CANDIDATE_TYPE_RELAYED;
                break;
            default:
                nice_cand_type = NICE_CANDIDATE_TYPE_HOST;
                break;
            }

            NiceCandidate* thecandidate = nice_candidate_new(nice_cand_type);
            NiceAddress* naddr = nice_address_new();
            nice_address_set_from_string(naddr, cinfo.hostAddress.c_str());
            nice_address_set_port(naddr, cinfo.hostPort);
            thecandidate->addr = *naddr;
            sprintf(thecandidate->foundation, "%s", cinfo.foundation.c_str());

            thecandidate->username = strdup(cinfo.username.c_str());
            thecandidate->password = strdup(cinfo.password.c_str());
            thecandidate->stream_id = (guint) 1;
            thecandidate->component_id = cinfo.componentId;
            thecandidate->priority = cinfo.priority;
            thecandidate->transport = NICE_CANDIDATE_TRANSPORT_UDP;
            candList = g_slist_append(candList, thecandidate);
            ELOG_DEBUG("New Candidate SET %s %d", cinfo.hostAddress.c_str(), cinfo.hostPort);

        }
        nice_agent_set_remote_candidates(agent_, (guint) 1, compId, candList);
    }

    ELOG_DEBUG("Candidates SET");
    this->updateIceState(NICE_CANDIDATES_RECEIVED);
    return true;
}
Exemplo n.º 2
0
static void
test_ipv4 (void)
{
  NiceAddress addr;
  NiceAddress other;
  gchar str[NICE_ADDRESS_STRING_LEN];

  nice_address_init (&addr);
  nice_address_init (&other);
  nice_address_set_ipv4 (&addr, 0x01020304);
  g_assert (addr.s.ip4.sin_family == AF_INET);

  nice_address_to_string (&addr, str);
  g_assert (0 == strcmp (str, "1.2.3.4"));

  nice_address_to_string (&addr, str);

  /* same address */
  nice_address_set_ipv4 (&other, 0x01020304);
  g_assert (TRUE == nice_address_equal (&addr, &other));

  /* from sockaddr_in */
  nice_address_set_port (&other, 9876); /* in native byte order */
  other.s.ip4.sin_family = AF_INET;
  nice_address_set_from_string (&addr, "1.2.3.4");
  nice_address_set_port (&addr, 9876); /* in native byte order */
  nice_address_to_string (&addr, str);
  nice_address_to_string (&other, str);
  g_assert (TRUE == nice_address_equal (&addr, &other));

  /* different IP */
  nice_address_set_ipv4 (&other, 0x01020305);
  g_assert (FALSE == nice_address_equal (&addr, &other));

  /* different port */
  nice_address_set_ipv4 (&other, 0x01020304);
  nice_address_set_port (&addr, 1);
  g_assert (FALSE == nice_address_equal (&addr, &other));

  /* test private address check */
  {
    NiceAddress *heap_addr = nice_address_new ();
    g_assert (nice_address_set_from_string (heap_addr, "127.0.0.1") == TRUE);
    g_assert (nice_address_is_private (heap_addr) == TRUE);
    g_assert (nice_address_set_from_string (heap_addr, "127.0.0.1.1") != TRUE);
    nice_address_free (heap_addr);
  }
}