void NiceConnection::gatheringDone(uint stream_id) { if (this->checkIceState() >= NICE_FINISHED) { ELOG_DEBUG("gathering Done after FINISHED"); nice_agent_remove_stream (agent_,1); return; } ELOG_DEBUG("Gathering Done %p", this); int currentCompId = 1; GSList* lcands = nice_agent_get_local_candidates(agent_, stream_id, currentCompId++); gchar *ufrag = NULL, *upass = NULL; nice_agent_get_local_credentials(agent_, stream_id, &ufrag, &upass); while (lcands != NULL) { for (GSList* iterator = lcands; iterator; iterator = iterator->next) { char address[NICE_ADDRESS_STRING_LEN], baseAddress[NICE_ADDRESS_STRING_LEN]; NiceCandidate *cand = (NiceCandidate*) iterator->data; nice_address_to_string(&cand->addr, address); nice_address_to_string(&cand->base_addr, baseAddress); if (strstr(address, ":") != NULL) { ELOG_DEBUG("Ignoring IPV6 candidate %s %p", address, this); continue; } CandidateInfo cand_info; cand_info.componentId = cand->component_id; cand_info.foundation = cand->foundation; cand_info.priority = cand->priority; cand_info.hostAddress = std::string(address); cand_info.hostPort = nice_address_get_port(&cand->addr); cand_info.mediaType = mediaType; /* * NICE_CANDIDATE_TYPE_HOST, * NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE, * NICE_CANDIDATE_TYPE_PEER_REFLEXIVE, * NICE_CANDIDATE_TYPE_RELAYED, */ switch (cand->type) { case NICE_CANDIDATE_TYPE_HOST: cand_info.hostType = HOST; break; case NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE: cand_info.hostType = SRFLX; cand_info.rAddress = std::string(baseAddress); cand_info.rPort = nice_address_get_port(&cand->base_addr); break; case NICE_CANDIDATE_TYPE_PEER_REFLEXIVE: cand_info.hostType = PRFLX; break; case NICE_CANDIDATE_TYPE_RELAYED: char turnAddres[NICE_ADDRESS_STRING_LEN]; ELOG_DEBUG("TURN LOCAL CANDIDATE"); nice_address_to_string(&cand->turn->server,turnAddres); ELOG_DEBUG("address %s", address); ELOG_DEBUG("baseAddress %s", baseAddress); ELOG_DEBUG("stream_id %u", cand->stream_id); ELOG_DEBUG("priority %u", cand->priority); ELOG_DEBUG("TURN ADDRESS %s", turnAddres); cand_info.hostType = RELAY; cand_info.rAddress = std::string(baseAddress); cand_info.rPort = nice_address_get_port(&cand->base_addr); break; default: break; } cand_info.netProtocol = "udp"; cand_info.transProtocol = std::string(*transportName.get()); cand_info.username = std::string(ufrag); cand_info.password = std::string(upass); localCandidates->push_back(cand_info); } // for nice_agent_get_local_candidates, the caller owns the returned GSList as well as the candidates contained within it. // let's free everything in the list, as well as the list. g_slist_free_full(lcands, (GDestroyNotify)&nice_candidate_free); lcands = nice_agent_get_local_candidates(agent_, stream_id, currentCompId++); } // According to libnice, this is how these must be free'd g_free(ufrag); g_free(upass); ELOG_INFO("candidate_gathering done with %lu candidates %p", localCandidates->size(), this); if (localCandidates->size()==0){ ELOG_WARN("No local candidates found, check your network connection"); exit(0); } updateIceState(NICE_CANDIDATES_GATHERED); }
void NiceConnection::gatheringDone(uint stream_id) { int currentCompId = 1; lcands = nice_agent_get_local_candidates(agent_, stream_id, currentCompId++); NiceCandidate *cand; GSList* iterator; gchar *ufrag = NULL, *upass = NULL; nice_agent_get_local_credentials(agent_, stream_id, &ufrag, &upass); //////False candidate for testing when there is no network (like in the train) :) /* NiceCandidate* thecandidate = nice_candidate_new(NICE_CANDIDATE_TYPE_HOST); NiceAddress* naddr = nice_address_new(); nice_address_set_from_string(naddr, "127.0.0.1"); nice_address_set_port(naddr, 50000); thecandidate->addr = *naddr; char* uname = (char*) malloc(50); char* pass = (char*) malloc(50); sprintf(thecandidate->foundation, "%s", "1"); sprintf(uname, "%s", "Pedro"); sprintf(pass, "%s", "oooo"); thecandidate->username = uname; thecandidate->password = pass; thecandidate->stream_id = (guint) 1; thecandidate->component_id = 1; thecandidate->priority = 1000; thecandidate->transport = NICE_CANDIDATE_TRANSPORT_UDP; lcands = g_slist_append(lcands, thecandidate); */ // ELOG_DEBUG("gathering done %u",stream_id); //ELOG_DEBUG("Candidates---------------------------------------------------->"); while (lcands != NULL) { for (iterator = lcands; iterator; iterator = iterator->next) { char address[40], baseAddress[40]; cand = (NiceCandidate*) iterator->data; nice_address_to_string(&cand->addr, address); nice_address_to_string(&cand->base_addr, baseAddress); if (strstr(address, ":") != NULL) { ELOG_DEBUG("Ignoring IPV6 candidate %s", address); continue; } // ELOG_DEBUG("foundation %s", cand->foundation); // ELOG_DEBUG("compid %u", cand->component_id); // ELOG_DEBUG("stream_id %u", cand->stream_id); // ELOG_DEBUG("priority %u", cand->priority); // ELOG_DEBUG("username %s", cand->username); // ELOG_DEBUG("password %s", cand->password); CandidateInfo cand_info; cand_info.componentId = cand->component_id; cand_info.foundation = cand->foundation; cand_info.priority = cand->priority; cand_info.hostAddress = std::string(address); cand_info.hostPort = nice_address_get_port(&cand->addr); cand_info.mediaType = mediaType; /* * NICE_CANDIDATE_TYPE_HOST, * NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE, * NICE_CANDIDATE_TYPE_PEER_REFLEXIVE, * NICE_CANDIDATE_TYPE_RELAYED, */ switch (cand->type) { case NICE_CANDIDATE_TYPE_HOST: cand_info.hostType = HOST; break; case NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE: cand_info.hostType = SRLFX; cand_info.baseAddress = std::string(baseAddress); cand_info.basePort = nice_address_get_port(&cand->base_addr); break; case NICE_CANDIDATE_TYPE_PEER_REFLEXIVE: cand_info.hostType = PRFLX; break; case NICE_CANDIDATE_TYPE_RELAYED: ELOG_DEBUG("WARNING TURN NOT IMPLEMENTED YET"); cand_info.hostType = RELAY; break; default: break; } cand_info.netProtocol = "udp"; cand_info.transProtocol = std::string(*transportName); cand_info.username = std::string(ufrag); cand_info.password = std::string(upass); /* if (cand->username) cand_info.username = std::string(cand->username); else cand_info.username = std::string("(null)"); if (cand->password) cand_info.password = std::string(cand->password); else cand_info.password = std::string("(null)"); */ localCandidates->push_back(cand_info); } lcands = nice_agent_get_local_candidates(agent_, stream_id, currentCompId++); } ELOG_INFO("candidate_gathering done with %d candidates", localCandidates->size()); if (localCandidates->size()==0) { ELOG_WARN("No local candidates found, check your network connection"); exit(0); } updateIceState(NICE_CANDIDATES_GATHERED); }
void NicerConnection::gatheringDone(uint stream_id) { ELOG_INFO("%s message: gathering done, stream_id: %u", toLog(), stream_id); updateIceState(IceState::CANDIDATES_RECEIVED); }