From 680e76afde11d4e7f6c8a3111114e6beeac4da26 Mon Sep 17 00:00:00 2001 From: jdelapla Date: Tue, 12 Dec 2023 18:12:32 -0800 Subject: [PATCH] Asynchronous get ice config (#1854) * Asynchronous get ice config * Fixing mac compile error, addressing comments, correcting spelling error * clang format * fixing test util functions to include new APIs * Unused variables for certain compile time flags breaking mac compile * fixing more compile errors for mac * Fix a dead lock, and fix a test with the API changes * iceAgentRestart does not remove the IceServers since the old design required them to be supplied at object creation. Initialize relay candidates at end of iceAgentRestart. * Update PIC build in an attempt to fix static build on Mac * Moving git tag back to develop, since develop has been updated * remove geticeconfig from standard connect state machine flow * Async test, and moving geticeserverconfig out of the standard signaling state machine flow * clang format * Incorrect state transition * fixing async test * Up the sleep time * change async func for test to handle answer and offer * change location of creating pointer pointer * Fixing tests * Fix gathering to allow reporting relay candidates even after all srflx candidates have been recieved * unit test, longer sleep on teardown of threadpool * Fixing tests * Update samples based off feedback, fix clang compile error in test * Moved iceUriCount increment, added comments to public API * fix mac compile error from unused variable for specific ifdef --- samples/Common.c | 105 +++++++--- samples/Samples.h | 9 + .../kinesis/video/webrtcclient/Include.h | 22 +- src/source/Ice/IceAgent.c | 90 +++++++- src/source/Ice/IceAgent.h | 2 + src/source/Ice/TurnConnectionStateMachine.c | 2 +- src/source/Include_i.h | 10 +- src/source/PeerConnection/PeerConnection.c | 27 +++ src/source/Signaling/StateMachine.c | 7 +- tst/IceFunctionalityTest.cpp | 25 ++- tst/PeerConnectionApiTest.cpp | 17 +- tst/PeerConnectionFunctionalityTest.cpp | 147 ++++++++----- tst/SignalingApiFunctionalityTest.cpp | 197 +++++++++++------- tst/SignalingApiTest.cpp | 28 ++- tst/WebRTCClientTestFixture.cpp | 144 +++++++++++-- tst/WebRTCClientTestFixture.h | 28 ++- 16 files changed, 648 insertions(+), 212 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index 3c5469af53..d8563f6084 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -356,13 +356,51 @@ VOID onIceCandidateHandler(UINT64 customData, PCHAR candidateJson) CHK_LOG_ERR(retStatus); } +PVOID asyncGetIceConfigInfo(PVOID args) +{ + STATUS retStatus = STATUS_SUCCESS; + AsyncGetIceStruct* data = (AsyncGetIceStruct*) args; + PIceConfigInfo pIceConfigInfo = NULL; + UINT32 uriCount = 0; + UINT32 i = 0, maxTurnServer = 1; + + if (data != NULL) { + /* signalingClientGetIceConfigInfoCount can return more than one turn server. Use only one to optimize + * candidate gathering latency. But user can also choose to use more than 1 turn server. */ + for (uriCount = 0, i = 0; i < maxTurnServer; i++) { + /* + * if configuration.iceServers[uriCount + 1].urls is "turn:ip:port?transport=udp" then ICE will try TURN over UDP + * if configuration.iceServers[uriCount + 1].urls is "turn:ip:port?transport=tcp" then ICE will try TURN over TCP/TLS + * if configuration.iceServers[uriCount + 1].urls is "turns:ip:port?transport=udp", it's currently ignored because sdk dont do TURN + * over DTLS yet. if configuration.iceServers[uriCount + 1].urls is "turns:ip:port?transport=tcp" then ICE will try TURN over TCP/TLS + * if configuration.iceServers[uriCount + 1].urls is "turn:ip:port" then ICE will try both TURN over UDP and TCP/TLS + * + * It's recommended to not pass too many TURN iceServers to configuration because it will slow down ice gathering in non-trickle mode. + */ + CHK_STATUS(signalingClientGetIceConfigInfo(data->signalingClientHandle, i, &pIceConfigInfo)); + CHECK(uriCount < MAX_ICE_SERVERS_COUNT); + uriCount += pIceConfigInfo->uriCount; + CHK_STATUS(addConfigToServerList(&(data->pRtcPeerConnection), pIceConfigInfo)); + } + } + *(data->pUriCount) += uriCount; + +CleanUp: + SAFE_MEMFREE(data); + CHK_LOG_ERR(retStatus); + return NULL; +} + STATUS initializePeerConnection(PSampleConfiguration pSampleConfiguration, PRtcPeerConnection* ppRtcPeerConnection) { ENTERS(); STATUS retStatus = STATUS_SUCCESS; RtcConfiguration configuration; - UINT32 i, j, iceConfigCount, uriCount = 0, maxTurnServer = 1; +#ifndef ENABLE_KVS_THREADPOOL + UINT32 i, j, maxTurnServer = 1; PIceConfigInfo pIceConfigInfo; + UINT32 uriCount = 0; +#endif UINT64 data; PRtcCertificate pRtcCertificate = NULL; @@ -385,37 +423,6 @@ STATUS initializePeerConnection(PSampleConfiguration pSampleConfiguration, PRtcP SNPRINTF(configuration.iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, KINESIS_VIDEO_STUN_URL, pSampleConfiguration->channelInfo.pRegion, pKinesisVideoStunUrlPostFix); - if (pSampleConfiguration->useTurn) { - // Set the URIs from the configuration - CHK_STATUS(signalingClientGetIceConfigInfoCount(pSampleConfiguration->signalingClientHandle, &iceConfigCount)); - - /* signalingClientGetIceConfigInfoCount can return more than one turn server. Use only one to optimize - * candidate gathering latency. But user can also choose to use more than 1 turn server. */ - for (uriCount = 0, i = 0; i < maxTurnServer; i++) { - CHK_STATUS(signalingClientGetIceConfigInfo(pSampleConfiguration->signalingClientHandle, i, &pIceConfigInfo)); - for (j = 0; j < pIceConfigInfo->uriCount; j++) { - CHECK(uriCount < MAX_ICE_SERVERS_COUNT); - /* - * if configuration.iceServers[uriCount + 1].urls is "turn:ip:port?transport=udp" then ICE will try TURN over UDP - * if configuration.iceServers[uriCount + 1].urls is "turn:ip:port?transport=tcp" then ICE will try TURN over TCP/TLS - * if configuration.iceServers[uriCount + 1].urls is "turns:ip:port?transport=udp", it's currently ignored because sdk dont do TURN - * over DTLS yet. if configuration.iceServers[uriCount + 1].urls is "turns:ip:port?transport=tcp" then ICE will try TURN over TCP/TLS - * if configuration.iceServers[uriCount + 1].urls is "turn:ip:port" then ICE will try both TURN over UDP and TCP/TLS - * - * It's recommended to not pass too many TURN iceServers to configuration because it will slow down ice gathering in non-trickle mode. - */ - - STRNCPY(configuration.iceServers[uriCount + 1].urls, pIceConfigInfo->uris[j], MAX_ICE_CONFIG_URI_LEN); - STRNCPY(configuration.iceServers[uriCount + 1].credential, pIceConfigInfo->password, MAX_ICE_CONFIG_CREDENTIAL_LEN); - STRNCPY(configuration.iceServers[uriCount + 1].username, pIceConfigInfo->userName, MAX_ICE_CONFIG_USER_NAME_LEN); - - uriCount++; - } - } - } - - pSampleConfiguration->iceUriCount = uriCount + 1; - // Check if we have any pregenerated certs and use them // NOTE: We are running under the config lock retStatus = stackQueueDequeue(pSampleConfiguration->pregeneratedCertificates, &data); @@ -430,6 +437,40 @@ STATUS initializePeerConnection(PSampleConfiguration pSampleConfiguration, PRtcP } CHK_STATUS(createPeerConnection(&configuration, ppRtcPeerConnection)); + + if (pSampleConfiguration->useTurn) { +#ifdef ENABLE_KVS_THREADPOOL + pSampleConfiguration->iceUriCount = 1; + AsyncGetIceStruct* pAsyncData = NULL; + + pAsyncData = (AsyncGetIceStruct*) MEMCALLOC(1, SIZEOF(AsyncGetIceStruct)); + pAsyncData->signalingClientHandle = pSampleConfiguration->signalingClientHandle; + pAsyncData->pRtcPeerConnection = *ppRtcPeerConnection; + pAsyncData->pUriCount = &(pSampleConfiguration->iceUriCount); + CHK_STATUS(peerConnectionAsync(asyncGetIceConfigInfo, (PVOID) pAsyncData)); +#else + + /* signalingClientGetIceConfigInfoCount can return more than one turn server. Use only one to optimize + * candidate gathering latency. But user can also choose to use more than 1 turn server. */ + for (uriCount = 0, i = 0; i < maxTurnServer; i++) { + /* + * if configuration.iceServers[uriCount + 1].urls is "turn:ip:port?transport=udp" then ICE will try TURN over UDP + * if configuration.iceServers[uriCount + 1].urls is "turn:ip:port?transport=tcp" then ICE will try TURN over TCP/TLS + * if configuration.iceServers[uriCount + 1].urls is "turns:ip:port?transport=udp", it's currently ignored because sdk dont do TURN + * over DTLS yet. if configuration.iceServers[uriCount + 1].urls is "turns:ip:port?transport=tcp" then ICE will try TURN over TCP/TLS + * if configuration.iceServers[uriCount + 1].urls is "turn:ip:port" then ICE will try both TURN over UDP and TCP/TLS + * + * It's recommended to not pass too many TURN iceServers to configuration because it will slow down ice gathering in non-trickle mode. + */ + CHK_STATUS(signalingClientGetIceConfigInfo(pSampleConfiguration->signalingClientHandle, i, &pIceConfigInfo)); + CHECK(uriCount < MAX_ICE_SERVERS_COUNT); + uriCount += pIceConfigInfo->uriCount; + CHK_STATUS(addConfigToServerList(ppRtcPeerConnection, pIceConfigInfo)); + } + pSampleConfiguration->iceUriCount = uriCount + 1; +#endif + } + CleanUp: CHK_LOG_ERR(retStatus); diff --git a/samples/Samples.h b/samples/Samples.h index 1bb705b800..01109e8a5d 100644 --- a/samples/Samples.h +++ b/samples/Samples.h @@ -166,6 +166,15 @@ struct __SampleStreamingSession { KvsIceAgentMetrics iceMetrics; }; +// TODO this should all be in a higher webrtccontext layer above PeerConnection +// Placing it here now since this is where all the current webrtccontext functions are placed +typedef struct { + SIGNALING_CLIENT_HANDLE signalingClientHandle; + PRtcPeerConnection pRtcPeerConnection; + PUINT32 pUriCount; + +} AsyncGetIceStruct; + VOID sigintHandler(INT32); STATUS readFrameFromDisk(PBYTE, PUINT32, PCHAR); PVOID sendVideoPackets(PVOID); diff --git a/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h b/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h index 27f597c642..080696fd59 100644 --- a/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h +++ b/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h @@ -236,7 +236,7 @@ extern "C" { #define STATUS_TURN_CONNECTION_PEER_NOT_USABLE STATUS_ICE_BASE + 0x00000027 #define STATUS_ICE_SERVER_INDEX_INVALID STATUS_ICE_BASE + 0x00000028 #define STATUS_ICE_CANDIDATE_STRING_MISSING_TYPE STATUS_ICE_BASE + 0x00000029 -#define STATUS_TURN_CONNECTION_ALLOCAITON_FAILED STATUS_ICE_BASE + 0x0000002a +#define STATUS_TURN_CONNECTION_ALLOCATION_FAILED STATUS_ICE_BASE + 0x0000002a #define STATUS_TURN_INVALID_STATE STATUS_ICE_BASE + 0x0000002b /*!@} */ @@ -1573,6 +1573,16 @@ typedef struct { */ PUBLIC_API STATUS createPeerConnection(PRtcConfiguration, PRtcPeerConnection*); +/** + * @brief Give peer connection an ice config to add to its server list + * + * @param[in] PRtcPeerConnection* initialized RtcPeerConnection + * @param[in] PIceConfigInfo Ice config info to add to this peer connection + * + * @return STATUS code of the execution. STATUS_SUCCESS on success + */ +PUBLIC_API STATUS addConfigToServerList(PRtcPeerConnection*, PIceConfigInfo); + /** * @brief Free a RtcPeerConnection * @@ -1649,6 +1659,16 @@ PUBLIC_API STATUS peerConnectionGetLocalDescription(PRtcPeerConnection, PRtcSess */ PUBLIC_API STATUS peerConnectionGetCurrentLocalDescription(PRtcPeerConnection, PRtcSessionDescriptionInit); +/** + * Allows use of internal threadpool + * + * @param[in] startRoutine function pointer to execute in threadpool + * @param[in] PVOID void pointer to pass to function pointer + * + * @return STATUS code of the execution. STATUS_SUCCESS on success + */ +PUBLIC_API STATUS peerConnectionAsync(startRoutine fn, PVOID data); + /** * @brief Populate the provided answer that contains an RFC 3264 offer * with the supported configurations for the session. diff --git a/src/source/Ice/IceAgent.c b/src/source/Ice/IceAgent.c index bd5adc8316..6d1a9ab0cf 100644 --- a/src/source/Ice/IceAgent.c +++ b/src/source/Ice/IceAgent.c @@ -262,6 +262,82 @@ STATUS freeIceAgent(PIceAgent* ppIceAgent) return retStatus; } +STATUS iceAgentAddConfig(PIceAgent pIceAgent, PIceConfigInfo pIceConfigInfo) +{ + STATUS retStatus = STATUS_SUCCESS; + UINT32 i = 0; + // used in PROFILE macro + UINT64 startTimeInMacro = 0; + BOOL locked = FALSE; + + CHK(pIceAgent != NULL && pIceConfigInfo != NULL, STATUS_NULL_ARG); + + for (i = 0; i < pIceConfigInfo->uriCount; i++) { + MUTEX_LOCK(pIceAgent->lock); + locked = TRUE; + PROFILE_CALL_WITH_T_OBJ(retStatus = parseIceServer(&pIceAgent->iceServers[pIceAgent->iceServersCount], (PCHAR) pIceConfigInfo->uris[i], + (PCHAR) pIceConfigInfo->userName, (PCHAR) pIceConfigInfo->password), + pIceAgent->iceAgentProfileDiagnostics.iceServerParsingTime[i], "ICE server parsing"); + MUTEX_UNLOCK(pIceAgent->lock); + locked = FALSE; + + if (STATUS_SUCCEEDED(retStatus)) { + MUTEX_LOCK(pIceAgent->lock); + locked = TRUE; + pIceAgent->rtcIceServerDiagnostics[i].port = (INT32) getInt16(pIceAgent->iceServers[i].ipAddress.port); + switch (pIceAgent->iceServers[pIceAgent->iceServersCount].transport) { + case KVS_SOCKET_PROTOCOL_UDP: + STRCPY(pIceAgent->rtcIceServerDiagnostics[i].protocol, ICE_TRANSPORT_TYPE_UDP); + break; + case KVS_SOCKET_PROTOCOL_TCP: + STRCPY(pIceAgent->rtcIceServerDiagnostics[i].protocol, ICE_TRANSPORT_TYPE_TCP); + break; + default: + MEMSET(pIceAgent->rtcIceServerDiagnostics[i].protocol, 0, SIZEOF(pIceAgent->rtcIceServerDiagnostics[i].protocol)); + } + STRCPY(pIceAgent->rtcIceServerDiagnostics[i].url, pIceConfigInfo->uris[i]); + + MUTEX_UNLOCK(pIceAgent->lock); + locked = FALSE; + + // important to unlock iceAgent lock before calling init relay candidate, since iceAgent APIs are thread safe + // if you don't unlock this can lead to a deadlock with the timerqueue. + // init candidate && pairs + if (pIceAgent->iceServers[pIceAgent->iceServersCount].isTurn) { + if (pIceAgent->iceServers[pIceAgent->iceServersCount].transport == KVS_SOCKET_PROTOCOL_UDP || + pIceAgent->iceServers[pIceAgent->iceServersCount].transport == KVS_SOCKET_PROTOCOL_NONE) { + CHK_STATUS(iceAgentInitRelayCandidate(pIceAgent, pIceAgent->iceServersCount, KVS_SOCKET_PROTOCOL_UDP)); + } + + if (pIceAgent->iceServers[pIceAgent->iceServersCount].transport == KVS_SOCKET_PROTOCOL_TCP || + pIceAgent->iceServers[pIceAgent->iceServersCount].transport == KVS_SOCKET_PROTOCOL_NONE) { + CHK_STATUS(iceAgentInitRelayCandidate(pIceAgent, pIceAgent->iceServersCount, KVS_SOCKET_PROTOCOL_TCP)); + } + } + + MUTEX_LOCK(pIceAgent->lock); + locked = TRUE; + + pIceAgent->iceServersCount++; + + MUTEX_UNLOCK(pIceAgent->lock); + locked = FALSE; + + } else { + DLOGE("Failed to parse ICE servers"); + } + } + +CleanUp: + CHK_LOG_ERR(retStatus); + + if (locked) { + MUTEX_UNLOCK(pIceAgent->lock); + } + + return retStatus; +} + STATUS iceAgentValidateKvsRtcConfig(PKvsRtcConfiguration pKvsRtcConfiguration) { STATUS retStatus = STATUS_SUCCESS; @@ -310,8 +386,6 @@ STATUS iceAgentReportNewLocalCandidate(PIceAgent pIceAgent, PIceCandidate pIceCa iceAgentLogNewCandidate(pIceCandidate); CHK_WARN(pIceAgent->iceAgentCallbacks.newLocalCandidateFn != NULL, retStatus, "newLocalCandidateFn callback not implemented"); - CHK_WARN(!ATOMIC_LOAD_BOOL(&pIceAgent->candidateGatheringFinished), retStatus, - "Cannot report new ice candidate because candidate gathering is already finished"); CHK_STATUS(iceCandidateSerialize(pIceCandidate, serializedIceCandidateBuf, &serializedIceCandidateBufLen)); pIceAgent->iceAgentCallbacks.newLocalCandidateFn(pIceAgent->iceAgentCallbacks.customData, serializedIceCandidateBuf); @@ -614,9 +688,6 @@ STATUS iceAgentStartGathering(PIceAgent pIceAgent) "Srflx candidates setup time"); } - PROFILE_CALL_WITH_T_OBJ(CHK_STATUS(iceAgentInitRelayCandidates(pIceAgent)), pIceAgent->iceAgentProfileDiagnostics.relayCandidateSetUpTime, - "Relay candidates setup time"); - // start listening for incoming data CHK_STATUS(connectionListenerStart(pIceAgent->pConnectionListener)); @@ -956,6 +1027,8 @@ STATUS iceAgentRestart(PIceAgent pIceAgent, PCHAR localIceUfrag, PCHAR localIceP CHK_STATUS(setStateMachineCurrentState(pIceAgent->pStateMachine, ICE_AGENT_STATE_NEW)); ATOMIC_STORE_BOOL(&pIceAgent->processStun, TRUE); + // this API does not reset servers, so re-initialize relay candidates now. + CHK_STATUS(iceAgentInitRelayCandidates(pIceAgent)); CleanUp: @@ -1857,16 +1930,17 @@ STATUS iceAgentInitRelayCandidate(PIceAgent pIceAgent, UINT32 iceServerIndex, KV callback.relayAddressAvailableFn = NULL; callback.turnStateFailedFn = turnStateFailedFn; + MUTEX_LOCK(pIceAgent->lock); + locked = TRUE; + CHK_STATUS(createTurnConnection(&pIceAgent->iceServers[iceServerIndex], pIceAgent->timerQueueHandle, TURN_CONNECTION_DATA_TRANSFER_MODE_SEND_INDIDATION, protocol, &callback, pNewCandidate->pSocketConnection, pIceAgent->pConnectionListener, &pTurnConnection)); pNewCandidate->pIceAgent = pIceAgent; pNewCandidate->pTurnConnection = pTurnConnection; - MUTEX_LOCK(pIceAgent->lock); - locked = TRUE; - CHK_STATUS(doubleListInsertItemHead(pIceAgent->localCandidates, (UINT64) pNewCandidate)); + CHK_STATUS(iceAgentReportNewLocalCandidate(pIceAgent, pNewCandidate)); pNewCandidate = NULL; /* add existing remote candidates to turn. Need to acquire lock because remoteCandidates can be mutated by diff --git a/src/source/Ice/IceAgent.h b/src/source/Ice/IceAgent.h index af94aa95ea..e0577dab2d 100644 --- a/src/source/Ice/IceAgent.h +++ b/src/source/Ice/IceAgent.h @@ -448,6 +448,8 @@ STATUS updateSelectedLocalRemoteCandidateStats(PIceAgent); STATUS getIceAgentStats(PIceAgent, PKvsIceAgentMetrics); +STATUS iceAgentAddConfig(PIceAgent, PIceConfigInfo); + #ifdef __cplusplus } #endif diff --git a/src/source/Ice/TurnConnectionStateMachine.c b/src/source/Ice/TurnConnectionStateMachine.c index 0bc54afd0b..268ce1da2d 100644 --- a/src/source/Ice/TurnConnectionStateMachine.c +++ b/src/source/Ice/TurnConnectionStateMachine.c @@ -364,7 +364,7 @@ STATUS executeAllocationTurnState(UINT64 customData, UINT64 time) pTurnConnection->state = TURN_STATE_ALLOCATION; } else { pTurnConnection->stateTryCount++; - CHK(pTurnConnection->stateTryCount < pTurnConnection->stateTryCountMax, STATUS_TURN_CONNECTION_ALLOCAITON_FAILED); + CHK(pTurnConnection->stateTryCount < pTurnConnection->stateTryCountMax, STATUS_TURN_CONNECTION_ALLOCATION_FAILED); } CHK_STATUS(iceUtilsSendStunPacket(pTurnConnection->pTurnPacket, pTurnConnection->longTermKey, ARRAY_SIZE(pTurnConnection->longTermKey), &pTurnConnection->turnServer.ipAddress, pTurnConnection->pControlChannel, NULL, FALSE)); diff --git a/src/source/Include_i.h b/src/source/Include_i.h index 9547012955..84fec5a69a 100644 --- a/src/source/Include_i.h +++ b/src/source/Include_i.h @@ -139,6 +139,11 @@ STATUS generateJSONSafeString(PCHAR, UINT32); #include "Ice/NatBehaviorDiscovery.h" #include "Srtp/SrtpSession.h" #include "Sctp/Sctp.h" +#include "Signaling/FileCache.h" +#include "Signaling/Signaling.h" +#include "Signaling/ChannelInfo.h" +#include "Signaling/StateMachine.h" +#include "Signaling/LwsApiCalls.h" #include "Rtp/RtpPacket.h" #include "Rtcp/RtcpPacket.h" #include "Rtcp/RollingBuffer.h" @@ -154,11 +159,6 @@ STATUS generateJSONSafeString(PCHAR, UINT32); #include "Rtp/Codecs/RtpH264Payloader.h" #include "Rtp/Codecs/RtpOpusPayloader.h" #include "Rtp/Codecs/RtpG711Payloader.h" -#include "Signaling/FileCache.h" -#include "Signaling/Signaling.h" -#include "Signaling/ChannelInfo.h" -#include "Signaling/StateMachine.h" -#include "Signaling/LwsApiCalls.h" #include "Metrics/Metrics.h" //////////////////////////////////////////////////// diff --git a/src/source/PeerConnection/PeerConnection.c b/src/source/PeerConnection/PeerConnection.c index 4091bf1b77..2588aceaa1 100644 --- a/src/source/PeerConnection/PeerConnection.c +++ b/src/source/PeerConnection/PeerConnection.c @@ -515,6 +515,15 @@ VOID onIceConnectionStateChange(UINT64 customData, UINT64 connectionState) CHK_LOG_ERR(retStatus); } +STATUS peerConnectionAsync(startRoutine fn, PVOID data) +{ + STATUS retStatus = STATUS_SUCCESS; + CHK_STATUS(threadpoolContextPush(fn, data)); +CleanUp: + + return retStatus; +} + VOID onNewIceLocalCandidate(UINT64 customData, PCHAR candidateSdpStr) { STATUS retStatus = STATUS_SUCCESS; @@ -1085,6 +1094,24 @@ STATUS peerConnectionOnIceCandidate(PRtcPeerConnection pRtcPeerConnection, UINT6 return retStatus; } +STATUS addConfigToServerList(PRtcPeerConnection* ppPeerConnection, PIceConfigInfo pIceConfigInfo) +{ + STATUS retStatus = STATUS_SUCCESS; + PKvsPeerConnection pKvsPeerConnection = NULL; + + CHK(ppPeerConnection != NULL && pIceConfigInfo != NULL, STATUS_NULL_ARG); + + pKvsPeerConnection = (PKvsPeerConnection) *ppPeerConnection; + + CHK(pKvsPeerConnection != NULL, STATUS_NULL_ARG); + + CHK_STATUS(iceAgentAddConfig(pKvsPeerConnection->pIceAgent, pIceConfigInfo)); + +CleanUp: + + return retStatus; +} + STATUS peerConnectionOnDataChannel(PRtcPeerConnection pRtcPeerConnection, UINT64 customData, RtcOnDataChannel rtcOnDataChannel) { ENTERS(); diff --git a/src/source/Signaling/StateMachine.c b/src/source/Signaling/StateMachine.c index 44462f2af7..5ac5046ee5 100644 --- a/src/source/Signaling/StateMachine.c +++ b/src/source/Signaling/StateMachine.c @@ -32,8 +32,9 @@ StateMachineState SIGNALING_STATE_MACHINE_STATES[] = { SIGNALING_STATE_GET_ICE_CONFIG, fromGetIceConfigSignalingState, executeGetIceConfigSignalingState, defaultSignalingStateTransitionHook, SIGNALING_STATES_DEFAULT_RETRY_COUNT, STATUS_SIGNALING_GET_ICE_CONFIG_CALL_FAILED}, - {SIGNALING_STATE_READY, SIGNALING_STATE_GET_ICE_CONFIG | SIGNALING_STATE_DISCONNECTED | SIGNALING_STATE_READY, fromReadySignalingState, - executeReadySignalingState, defaultSignalingStateTransitionHook, INFINITE_RETRY_COUNT_SENTINEL, STATUS_SIGNALING_READY_CALLBACK_FAILED}, + {SIGNALING_STATE_READY, SIGNALING_STATE_GET_ENDPOINT | SIGNALING_STATE_GET_ICE_CONFIG | SIGNALING_STATE_DISCONNECTED | SIGNALING_STATE_READY, + fromReadySignalingState, executeReadySignalingState, defaultSignalingStateTransitionHook, INFINITE_RETRY_COUNT_SENTINEL, + STATUS_SIGNALING_READY_CALLBACK_FAILED}, {SIGNALING_STATE_CONNECT, SIGNALING_STATE_READY | SIGNALING_STATE_DISCONNECTED | SIGNALING_STATE_CONNECTED | SIGNALING_STATE_CONNECT, fromConnectSignalingState, executeConnectSignalingState, defaultSignalingStateTransitionHook, INFINITE_RETRY_COUNT_SENTINEL, STATUS_SIGNALING_CONNECT_CALL_FAILED}, @@ -486,7 +487,7 @@ STATUS fromGetEndpointSignalingState(UINT64 customData, PUINT64 pState) result = ATOMIC_LOAD(&pSignalingClient->result); switch (result) { case SERVICE_CALL_RESULT_OK: - state = SIGNALING_STATE_GET_ICE_CONFIG; + state = SIGNALING_STATE_READY; break; case SERVICE_CALL_FORBIDDEN: diff --git a/tst/IceFunctionalityTest.cpp b/tst/IceFunctionalityTest.cpp index 6ab40aa894..8693f8711c 100644 --- a/tst/IceFunctionalityTest.cpp +++ b/tst/IceFunctionalityTest.cpp @@ -6,8 +6,7 @@ namespace kinesis { namespace video { namespace webrtcclient { -class IceFunctionalityTest : public WebRtcClientTestBase { -}; +class IceFunctionalityTest : public WebRtcClientTestBase {}; // check if iceCandidatePairs is in descending order BOOL candidatePairsInOrder(PDoubleList iceCandidatePairs) @@ -135,7 +134,7 @@ PVOID connectionListenAddConnectionRoutine(PVOID arg) } for (i = 0; i < pCustomData->connectionToAdd; ++i) { - randomDelay = (UINT64)(RAND() % 300) * HUNDREDS_OF_NANOS_IN_A_MILLISECOND; + randomDelay = (UINT64) (RAND() % 300) * HUNDREDS_OF_NANOS_IN_A_MILLISECOND; THREAD_SLEEP(randomDelay); CHECK(STATUS_SUCCEEDED(createSocketConnection((KVS_IP_FAMILY_TYPE) localhost.family, KVS_SOCKET_PROTOCOL_UDP, &localhost, NULL, 0, NULL, 0, &pSocketConnection))); @@ -151,7 +150,7 @@ TEST_F(IceFunctionalityTest, connectionListenerFunctionalityTest) PConnectionListener pConnectionListener; ConnectionListenerTestCustomData routine1CustomData, routine2CustomData; TID routine1, routine2; - UINT32 connectionCount , newConnectionCount, i; + UINT32 connectionCount, newConnectionCount, i; PSocketConnection pSocketConnection = NULL; KvsIpAddress localhost; TID threadId; @@ -203,7 +202,7 @@ TEST_F(IceFunctionalityTest, connectionListenerFunctionalityTest) MUTEX_LOCK(pConnectionListener->lock); threadId = pConnectionListener->receiveDataRoutine; MUTEX_UNLOCK(pConnectionListener->lock); - EXPECT_TRUE( IS_VALID_TID_VALUE(threadId)); + EXPECT_TRUE(IS_VALID_TID_VALUE(threadId)); ATOMIC_STORE_BOOL(&pConnectionListener->terminate, TRUE); THREAD_JOIN(threadId, NULL); @@ -359,7 +358,7 @@ TEST_F(IceFunctionalityTest, IceAgentAddRemoteCandidateUnitTest) EXPECT_EQ(STATUS_SUCCESS, doubleListGetHeadNode(iceAgent.remoteCandidates, &pCurNode)); // parsing candidate priority correctly - EXPECT_EQ(2122260223, ((PIceCandidate)pCurNode->data)->priority); + EXPECT_EQ(2122260223, ((PIceCandidate) pCurNode->data)->priority); // candidate pair formed EXPECT_EQ(STATUS_SUCCESS, doubleListGetNodeCount(iceAgent.iceCandidatePairs, &iceCandidateCount)); @@ -378,7 +377,7 @@ TEST_F(IceFunctionalityTest, IceAgentAddRemoteCandidateUnitTest) // parsing candidate priority correctly EXPECT_EQ(STATUS_SUCCESS, doubleListGetHeadNode(iceAgent.remoteCandidates, &pCurNode)); - EXPECT_EQ(2122262783, ((PIceCandidate)pCurNode->data)->priority); + EXPECT_EQ(2122262783, ((PIceCandidate) pCurNode->data)->priority); iceAgent.iceAgentState = ICE_AGENT_STATE_CHECK_CONNECTION; EXPECT_EQ(STATUS_SUCCESS, iceAgentAddRemoteCandidate(&iceAgent, relayCandidateStr)); @@ -390,7 +389,7 @@ TEST_F(IceFunctionalityTest, IceAgentAddRemoteCandidateUnitTest) EXPECT_EQ(STATUS_SUCCESS, doubleListGetHeadNode(iceAgent.remoteCandidates, &pCurNode)); // parsing candidate priority correctly - EXPECT_EQ(41885439, ((PIceCandidate)pCurNode->data)->priority); + EXPECT_EQ(41885439, ((PIceCandidate) pCurNode->data)->priority); MUTEX_FREE(iceAgent.lock); EXPECT_EQ(STATUS_SUCCESS, doubleListGetHeadNode(iceAgent.iceCandidatePairs, &pCurNode)); @@ -663,7 +662,9 @@ TEST_F(IceFunctionalityTest, IceAgentCandidateGatheringTest) MEMSET(&iceAgentCallbacks, 0x00, SIZEOF(IceAgentCallbacks)); initializeSignalingClient(); - getIceServers(&configuration); + + SNPRINTF(configuration.iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, KINESIS_VIDEO_STUN_URL, TEST_DEFAULT_REGION, + TEST_DEFAULT_STUN_URL_POSTFIX); auto onICECandidateHdlr = [](UINT64 customData, PCHAR candidateStr) -> void { CandidateList* candidateList1 = (CandidateList*) customData; @@ -679,6 +680,9 @@ TEST_F(IceFunctionalityTest, IceAgentCandidateGatheringTest) iceAgentCallbacks.customData = (UINT64) &candidateList; iceAgentCallbacks.newLocalCandidateFn = onICECandidateHdlr; + // Set the STUN server + SNPRINTF(configuration.iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, KINESIS_VIDEO_STUN_URL, TEST_DEFAULT_REGION, TEST_DEFAULT_STUN_URL_POSTFIX); + EXPECT_EQ(STATUS_SUCCESS, generateJSONSafeString(localIceUfrag, LOCAL_ICE_UFRAG_LEN)); EXPECT_EQ(STATUS_SUCCESS, generateJSONSafeString(localIcePwd, LOCAL_ICE_PWD_LEN)); EXPECT_EQ(STATUS_SUCCESS, createConnectionListener(&pConnectionListener)); @@ -687,12 +691,11 @@ TEST_F(IceFunctionalityTest, IceAgentCandidateGatheringTest) createIceAgent(localIceUfrag, localIcePwd, &iceAgentCallbacks, &configuration, timerQueueHandle, pConnectionListener, &pIceAgent)); EXPECT_EQ(STATUS_SUCCESS, iceAgentStartGathering(pIceAgent)); + getIceServers(&configuration, pIceAgent); THREAD_SLEEP(KVS_ICE_GATHER_REFLEXIVE_AND_RELAYED_CANDIDATE_TIMEOUT + 2 * HUNDREDS_OF_NANOS_IN_A_SECOND); - // newLocalCandidateFn should've returned null in its last invocation, which was converted to empty string candidateList.lock.lock(); - EXPECT_TRUE(candidateList.list[candidateList.list.size() - 1].empty()); for (std::vector::iterator it = candidateList.list.begin(); it != candidateList.list.end(); ++it) { std::string candidateStr = *it; diff --git a/tst/PeerConnectionApiTest.cpp b/tst/PeerConnectionApiTest.cpp index 180933a8c9..d2cd4be672 100644 --- a/tst/PeerConnectionApiTest.cpp +++ b/tst/PeerConnectionApiTest.cpp @@ -6,8 +6,7 @@ namespace kinesis { namespace video { namespace webrtcclient { -class PeerConnectionApiTest : public WebRtcClientTestBase { -}; +class PeerConnectionApiTest : public WebRtcClientTestBase {}; TEST_F(PeerConnectionApiTest, deserializeRtcIceCandidateInit) { @@ -198,6 +197,20 @@ TEST_F(PeerConnectionApiTest, connectionState) freePeerConnection(&pc); } +TEST_F(PeerConnectionApiTest, addConfigToServerListUnitTest) +{ + PRtcPeerConnection pc = nullptr; + PIceConfigInfo pIceConfigInfo = nullptr; + RtcConfiguration config{}; + EXPECT_NE(STATUS_SUCCESS, addConfigToServerList(&pc, pIceConfigInfo)); + EXPECT_EQ(STATUS_SUCCESS, createPeerConnection(&config, &pc)); + + EXPECT_NE(STATUS_SUCCESS, addConfigToServerList(&pc, pIceConfigInfo)); + + closePeerConnection(pc); + freePeerConnection(&pc); +} + } // namespace webrtcclient } // namespace video } // namespace kinesis diff --git a/tst/PeerConnectionFunctionalityTest.cpp b/tst/PeerConnectionFunctionalityTest.cpp index ace56788d2..ec74af611d 100644 --- a/tst/PeerConnectionFunctionalityTest.cpp +++ b/tst/PeerConnectionFunctionalityTest.cpp @@ -6,8 +6,7 @@ namespace kinesis { namespace video { namespace webrtcclient { -class PeerConnectionFunctionalityTest : public WebRtcClientTestBase { -}; +class PeerConnectionFunctionalityTest : public WebRtcClientTestBase {}; // Assert that two PeerConnections can connect to each other and go to connected TEST_F(PeerConnectionFunctionalityTest, connectTwoPeers) @@ -29,6 +28,32 @@ TEST_F(PeerConnectionFunctionalityTest, connectTwoPeers) freePeerConnection(&answerPc); } +TEST_F(PeerConnectionFunctionalityTest, connectTwoPeersWithAsyncGetIceConfigForceTurn) +{ + RtcConfiguration configuration; + PRtcPeerConnection offerPc = NULL, answerPc = NULL; + + MEMSET(&configuration, 0x00, SIZEOF(RtcConfiguration)); + SNPRINTF(configuration.iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, KINESIS_VIDEO_STUN_URL, TEST_DEFAULT_REGION, + TEST_DEFAULT_STUN_URL_POSTFIX); + configuration.iceTransportPolicy = ICE_TRANSPORT_POLICY_RELAY; + + initializeSignalingClient(); + + EXPECT_EQ(createPeerConnection(&configuration, &offerPc), STATUS_SUCCESS); + EXPECT_EQ(createPeerConnection(&configuration, &answerPc), STATUS_SUCCESS); + + EXPECT_EQ(connectTwoPeersAsyncIce(offerPc, answerPc), TRUE); + + closePeerConnection(offerPc); + closePeerConnection(answerPc); + + freePeerConnection(&offerPc); + freePeerConnection(&answerPc); + + deinitializeSignalingClient(); +} + TEST_F(PeerConnectionFunctionalityTest, connectTwoPeersWithDelay) { RtcConfiguration configuration; @@ -198,11 +223,13 @@ TEST_F(PeerConnectionFunctionalityTest, connectTwoPeersForcedTURN) configuration.iceTransportPolicy = ICE_TRANSPORT_POLICY_RELAY; initializeSignalingClient(); - getIceServers(&configuration); EXPECT_EQ(createPeerConnection(&configuration, &offerPc), STATUS_SUCCESS); EXPECT_EQ(createPeerConnection(&configuration, &answerPc), STATUS_SUCCESS); + getIceServers(&configuration, offerPc); + getIceServers(&configuration, answerPc); + EXPECT_EQ(connectTwoPeers(offerPc, answerPc), TRUE); closePeerConnection(offerPc); @@ -292,10 +319,11 @@ TEST_F(PeerConnectionFunctionalityTest, sendDataWithClosedSocketConnectionWithFo configuration.iceTransportPolicy = ICE_TRANSPORT_POLICY_RELAY; initializeSignalingClient(); - getIceServers(&configuration); EXPECT_EQ(createPeerConnection(&configuration, &offerPc), STATUS_SUCCESS); EXPECT_EQ(createPeerConnection(&configuration, &answerPc), STATUS_SUCCESS); + getIceServers(&configuration, offerPc); + getIceServers(&configuration, answerPc); // addTrackToPeerConnection is necessary because we need to add a transceiver which will trigger the RTCP callback. The RTCP callback // will send application data. The expected behavior for the PeerConnection is to bail out when the socket connection that's being used @@ -354,11 +382,13 @@ TEST_F(PeerConnectionFunctionalityTest, shutdownTurnDueToP2PFoundBeforeTurnEstab MEMSET(&configuration, 0x00, SIZEOF(RtcConfiguration)); initializeSignalingClient(); - getIceServers(&configuration); EXPECT_EQ(createPeerConnection(&configuration, &offerPc), STATUS_SUCCESS); EXPECT_EQ(createPeerConnection(&configuration, &answerPc), STATUS_SUCCESS); + getIceServers(&configuration, offerPc); + getIceServers(&configuration, answerPc); + EXPECT_EQ(connectTwoPeers(offerPc, answerPc), TRUE); THREAD_SLEEP(5 * HUNDREDS_OF_NANOS_IN_A_SECOND); @@ -416,11 +446,13 @@ TEST_F(PeerConnectionFunctionalityTest, shutdownTurnDueToP2PFoundAfterTurnEstabl MEMSET(&configuration, 0x00, SIZEOF(RtcConfiguration)); initializeSignalingClient(); - getIceServers(&configuration); EXPECT_EQ(createPeerConnection(&configuration, &offerPc), STATUS_SUCCESS); EXPECT_EQ(createPeerConnection(&configuration, &answerPc), STATUS_SUCCESS); + getIceServers(&configuration, offerPc); + getIceServers(&configuration, answerPc); + auto onICECandidateHdlr = [](UINT64 customData, PCHAR candidateStr) -> void { PSIZE_T pDoneGatherCandidate = (PSIZE_T) customData; if (candidateStr == NULL) { @@ -860,11 +892,13 @@ TEST_F(PeerConnectionFunctionalityTest, iceRestartTestForcedTurn) configuration.iceTransportPolicy = ICE_TRANSPORT_POLICY_RELAY; initializeSignalingClient(); - getIceServers(&configuration); EXPECT_EQ(createPeerConnection(&configuration, &offerPc), STATUS_SUCCESS); EXPECT_EQ(createPeerConnection(&configuration, &answerPc), STATUS_SUCCESS); + getIceServers(&configuration, offerPc); + getIceServers(&configuration, answerPc); + EXPECT_EQ(connectTwoPeers(offerPc, answerPc), TRUE); EXPECT_EQ(restartIce(offerPc), STATUS_SUCCESS); @@ -893,11 +927,13 @@ TEST_F(PeerConnectionFunctionalityTest, peerConnectionOfferCloseConnection) MEMSET(&configuration, 0x00, SIZEOF(RtcConfiguration)); initializeSignalingClient(); - getIceServers(&configuration); EXPECT_EQ(createPeerConnection(&configuration, &offerPc), STATUS_SUCCESS); EXPECT_EQ(createPeerConnection(&configuration, &answerPc), STATUS_SUCCESS); + getIceServers(&configuration, offerPc); + getIceServers(&configuration, answerPc); + EXPECT_EQ(connectTwoPeers(offerPc, answerPc), TRUE); closePeerConnection(offerPc); @@ -919,11 +955,13 @@ TEST_F(PeerConnectionFunctionalityTest, peerConnectionAnswerCloseConnection) MEMSET(&configuration, 0x00, SIZEOF(RtcConfiguration)); initializeSignalingClient(); - getIceServers(&configuration); EXPECT_EQ(createPeerConnection(&configuration, &offerPc), STATUS_SUCCESS); EXPECT_EQ(createPeerConnection(&configuration, &answerPc), STATUS_SUCCESS); + getIceServers(&configuration, offerPc); + getIceServers(&configuration, answerPc); + EXPECT_EQ(connectTwoPeers(offerPc, answerPc), TRUE); closePeerConnection(answerPc); @@ -960,11 +998,13 @@ TEST_F(PeerConnectionFunctionalityTest, DISABLED_exchangeMediaThroughTurnRandomS for (int i = 0; i < iteration; ++i) { MEMSET(&configuration, 0x00, SIZEOF(RtcConfiguration)); configuration.iceTransportPolicy = ICE_TRANSPORT_POLICY_RELAY; - getIceServers(&configuration); EXPECT_EQ(createPeerConnection(&configuration, &offerPc), STATUS_SUCCESS); EXPECT_EQ(createPeerConnection(&configuration, &answerPc), STATUS_SUCCESS); + getIceServers(&configuration, offerPc); + getIceServers(&configuration, answerPc); + addTrackToPeerConnection(offerPc, &offerVideoTrack, &offerVideoTransceiver, RTC_CODEC_VP8, MEDIA_STREAM_TRACK_KIND_VIDEO); addTrackToPeerConnection(offerPc, &offerAudioTrack, &offerAudioTransceiver, RTC_CODEC_OPUS, MEDIA_STREAM_TRACK_KIND_AUDIO); addTrackToPeerConnection(answerPc, &answerVideoTrack, &answerVideoTransceiver, RTC_CODEC_VP8, MEDIA_STREAM_TRACK_KIND_VIDEO); @@ -980,7 +1020,7 @@ TEST_F(PeerConnectionFunctionalityTest, DISABLED_exchangeMediaThroughTurnRandomS MEMSET(stateChangeCount, 0x00, SIZEOF(stateChangeCount)); EXPECT_EQ(connectTwoPeers(offerPc, answerPc), TRUE); - streamingTimeMs = (UINT64)(RAND() % (maxStreamingDurationMs - minStreamingDurationMs)) + minStreamingDurationMs; + streamingTimeMs = (UINT64) (RAND() % (maxStreamingDurationMs - minStreamingDurationMs)) + minStreamingDurationMs; DLOGI("Stop streaming after %u milliseconds.", streamingTimeMs); auto sendVideoWorker = [](PRtcRtpTransceiver pRtcRtpTransceiver, Frame frame, PSIZE_T pTerminationFlag) -> void { @@ -1022,17 +1062,17 @@ TEST_F(PeerConnectionFunctionalityTest, DISABLED_exchangeMediaThroughTurnRandomS deinitializeSignalingClient(); } -//Check that even when multiple successful candidate pairs are found, only one dtls negotiation takes place -//and that it is on the same candidate throughout the connection. +// Check that even when multiple successful candidate pairs are found, only one dtls negotiation takes place +// and that it is on the same candidate throughout the connection. TEST_F(PeerConnectionFunctionalityTest, multipleCandidateSuccessOneDTLSCheck) { RtcConfiguration configuration; PRtcPeerConnection offerPc = NULL, answerPc = NULL; - //This test can succeed if the highest priority candidate pair happens to be the first one - //to be nominated, even if the DTLS is broken. To be sure that this issue is fixed we want to - //run the test 10 times and have it never break once in that cycle. - for(auto i = 0; i < 10; i++) { + // This test can succeed if the highest priority candidate pair happens to be the first one + // to be nominated, even if the DTLS is broken. To be sure that this issue is fixed we want to + // run the test 10 times and have it never break once in that cycle. + for (auto i = 0; i < 10; i++) { offerPc = NULL; answerPc = NULL; MEMSET(&configuration, 0x00, SIZEOF(RtcConfiguration)); @@ -1040,23 +1080,23 @@ TEST_F(PeerConnectionFunctionalityTest, multipleCandidateSuccessOneDTLSCheck) EXPECT_EQ(createPeerConnection(&configuration, &offerPc), STATUS_SUCCESS); EXPECT_EQ(createPeerConnection(&configuration, &answerPc), STATUS_SUCCESS); - //create a callback that can check values at every state of the ice agent state machine + // create a callback that can check values at every state of the ice agent state machine auto masterOnIceConnectionStateChangeTest = [](UINT64 customData, UINT64 connectionState) -> void { static PIceCandidatePair pSendingPair; PKvsPeerConnection pKvsPeerConnection = (PKvsPeerConnection) customData; - //still use normal callback + // still use normal callback onIceConnectionStateChange(customData, connectionState); - switch(connectionState) { + switch (connectionState) { case ICE_AGENT_STATE_CHECK_CONNECTION: - //sleep(1); + // sleep(1); break; case ICE_AGENT_STATE_CONNECTED: - if(pKvsPeerConnection->pIceAgent->pDataSendingIceCandidatePair != NULL) { + if (pKvsPeerConnection->pIceAgent->pDataSendingIceCandidatePair != NULL) { pSendingPair = pKvsPeerConnection->pIceAgent->pDataSendingIceCandidatePair; } break; case ICE_AGENT_STATE_READY: - if(pSendingPair != NULL) { + if (pSendingPair != NULL) { EXPECT_EQ(pSendingPair, pKvsPeerConnection->pIceAgent->pDataSendingIceCandidatePair); pSendingPair = NULL; } @@ -1072,11 +1112,11 @@ TEST_F(PeerConnectionFunctionalityTest, multipleCandidateSuccessOneDTLSCheck) PDoubleListNode pCurNode = NULL; PIceCandidatePair pIceCandidatePair; BOOL locked = FALSE; - //still use normal callback + // still use normal callback onIceConnectionStateChange(customData, connectionState); - switch(connectionState) { + switch (connectionState) { case ICE_AGENT_STATE_CONNECTED: - //send 'USE_CANDIDATE' for every ice candidate pair + // send 'USE_CANDIDATE' for every ice candidate pair MUTEX_LOCK(pIceAgent->lock); locked = TRUE; doubleListGetHeadNode(pIceAgent->iceCandidatePairs, &pCurNode); @@ -1096,9 +1136,9 @@ TEST_F(PeerConnectionFunctionalityTest, multipleCandidateSuccessOneDTLSCheck) } }; - //overwrite normal callback - ((PKvsPeerConnection)answerPc)->pIceAgent->iceAgentCallbacks.connectionStateChangedFn = masterOnIceConnectionStateChangeTest; - ((PKvsPeerConnection)offerPc)->pIceAgent->iceAgentCallbacks.connectionStateChangedFn = viewerOnIceConnectionStateChangeTest; + // overwrite normal callback + ((PKvsPeerConnection) answerPc)->pIceAgent->iceAgentCallbacks.connectionStateChangedFn = masterOnIceConnectionStateChangeTest; + ((PKvsPeerConnection) offerPc)->pIceAgent->iceAgentCallbacks.connectionStateChangedFn = viewerOnIceConnectionStateChangeTest; EXPECT_EQ(connectTwoPeers(offerPc, answerPc), TRUE); @@ -1107,25 +1147,25 @@ TEST_F(PeerConnectionFunctionalityTest, multipleCandidateSuccessOneDTLSCheck) freePeerConnection(&offerPc); freePeerConnection(&answerPc); - MEMSET(this->stateChangeCount, 0, SIZEOF(SIZE_T)*RTC_PEER_CONNECTION_TOTAL_STATE_COUNT); - if(::testing::Test::HasFailure()) { + MEMSET(this->stateChangeCount, 0, SIZEOF(SIZE_T) * RTC_PEER_CONNECTION_TOTAL_STATE_COUNT); + if (::testing::Test::HasFailure()) { break; } } } -//Check that even when multiple successful candidate pairs are found, only one dtls negotiation takes place -//and that it is on the same candidate throughout the connection. This time setting the viewer to use -//aggressive nomination +// Check that even when multiple successful candidate pairs are found, only one dtls negotiation takes place +// and that it is on the same candidate throughout the connection. This time setting the viewer to use +// aggressive nomination TEST_F(PeerConnectionFunctionalityTest, aggressiveNominationDTLSRaceConditionCheck) { RtcConfiguration configuration; PRtcPeerConnection offerPc = NULL, answerPc = NULL; - //This test can succeed if the highest priority candidate pair happens to be the first one - //to be nominated, even if the DTLS is broken. To be sure that this issue is fixed we want to - //run the test 10 times and have it never break once in that cycle. - for(auto i = 0; i < 10; i++) { + // This test can succeed if the highest priority candidate pair happens to be the first one + // to be nominated, even if the DTLS is broken. To be sure that this issue is fixed we want to + // run the test 10 times and have it never break once in that cycle. + for (auto i = 0; i < 10; i++) { offerPc = NULL; answerPc = NULL; MEMSET(&configuration, 0x00, SIZEOF(RtcConfiguration)); @@ -1133,23 +1173,23 @@ TEST_F(PeerConnectionFunctionalityTest, aggressiveNominationDTLSRaceConditionChe EXPECT_EQ(createPeerConnection(&configuration, &offerPc), STATUS_SUCCESS); EXPECT_EQ(createPeerConnection(&configuration, &answerPc), STATUS_SUCCESS); - //create a callback that can check values at every state of the ice agent state machine + // create a callback that can check values at every state of the ice agent state machine auto masterOnIceConnectionStateChangeTest = [](UINT64 customData, UINT64 connectionState) -> void { static PIceCandidatePair pSendingPair; PKvsPeerConnection pKvsPeerConnection = (PKvsPeerConnection) customData; - //still use normal callback + // still use normal callback onIceConnectionStateChange(customData, connectionState); - switch(connectionState) { + switch (connectionState) { case ICE_AGENT_STATE_CHECK_CONNECTION: - //sleep(1); + // sleep(1); break; case ICE_AGENT_STATE_CONNECTED: - if(pKvsPeerConnection->pIceAgent->pDataSendingIceCandidatePair != NULL) { + if (pKvsPeerConnection->pIceAgent->pDataSendingIceCandidatePair != NULL) { pSendingPair = pKvsPeerConnection->pIceAgent->pDataSendingIceCandidatePair; } break; case ICE_AGENT_STATE_READY: - if(pSendingPair != NULL) { + if (pSendingPair != NULL) { EXPECT_EQ(pSendingPair, pKvsPeerConnection->pIceAgent->pDataSendingIceCandidatePair); pSendingPair = NULL; } @@ -1166,13 +1206,13 @@ TEST_F(PeerConnectionFunctionalityTest, aggressiveNominationDTLSRaceConditionChe PDoubleListNode pCurNode = NULL; PIceCandidatePair pIceCandidatePair; BOOL locked = FALSE; - //still use normal callback + // still use normal callback onIceConnectionStateChange(customData, connectionState); - switch(connectionState) { + switch (connectionState) { case ICE_AGENT_STATE_CHECK_CONNECTION: MUTEX_LOCK(pIceAgent->lock); locked = TRUE; - if(!setUseCandidate) { + if (!setUseCandidate) { setUseCandidate = TRUE; appendStunFlagAttribute(pIceAgent->pBindingRequest, STUN_ATTRIBUTE_TYPE_USE_CANDIDATE); } @@ -1189,7 +1229,7 @@ TEST_F(PeerConnectionFunctionalityTest, aggressiveNominationDTLSRaceConditionChe } break; case ICE_AGENT_STATE_CONNECTED: - //send 'USE_CANDIDATE' for every ice candidate pair + // send 'USE_CANDIDATE' for every ice candidate pair setUseCandidate = FALSE; MUTEX_LOCK(pIceAgent->lock); locked = TRUE; @@ -1210,9 +1250,9 @@ TEST_F(PeerConnectionFunctionalityTest, aggressiveNominationDTLSRaceConditionChe } }; - //overwrite normal callback - ((PKvsPeerConnection)answerPc)->pIceAgent->iceAgentCallbacks.connectionStateChangedFn = masterOnIceConnectionStateChangeTest; - ((PKvsPeerConnection)offerPc)->pIceAgent->iceAgentCallbacks.connectionStateChangedFn = viewerOnIceConnectionStateChangeTest; + // overwrite normal callback + ((PKvsPeerConnection) answerPc)->pIceAgent->iceAgentCallbacks.connectionStateChangedFn = masterOnIceConnectionStateChangeTest; + ((PKvsPeerConnection) offerPc)->pIceAgent->iceAgentCallbacks.connectionStateChangedFn = viewerOnIceConnectionStateChangeTest; EXPECT_EQ(connectTwoPeers(offerPc, answerPc), TRUE); @@ -1221,14 +1261,13 @@ TEST_F(PeerConnectionFunctionalityTest, aggressiveNominationDTLSRaceConditionChe freePeerConnection(&offerPc); freePeerConnection(&answerPc); - MEMSET(this->stateChangeCount, 0, SIZEOF(SIZE_T)*RTC_PEER_CONNECTION_TOTAL_STATE_COUNT); - if(::testing::Test::HasFailure()) { + MEMSET(this->stateChangeCount, 0, SIZEOF(SIZE_T) * RTC_PEER_CONNECTION_TOTAL_STATE_COUNT); + if (::testing::Test::HasFailure()) { break; } } } - } // namespace webrtcclient } // namespace video } // namespace kinesis diff --git a/tst/SignalingApiFunctionalityTest.cpp b/tst/SignalingApiFunctionalityTest.cpp index 9990f5a361..9d5ed74219 100644 --- a/tst/SignalingApiFunctionalityTest.cpp +++ b/tst/SignalingApiFunctionalityTest.cpp @@ -973,14 +973,14 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshNotConnectedVariatio EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); - // The ICE api should have been called - EXPECT_EQ(1, getIceConfigCount); + // The ICE api shouldn't have been called + EXPECT_EQ(0, getIceConfigCount); // Ensure we can get the ICE configurations EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfoCount(signalingHandle, &iceCount)); @@ -988,7 +988,7 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshNotConnectedVariatio for (i = 0; i < iceCount; i++) { EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfo(signalingHandle, i, &pIceConfigInfo)); } - // Make sure no APIs have been called + // Make sure APIs have been called EXPECT_EQ(1, getIceConfigCount); // Other state transacted @@ -998,7 +998,7 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshNotConnectedVariatio EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); + EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); @@ -1035,7 +1035,7 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshNotConnectedVariatio EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); - EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); + EXPECT_EQ(3, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); @@ -1071,7 +1071,7 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshNotConnectedVariatio EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); EXPECT_EQ(3, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); - EXPECT_EQ(3, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); + EXPECT_EQ(4, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); @@ -1108,7 +1108,7 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshNotConnectedVariatio EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); EXPECT_EQ(4, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); - EXPECT_EQ(4, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); + EXPECT_EQ(5, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); @@ -1143,7 +1143,7 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshNotConnectedVariatio EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); EXPECT_EQ(5, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); - EXPECT_EQ(5, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); + EXPECT_EQ(6, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); @@ -1237,14 +1237,14 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshConnectedVariations) EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); - // The ICE api should have been called - EXPECT_EQ(1, getIceConfigCount); + // The ICE api shouldn't have been called + EXPECT_EQ(0, getIceConfigCount); // Ensure we can get the ICE configurations EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfoCount(signalingHandle, &iceCount)); @@ -1263,9 +1263,9 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshConnectedVariations) EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); + EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); + EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); + EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); @@ -1300,9 +1300,9 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshConnectedVariations) EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); - EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); - EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); - EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); + EXPECT_EQ(3, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); + EXPECT_EQ(3, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); + EXPECT_EQ(3, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); @@ -1336,9 +1336,9 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshConnectedVariations) EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); EXPECT_EQ(3, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); - EXPECT_EQ(3, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); - EXPECT_EQ(3, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); - EXPECT_EQ(3, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); + EXPECT_EQ(4, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); + EXPECT_EQ(4, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); + EXPECT_EQ(4, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); @@ -1373,9 +1373,9 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshConnectedVariations) EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); EXPECT_EQ(4, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); - EXPECT_EQ(4, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); - EXPECT_EQ(4, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); - EXPECT_EQ(4, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); + EXPECT_EQ(5, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); + EXPECT_EQ(5, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); + EXPECT_EQ(5, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); // @@ -1408,9 +1408,9 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshConnectedVariations) EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); EXPECT_EQ(5, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); - EXPECT_EQ(5, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); - EXPECT_EQ(5, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); - EXPECT_EQ(5, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); + EXPECT_EQ(6, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); + EXPECT_EQ(6, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); + EXPECT_EQ(6, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); // @@ -1488,12 +1488,30 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshNotConnectedAuthExpi EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); + //get config + EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfoCount(signalingHandle, &iceCount)); + EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfo(signalingHandle, 0, &pIceConfigInfo)); + EXPECT_NE(0, iceCount); + EXPECT_NE((UINT64) NULL, (UINT64) pIceConfigInfo); + + // Check the states first + EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_NEW]); + EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_CREDENTIALS]); + EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); + EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); + EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); + EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); + EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); + EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); + EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); + // Make sure the credentials expire THREAD_SLEEP(7 * HUNDREDS_OF_NANOS_IN_A_SECOND); @@ -1520,7 +1538,7 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshNotConnectedAuthExpi EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); EXPECT_EQ(3, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); + EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); @@ -1537,7 +1555,7 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshNotConnectedAuthExpi EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); EXPECT_EQ(4, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); - EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); + EXPECT_EQ(3, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); @@ -1612,12 +1630,31 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshConnectedAuthExpirat EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); + //get config before credentials expire + EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfoCount(signalingHandle, &iceCount)); + EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfo(signalingHandle, 0, &pIceConfigInfo)); + EXPECT_NE(0, iceCount); + EXPECT_NE((UINT64) NULL, (UINT64) pIceConfigInfo); + + // Check the states first + EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_NEW]); + EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_CREDENTIALS]); + EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); + EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); + EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); + EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); + EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); + EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); + EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); + + // Make sure the credentials expire THREAD_SLEEP(7 * HUNDREDS_OF_NANOS_IN_A_SECOND); @@ -1644,9 +1681,9 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshConnectedAuthExpirat EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); EXPECT_EQ(3, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); + EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); + EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); + EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); // Attempt to retrieve the ice configuration should succeed @@ -1661,9 +1698,9 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshConnectedAuthExpirat EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); EXPECT_EQ(4, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); - EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); - EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); - EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); + EXPECT_EQ(3, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); + EXPECT_EQ(3, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); + EXPECT_EQ(3, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); // We should have already been connected. This should be a No-op @@ -1737,7 +1774,7 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshNotConnectedWithFaul EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); @@ -1756,7 +1793,7 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshNotConnectedWithFaul EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); @@ -1769,7 +1806,7 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshNotConnectedWithFaul EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); @@ -1852,7 +1889,7 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshConnectedWithFaultIn EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); @@ -1867,14 +1904,13 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshConnectedWithFaultIn EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); // Trigger the ICE refresh on the next call - pSignalingClient->iceConfigCount = 0; EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfoCount(signalingHandle, &iceCount)); EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfo(signalingHandle, 0, &pIceConfigInfo)); EXPECT_NE(0, iceCount); @@ -1886,7 +1922,7 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshConnectedWithFaultIn EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); @@ -1961,6 +1997,8 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshNotConnectedWithFaul EXPECT_TRUE(IS_VALID_SIGNALING_CLIENT_HANDLE(signalingHandle)); EXPECT_EQ(STATUS_SUCCESS,signalingClientFetchSync(signalingHandle)); + EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfoCount(signalingHandle, &iceCount)); + EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfo(signalingHandle, 0, &pIceConfigInfo)); pActiveClient = pSignalingClient; // Check the states first @@ -1970,7 +2008,7 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshNotConnectedWithFaul EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); + EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); @@ -1987,7 +2025,7 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshNotConnectedWithFaul EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); EXPECT_LT(4, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); + EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); @@ -2000,7 +2038,7 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshNotConnectedWithFaul EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); EXPECT_LT(4, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); + EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); @@ -2075,6 +2113,8 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshConnectedWithFaultIn EXPECT_EQ(STATUS_SUCCESS,signalingClientFetchSync(signalingHandle)); pActiveClient = pSignalingClient; + EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfoCount(signalingHandle, &iceCount)); + EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfo(signalingHandle, 0, &pIceConfigInfo)); // Connect first EXPECT_EQ(STATUS_SUCCESS, signalingClientConnectSync(signalingHandle)); @@ -2086,7 +2126,7 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshConnectedWithFaultIn EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); + EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); @@ -2103,7 +2143,7 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshConnectedWithFaultIn EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); EXPECT_LT(4, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); + EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); @@ -2116,7 +2156,7 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshConnectedWithFaultIn EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); EXPECT_LT(4, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); + EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); @@ -2183,6 +2223,10 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshNotConnectedWithBadA EXPECT_TRUE(IS_VALID_SIGNALING_CLIENT_HANDLE(signalingHandle)); EXPECT_EQ(STATUS_SUCCESS,signalingClientFetchSync(signalingHandle)); + EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfoCount(signalingHandle, &iceCount)); + EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfo(signalingHandle, 0, &pIceConfigInfo)); + + pActiveClient = pSignalingClient; // Check the states first @@ -2192,7 +2236,7 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshNotConnectedWithBadA EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); + EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); @@ -2217,7 +2261,7 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshNotConnectedWithBadA EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); EXPECT_LT(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); + EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); @@ -2235,7 +2279,7 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshNotConnectedWithBadA EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); EXPECT_LT(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); - EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); + EXPECT_EQ(3, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); @@ -2314,7 +2358,7 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshConnectedWithBadAuth EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); @@ -2339,7 +2383,7 @@ TEST_F(SignalingApiFunctionalityTest, iceServerConfigRefreshConnectedWithBadAuth EXPECT_LT(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_LT(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_LT(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); @@ -2610,7 +2654,7 @@ TEST_F(SignalingApiFunctionalityTest, connectTimeoutEmulation) EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); @@ -2632,7 +2676,7 @@ TEST_F(SignalingApiFunctionalityTest, connectTimeoutEmulation) EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_LE(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_LE(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_LE(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_LE(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_LE(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); @@ -2728,7 +2772,7 @@ TEST_F(SignalingApiFunctionalityTest, channelInfoArnSkipDescribe) EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); @@ -2781,7 +2825,7 @@ TEST_F(SignalingApiFunctionalityTest, channelInfoArnSkipDescribe) EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); @@ -2860,7 +2904,7 @@ TEST_F(SignalingApiFunctionalityTest, deleteChannelCreatedWithArn) EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); @@ -2913,7 +2957,7 @@ TEST_F(SignalingApiFunctionalityTest, deleteChannelCreatedWithArn) EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); @@ -2994,7 +3038,7 @@ TEST_F(SignalingApiFunctionalityTest, deleteChannelCreatedAuthExpiration) EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); @@ -3012,7 +3056,7 @@ TEST_F(SignalingApiFunctionalityTest, deleteChannelCreatedAuthExpiration) EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); @@ -3032,7 +3076,7 @@ TEST_F(SignalingApiFunctionalityTest, deleteChannelCreatedAuthExpiration) EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); @@ -3165,7 +3209,7 @@ TEST_F(SignalingApiFunctionalityTest, cachingWithFaultInjection) // Account for 1 time failure EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); @@ -3187,7 +3231,7 @@ TEST_F(SignalingApiFunctionalityTest, cachingWithFaultInjection) EXPECT_LE(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_LE(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_LE(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_LE(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_LE(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_LE(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); @@ -3209,7 +3253,7 @@ TEST_F(SignalingApiFunctionalityTest, cachingWithFaultInjection) EXPECT_LE(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_LE(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_LE(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_LE(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_LE(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_LE(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); @@ -3544,12 +3588,17 @@ TEST_F(SignalingApiFunctionalityTest, receivingIceConfigOffer) EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); + EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfoCount(signalingHandle, &iceCount)); + EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfo(signalingHandle, 0, &pIceConfigInfo)); + EXPECT_NE(0, iceCount); + EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + // Ensure the ICE is not refreshed as we already have a current non-expired set EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfoCount(signalingHandle, &iceCount)); EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfo(signalingHandle, 0, &pIceConfigInfo)); @@ -3733,12 +3782,17 @@ TEST_F(SignalingApiFunctionalityTest, receivingIceConfigOffer_SlowClockSkew) EXPECT_EQ(3, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); + EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfoCount(signalingHandle, &iceCount)); + EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfo(signalingHandle, 0, &pIceConfigInfo)); + EXPECT_NE(0, iceCount); + EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + // Ensure the ICE is not refreshed as we already have a current non-expired set EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfoCount(signalingHandle, &iceCount)); EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfo(signalingHandle, 0, &pIceConfigInfo)); @@ -3923,13 +3977,12 @@ TEST_F(SignalingApiFunctionalityTest, receivingIceConfigOffer_FastClockSkew) EXPECT_EQ(3, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_DISCONNECTED]); - // Ensure the ICE is not refreshed as we already have a current non-expired set EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfoCount(signalingHandle, &iceCount)); EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfo(signalingHandle, 0, &pIceConfigInfo)); EXPECT_NE(0, iceCount); @@ -4115,7 +4168,7 @@ TEST_F(SignalingApiFunctionalityTest, receivingIceConfigOffer_FastClockSkew_Veri EXPECT_EQ(3, signalingStatesCounts[SIGNALING_CLIENT_STATE_DESCRIBE]); EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_CREATE]); EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ENDPOINT]); - EXPECT_EQ(2, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); + EXPECT_EQ(0, signalingStatesCounts[SIGNALING_CLIENT_STATE_GET_ICE_CONFIG]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_READY]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTING]); EXPECT_EQ(1, signalingStatesCounts[SIGNALING_CLIENT_STATE_CONNECTED]); diff --git a/tst/SignalingApiTest.cpp b/tst/SignalingApiTest.cpp index affcc3b5b1..7564b6ff7b 100644 --- a/tst/SignalingApiTest.cpp +++ b/tst/SignalingApiTest.cpp @@ -319,11 +319,11 @@ TEST_F(SignalingApiTest, signalingClientGetMetrics) EXPECT_EQ(0, metrics.signalingClientStats.numberOfMessagesReceived); EXPECT_EQ(0, metrics.signalingClientStats.numberOfErrors); EXPECT_EQ(0, metrics.signalingClientStats.numberOfRuntimeErrors); - EXPECT_EQ(1, metrics.signalingClientStats.iceRefreshCount); + EXPECT_EQ(0, metrics.signalingClientStats.iceRefreshCount); EXPECT_NE(0, metrics.signalingClientStats.signalingClientUptime); EXPECT_EQ(0, metrics.signalingClientStats.connectionDuration); EXPECT_NE(0, metrics.signalingClientStats.cpApiCallLatency); - EXPECT_NE(0, metrics.signalingClientStats.dpApiCallLatency); + EXPECT_EQ(0, metrics.signalingClientStats.dpApiCallLatency); // Connect and get metrics EXPECT_EQ(STATUS_SUCCESS, signalingClientConnectSync(mSignalingClientHandle)); @@ -337,11 +337,11 @@ TEST_F(SignalingApiTest, signalingClientGetMetrics) EXPECT_EQ(0, metrics.signalingClientStats.numberOfMessagesReceived); EXPECT_EQ(0, metrics.signalingClientStats.numberOfErrors); EXPECT_EQ(0, metrics.signalingClientStats.numberOfRuntimeErrors); - EXPECT_EQ(1, metrics.signalingClientStats.iceRefreshCount); + EXPECT_EQ(0, metrics.signalingClientStats.iceRefreshCount); EXPECT_NE(0, metrics.signalingClientStats.signalingClientUptime); EXPECT_NE(0, metrics.signalingClientStats.connectionDuration); EXPECT_NE(0, metrics.signalingClientStats.cpApiCallLatency); - EXPECT_NE(0, metrics.signalingClientStats.dpApiCallLatency); + EXPECT_EQ(0, metrics.signalingClientStats.dpApiCallLatency); // Send a message and get metrics signalingMessage.version = SIGNALING_MESSAGE_CURRENT_VERSION; @@ -359,11 +359,11 @@ TEST_F(SignalingApiTest, signalingClientGetMetrics) EXPECT_EQ(0, metrics.signalingClientStats.numberOfMessagesReceived); EXPECT_EQ(0, metrics.signalingClientStats.numberOfErrors); EXPECT_EQ(0, metrics.signalingClientStats.numberOfRuntimeErrors); - EXPECT_EQ(1, metrics.signalingClientStats.iceRefreshCount); + EXPECT_EQ(0, metrics.signalingClientStats.iceRefreshCount); EXPECT_NE(0, metrics.signalingClientStats.signalingClientUptime); EXPECT_NE(0, metrics.signalingClientStats.connectionDuration); EXPECT_NE(0, metrics.signalingClientStats.cpApiCallLatency); - EXPECT_NE(0, metrics.signalingClientStats.dpApiCallLatency); + EXPECT_EQ(0, metrics.signalingClientStats.dpApiCallLatency); // Make a couple of bad API invocations EXPECT_NE(STATUS_SUCCESS, signalingClientGetIceConfigInfoCount(mSignalingClientHandle, NULL)); @@ -372,6 +372,22 @@ TEST_F(SignalingApiTest, signalingClientGetMetrics) EXPECT_NE(STATUS_SUCCESS, signalingClientGetMetrics(mSignalingClientHandle, NULL)); EXPECT_NE(STATUS_SUCCESS, signalingClientSendMessageSync(mSignalingClientHandle, NULL)); + EXPECT_EQ(STATUS_SUCCESS, signalingClientGetMetrics(mSignalingClientHandle, &metrics)); + EXPECT_EQ(0, metrics.signalingClientStats.numberOfReconnects); + EXPECT_EQ(1, metrics.signalingClientStats.numberOfMessagesSent); + EXPECT_EQ(0, metrics.signalingClientStats.numberOfMessagesReceived); + EXPECT_EQ(5, metrics.signalingClientStats.numberOfErrors); + EXPECT_EQ(0, metrics.signalingClientStats.numberOfRuntimeErrors); + EXPECT_EQ(0, metrics.signalingClientStats.iceRefreshCount); + EXPECT_NE(0, metrics.signalingClientStats.signalingClientUptime); + EXPECT_NE(0, metrics.signalingClientStats.connectionDuration); + EXPECT_NE(0, metrics.signalingClientStats.cpApiCallLatency); + EXPECT_EQ(0, metrics.signalingClientStats.dpApiCallLatency); + + UINT32 iceCount = 0; + //Get ice config + EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfoCount(mSignalingClientHandle, &iceCount)); + EXPECT_EQ(STATUS_SUCCESS, signalingClientGetMetrics(mSignalingClientHandle, &metrics)); EXPECT_EQ(0, metrics.signalingClientStats.numberOfReconnects); EXPECT_EQ(1, metrics.signalingClientStats.numberOfMessagesSent); diff --git a/tst/WebRTCClientTestFixture.cpp b/tst/WebRTCClientTestFixture.cpp index 5ad7763251..af8ccd234b 100644 --- a/tst/WebRTCClientTestFixture.cpp +++ b/tst/WebRTCClientTestFixture.cpp @@ -16,31 +16,62 @@ UINT64 gTotalWebRtcClientMemoryUsage = 0; // MUTEX gTotalWebRtcClientMemoryMutex; -STATUS createRtpPacketWithSeqNum(UINT16 seqNum, PRtpPacket *ppRtpPacket) { +STATUS createRtpPacketWithSeqNum(UINT16 seqNum, PRtpPacket* ppRtpPacket) +{ STATUS retStatus = STATUS_SUCCESS; BYTE payload[10]; PRtpPacket pRtpPacket = NULL; - CHK_STATUS(createRtpPacket(2, FALSE, FALSE, 0, FALSE, - 96, seqNum, 100, 0x1234ABCD, NULL, 0, 0, NULL, payload, 10, &pRtpPacket)); + CHK_STATUS(createRtpPacket(2, FALSE, FALSE, 0, FALSE, 96, seqNum, 100, 0x1234ABCD, NULL, 0, 0, NULL, payload, 10, &pRtpPacket)); *ppRtpPacket = pRtpPacket; CHK_STATUS(createBytesFromRtpPacket(pRtpPacket, NULL, &pRtpPacket->rawPacketLength)); CHK(NULL != (pRtpPacket->pRawPacket = (PBYTE) MEMALLOC(pRtpPacket->rawPacketLength)), STATUS_NOT_ENOUGH_MEMORY); CHK_STATUS(createBytesFromRtpPacket(pRtpPacket, pRtpPacket->pRawPacket, &pRtpPacket->rawPacketLength)); - CleanUp: +CleanUp: return retStatus; } -WebRtcClientTestBase::WebRtcClientTestBase() : - mSignalingClientHandle(INVALID_SIGNALING_CLIENT_HANDLE_VALUE), - mAccessKey(NULL), - mSecretKey(NULL), - mSessionToken(NULL), - mRegion(NULL), - mCaCertPath(NULL), - mAccessKeyIdSet(FALSE) +PVOID asyncGetIceConfigInfo(PVOID args) +{ + STATUS retStatus = STATUS_SUCCESS; + AsyncGetIceStruct* data = (AsyncGetIceStruct*) args; + PIceConfigInfo pIceConfigInfo = NULL; + UINT32 uriCount = 0; + UINT32 i = 0, maxTurnServer = 1; + + if (data != NULL) { + /* signalingClientGetIceConfigInfoCount can return more than one turn server. Use only one to optimize + * candidate gathering latency. But user can also choose to use more than 1 turn server. */ + for (uriCount = 0, i = 0; i < maxTurnServer; i++) { + /* + * if configuration.iceServers[uriCount + 1].urls is "turn:ip:port?transport=udp" then ICE will try TURN over UDP + * if configuration.iceServers[uriCount + 1].urls is "turn:ip:port?transport=tcp" then ICE will try TURN over TCP/TLS + * if configuration.iceServers[uriCount + 1].urls is "turns:ip:port?transport=udp", it's currently ignored because sdk dont do TURN + * over DTLS yet. if configuration.iceServers[uriCount + 1].urls is "turns:ip:port?transport=tcp" then ICE will try TURN over TCP/TLS + * if configuration.iceServers[uriCount + 1].urls is "turn:ip:port" then ICE will try both TURN over UDP and TCP/TLS + * + * It's recommended to not pass too many TURN iceServers to configuration because it will slow down ice gathering in non-trickle mode. + */ + CHK_STATUS(signalingClientGetIceConfigInfo(data->signalingClientHandle, i, &pIceConfigInfo)); + CHECK(uriCount < MAX_ICE_SERVERS_COUNT); + uriCount += pIceConfigInfo->uriCount; + CHK_STATUS(addConfigToServerList(&(data->pAnswer), pIceConfigInfo)); + CHK_STATUS(addConfigToServerList(&(data->pOffer), pIceConfigInfo)); + } + } + *(data->pUriCount) += uriCount; + +CleanUp: + SAFE_MEMFREE(data); + CHK_LOG_ERR(retStatus); + return NULL; +} + +WebRtcClientTestBase::WebRtcClientTestBase() + : mSignalingClientHandle(INVALID_SIGNALING_CLIENT_HANDLE_VALUE), mAccessKey(NULL), mSecretKey(NULL), mSessionToken(NULL), mRegion(NULL), + mCaCertPath(NULL), mAccessKeyIdSet(FALSE) { // Initialize the endianness of the library initializeEndianness(); @@ -114,7 +145,7 @@ void WebRtcClientTestBase::TearDown() deinitKvsWebRtc(); // Need this sleep for threads in threadpool to close - THREAD_SLEEP(100 * HUNDREDS_OF_NANOS_IN_A_MILLISECOND); + THREAD_SLEEP(400 * HUNDREDS_OF_NANOS_IN_A_MILLISECOND); freeStaticCredentialProvider(&mTestCredentialProvider); @@ -233,6 +264,60 @@ bool WebRtcClientTestBase::connectTwoPeers(PRtcPeerConnection offerPc, PRtcPeerC return ATOMIC_LOAD(&this->stateChangeCount[RTC_PEER_CONNECTION_STATE_CONNECTED]) == 2; } +bool WebRtcClientTestBase::connectTwoPeersAsyncIce(PRtcPeerConnection offerPc, PRtcPeerConnection answerPc, PCHAR pOfferCertFingerprint, + PCHAR pAnswerCertFingerprint) +{ + RtcSessionDescriptionInit sdp; + + auto onICECandidateHdlr = [](UINT64 customData, PCHAR candidateStr) -> void { + if (candidateStr != NULL) { + std::thread( + [customData](std::string candidate) { + RtcIceCandidateInit iceCandidate; + EXPECT_EQ(STATUS_SUCCESS, deserializeRtcIceCandidateInit((PCHAR) candidate.c_str(), STRLEN(candidate.c_str()), &iceCandidate)); + EXPECT_EQ(STATUS_SUCCESS, addIceCandidate((PRtcPeerConnection) customData, iceCandidate.candidate)); + }, + std::string(candidateStr)) + .detach(); + } + }; + + EXPECT_EQ(STATUS_SUCCESS, peerConnectionOnIceCandidate(offerPc, (UINT64) answerPc, onICECandidateHdlr)); + EXPECT_EQ(STATUS_SUCCESS, peerConnectionOnIceCandidate(answerPc, (UINT64) offerPc, onICECandidateHdlr)); + + auto onICEConnectionStateChangeHdlr = [](UINT64 customData, RTC_PEER_CONNECTION_STATE newState) -> void { + ATOMIC_INCREMENT((PSIZE_T) customData + newState); + }; + + EXPECT_EQ(STATUS_SUCCESS, peerConnectionOnConnectionStateChange(offerPc, (UINT64) this->stateChangeCount, onICEConnectionStateChangeHdlr)); + EXPECT_EQ(STATUS_SUCCESS, peerConnectionOnConnectionStateChange(answerPc, (UINT64) this->stateChangeCount, onICEConnectionStateChangeHdlr)); + + EXPECT_EQ(STATUS_SUCCESS, createOffer(offerPc, &sdp)); + EXPECT_EQ(STATUS_SUCCESS, setLocalDescription(offerPc, &sdp)); + EXPECT_EQ(STATUS_SUCCESS, setRemoteDescription(answerPc, &sdp)); + + // Validate the cert fingerprint if we are asked to do so + if (pOfferCertFingerprint != NULL) { + EXPECT_NE((PCHAR) NULL, STRSTR(sdp.sdp, pOfferCertFingerprint)); + } + + EXPECT_EQ(STATUS_SUCCESS, createAnswer(answerPc, &sdp)); + EXPECT_EQ(STATUS_SUCCESS, setLocalDescription(answerPc, &sdp)); + EXPECT_EQ(STATUS_SUCCESS, setRemoteDescription(offerPc, &sdp)); + + asyncGetIceConfig(offerPc, answerPc); + + if (pAnswerCertFingerprint != NULL) { + EXPECT_NE((PCHAR) NULL, STRSTR(sdp.sdp, pAnswerCertFingerprint)); + } + + for (auto i = 0; i <= 100 && ATOMIC_LOAD(&this->stateChangeCount[RTC_PEER_CONNECTION_STATE_CONNECTED]) != 2; i++) { + THREAD_SLEEP(HUNDREDS_OF_NANOS_IN_A_SECOND); + } + + return ATOMIC_LOAD(&this->stateChangeCount[RTC_PEER_CONNECTION_STATE_CONNECTED]) == 2; +} + // Create track and transceiver and adds to PeerConnection void WebRtcClientTestBase::addTrackToPeerConnection(PRtcPeerConnection pRtcPeerConnection, PRtcMediaStreamTrack track, PRtcRtpTransceiver* transceiver, RTC_CODEC codec, MEDIA_STREAM_TRACK_KIND kind) @@ -249,16 +334,42 @@ void WebRtcClientTestBase::addTrackToPeerConnection(PRtcPeerConnection pRtcPeerC EXPECT_EQ(STATUS_SUCCESS, addTransceiver(pRtcPeerConnection, track, NULL, transceiver)); } -void WebRtcClientTestBase::getIceServers(PRtcConfiguration pRtcConfiguration) +void WebRtcClientTestBase::getIceServers(PRtcConfiguration pRtcConfiguration, PIceAgent pIceAgent) +{ + UINT32 i, j, iceConfigCount = 0, uriCount; + PIceConfigInfo pIceConfigInfo; + + // Assume signaling client is already created + EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfoCount(mSignalingClientHandle, &iceConfigCount)); + + // Set the STUN server + SNPRINTF(pRtcConfiguration->iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, KINESIS_VIDEO_STUN_URL, TEST_DEFAULT_REGION, + TEST_DEFAULT_STUN_URL_POSTFIX); + + for (uriCount = 0, i = 0; i < iceConfigCount; i++) { + EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfo(mSignalingClientHandle, i, &pIceConfigInfo)); + for (j = 0; j < pIceConfigInfo->uriCount; j++) { + STRNCPY(pRtcConfiguration->iceServers[uriCount + 1].urls, pIceConfigInfo->uris[j], MAX_ICE_CONFIG_URI_LEN); + STRNCPY(pRtcConfiguration->iceServers[uriCount + 1].credential, pIceConfigInfo->password, MAX_ICE_CONFIG_CREDENTIAL_LEN); + STRNCPY(pRtcConfiguration->iceServers[uriCount + 1].username, pIceConfigInfo->userName, MAX_ICE_CONFIG_USER_NAME_LEN); + + uriCount++; + } + EXPECT_EQ(STATUS_SUCCESS, iceAgentAddConfig(pIceAgent, pIceConfigInfo)); + } +} + +void WebRtcClientTestBase::getIceServers(PRtcConfiguration pRtcConfiguration, PRtcPeerConnection pRtcPeerConnection) { - UINT32 i, j, iceConfigCount, uriCount; + UINT32 i, j, iceConfigCount = 0, uriCount; PIceConfigInfo pIceConfigInfo; // Assume signaling client is already created EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfoCount(mSignalingClientHandle, &iceConfigCount)); // Set the STUN server - SNPRINTF(pRtcConfiguration->iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, KINESIS_VIDEO_STUN_URL, TEST_DEFAULT_REGION, TEST_DEFAULT_STUN_URL_POSTFIX); + SNPRINTF(pRtcConfiguration->iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, KINESIS_VIDEO_STUN_URL, TEST_DEFAULT_REGION, + TEST_DEFAULT_STUN_URL_POSTFIX); for (uriCount = 0, i = 0; i < iceConfigCount; i++) { EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfo(mSignalingClientHandle, i, &pIceConfigInfo)); @@ -269,6 +380,7 @@ void WebRtcClientTestBase::getIceServers(PRtcConfiguration pRtcConfiguration) uriCount++; } + EXPECT_EQ(STATUS_SUCCESS, addConfigToServerList(&pRtcPeerConnection, pIceConfigInfo)); } } diff --git a/tst/WebRTCClientTestFixture.h b/tst/WebRTCClientTestFixture.h index 229b7dd439..d774e97b07 100644 --- a/tst/WebRTCClientTestFixture.h +++ b/tst/WebRTCClientTestFixture.h @@ -23,6 +23,13 @@ #define MAX_TEST_AWAIT_DURATION (2 * HUNDREDS_OF_NANOS_IN_A_SECOND) #define TEST_CACHE_FILE_PATH (PCHAR) "./.TestSignalingCache_v0" +typedef struct { + SIGNALING_CLIENT_HANDLE signalingClientHandle; + PRtcPeerConnection pOffer; + PRtcPeerConnection pAnswer; + PUINT32 pUriCount; +} AsyncGetIceStruct; + namespace com { namespace amazonaws { namespace kinesis { @@ -38,6 +45,8 @@ typedef struct { STATUS createRtpPacketWithSeqNum(UINT16 seqNum, PRtpPacket* ppRtpPacket); +PVOID asyncGetIceConfigInfo(PVOID args); + class WebRtcClientTestBase : public ::testing::Test { public: PUINT32 mExpectedFrameSizeArr; @@ -47,6 +56,7 @@ class WebRtcClientTestBase : public ::testing::Test { UINT32 mExpectedDroppedFrameCount; PRtpPacket* mPRtpPackets; UINT32 mRtpPacketCount; + UINT32 mUriCount = 0; SIGNALING_CLIENT_HANDLE mSignalingClientHandle; WebRtcClientTestBase(); @@ -149,6 +159,18 @@ class WebRtcClientTestBase : public ::testing::Test { return STATUS_SUCCESS; } + STATUS asyncGetIceConfig(PRtcPeerConnection pOffer, PRtcPeerConnection pAnswer) + { + AsyncGetIceStruct* pAsyncData = NULL; + pAsyncData = (AsyncGetIceStruct*) MEMCALLOC(1, SIZEOF(AsyncGetIceStruct)); + pAsyncData->signalingClientHandle = mSignalingClientHandle; + pAsyncData->pAnswer = pAnswer; + pAsyncData->pOffer = pOffer; + pAsyncData->pUriCount = &(this->mUriCount); + EXPECT_EQ(STATUS_SUCCESS, peerConnectionAsync(asyncGetIceConfigInfo, (PVOID) pAsyncData)); + return STATUS_SUCCESS; + } + static STATUS testFrameReadyFunc(UINT64 customData, UINT16 startIndex, UINT16 endIndex, UINT32 frameSize) { WebRtcClientTestBase* base = (WebRtcClientTestBase*) customData; @@ -270,9 +292,13 @@ class WebRtcClientTestBase : public ::testing::Test { bool connectTwoPeers(PRtcPeerConnection offerPc, PRtcPeerConnection answerPc, PCHAR pOfferCertFingerprint = NULL, PCHAR pAnswerCertFingerprint = NULL); + bool connectTwoPeersAsyncIce(PRtcPeerConnection offerPc, PRtcPeerConnection answerPc, PCHAR pOfferCertFingerprint = NULL, + PCHAR pAnswerCertFingerprint = NULL); void addTrackToPeerConnection(PRtcPeerConnection pRtcPeerConnection, PRtcMediaStreamTrack track, PRtcRtpTransceiver* transceiver, RTC_CODEC codec, MEDIA_STREAM_TRACK_KIND kind); - void getIceServers(PRtcConfiguration pRtcConfiguration); + void getIceServers(PRtcConfiguration pRtcConfiguration, PRtcPeerConnection pRtcPeerConnection); + + void getIceServers(PRtcConfiguration pRtcConfiguration, PIceAgent pIceAgent); protected: virtual void SetUp();