diff --git a/include/icelib.h b/include/icelib.h index 724868b..4574e98 100644 --- a/include/icelib.h +++ b/include/icelib.h @@ -106,7 +106,17 @@ typedef ICELIB_Result (* ICELIB_connectivityChecksComplete)(void* pUserData, isControlling, bool iceFailed); - +/* */ +/* ----- Callback to signal that a canidate pair has been nominated */ +/* */ +typedef ICELIB_Result (* ICELIB_nominated)(void* pUserData, + uint32_t userValue1, + uint32_t userValue2, + uint32_t componentId, + uint64_t priority, + int32_t proto, + const struct sockaddr* local, + const struct sockaddr* remote); /* */ /* ----- Callback used to generate keepalives */ @@ -153,6 +163,12 @@ typedef struct { ICELIB_INSTANCE_* pInstance; } ICELIB_CALLBACK_COMPLETE; +typedef struct { + ICELIB_nominated pICELIB_nominated; + void* pNominatedUserData; + ICELIB_INSTANCE_* pInstance; +} ICELIB_CALLBACK_NOMINATED; + typedef struct { ICELIB_outgoingBindingRequest pICELIB_sendBindingRequest; void* pBindingRequestUserData; @@ -198,6 +214,7 @@ typedef struct { ICELIB_CALLBACK_RESPONSE callbackResponse; ICELIB_CALLBACK_KEEPALIVE callbackKeepAlive; ICELIB_CALLBACK_COMPLETE callbackComplete; + ICELIB_CALLBACK_NOMINATED callbackNominated; ICELIB_CALLBACK_CANCEL_REQUEST callbackCancelRequest; ICELIB_CALLBACK_PASSWORD_UPDATE callbackPasswordUpdate; ICELIB_CALLBACK_LOG callbackLog; @@ -306,6 +323,10 @@ ICELIB_setCallbackConnecitivityChecksComplete( void* userData); void +ICELIB_setCallbackNominated(ICELIB_INSTANCE* pInstance, + ICELIB_nominated pICELIB_nominated, + void* userData); +void ICELIB_setCallbackOutgoingBindingRequest( ICELIB_INSTANCE* pInstance, ICELIB_outgoingBindingRequest pICELIB_sendBindingRequest, diff --git a/include/icelib_defines.h b/include/icelib_defines.h index 0db6e2a..4a13275 100644 --- a/include/icelib_defines.h +++ b/include/icelib_defines.h @@ -28,17 +28,6 @@ #define ICELIB_REFLEX_TYPEREF 100 #define ICELIB_RELAY_TYPEREF 0 - - -#define ICELIB_COMPLETE_WEIGHT 150 -/*Warning. No equal values are allowed. (Used to ensure that RTP and RTCP has - * the same path)*/ -#define ICELIB_HOST_WEIGHT 50 -#define ICELIB_SRFLX_WEIGHT 25 -#define ICELIB_PRFLX_WEIGHT 20 -#define ICELIB_RELAY_WEIGHT 10 -#define ICELIB_TIME_MULTIPLIER_INCREASE_MS 250 - #define ICELIB_RTP_COMPONENT_ID 1 #define ICELIB_RTCP_COMPONENT_ID 2 diff --git a/include/icelibtypes.h b/include/icelibtypes.h index 28d9d8e..fe67c1c 100644 --- a/include/icelibtypes.h +++ b/include/icelibtypes.h @@ -260,8 +260,6 @@ typedef struct { typedef struct { ICELIB_LIST_VL pairs; uint32_t nextPairId; - uint32_t readyToNominateWeighting; - uint32_t nominatedPathScore; } ICELIB_VALIDLIST; diff --git a/src/icelib.c b/src/icelib.c index fecca31..ec748a6 100644 --- a/src/icelib.c +++ b/src/icelib.c @@ -2366,8 +2366,6 @@ pICELIB_validListFindPairById(ICELIB_VALIDLIST* pValidList, void ICELIB_storeRemoteCandidates(ICELIB_INSTANCE* pInstance) { - - ICELIB_VALIDLIST* pValidList; unsigned int i,j; @@ -2546,7 +2544,6 @@ ICELIB_countNominatedPairsInValidList(ICELIB_VALIDLIST* pValidList) ++count; } } - return count; } @@ -3028,7 +3025,7 @@ ICELIB_processSuccessResponse(ICELIB_INSTANCE* pInstance, bool iceControlling) { bool listFull; - int proto; + int32_t proto; uint16_t componentId; ICELIB_LIST_PAIR candidatePair; ICELIB_LIST_PAIR* pKnownPair = NULL; @@ -3077,7 +3074,22 @@ ICELIB_processSuccessResponse(ICELIB_INSTANCE* pInstance, ICELIB_log(&pInstance->callbacks.callbackLog, ICELIB_logDebug, "Pair Nominated!"); - + if (pInstance->iceConfiguration.aggressiveNomination) + { + ICELIB_nominated Nominated; + Nominated = pInstance->callbacks.callbackNominated.pICELIB_nominated; + if (Nominated != NULL) + { + Nominated(pInstance->callbacks.callbackNominated.pNominatedUserData, + pLocalMediaStream->userValue1, + pLocalMediaStream->userValue2, + pPair->pLocalCandidate->componentid, + pPair->pairPriority, + proto, + (const struct sockaddr*)&pPair->pLocalCandidate->connectionAddr, + (const struct sockaddr*)&pPair->pRemoteCandidate->connectionAddr); + } + } ICELIB_updatingStates(pInstance); return; } @@ -4468,64 +4480,88 @@ ICELIB_incomingBindingRequest(ICELIB_INSTANCE* pInstance, /* updating of state machinery. */ /* */ -bool -ICELIB_isNominatingCriteriaMet(ICELIB_VALIDLIST* pValidList) + +uint64_t +ICELIB_getMaxpairPriority(ICELIB_CHECKLIST* pChecklist, + uint32_t componentId) { - if (pValidList->readyToNominateWeighting >= ICELIB_COMPLETE_WEIGHT) + uint64_t max = 0; + for (uint32_t i = 0; i < pChecklist->numberOfPairs; i++) { - return true; + if ( (pChecklist->checkListPairs[i].pairPriority > max) && + (pChecklist->checkListPairs[i].pLocalCandidate->componentid == + componentId) ) + { + max = pChecklist->checkListPairs[i].pairPriority; + } } - return false; + return max; } bool -ICELIB_isNominatingCriteriaMetForAllMediaStreams(ICELIB_INSTANCE* pInstance) +ICELIB_isNominatingCriteriaMet(ICELIB_VALIDLIST* pValidList, + ICELIB_CHECKLIST* pCheckList) { - unsigned int i; - ICELIB_VALIDLIST* pValidList; - ICELIB_CHECKLIST* pCheckList = NULL; - uint32_t pathScore = 0; + /* This is iffy, must change all of this. Just to get going... */ + bool compOk[ICE_MAX_COMPONENTS]; - for (i = 0; i < pInstance->numberOfMediaStreams; ++i) + memset(&compOk, 0, sizeof compOk); + + for (uint32_t i = 0; i < pCheckList->componentList.numberOfComponents; i++) { - pValidList = &pInstance->streamControllers[ i].validList; + uint32_t id = pCheckList->componentList.componentIds[i]; + uint64_t max_priority = ICELIB_getMaxpairPriority(pCheckList, id); - if ( (pInstance->localIceMedia.mediaStream[i].numberOfCandidates == 0) || - (pInstance->remoteIceMedia.mediaStream[i].numberOfCandidates == 0) ) + for (uint32_t j = 0; j < pValidList->pairs.numberOfElements; j++) { - /* Disabled medialine. Ignore */ - continue; + if ( (pValidList->pairs.elements[j].pairPriority == max_priority) && + (pValidList->pairs.elements[j].pLocalCandidate->componentid == id) ) + { + compOk[i] = true; + } } - if ( !ICELIB_isNominatingCriteriaMet(pValidList) ) + } + + for (uint32_t i = 0; i < pCheckList->componentList.numberOfComponents; i++) + { + if (compOk[i] == false) { return false; } } - /* Do additional check that all paths for all media streams are the same; */ - pValidList = &pInstance->streamControllers[0].validList; - pathScore = pValidList->nominatedPathScore; + return true; +} - for (i = 1; i < pInstance->numberOfMediaStreams; i++) +bool +ICELIB_isNominatingCriteriaMetForAllMediaStreams(ICELIB_INSTANCE* pInstance) +{ + unsigned int i; + ICELIB_VALIDLIST* pValidList; + ICELIB_CHECKLIST* pCheckList; + /* printf("/n ICELIB cheking if ready to nominate (%i)\n", */ + /* pInstance->numberOfMediaStreams); */ + for (i = 0; i < pInstance->numberOfMediaStreams; ++i) { - pValidList = &pInstance->streamControllers[i].validList; - pCheckList = &pInstance->streamControllers[i].checkList; + /* printf(" media line: %i\n", i); */ + pValidList = &pInstance->streamControllers[ i].validList; + pCheckList = &pInstance->streamControllers[ i].checkList; if ( (pInstance->localIceMedia.mediaStream[i].numberOfCandidates == 0) || (pInstance->remoteIceMedia.mediaStream[i].numberOfCandidates == 0) ) { /* Disabled medialine. Ignore */ + /* printf(" -> Disabled (ignoring)\n"); */ continue; } - - if (pathScore != pValidList->nominatedPathScore) + if ( !ICELIB_isNominatingCriteriaMet(pValidList, pCheckList) ) { - ICELIB_updateValidPairReadyToNominateWeightingMediaStream( pCheckList, - pValidList, - ICELIB_getWeightTimeMultiplier( - pInstance) ); + /* printf(" -> Not ready\n"); */ return false; } + /* printf(" -> Ready\n"); */ } + /* ToDo additional check that all paths for all media streams are the same; */ + return true; } @@ -4542,8 +4578,6 @@ ICELIB_stopChecks(ICELIB_INSTANCE* pInstance, "Stopping checks (%i)", pCheckList->numberOfPairs); - - pCheckList->stopChecks = true; CancelReq = @@ -4589,59 +4623,47 @@ ICELIB_stopChecks(ICELIB_INSTANCE* pInstance, ICELIB_LIST_PAIR* -pICELIB_pickValidPairForNominationNormalMode(ICELIB_VALIDLIST* pValidList, - uint32_t componentId) - +pICELIB_pickValidPairForNomination(ICELIB_VALIDLIST* pValidList, + uint32_t componentId) { - unsigned int i; + int32_t bestpair_idx = -1; + uint64_t max_pri = 0; - for (i = 0; i < pValidList->pairs.numberOfElements; i++) + if (pValidList->pairs.numberOfElements == 0) { + return NULL; + } - const ICE_CANDIDATE* pLocalCandidate = - pValidList->pairs.elements[i].pLocalCandidate; - const ICE_CANDIDATE* pRemoteCandidate = - pValidList->pairs.elements[i].pRemoteCandidate; - - uint32_t pathScore = ICELIB_calculateReadyWeight(pLocalCandidate->type, - pRemoteCandidate->type, - 1); - - if (pLocalCandidate->componentid == componentId) + for (uint32_t i = 0; i < pValidList->pairs.numberOfElements; i++) + { + if (componentId == + pValidList->pairs.elements[i].pLocalCandidate->componentid) { - if (pathScore == pValidList->nominatedPathScore) + if (pValidList->pairs.elements[i].pairPriority > max_pri) { - - if (pValidList->pairs.elements[i].nominatedPair) - { - /* Already nominated.. */ - return NULL; - } - else - { - return &pValidList->pairs.elements[i]; - } + max_pri = pValidList->pairs.elements[i].pairPriority; + bestpair_idx = i; } } } - return NULL; -} - + if (bestpair_idx == -1) + { + return NULL; + } + if (pValidList->pairs.elements[bestpair_idx].sentUseCandidateAlready) + { + /* Already nominated.. */ + return NULL; + } + else + { + return &pValidList->pairs.elements[bestpair_idx]; + } -ICELIB_LIST_PAIR* -pICELIB_pickValidPairForNomination(ICELIB_INSTANCE* pInstance, - ICELIB_VALIDLIST* pValidList, - ICELIB_CHECKLIST* pCheckList, - uint32_t componentId) -{ - (void)pInstance; - (void)pCheckList; - return pICELIB_pickValidPairForNominationNormalMode(pValidList, componentId); } - void ICELIB_enqueueValidPair(ICELIB_TRIGGERED_FIFO* pTriggeredChecksFifo, ICELIB_CHECKLIST* pCheckList, @@ -4682,13 +4704,63 @@ ICELIB_enqueueValidPair(ICELIB_TRIGGERED_FIFO* pTriggeredChecksFifo, void ICELIB_nominateAggressive(ICELIB_INSTANCE* pInstance) { + ICELIB_CHECKLIST* pCheckList; + ICELIB_VALIDLIST* pValidList; + ICELIB_TRIGGERED_FIFO* pTriggeredChecksFifo; + ICELIB_LIST_PAIR* pValidPair; + ICELIB_log(&pInstance->callbacks.callbackLog, ICELIB_logInfo, "Aggressive nomination"); -/* */ -/* ----- ICE-19: 8.1.1.2 Aggressive Nomination */ -/* */ -/* TODO: Implement */ + + /* Go through valid list to see if we can nominate anything? */ + for (uint32_t i = 0; i < pInstance->numberOfMediaStreams; ++i) + { + unsigned int numberOfComp = 0; + pCheckList = &pInstance->streamControllers[ i].checkList; + pValidList = &pInstance->streamControllers[ i].validList; + pTriggeredChecksFifo = + &pInstance->streamControllers[ i].triggeredChecksFifo; + numberOfComp = pCheckList->componentList.numberOfComponents; + + + for (uint32_t j = 0; j < numberOfComp; j++) + { + uint32_t componentId = pCheckList->componentList.componentIds[j]; + + pValidPair = pICELIB_pickValidPairForNomination(pValidList, + componentId); + + + if (pValidPair != NULL) + { + + pValidPair->sentUseCandidateAlready = true; + ICELIB_log(&pInstance->callbacks.callbackLog, ICELIB_logDebug, + "Enqueueing valid pair (Aggressive)"); + + ICELIB_pairDumpLog(&pInstance->callbacks.callbackLog, + ICELIB_logDebug, + pValidPair); + + ICELIB_enqueueValidPair(pTriggeredChecksFifo, + pCheckList, + &pInstance->callbacks.callbackLog, + pValidPair); + } + else + { + ICELIB_log1(&pInstance->callbacks.callbackLog, + ICELIB_logWarning, + "Could not pick valid pair for nomination (CompId: %i)", + componentId); + + ICELIB_log(&pInstance->callbacks.callbackLog, ICELIB_logError, + "Could not pick a valid pair!"); + } + } + } + } @@ -4703,13 +4775,13 @@ ICELIB_nominateRegularIfComplete(ICELIB_INSTANCE* pInstance) if ( ICELIB_isNominatingCriteriaMetForAllMediaStreams(pInstance) ) { - unsigned int i; + /* printf("Nominating criteria met for all\n"); */ ICELIB_log1(&pInstance->callbacks.callbackLog, ICELIB_logDebug, "All media streams are ready to be nominated (%i)", pInstance->numberOfMediaStreams); - for (i = 0; i < pInstance->numberOfMediaStreams; ++i) + for (uint32_t i = 0; i < pInstance->numberOfMediaStreams; ++i) { unsigned int numberOfComp = 0; pCheckList = &pInstance->streamControllers[ i].checkList; @@ -4724,20 +4796,22 @@ ICELIB_nominateRegularIfComplete(ICELIB_INSTANCE* pInstance) } else { - uint32_t j; ICELIB_stopChecks(pInstance, pCheckList, pTriggeredChecksFifo); - for (j = 0; j < numberOfComp; j++) + for (uint32_t j = 0; j < numberOfComp; j++) { uint32_t componentId = pCheckList->componentList.componentIds[j]; - pValidPair = pICELIB_pickValidPairForNomination(pInstance, - pValidList, - pCheckList, + pValidPair = pICELIB_pickValidPairForNomination(pValidList, componentId); + if (pValidPair != NULL) { ICELIB_log(&pInstance->callbacks.callbackLog, ICELIB_logDebug, - "Enqueueing valid pair..."); + "Enqueueing valid pair"); + + ICELIB_pairDumpLog(&pInstance->callbacks.callbackLog, + ICELIB_logDebug, + pValidPair); ICELIB_enqueueValidPair(pTriggeredChecksFifo, pCheckList, @@ -4859,7 +4933,8 @@ ICELIB_removeWaitingAndFrozen(ICELIB_CHECKLIST* pCheckList, ICELIB_validListIteratorConstructor(&vlIterator, pValidList); - while ( ( pValidPair = pICELIB_validListIteratorNext(&vlIterator) ) != NULL ) + while ( ( pValidPair = pICELIB_validListIteratorNext(&vlIterator) ) != + NULL ) { if (pValidPair->nominatedPair) { @@ -4901,7 +4976,8 @@ ICELIB_ceaseRetransmissions(ICELIB_CHECKLIST* pCheckList, /* ----- ICE-19: 8.1.2 Update State for a single check list */ /* */ void -ICELIB_updateCheckListStateConcluding(ICELIB_CHECKLIST* pCheckList, +ICELIB_updateCheckListStateConcluding(ICELIB_INSTANCE* pInstance, + ICELIB_CHECKLIST* pCheckList, ICELIB_VALIDLIST* pValidList, ICELIB_TRIGGERED_FIFO* pTriggeredChecksFifo, ICELIB_CALLBACK_LOG* pCallbackLog) @@ -4918,11 +4994,34 @@ ICELIB_updateCheckListStateConcluding(ICELIB_CHECKLIST* pCheckList, } else { - ICELIB_removeWaitingAndFrozen(pCheckList, - pValidList, - pTriggeredChecksFifo, - pCallbackLog); - ICELIB_ceaseRetransmissions(pCheckList, pValidList, pTriggeredChecksFifo); + if (pInstance->iceConfiguration.aggressiveNomination) + { + /* Did we nominate the pair with highest pri in the checlist? */ + /* Valid list is sorted. So we just compare the first entry. */ + uint64_t maxpri; + maxpri = ICELIB_getMaxpairPriority(pCheckList, 1); + + if (pValidList->pairs.elements[0].pairPriority != maxpri) + { + return; + } + else + { + if (!pValidList->pairs.elements[0].nominatedPair) + { + return; + } + } + } + else + { + ICELIB_removeWaitingAndFrozen(pCheckList, + pValidList, + pTriggeredChecksFifo, + pCallbackLog); + ICELIB_ceaseRetransmissions(pCheckList, pValidList, + pTriggeredChecksFifo); + } } /* Once there is at least one nominated pair in the valid list for */ /* every component of at least one media stream and the state of the */ @@ -4940,7 +5039,6 @@ ICELIB_updateCheckListStateConcluding(ICELIB_CHECKLIST* pCheckList, if ( pValidList->pairs.elements[j].nominatedPair && (pLocalCandidate->componentid == componentId) ) { - foundComp++; if (foundComp == numberOfComp) { @@ -4955,16 +5053,6 @@ ICELIB_updateCheckListStateConcluding(ICELIB_CHECKLIST* pCheckList, } } -uint32_t -ICELIB_getWeightTimeMultiplier(ICELIB_INSTANCE* pInstance) -{ - uint32_t timeMS; - - timeMS = pInstance->tickCount * pInstance->iceConfiguration.tickIntervalMS; - /* Don't want to return a multiplier less than 1 */ - return (timeMS / ICELIB_TIME_MULTIPLIER_INCREASE_MS) + 1; -} - /* */ /* ----- ICE-19: 8.1.2 Updating States */ @@ -4989,12 +5077,21 @@ ICELIB_updatingStates(ICELIB_INSTANCE* pInstance) for (i = 0; i < pInstance->numberOfMediaStreams; ++i) { + if ( (pInstance->localIceMedia.mediaStream[i].numberOfCandidates == 0) || + (pInstance->remoteIceMedia.mediaStream[i].numberOfCandidates == 0) ) + { + /* Disabled medialine. Ignore */ + continue; + } + + pCheckList = &pInstance->streamControllers[ i].checkList; pValidList = &pInstance->streamControllers[ i].validList; pTriggeredChecksFifo = &pInstance->streamControllers[ i].triggeredChecksFifo; - ICELIB_updateCheckListStateConcluding(pCheckList, + ICELIB_updateCheckListStateConcluding(pInstance, + pCheckList, pValidList, pTriggeredChecksFifo, pCallbackLog); @@ -5034,22 +5131,49 @@ ICELIB_updatingStates(ICELIB_INSTANCE* pInstance) uint32_t timeMS = pInstance->tickCount * pInstance->iceConfiguration.tickIntervalMS; - if (timeMS > ICELIB_FAIL_AFTER_MS /*5 sec*/) + if (timeMS > ICELIB_FAIL_AFTER_MS) { ICELIB_connectivityChecksComplete ConnectivityCheckComplete; ConnectivityCheckComplete = - pInstance->callbacks.callbackComplete.pICELIB_connectivityChecksComplete; - pInstance->iceState = ICELIB_FAILED; - ICELIB_log(&pInstance->callbacks.callbackLog, ICELIB_logInfo, - "ICE failed (Timeout)"); - if (ConnectivityCheckComplete != NULL) + pInstance->callbacks.callbackComplete. + pICELIB_connectivityChecksComplete; + + /* If aggressive and nominated pair exist, this is actually a sucsess */ + /* Maybee check for partial failures..?? */ + if ( pInstance->iceConfiguration.aggressiveNomination && + (ICELIB_countNominatedPairsInValidList(pValidList) > 0) ) + { + pInstance->iceState = ICELIB_COMPLETED; + ICELIB_storeRemoteCandidates(pInstance); + ICELIB_log(&pInstance->callbacks.callbackLog, ICELIB_logInfo, + "ICE sucsess agressive (Timeout)"); + if (ConnectivityCheckComplete != NULL) + { + ConnectivityCheckComplete( + pInstance->callbacks.callbackComplete.pConnectivityChecksCompleteUserData, + pInstance->localIceMedia.mediaStream[0].userValue1, + pInstance->iceControlling, + false); + } + + } + else { - ConnectivityCheckComplete( - pInstance->callbacks.callbackComplete.pConnectivityChecksCompleteUserData, - pInstance->localIceMedia.mediaStream[0].userValue1, - pInstance->iceControlling, - true); + + pInstance->iceState = ICELIB_FAILED; + ICELIB_log(&pInstance->callbacks.callbackLog, ICELIB_logInfo, + "ICE failed (Timeout)"); + if (ConnectivityCheckComplete != NULL) + { + ConnectivityCheckComplete( + pInstance->callbacks.callbackComplete.pConnectivityChecksCompleteUserData, + pInstance->localIceMedia.mediaStream[0].userValue1, + pInstance->iceControlling, + true); + } } + + } } } @@ -5065,7 +5189,10 @@ ICE_concludeFullIfComplete(ICELIB_INSTANCE* pInstance) /* */ if (pInstance->iceConfiguration.aggressiveNomination) { - ICELIB_nominateAggressive(pInstance); + if (pInstance->iceControlling) + { + ICELIB_nominateAggressive(pInstance); + } } else { @@ -5123,144 +5250,6 @@ ICELIB_resetAllStreamControllers(ICELIB_INSTANCE* pInstance) } } -uint32_t -ICELIB_getCandidateTypeWeight(ICE_CANDIDATE_TYPE type) -{ - switch (type) - { - case ICE_CAND_TYPE_NONE: - return 0; - case ICE_CAND_TYPE_HOST: - return ICELIB_HOST_WEIGHT; - case ICE_CAND_TYPE_SRFLX: - return ICELIB_SRFLX_WEIGHT; - case ICE_CAND_TYPE_RELAY: - return ICELIB_RELAY_WEIGHT; - case ICE_CAND_TYPE_PRFLX: - return ICELIB_PRFLX_WEIGHT; - } - return 0; -} - -uint32_t -ICELIB_calculateReadyWeight(ICE_CANDIDATE_TYPE localType, - ICE_CANDIDATE_TYPE remoteType, - uint32_t timeMultiplier) -{ - uint32_t weight = 0; - - weight += ICELIB_getCandidateTypeWeight(localType); - weight += ( 2 * ICELIB_getCandidateTypeWeight(remoteType) ); - - weight *= timeMultiplier; - return weight; -} - -static uint32_t -ICELIB_getBestWeight(ICELIB_VALIDLIST* pValidList, - uint32_t componentId, - uint32_t timeMultiplier) -{ - uint32_t i; - uint32_t weight = 0; - - for (i = 0; i < pValidList->pairs.numberOfElements; i++) - { - - if (componentId == - pValidList->pairs.elements[i].pLocalCandidate->componentid) - { - uint32_t tmpWeight = ICELIB_calculateReadyWeight( - pValidList->pairs.elements[i].pLocalCandidate->type, - pValidList->pairs.elements[ - i].pRemoteCandidate->type, - timeMultiplier); - if (tmpWeight > weight) - { - weight = tmpWeight; - } - } - } - - return weight; -} - -static uint32_t -ICELIB_getBestScore(ICELIB_VALIDLIST* pValidList, - uint32_t componentId) -{ - return ICELIB_getBestWeight(pValidList, componentId, 1); -} - - -void -ICELIB_updateValidPairReadyToNominateWeightingMediaStream( - ICELIB_CHECKLIST* pCheckList, - ICELIB_VALIDLIST* pValidList, - uint32_t timeMultiplier) -{ - uint32_t weight = 0; - uint32_t numberOfComp = pCheckList->componentList.numberOfComponents; - uint32_t i; - - for (i = 0; i < numberOfComp; i++) - { - /* Get the one with highest path score in the list. */ - if (weight == 0) - { - weight = ICELIB_getBestWeight(pValidList, - pCheckList->componentList.componentIds[i], - timeMultiplier); - /* Special case with one component only */ - if (numberOfComp == 1) - { - pValidList->readyToNominateWeighting = weight; - pValidList->nominatedPathScore = ICELIB_getBestScore(pValidList, - pCheckList->componentList.componentIds[ - i]); - return; - } - - } - else - { - uint32_t tmpWeight = ICELIB_getBestWeight(pValidList, - pCheckList->componentList.componentIds[ - i], - timeMultiplier); - if (tmpWeight == weight) - { - /* We have same for all components */ - pValidList->readyToNominateWeighting = weight; - pValidList->nominatedPathScore = ICELIB_getBestScore(pValidList, - pCheckList->componentList.componentIds[ - i]); - - } - else - { - pValidList->readyToNominateWeighting = 0; - - } - } - } -} - -void -ICELIB_updateValidPairReadyToNominateWeighting(ICELIB_INSTANCE* pInstance) -{ - unsigned int i; - for (i = 0; i < pInstance->numberOfMediaStreams; i++) - { - ICELIB_updateValidPairReadyToNominateWeightingMediaStream( - &pInstance->streamControllers[i].checkList, - &pInstance->streamControllers[ - i].validList, - ICELIB_getWeightTimeMultiplier( - pInstance) ); - } - -} /* ----------------------------------------------------------------------------- * */ @@ -5480,10 +5469,11 @@ ICELIB_doKeepAlive(ICELIB_INSTANCE* pInstance) { ICELIB_log(&pInstance->callbacks.callbackLog, ICELIB_logDebug, "Sending KeepAlive"); - SendKeepAlive(pInstance->callbacks.callbackKeepAlive.pUserDataKeepAlive, - pInstance->localIceMedia.mediaStream[mediaIdx].userValue1, - pInstance->localIceMedia.mediaStream[mediaIdx].userValue2, - mediaIdx); + SendKeepAlive( + pInstance->callbacks.callbackKeepAlive.pUserDataKeepAlive, + pInstance->localIceMedia.mediaStream[mediaIdx].userValue1, + pInstance->localIceMedia.mediaStream[mediaIdx].userValue2, + mediaIdx); } } @@ -5508,7 +5498,8 @@ ICELIB_ReStart(ICELIB_INSTANCE* pInstance) pInstance->keepAliveTickCount = 0; pInstance->tieBreaker = ICELIB_makeTieBreaker(); ICELIB_resetAllStreamControllers(pInstance); - memset( &pInstance->remoteIceMedia, 0, sizeof (pInstance->remoteIceMedia) ); + memset( &pInstance->remoteIceMedia, 0, + sizeof (pInstance->remoteIceMedia) ); pInstance->iceState = ICELIB_IDLE; } } @@ -5523,7 +5514,6 @@ ICELIB_Tick(ICELIB_INSTANCE* pInstance) ICELIB_tickStreamController(pInstance); if (pInstance->iceState == ICELIB_RUNNING) { - ICELIB_updateValidPairReadyToNominateWeighting(pInstance); ICELIB_concludeICEProcessingIfComplete(pInstance); ICELIB_updatingStates(pInstance); } @@ -5592,6 +5582,18 @@ ICELIB_setCallbackConnecitivityChecksComplete( pInstance->callbacks.callbackComplete.pInstance = pInstance; } +void +ICELIB_setCallbackNominated(ICELIB_INSTANCE* pInstance, + ICELIB_nominated pICELIB_nominated, + void* userData) +{ + pInstance->callbacks.callbackNominated.pICELIB_nominated = + pICELIB_nominated; + pInstance->callbacks.callbackNominated.pNominatedUserData = + userData; + pInstance->callbacks.callbackNominated.pInstance = pInstance; +} + void ICELIB_setCallbackKeepAlive(ICELIB_INSTANCE* pInstance, ICELIB_sendKeepAlive pICELIB_sendKeepAlive, @@ -5660,8 +5662,8 @@ ICELIB_getActiveRemoteCandidates(const ICELIB_INSTANCE* pInstance, if ( pInstance && - (pInstance->streamControllers[mediaLineId].checkList.checkListState == - ICELIB_CHECKLIST_COMPLETED) ) + (pInstance->streamControllers[mediaLineId].checkList.checkListState != + ICELIB_CHECKLIST_FAILED) ) { return &pInstance->streamControllers[mediaLineId].remoteCandidates; } @@ -5793,7 +5795,8 @@ ICELIB_getActiveCandidate(const ICELIB_INSTANCE* pInstance, } } } - /* We should look up the default candididate for the media stream and use that + /* We should look up the default candididate for the media stream and use + * that * */ if ( pInstance && (pInstance->localIceMedia.numberOfICEMediaLines > (uint) mediaLineId) ) @@ -6006,6 +6009,10 @@ ICELIB_pairDumpLog(const ICELIB_CALLBACK_LOG* pCallbackLog, logLevel, "Use-Cand=%d, ", pPair->useCandidate); + ICELIB_logVaString(pCallbackLog, + logLevel, + "sentUseCandidateAlready=%d, ", + pPair->sentUseCandidateAlready); ICELIB_logVaString(pCallbackLog, logLevel, "Triggered-Use-Cand=%d, ", @@ -6065,13 +6072,16 @@ ICELIB_checkListDumpLog(const ICELIB_CALLBACK_LOG* pCallbackLog, ICE_MAX_UFRAG_PAIR_LENGTH, pCheckList, true) ); - ICELIB_logVaString( pCallbackLog, logLevel,"Check list Local passwd: '%s'\n", + ICELIB_logVaString( pCallbackLog, logLevel, + "Check list Local passwd: '%s'\n", ICELIB_getCheckListLocalPasswd(pCheckList) ); - ICELIB_logVaString( pCallbackLog, logLevel,"Check list Remote passwd: '%s'\n", + ICELIB_logVaString( pCallbackLog, logLevel, + "Check list Remote passwd: '%s'\n", ICELIB_getCheckListRemotePasswd(pCheckList) ); ICELIB_logVaString( pCallbackLog, logLevel,"Check list state : '%s'\n", - ICELIB_toString_CheckListState(pCheckList->checkListState) ); + ICELIB_toString_CheckListState(pCheckList-> + checkListState) ); ICELIB_logVaString(pCallbackLog, logLevel, "List of component IDs: "); ICELIB_componentIdsDumpLog(pCallbackLog, logLevel, @@ -6088,7 +6098,8 @@ ICELIB_checkListDumpLog(const ICELIB_CALLBACK_LOG* pCallbackLog, logLevel, "Pair[ %u] ====================================================\n", i); - ICELIB_pairDumpLog(pCallbackLog, logLevel, &pCheckList->checkListPairs[ i]); + ICELIB_pairDumpLog(pCallbackLog, logLevel, + &pCheckList->checkListPairs[ i]); } } @@ -6132,7 +6143,8 @@ ICELIB_validListDumpLog(const ICELIB_CALLBACK_LOG* pCallbackLog, ICELIB_validListIteratorConstructor(&vlIterator, pValidList); - while ( ( pValidPair = pICELIB_validListIteratorNext(&vlIterator) ) != NULL ) + while ( ( pValidPair = pICELIB_validListIteratorNext(&vlIterator) ) != + NULL ) { ICELIB_logVaString(pCallbackLog, logLevel, @@ -6349,7 +6361,8 @@ ICELIB_getLocalCandidateType(const ICELIB_INSTANCE* pInstance, return ICE_CAND_TYPE_NONE; } - return pInstance->localIceMedia.mediaStream[mediaIdx].candidate[candIdx].type; + return pInstance->localIceMedia.mediaStream[mediaIdx].candidate[candIdx]. + type; } @@ -6370,7 +6383,8 @@ ICELIB_getRemoteCandidateType(const ICELIB_INSTANCE* pInstance, return ICE_CAND_TYPE_NONE; } - return pInstance->remoteIceMedia.mediaStream[mediaIdx].candidate[candIdx].type; + return pInstance->remoteIceMedia.mediaStream[mediaIdx].candidate[candIdx]. + type; } @@ -6798,13 +6812,15 @@ ICELIB_getLocalRelayAddr(const ICELIB_INSTANCE* pInstance, if (mediaIdx <= pInstance->localIceMedia.numberOfICEMediaLines) { for (i = 0; - i < pInstance->localIceMedia.mediaStream[mediaIdx].numberOfCandidates; + i < + pInstance->localIceMedia.mediaStream[mediaIdx].numberOfCandidates; i++) { if (pInstance->localIceMedia.mediaStream[mediaIdx].candidate[i].type == ICE_CAND_TYPE_RELAY) { - return (struct sockaddr*)&pInstance->localIceMedia.mediaStream[mediaIdx] + return (struct sockaddr*)&pInstance->localIceMedia.mediaStream[ + mediaIdx] .candidate[i].connectionAddr; } } @@ -6822,10 +6838,12 @@ ICELIB_getLocalRelayCandidate(const ICELIB_INSTANCE* pInstance, if (mediaIdx <= pInstance->localIceMedia.numberOfICEMediaLines) { for (i = 0; - i < pInstance->localIceMedia.mediaStream[mediaIdx].numberOfCandidates; + i < + pInstance->localIceMedia.mediaStream[mediaIdx].numberOfCandidates; i++) { - if ( (pInstance->localIceMedia.mediaStream[mediaIdx].candidate[i].type == + if ( (pInstance->localIceMedia.mediaStream[mediaIdx].candidate[i].type + == ICE_CAND_TYPE_RELAY) && (pInstance->localIceMedia.mediaStream[mediaIdx].candidate[i]. componentid == componentId) ) @@ -6857,7 +6875,8 @@ struct sockaddr const* ICELIB_getLocalRelayAddrFromHostAddr(const ICELIB_INSTANCE* pInstance, const struct sockaddr* hostAddr) { - /* TODO: Rewrite Not using MAX values (Use actual number of stred instead) */ + /* TODO: Rewrite Not using MAX values (Use actual number of stred instead) + * */ int i,j,k = 0; for (i = 0; i < ICE_MAX_MEDIALINES; i++) @@ -6876,7 +6895,8 @@ ICELIB_getLocalRelayAddrFromHostAddr(const ICELIB_INSTANCE* pInstance, { if ( (pInstance->localIceMedia.mediaStream[i].candidate[k].type == ICE_CAND_TYPE_RELAY) && - (pInstance->localIceMedia.mediaStream[i].candidate[k].componentid + (pInstance->localIceMedia.mediaStream[i].candidate[k]. + componentid == compId) ) { diff --git a/src/icelib_intern.h b/src/icelib_intern.h index 68c857c..8b06f68 100644 --- a/src/icelib_intern.h +++ b/src/icelib_intern.h @@ -475,7 +475,9 @@ ICELIB_processIncommingFull(ICELIB_INSTANCE* pInstance, uint16_t componentId); bool -ICELIB_isNominatingCriteriaMet(ICELIB_VALIDLIST* pValidList); +ICELIB_isNominatingCriteriaMet(ICELIB_VALIDLIST* pValidList, + ICELIB_CHECKLIST* pChecklist); + bool ICELIB_isNominatingCriteriaMetForAllMediaStreams(ICELIB_INSTANCE* pInstance); @@ -489,11 +491,10 @@ pICELIB_pickValidPairForNominationNormalMode(ICELIB_VALIDLIST* pValidList, uint32_t componentId); ICELIB_LIST_PAIR* -pICELIB_pickValidPairForNomination(ICELIB_INSTANCE* pInstance, - ICELIB_VALIDLIST* pValidList, - ICELIB_CHECKLIST* pCheckList, +pICELIB_pickValidPairForNomination(ICELIB_VALIDLIST* pValidList, uint32_t componentId); + void ICELIB_enqueueValidPair(ICELIB_TRIGGERED_FIFO* pTriggeredChecksFifo, ICELIB_CHECKLIST* pCheckList, @@ -535,7 +536,8 @@ ICELIB_ceaseRetransmissions(ICELIB_CHECKLIST* pCheckList, ICELIB_TRIGGERED_FIFO* pTriggeredChecksFifo); void -ICELIB_updateCheckListStateConcluding(ICELIB_CHECKLIST* pCheckList, +ICELIB_updateCheckListStateConcluding(ICELIB_INSTANCE* pInstance, + ICELIB_CHECKLIST* pCheckList, ICELIB_VALIDLIST* pValidList, ICELIB_TRIGGERED_FIFO* pTriggeredChecksFifo, ICELIB_CALLBACK_LOG* pCallbackLog); @@ -555,14 +557,6 @@ ICELIB_resetAllStreamControllers(ICELIB_INSTANCE* pInstance); uint32_t ICELIB_getWeightTimeMultiplier(ICELIB_INSTANCE* pInstance); -void -ICELIB_updateValidPairReadyToNominateWeightingMediaStream( - ICELIB_CHECKLIST* pCheckList, - ICELIB_VALIDLIST* pValidList, - uint32_t timeMultiplier); - -void -ICELIB_updateValidPairReadyToNominateWeighting(ICELIB_INSTANCE* pInstance); void ICELIB_PasswordUpdate(ICELIB_INSTANCE* pInstance); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ae07042..fe6c1de 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -14,5 +14,6 @@ sa_test ( icelib ) sa_test ( icelibtypes ) sa_test ( icelib_running ) sa_test ( icelib_ce ) +sa_test ( icelib_nomination ) include ( CTest ) diff --git a/test/ctest.h b/test/ctest.h index 75fda66..2a585c7 100644 --- a/test/ctest.h +++ b/test/ctest.h @@ -17,83 +17,88 @@ #define CTEST_H #ifndef UNUSED_PARAM - /** - * \def UNUSED_PARAM(p); - * - * A macro for quelling compiler warnings about unused variables. - */ -# define UNUSED_PARAM(p) ((void)&(p)) +/** + * \def UNUSED_PARAM(p); + * + * A macro for quelling compiler warnings about unused variables. + */ +# define UNUSED_PARAM(p) ( (void)&(p) ) #endif /* UNUSED_PARM */ -typedef void (*SetupFunc)(void*); -typedef void (*TearDownFunc)(void*); +typedef void (* SetupFunc)(void*); +typedef void (* TearDownFunc)(void*); struct ctest { - const char* ssname; // suite name - const char* ttname; // test name - void (*run)(); - int skip; + const char* ssname; /* suite name */ + const char* ttname; /* test name */ + void (* run)(); + int skip; - void* data; - SetupFunc setup; - TearDownFunc teardown; + void* data; + SetupFunc setup; + TearDownFunc teardown; - unsigned int magic; + unsigned int magic; }; -#define __FNAME(sname, tname) __ctest_##sname##_##tname##_run -#define __TNAME(sname, tname) __ctest_##sname##_##tname +#define __FNAME(sname, tname) __ctest_ ## sname ## _ ## tname ## _run +#define __TNAME(sname, tname) __ctest_ ## sname ## _ ## tname #define __CTEST_MAGIC (0xdeadbeef) #ifdef __APPLE__ -#define __Test_Section __attribute__ ((unused,section ("__DATA, .ctest"))) +#define __Test_Section __attribute__ ( ( unused,section("__DATA, .ctest") ) ) #else -#define __Test_Section __attribute__ ((unused,section (".ctest"))) +#define __Test_Section __attribute__ ( ( unused,section(".ctest") ) ) #endif #define __CTEST_STRUCT(sname, tname, _skip, __data, __setup, __teardown) \ - struct ctest __TNAME(sname, tname) __Test_Section = { \ - .ssname=#sname, \ - .ttname=#tname, \ - .run = __FNAME(sname, tname), \ - .skip = _skip, \ - .data = __data, \ - .setup = (SetupFunc)__setup, \ - .teardown = (TearDownFunc)__teardown, \ - .magic = __CTEST_MAGIC }; - -#define CTEST_DATA(sname) struct sname##_data + struct ctest __TNAME(sname, tname) __Test_Section = { \ + .ssname =#sname, \ + .ttname =#tname, \ + .run = __FNAME(sname, tname), \ + .skip = _skip, \ + .data = __data, \ + .setup = (SetupFunc)__setup, \ + .teardown = (TearDownFunc)__teardown, \ + .magic = __CTEST_MAGIC }; + +#define CTEST_DATA(sname) struct sname ## _data #define CTEST_SETUP(sname) \ - void __attribute__ ((weak)) sname##_setup(struct sname##_data* data) + void __attribute__ ( (weak) ) sname ## _setup(struct sname ## _data* data) #define CTEST_TEARDOWN(sname) \ - void __attribute__ ((weak)) sname##_teardown(struct sname##_data* data) + void __attribute__ ( (weak) ) sname ## _teardown(struct sname ## _data* data) #define __CTEST_INTERNAL(sname, tname, _skip) \ - void __FNAME(sname, tname)(); \ - __CTEST_STRUCT(sname, tname, _skip, NULL, NULL, NULL) \ - void __FNAME(sname, tname)() + void __FNAME(sname, tname)(); \ + __CTEST_STRUCT(sname, tname, _skip, NULL, NULL, NULL) \ + void __FNAME(sname, tname)() #ifdef __APPLE__ #define SETUP_FNAME(sname) NULL #define TEARDOWN_FNAME(sname) NULL #else -#define SETUP_FNAME(sname) sname##_setup -#define TEARDOWN_FNAME(sname) sname##_teardown +#define SETUP_FNAME(sname) sname ## _setup +#define TEARDOWN_FNAME(sname) sname ## _teardown #endif #define __CTEST2_INTERNAL(sname, tname, _skip) \ - static struct sname##_data __ctest_##sname##_data; \ - CTEST_SETUP(sname); \ - CTEST_TEARDOWN(sname); \ - void __FNAME(sname, tname)(struct sname##_data* data); \ - __CTEST_STRUCT(sname, tname, _skip, &__ctest_##sname##_data, SETUP_FNAME(sname), TEARDOWN_FNAME(sname)) \ - void __FNAME(sname, tname)(struct sname##_data* data) - - -void CTEST_LOG(char *fmt, ...); -void CTEST_ERR(char *fmt, ...); // doesn't return + static struct sname ## _data __ctest_ ## sname ## _data; \ + CTEST_SETUP(sname); \ + CTEST_TEARDOWN(sname); \ + void __FNAME(sname, tname)(struct sname ## _data* data); \ + __CTEST_STRUCT( sname, tname, _skip, &__ctest_ ## sname ## _data, \ + SETUP_FNAME(sname), TEARDOWN_FNAME(sname) ) \ + void __FNAME(sname, tname)(struct sname ## _data* data) + + +void +CTEST_LOG(char* fmt, + ...); +void +CTEST_ERR(char* fmt, + ...); /* doesn't return */ #define CTEST(sname, tname) __CTEST_INTERNAL(sname, tname, 0) #define CTEST_SKIP(sname, tname) __CTEST_INTERNAL(sname, tname, 1) @@ -102,34 +107,67 @@ void CTEST_ERR(char *fmt, ...); // doesn't return #define CTEST2_SKIP(sname, tname) __CTEST2_INTERNAL(sname, tname, 1) -void assert_str(const char* exp, const char* real, const char* caller, int line); +void +assert_str(const char* exp, + const char* real, + const char* caller, + int line); #define ASSERT_STR(exp, real) assert_str(exp, real, __FILE__, __LINE__) -void assert_data(const unsigned char* exp, int expsize, - const unsigned char* real, int realsize, - const char* caller, int line); +void +assert_data(const unsigned char* exp, + int expsize, + const unsigned char* real, + int realsize, + const char* caller, + int line); #define ASSERT_DATA(exp, expsize, real, realsize) \ - assert_data(exp, expsize, real, realsize, __FILE__, __LINE__) + assert_data(exp, expsize, real, realsize, __FILE__, __LINE__) -void assert_equal(long exp, long real, const char* caller, int line); +void +assert_equal(long exp, + long real, + const char* caller, + int line); #define ASSERT_EQUAL(exp, real) assert_equal(exp, real, __FILE__, __LINE__) -void assert_not_equal(long exp, long real, const char* caller, int line); -#define ASSERT_NOT_EQUAL(exp, real) assert_not_equal(exp, real, __FILE__, __LINE__) - -void assert_null(void* real, const char* caller, int line); -#define ASSERT_NULL(real) assert_null((void*)real, __FILE__, __LINE__) - -void assert_not_null(const void* real, const char* caller, int line); +void +assert_not_equal(long exp, + long real, + const char* caller, + int line); +#define ASSERT_NOT_EQUAL(exp, real) assert_not_equal(exp, \ + real, \ + __FILE__, \ + __LINE__) + +void +assert_null(void* real, + const char* caller, + int line); +#define ASSERT_NULL(real) assert_null( (void*)real, __FILE__, __LINE__ ) + +void +assert_not_null(const void* real, + const char* caller, + int line); #define ASSERT_NOT_NULL(real) assert_not_null(real, __FILE__, __LINE__) -void assert_true(int real, const char* caller, int line); +void +assert_true(int real, + const char* caller, + int line); #define ASSERT_TRUE(real) assert_true(real, __FILE__, __LINE__) -void assert_false(int real, const char* caller, int line); +void +assert_false(int real, + const char* caller, + int line); #define ASSERT_FALSE(real) assert_false(real, __FILE__, __LINE__) -void assert_fail(const char* caller, int line); +void +assert_fail(const char* caller, + int line); #define ASSERT_FAIL() assert_fail(__FILE__, __LINE__) #ifdef CTEST_MAIN @@ -148,17 +186,17 @@ void assert_fail(const char* caller, int line); #include #endif -//#define COLOR_OK +/* #define COLOR_OK */ static size_t ctest_errorsize; -static char* ctest_errormsg; +static char* ctest_errormsg; #define MSG_SIZE 4096 -static char ctest_errorbuffer[MSG_SIZE]; -static jmp_buf ctest_err; -static int color_output = 1; +static char ctest_errorbuffer[MSG_SIZE]; +static jmp_buf ctest_err; +static int color_output = 1; static const char* suite_name; -typedef int (*filter_func)(struct ctest*); +typedef int (* filter_func)(struct ctest*); #define ANSI_BLACK "\033[0;30m" #define ANSI_RED "\033[0;31m" @@ -178,280 +216,412 @@ typedef int (*filter_func)(struct ctest*); #define ANSI_WHITE "\033[01;37m" #define ANSI_NORMAL "\033[0m" -static CTEST(suite, test) { } +static CTEST(suite, test) { +} -static void msg_start(const char* color, const char* title) { - int size; - if (color_output) { - size = snprintf(ctest_errormsg, ctest_errorsize, "%s", color); - ctest_errorsize -= size; - ctest_errormsg += size; - } - size = snprintf(ctest_errormsg, ctest_errorsize, " %s: ", title); +static void +msg_start(const char* color, + const char* title) +{ + int size; + if (color_output) + { + size = snprintf(ctest_errormsg, ctest_errorsize, "%s", color); ctest_errorsize -= size; - ctest_errormsg += size; + ctest_errormsg += size; + } + size = snprintf(ctest_errormsg, ctest_errorsize, " %s: ", title); + ctest_errorsize -= size; + ctest_errormsg += size; } -static void msg_end() { - int size; - if (color_output) { - size = snprintf(ctest_errormsg, ctest_errorsize, ANSI_NORMAL); - ctest_errorsize -= size; - ctest_errormsg += size; - } - size = snprintf(ctest_errormsg, ctest_errorsize, "\n"); +static void +msg_end() +{ + int size; + if (color_output) + { + size = snprintf(ctest_errormsg, ctest_errorsize, ANSI_NORMAL); ctest_errorsize -= size; - ctest_errormsg += size; + ctest_errormsg += size; + } + size = snprintf(ctest_errormsg, ctest_errorsize, "\n"); + ctest_errorsize -= size; + ctest_errormsg += size; } -void CTEST_LOG(char *fmt, ...) +void +CTEST_LOG(char* fmt, + ...) { - va_list argp; - msg_start(ANSI_BLUE, "LOG"); + va_list argp; + msg_start(ANSI_BLUE, "LOG"); - va_start(argp, fmt); - int size = vsnprintf(ctest_errormsg, ctest_errorsize, fmt, argp); - ctest_errorsize -= size; - ctest_errormsg += size; - va_end(argp); + va_start(argp, fmt); + int size = vsnprintf(ctest_errormsg, ctest_errorsize, fmt, argp); + ctest_errorsize -= size; + ctest_errormsg += size; + va_end(argp); - msg_end(); + msg_end(); } -void CTEST_ERR(char *fmt, ...) +void +CTEST_ERR(char* fmt, + ...) { - va_list argp; - msg_start(ANSI_YELLOW, "ERR"); + va_list argp; + msg_start(ANSI_YELLOW, "ERR"); - va_start(argp, fmt); - int size = vsnprintf(ctest_errormsg, ctest_errorsize, fmt, argp); - ctest_errorsize -= size; - ctest_errormsg += size; - va_end(argp); + va_start(argp, fmt); + int size = vsnprintf(ctest_errormsg, ctest_errorsize, fmt, argp); + ctest_errorsize -= size; + ctest_errormsg += size; + va_end(argp); - msg_end(); - longjmp(ctest_err, 1); + msg_end(); + longjmp(ctest_err, 1); } -void assert_str(const char* exp, const char* real, const char* caller, int line) { - if ((exp == NULL && real != NULL) || - (exp != NULL && real == NULL) || - (exp && real && strcmp(exp, real) != 0)) { - CTEST_ERR("%s:%d expected '%s', got '%s'", caller, line, exp, real); - } +void +assert_str(const char* exp, + const char* real, + const char* caller, + int line) +{ + if ( ( (exp == NULL) && (real != NULL) ) || + ( (exp != NULL) && (real == NULL) ) || + ( exp && real && (strcmp(exp, real) != 0) ) ) + { + CTEST_ERR("%s:%d expected '%s', got '%s'", caller, line, exp, real); + } } -void assert_data(const unsigned char* exp, int expsize, - const unsigned char* real, int realsize, - const char* caller, int line) { - int i; - if (expsize != realsize) { - CTEST_ERR("%s:%d expected %d bytes, got %d", caller, line, expsize, realsize); - } - for (i=0; issname, strlen(suite_name)) == 0; +static int +suite_filter(struct ctest* t) +{ + return strncmp( suite_name, t->ssname, strlen(suite_name) ) == 0; } -static uint64_t getCurrentTime() { - struct timeval now; - gettimeofday(&now, NULL); - uint64_t now64 = now.tv_sec; - now64 *= 1000000; - now64 += (now.tv_usec); - return now64; +static uint64_t +getCurrentTime() +{ + struct timeval now; + gettimeofday(&now, NULL); + uint64_t now64 = now.tv_sec; + now64 *= 1000000; + now64 += (now.tv_usec); + return now64; } -static void color_print(const char* color, const char* text) { - if (color_output) - printf("%s%s"ANSI_NORMAL"\n", color, text); - else - printf("%s\n", text); +static void +color_print(const char* color, + const char* text) +{ + if (color_output) + { + printf("%s%s"ANSI_NORMAL "\n", color, text); + } + else + { + printf("%s\n", text); + } } #ifdef __APPLE__ -static void *find_symbol(struct ctest *test, const char *fname) +static void* +find_symbol(struct ctest* test, + const char* fname) { - size_t len = strlen(test->ssname) + 1 + strlen(fname); - char *symbol_name = (char *) malloc(len + 1); - memset(symbol_name, 0, len + 1); - snprintf(symbol_name, len + 1, "%s_%s", test->ssname, fname); - - //fprintf(stderr, ">>>> dlsym: loading %s\n", symbol_name); - void *symbol = dlsym(RTLD_DEFAULT, symbol_name); - if (!symbol) { - //fprintf(stderr, ">>>> ERROR: %s\n", dlerror()); - } - // returns NULL on error - - free(symbol_name); - return symbol; + size_t len = strlen(test->ssname) + 1 + strlen(fname); + char* symbol_name = (char*) malloc(len + 1); + memset(symbol_name, 0, len + 1); + snprintf(symbol_name, len + 1, "%s_%s", test->ssname, fname); + + /* fprintf(stderr, ">>>> dlsym: loading %s\n", symbol_name); */ + void* symbol = dlsym(RTLD_DEFAULT, symbol_name); + if (!symbol) + { + /* fprintf(stderr, ">>>> ERROR: %s\n", dlerror()); */ + } + /* returns NULL on error */ + + free(symbol_name); + return symbol; } #endif #ifdef CTEST_SEGFAULT #include -static void sighandler(int signum) +static void +sighandler(int signum) { - char msg[128]; - sprintf(msg, "[SIGNAL %d: %s]", signum, sys_siglist[signum]); - color_print(ANSI_BRED, msg); - fflush(stdout); - - /* "Unregister" the signal handler and send the signal back to the process - * so it can terminate as expected */ - signal(signum, SIG_DFL); - kill(getpid(), signum); + char msg[128]; + sprintf(msg, "[SIGNAL %d: %s]", signum, sys_siglist[signum]); + color_print(ANSI_BRED, msg); + fflush(stdout); + + /* "Unregister" the signal handler and send the signal back to the process + * so it can terminate as expected */ + signal(signum, SIG_DFL); + kill(getpid(), signum); } #endif -int ctest_main(int argc, const char *argv[]) +int +ctest_main(int argc, + const char* argv[]) { - static int total = 0; - static int num_ok = 0; - static int num_fail = 0; - static int num_skip = 0; - static int index = 1; - static filter_func filter = suite_all; + static int total = 0; + static int num_ok = 0; + static int num_fail = 0; + static int num_skip = 0; + static int index = 1; + static filter_func filter = suite_all; #ifdef CTEST_SEGFAULT - signal(SIGSEGV, sighandler); + signal(SIGSEGV, sighandler); #endif - if (argc == 2) { - suite_name = argv[1]; - filter = suite_filter; + if (argc == 2) + { + suite_name = argv[1]; + filter = suite_filter; + } + + color_output = isatty(1); + uint64_t t1 = getCurrentTime(); + + struct ctest* ctest_begin = &__TNAME(suite, test); + struct ctest* ctest_end = &__TNAME(suite, test); + /* find begin and end of section by comparing magics */ + while (1) + { + struct ctest* t = ctest_begin - 1; + if (t->magic != __CTEST_MAGIC) + { + break; } - - color_output = isatty(1); - uint64_t t1 = getCurrentTime(); - - struct ctest* ctest_begin = &__TNAME(suite, test); - struct ctest* ctest_end = &__TNAME(suite, test); - // find begin and end of section by comparing magics - while (1) { - struct ctest* t = ctest_begin-1; - if (t->magic != __CTEST_MAGIC) break; - ctest_begin--; + ctest_begin--; + } + while (1) + { + struct ctest* t = ctest_end + 1; + if (t->magic != __CTEST_MAGIC) + { + break; } - while (1) { - struct ctest* t = ctest_end+1; - if (t->magic != __CTEST_MAGIC) break; - ctest_end++; + ctest_end++; + } + ctest_end++; /* end after last one */ + + static struct ctest* test; + for (test = ctest_begin; test != ctest_end; test++) + { + if (test == &__ctest_suite_test) + { + continue; } - ctest_end++; // end after last one - - static struct ctest* test; - for (test = ctest_begin; test != ctest_end; test++) { - if (test == &__ctest_suite_test) continue; - if (filter(test)) total++; + if ( filter(test) ) + { + total++; } + } - for (test = ctest_begin; test != ctest_end; test++) { - if (test == &__ctest_suite_test) continue; - if (filter(test)) { - ctest_errorbuffer[0] = 0; - ctest_errorsize = MSG_SIZE-1; - ctest_errormsg = ctest_errorbuffer; - printf("TEST %d/%d %s:%s ", index, total, test->ssname, test->ttname); - fflush(stdout); - if (test->skip) { - color_print(ANSI_BYELLOW, "[SKIPPED]"); - num_skip++; - } else { - int result = setjmp(ctest_err); - if (result == 0) { + for (test = ctest_begin; test != ctest_end; test++) + { + if (test == &__ctest_suite_test) + { + continue; + } + if ( filter(test) ) + { + ctest_errorbuffer[0] = 0; + ctest_errorsize = MSG_SIZE - 1; + ctest_errormsg = ctest_errorbuffer; + printf("TEST %d/%d %s:%s ", index, total, test->ssname, test->ttname); + fflush(stdout); + if (test->skip) + { + color_print(ANSI_BYELLOW, "[SKIPPED]"); + num_skip++; + } + else + { + int result = setjmp(ctest_err); + if (result == 0) + { #ifdef __APPLE__ - if (!test->setup) { - test->setup = (SetupFunc)find_symbol(test, "setup"); - } - if (!test->teardown) { - test->teardown = (SetupFunc)find_symbol(test, "teardown"); - } + if (!test->setup) + { + test->setup = (SetupFunc)find_symbol(test, "setup"); + } + if (!test->teardown) + { + test->teardown = (SetupFunc)find_symbol(test, "teardown"); + } #endif - if (test->setup) test->setup(test->data); - if (test->data) - test->run(test->data); - else - test->run(); - if (test->teardown) test->teardown(test->data); - // if we got here it's ok + if (test->setup) + { + test->setup(test->data); + } + if (test->data) + { + test->run(test->data); + } + else + { + test->run(); + } + if (test->teardown) + { + test->teardown(test->data); + } + /* if we got here it's ok */ #ifdef COLOR_OK - color_print(ANSI_BGREEN, "[OK]"); + color_print(ANSI_BGREEN, "[OK]"); #else - printf("[OK]\n"); + printf("[OK]\n"); #endif - num_ok++; - } else { - color_print(ANSI_BRED, "[FAIL]"); - num_fail++; - } - if (ctest_errorsize != MSG_SIZE-1) printf("%s", ctest_errorbuffer); - } - index++; + num_ok++; + } + else + { + color_print(ANSI_BRED, "[FAIL]"); + num_fail++; } + if (ctest_errorsize != MSG_SIZE - 1) + { + printf("%s", ctest_errorbuffer); + } + } + index++; } - uint64_t t2 = getCurrentTime(); - - const char* color = (num_fail) ? ANSI_BRED : ANSI_GREEN; - char results[80]; - sprintf(results, "RESULTS: %d tests (%d ok, %d failed, %d skipped) ran in %"PRIu64" ms", total, num_ok, num_fail, num_skip, (t2 - t1)/1000); - color_print(color, results); - return num_fail; + } + uint64_t t2 = getCurrentTime(); + + const char* color = (num_fail) ? ANSI_BRED : ANSI_GREEN; + char results[80]; + sprintf(results, + "RESULTS: %d tests (%d ok, %d failed, %d skipped) ran in %" PRIu64 " ms", + total, + num_ok, + num_fail, + num_skip, + (t2 - t1) / 1000); + color_print(color, results); + return num_fail; } #endif diff --git a/test/icelib_nomination_test.c b/test/icelib_nomination_test.c new file mode 100644 index 0000000..7f764b5 --- /dev/null +++ b/test/icelib_nomination_test.c @@ -0,0 +1,512 @@ +#include +#include +#include +#include + +#include "test_utils.h" +#include "icelib.h" + + +ICELIB_INSTANCE* m_icelib; +static char remoteUfrag[] = "rm0Uf"; +static char remotePasswd[] = "rm0Pa"; + + +typedef struct { + bool gotCB; + const struct sockaddr* destination; + const struct sockaddr* source; + uint32_t userValue1; + uint32_t userValue2; + uint32_t componentId; + bool useRelay; + char ufrag[ ICE_MAX_UFRAG_LENGTH]; + /* const char *pUfrag; */ + const char* pPasswd; + uint32_t peerPriority; + bool useCandidate; + bool iceControlling; + bool iceControlled; + uint64_t tieBreaker; + StunMsgId transactionId; +}m_ConncheckCB; + + +typedef struct { + uint64_t priority; + int32_t proto; + struct sockaddr_storage local; + struct sockaddr_storage remote; +}m_NominationCB; + +m_ConncheckCB m_connChkCB[50]; +uint32_t num_checks = 0; + +m_ConncheckCB m_nomChkCB[50]; +uint32_t num_nom = 0; /* sorry could not resist the name..*/ + +m_NominationCB m_nominationCB[50]; +uint32_t num_pair_nom = 0; + +ICELIB_Result +Nominated(void* pUserData, + uint32_t userValue1, + uint32_t userValue2, + uint32_t componentId, + uint64_t priority, + int32_t proto, + const struct sockaddr* local, + const struct sockaddr* remote) +{ + (void)pUserData; + (void)userValue1; + (void)userValue2; + (void)componentId; + (void)priority; + (void) proto; + (void)local; + (void) remote; + + m_nominationCB[num_pair_nom].priority = priority; + m_nominationCB[num_pair_nom].proto = proto; + sockaddr_copy( (struct sockaddr*)&m_nominationCB[num_pair_nom].local, + local ); + sockaddr_copy( (struct sockaddr*)&m_nominationCB[num_pair_nom].remote, + remote ); + num_pair_nom++; + return 0; +} + +ICELIB_Result +sendConnectivityCheck(void* pUserData, + int proto, + const struct sockaddr* destination, + const struct sockaddr* source, + uint32_t userValue1, + uint32_t userValue2, + uint32_t componentId, + bool useRelay, + const char* pUfrag, + const char* pPasswd, + uint32_t peerPriority, + bool useCandidate, + bool iceControlling, + bool iceControlled, + uint64_t tieBreaker, + StunMsgId transactionId) +{ + (void)pUserData; + (void) proto; + if (useCandidate) + { + m_nomChkCB[num_nom].gotCB = true; + m_nomChkCB[num_nom].destination = destination; + m_nomChkCB[num_nom].source = source; + m_nomChkCB[num_nom].userValue1 = userValue1; + m_nomChkCB[num_nom].userValue2 = userValue2; + m_nomChkCB[num_nom].componentId = componentId; + m_nomChkCB[num_nom].useRelay = useRelay; + strncpy(m_nomChkCB[num_nom].ufrag, pUfrag, ICE_MAX_UFRAG_LENGTH); + m_nomChkCB[num_nom].pPasswd = pPasswd; + m_nomChkCB[num_nom].peerPriority = peerPriority; + m_nomChkCB[num_nom].useCandidate = useCandidate; + m_nomChkCB[num_nom].iceControlling = iceControlling; + m_nomChkCB[num_nom].iceControlled = iceControlled; + m_nomChkCB[num_nom].transactionId = transactionId; + m_nomChkCB[num_nom].tieBreaker = tieBreaker; + num_nom++; + } + else + { + m_connChkCB[num_checks].gotCB = true; + m_connChkCB[num_checks].destination = destination; + m_connChkCB[num_checks].source = source; + m_connChkCB[num_checks].userValue1 = userValue1; + m_connChkCB[num_checks].userValue2 = userValue2; + m_connChkCB[num_checks].componentId = componentId; + m_connChkCB[num_checks].useRelay = useRelay; + strncpy(m_connChkCB[num_checks].ufrag, pUfrag, ICE_MAX_UFRAG_LENGTH); + m_connChkCB[num_checks].pPasswd = pPasswd; + m_connChkCB[num_checks].peerPriority = peerPriority; + m_connChkCB[num_checks].useCandidate = useCandidate; + m_connChkCB[num_checks].iceControlling = iceControlling; + m_connChkCB[num_checks].iceControlled = iceControlled; + m_connChkCB[num_checks].transactionId = transactionId; + m_connChkCB[num_checks].tieBreaker = tieBreaker; + + num_checks++; + } + return 0; +} + +void +printLog(void* pUserData, + ICELIB_logLevel logLevel, + const char* str) +{ + (void)pUserData; + (void)logLevel; + (void)str; + /* printf("%s\n", str); */ +} + +CTEST_DATA(data) +{ + int a; +}; + + +CTEST_SETUP(data) +{ + (void)data; + struct sockaddr_storage m0_defaultAddr; + struct sockaddr_storage m0_localHostRtp; + + ICELIB_CONFIGURATION iceConfig; + + uint32_t mediaIdx; + + srand( time(NULL) ); + num_checks = 0; + num_nom = 0; + num_pair_nom = 0; + + m_icelib = (ICELIB_INSTANCE*)malloc( sizeof(ICELIB_INSTANCE) ); + + /* ------------ Media Line: 0 */ + sockaddr_initFromString( (struct sockaddr*)&m0_localHostRtp, + "192.168.2.10:56780" ); + + + iceConfig.tickIntervalMS = 20; + iceConfig.keepAliveIntervalS = 15; + iceConfig.maxCheckListPairs = ICELIB_MAX_PAIRS; + iceConfig.aggressiveNomination = true; + iceConfig.iceLite = false; + iceConfig.logLevel = ICELIB_logDebug; + /* iceConfig.logLevel = ICELIB_logDisable; */ + + + ICELIB_Constructor(m_icelib, + &iceConfig); + + ICELIB_setCallbackOutgoingBindingRequest(m_icelib, + sendConnectivityCheck, + NULL); + + ICELIB_setCallbackLog(m_icelib, + printLog, + NULL, + ICELIB_logDebug); + + ICELIB_setCallbackNominated(m_icelib, + Nominated, + NULL); + + /* Local side */ + /* Medialine: 0 */ + mediaIdx = ICELIB_addLocalMediaStream(m_icelib, 42, 42, ICE_CAND_TYPE_HOST); + ICELIB_addLocalCandidate(m_icelib, + mediaIdx, + 1, + (struct sockaddr*)&m0_localHostRtp, + NULL, + ICE_TRANS_UDP, + ICE_CAND_TYPE_HOST, + 0xffff); + + /* Remote side */ + /* Medialine: + * 0 */ + sockaddr_initFromString( (struct sockaddr*)&m0_defaultAddr, + "158.38.48.10:5004" ); + + ICELIB_addRemoteMediaStream(m_icelib, remoteUfrag, remotePasswd, + (struct sockaddr*)&m0_defaultAddr); + ICELIB_addRemoteCandidate(m_icelib, + 0, + "1", + 1, + 1, + 2130706431, + "158.38.48.10", + 5004, + ICE_TRANS_UDP, + ICE_CAND_TYPE_HOST); + + ICELIB_addRemoteCandidate(m_icelib, + 0, + "1", + 1, + 1, + 2130705430, + "158.38.48.10", + 3478, + ICE_TRANS_UDP, + ICE_CAND_TYPE_HOST); + + ICELIB_addRemoteCandidate(m_icelib, + 0, + "1", + 1, + 1, + 2130206431, + "158.38.48.10", + 33434, + ICE_TRANS_UDP, + ICE_CAND_TYPE_HOST); +} + + + + +CTEST_TEARDOWN(data) +{ + (void) data; + ICELIB_Destructor(m_icelib); + free(m_icelib); +} + + + +CTEST2(data, multiple_host_addr) +{ + (void) data; + memset( &m_connChkCB, 0, sizeof(m_ConncheckCB) ); + memset( &m_nomChkCB, 0, sizeof(m_ConncheckCB) ); + memset( &m_nominationCB, 0, sizeof(m_NominationCB) ); + + ASSERT_TRUE( ICELIB_Start(m_icelib, true) ); + + ASSERT_TRUE( ICELIB_isRunning(m_icelib) ); + + ASSERT_FALSE( ICELIB_Mangled(m_icelib) ); + + for (int i = 0; i < 15; i++) + { + ICELIB_Tick(m_icelib); + + } + /* All the chacks are sent.. Lets trigger some responses */ + /* Let the lowest pri finish first.. */ + ICELIB_incomingBindingResponse(m_icelib, + 200, + m_connChkCB[2].transactionId, + m_connChkCB[2].destination, + m_connChkCB[2].source, + m_connChkCB[2].source); + ICELIB_Tick(m_icelib); + ICELIB_Tick(m_icelib); + + ICELIB_incomingBindingResponse(m_icelib, + 200, + m_nomChkCB[0].transactionId, + m_nomChkCB[0].destination, + m_nomChkCB[0].source, + m_nomChkCB[0].source); + ICELIB_Tick(m_icelib); + ICELIB_Tick(m_icelib); + +/* Insert check to verify nomination here.. */ + ASSERT_TRUE(sockaddr_ipPort( + (const struct sockaddr*)&m_nominationCB[0].local) == 56780); + ASSERT_TRUE(sockaddr_ipPort( + (const struct sockaddr*)&m_nominationCB[0].remote) == 33434); + + + /* So lets see what happens if a beetr pri pair shows up.. */ + ICELIB_incomingBindingResponse(m_icelib, + 200, + m_connChkCB[1].transactionId, + m_connChkCB[1].destination, + m_connChkCB[1].source, + m_connChkCB[1].source); + + ICELIB_Tick(m_icelib); + ICELIB_Tick(m_icelib); + + ICELIB_incomingBindingResponse(m_icelib, + 200, + m_nomChkCB[1].transactionId, + m_nomChkCB[1].destination, + m_nomChkCB[1].source, + m_nomChkCB[1].source); + ICELIB_Tick(m_icelib); + ICELIB_Tick(m_icelib); + ASSERT_TRUE(sockaddr_ipPort( + (const struct sockaddr*)&m_nominationCB[1].local) == 56780); + ASSERT_TRUE(sockaddr_ipPort( + (const struct sockaddr*)&m_nominationCB[1].remote) == 3478); + +#if 0 + for (int i = 0; i < 2000; i++) + { + ICELIB_Tick(m_icelib); + + } +#endif + + + ICELIB_incomingBindingResponse(m_icelib, + 200, + m_connChkCB[0].transactionId, + m_connChkCB[0].destination, + m_connChkCB[0].source, + m_connChkCB[0].source); + + ICELIB_Tick(m_icelib); + ICELIB_Tick(m_icelib); + ICELIB_incomingBindingResponse(m_icelib, + 200, + m_nomChkCB[2].transactionId, + m_nomChkCB[2].destination, + m_nomChkCB[2].source, + m_nomChkCB[2].source); + + ICELIB_Tick(m_icelib); + ICELIB_Tick(m_icelib); + + ASSERT_TRUE(sockaddr_ipPort( + (const struct sockaddr*)&m_nominationCB[2].local) == 56780); + ASSERT_TRUE(sockaddr_ipPort( + (const struct sockaddr*)&m_nominationCB[2].remote) == 5004); + + + + #if 0 + /* Reverse the order vi got the checks */ + for (int i = num_checks - 1; i >= 0; i--) + { + printf("-----> Binding response (%i)\n", i); + ICELIB_incomingBindingResponse(m_icelib, + 200, + m_connChkCB[i].transactionId, + m_connChkCB[i].destination, + m_connChkCB[i].source, + m_connChkCB[i].source); + ICELIB_Tick(m_icelib); + + printf("-----> Binding nomination (%i)\n", num_nom); + + } + + for (uint32_t i = 0; i < num_nom; i++) + { + ICELIB_Tick(m_icelib); + ICELIB_incomingBindingResponse(m_icelib, + 200, + m_nomChkCB[i].transactionId, + m_nomChkCB[i].destination, + m_nomChkCB[i].source, + m_nomChkCB[i].source); + ICELIB_Tick(m_icelib); + } + #endif + + + + + /* for (int i = 0; i < 15; i++) */ + /* { */ + /* ICELIB_Tick(m_icelib); */ + /* if (num_checks == 1) */ + /* { */ + /* ICELIB_incomingBindingResponse(m_icelib, */ + /* 200, */ + /* m_connChkCB[0].transactionId, */ + /* m_connChkCB[0].destination, */ + /* m_connChkCB[0].source, */ + /* m_connChkCB[0].source); */ + /* num_checks = 0; */ + /* } */ + /* } */ + + ASSERT_TRUE( ICELIB_isIceComplete(m_icelib) ); +/* ICELIB_validListDump(&m_icelib->streamControllers[0].validList); */ + + ASSERT_TRUE( m_icelib->iceState == ICELIB_COMPLETED); + +} + +CTEST2(data, multiple_host_addr_missing) +{ + (void) data; + memset( &m_connChkCB, 0, sizeof(m_ConncheckCB) ); + memset( &m_nomChkCB, 0, sizeof(m_ConncheckCB) ); + memset( &m_nominationCB, 0, sizeof(m_NominationCB) ); + + ASSERT_TRUE( ICELIB_Start(m_icelib, true) ); + + ASSERT_TRUE( ICELIB_isRunning(m_icelib) ); + + ASSERT_FALSE( ICELIB_Mangled(m_icelib) ); + + for (int i = 0; i < 15; i++) + { + ICELIB_Tick(m_icelib); + + } + /* All the chacks are sent.. Lets trigger some responses */ + /* Let the lowest pri finish first.. */ + ICELIB_incomingBindingResponse(m_icelib, + 200, + m_connChkCB[2].transactionId, + m_connChkCB[2].destination, + m_connChkCB[2].source, + m_connChkCB[2].source); + ICELIB_Tick(m_icelib); + ICELIB_Tick(m_icelib); + + ICELIB_incomingBindingResponse(m_icelib, + 200, + m_nomChkCB[0].transactionId, + m_nomChkCB[0].destination, + m_nomChkCB[0].source, + m_nomChkCB[0].source); + ICELIB_Tick(m_icelib); + ICELIB_Tick(m_icelib); + +/* Insert check to verify nomination here.. */ + ASSERT_TRUE(sockaddr_ipPort( + (const struct sockaddr*)&m_nominationCB[0].local) == 56780); + ASSERT_TRUE(sockaddr_ipPort( + (const struct sockaddr*)&m_nominationCB[0].remote) == 33434); + + + /* So lets see what happens if a beetr pri pair shows up.. */ + ICELIB_incomingBindingResponse(m_icelib, + 200, + m_connChkCB[1].transactionId, + m_connChkCB[1].destination, + m_connChkCB[1].source, + m_connChkCB[1].source); + + ICELIB_Tick(m_icelib); + ICELIB_Tick(m_icelib); + + ICELIB_incomingBindingResponse(m_icelib, + 200, + m_nomChkCB[1].transactionId, + m_nomChkCB[1].destination, + m_nomChkCB[1].source, + m_nomChkCB[1].source); + ICELIB_Tick(m_icelib); + ICELIB_Tick(m_icelib); + ASSERT_TRUE(sockaddr_ipPort( + (const struct sockaddr*)&m_nominationCB[1].local) == 56780); + ASSERT_TRUE(sockaddr_ipPort( + (const struct sockaddr*)&m_nominationCB[1].remote) == 3478); + + + for (int i = 0; i < 2000; i++) + { + ICELIB_Tick(m_icelib); + + } + + + ASSERT_TRUE( ICELIB_isIceComplete(m_icelib) ); + + ASSERT_TRUE( m_icelib->iceState == ICELIB_COMPLETED); + +} diff --git a/test/icelib_running_test.c b/test/icelib_running_test.c index 2b9d2b2..61b786e 100644 --- a/test/icelib_running_test.c +++ b/test/icelib_running_test.c @@ -613,7 +613,7 @@ CTEST2(data, multiple_medialines) ASSERT_FALSE( ICELIB_Mangled(m_icelib) ); - for (i = 0; i < 1000; i++) + for (i = 0; i < 15; i++) { ICELIB_Tick(m_icelib); if (m_connChkCB.gotCB) @@ -695,7 +695,6 @@ CTEST2(data, medialines_local_inactive) } - CTEST2(data, medialines_remote_inactive) { (void) data; @@ -744,8 +743,6 @@ CTEST2(data, medialines_remote_inactive) ASSERT_TRUE( ICELIB_isIceComplete(m_icelib) ); ASSERT_TRUE( m_icelib->iceState == ICELIB_COMPLETED); - - } @@ -854,7 +851,8 @@ CTEST2(data, medialines_remote_last_inactive) } -#if 0 + + CTEST2(data, medialines_remote_first_inactive) { (void) data; @@ -905,9 +903,9 @@ CTEST2(data, medialines_remote_first_inactive) } -#endif -#if 0 + + CTEST2(data, medialines_both_mixed_inactive) { (void)data; @@ -959,7 +957,8 @@ CTEST2(data, medialines_both_mixed_inactive) } -#endif + + CTEST2(data, medialines_both_mixed_inactive_fail) { @@ -1145,7 +1144,7 @@ CTEST2(data, controlled) NULL, 1); ICELIB_Tick(m_icelib); - stunlib_createId(&stunId ); + stunlib_createId(&stunId); sockaddr_initFromString( (struct sockaddr*)&srcAddr, m1_remoteHostRtcpAddr ); sockaddr_initFromString( (struct sockaddr*)&dstAddr, "192.168.2.10:3459" ); @@ -1167,7 +1166,7 @@ CTEST2(data, controlled) 2); /* Medialine: 2 */ - stunlib_createId(&stunId ); + stunlib_createId(&stunId); sockaddr_initFromString( (struct sockaddr*)&srcAddr, m2_remoteHostRtpAddr ); sockaddr_initFromString( (struct sockaddr*)&dstAddr, "192.168.2.10:3460" ); ICELIB_getCheckListRemoteUsernamePair(ufragPair, @@ -1191,7 +1190,7 @@ CTEST2(data, controlled) NULL, 1); - stunlib_createId(&stunId ); + stunlib_createId(&stunId); sockaddr_initFromString( (struct sockaddr*)&srcAddr, m2_remoteHostRtcpAddr ); sockaddr_initFromString( (struct sockaddr*)&dstAddr, "192.168.2.10:3461" ); @@ -1277,7 +1276,7 @@ CTEST2(data, controlled_inactive) } /* send some nominating messages.. */ /* Medialine: 0 */ - stunlib_createId(&stunId ); + stunlib_createId(&stunId); sockaddr_initFromString( (struct sockaddr*)&srcAddr, m0_remoteHostRtpAddr ); sockaddr_initFromString( (struct sockaddr*)&dstAddr, "192.168.2.10:3456" ); ICELIB_getCheckListRemoteUsernamePair(ufragPair, @@ -1301,7 +1300,7 @@ CTEST2(data, controlled_inactive) NULL, 1); ICELIB_Tick(m_icelib); - stunlib_createId(&stunId ); + stunlib_createId(&stunId); sockaddr_initFromString( (struct sockaddr*)&srcAddr, m0_remoteHostRtcpAddr ); sockaddr_initFromString( (struct sockaddr*)&dstAddr, "192.168.2.10:3457" ); @@ -1324,7 +1323,7 @@ CTEST2(data, controlled_inactive) ICELIB_Tick(m_icelib); /* Medialine: 1 */ - stunlib_createId(&stunId ); + stunlib_createId(&stunId); sockaddr_initFromString( (struct sockaddr*)&srcAddr, m1_remoteHostRtpAddr ); sockaddr_initFromString( (struct sockaddr*)&dstAddr, "192.168.2.10:3458" ); ICELIB_getCheckListRemoteUsernamePair(ufragPair, @@ -1349,7 +1348,7 @@ CTEST2(data, controlled_inactive) NULL, 1); ICELIB_Tick(m_icelib); - stunlib_createId(&stunId ); + stunlib_createId(&stunId); sockaddr_initFromString( (struct sockaddr*)&srcAddr, m1_remoteHostRtcpAddr ); sockaddr_initFromString( (struct sockaddr*)&dstAddr, "192.168.2.10:3459" ); @@ -1371,7 +1370,7 @@ CTEST2(data, controlled_inactive) 2); /* Medialine: 2 */ - stunlib_createId(&stunId ); + stunlib_createId(&stunId); sockaddr_initFromString( (struct sockaddr*)&srcAddr, m2_remoteHostRtpAddr ); sockaddr_initFromString( (struct sockaddr*)&dstAddr, "192.168.2.10:3460" ); ICELIB_getCheckListRemoteUsernamePair(ufragPair, @@ -1395,7 +1394,7 @@ CTEST2(data, controlled_inactive) NULL, 1); - stunlib_createId(&stunId ); + stunlib_createId(&stunId); sockaddr_initFromString( (struct sockaddr*)&srcAddr, m2_remoteHostRtcpAddr ); sockaddr_initFromString( (struct sockaddr*)&dstAddr, "192.168.2.10:3461" ); diff --git a/test/icelib_test.c b/test/icelib_test.c index 121f987..f9b182b 100644 --- a/test/icelib_test.c +++ b/test/icelib_test.c @@ -22,6 +22,19 @@ #define FOUNDATION_RELAY "4" #define FOUNDATION_PRFLX "2" + +void +printLog(void* pUserData, + ICELIB_logLevel logLevel, + const char* str) +{ + (void)pUserData; + (void)logLevel; + (void)str; + printf("%s\n", str); +} + + ICELIB_Result ICELIB_TEST_sendConnectivityCheck(void* pUserData, int proto, @@ -117,6 +130,11 @@ ICELIB_TEST_sendConnectivityCheck(void* pUserData, (void) pUserData; (void) proto; /* Todo add TCP checks; */ + printf("\n --------- Sending connectivity check -----------\n"); + if (useCandidate) + { + printf(" Use Candidate \n"); + } connChkCB.gotCB = true; connChkCB.destination = destination; connChkCB.source = source; @@ -194,8 +212,8 @@ CTEST_SETUP(data) iceConfig.maxCheckListPairs = ICELIB_MAX_PAIRS; iceConfig.aggressiveNomination = false; iceConfig.iceLite = false; - /* iceConfig.logLevel = ICELIB_logDebug; */ - iceConfig.logLevel = ICELIB_logDisable; + iceConfig.logLevel = ICELIB_logDebug; + /* iceConfig.logLevel = ICELIB_logDisable; */ ICELIB_Constructor(icelib, @@ -204,6 +222,11 @@ CTEST_SETUP(data) ICELIB_setCallbackOutgoingBindingRequest(icelib, ICELIB_TEST_sendConnectivityCheck, NULL); + ICELIB_setCallbackLog(icelib, + printLog, + NULL, + ICELIB_logDebug); + /* Local side */ mediaIdx = ICELIB_addLocalMediaStream(icelib, @@ -1441,7 +1464,7 @@ CTEST2(data, conncheck_withIncomming) INET_ADDRSTRLEN) == 0); ASSERT_FALSE(connChkCB.useRelay); - stunlib_createId(&stunId ); + stunlib_createId(&stunId); sockaddr_initFromString( (struct sockaddr*)&srcAddr, srcAddrStr ); sockaddr_initFromString( (struct sockaddr*)&dstAddr, "192.168.2.10:3456" ); ICELIB_getCheckListRemoteUsernamePair(ufragPair, @@ -1643,7 +1666,7 @@ CTEST2(data, ICE_Incomming_Response) /* 1. Tick */ - for (i = 0; i < 10000; i++) + for (i = 0; i < 5000; i++) { ICELIB_Tick(icelib); if (connChkCB.gotCB) @@ -1654,7 +1677,7 @@ CTEST2(data, ICE_Incomming_Response) true ); /* We pretend to be the perfect network. Responses arrive imediately! */ - + printf(" -------> Testclient sending response\n"); ICELIB_incomingBindingResponse(icelib, 200, connChkCB.transactionId, @@ -1666,7 +1689,7 @@ CTEST2(data, ICE_Incomming_Response) } } - /* ICELIB_validListDump(&icelib->streamControllers[0].validList); */ + ICELIB_validListDump(&icelib->streamControllers[0].validList); ASSERT_TRUE(icelib->iceState == ICELIB_COMPLETED); } @@ -1682,7 +1705,7 @@ CTEST(icelib, compareTransactionId) StunMsgId id2; StunMsgId id3; - stunlib_createId(&id1 ); + stunlib_createId(&id1); memcpy(&id3, &id1, STUN_MSG_ID_SIZE); @@ -1774,9 +1797,10 @@ CTEST(icelib,findCandidates) sockaddr_copy( (struct sockaddr*)&mediaStream.candidate[0].connectionAddr, (struct sockaddr*)&addr1 ); - mediaStream.candidate[0].transport = ICE_TRANS_UDP; - //mediaStream.candidate[0].transport = ICE_TRANSPORT_proto(ICE_TRANS_UDP); - //mediaStream.candidate[0].transport = IPPROTO_UDP; + mediaStream.candidate[0].transport = ICE_TRANS_UDP; + /* mediaStream.candidate[0].transport = ICE_TRANSPORT_proto(ICE_TRANS_UDP); + * */ + /* mediaStream.candidate[0].transport = IPPROTO_UDP; */ mediaStream.candidate[0].componentid = 1;