@@ -116,7 +116,7 @@ STATUS createIceAgent(PCHAR username, PCHAR password, PIceAgentCallbacks pIceAge
116116 if (doStatCalcs ) {
117117 CHK (NULL != (pIceAgent -> pRtcIceServerDiagnostics [i ] = (PRtcIceServerDiagnostics ) MEMCALLOC (1 , SIZEOF (RtcIceServerDiagnostics ))),
118118 STATUS_NOT_ENOUGH_MEMORY );
119- pIceAgent -> pRtcIceServerDiagnostics [i ]-> port = (INT32 ) getInt16 (pIceAgent -> iceServers [i ].ipAddress .port );
119+ pIceAgent -> pRtcIceServerDiagnostics [i ]-> port = (INT32 ) getInt16 (pIceAgent -> iceServers [i ].ipAddresses . ipv4Address .port );
120120 switch (pIceAgent -> iceServers [pIceAgent -> iceServersCount ].transport ) {
121121 case KVS_SOCKET_PROTOCOL_UDP :
122122 STRCPY (pIceAgent -> pRtcIceServerDiagnostics [i ]-> protocol , ICE_TRANSPORT_TYPE_UDP );
@@ -639,8 +639,9 @@ STATUS iceAgentStartGathering(PIceAgent pIceAgent)
639639 "Srflx candidates setup time" );
640640 }
641641
642- PROFILE_CALL_WITH_T_OBJ (CHK_STATUS (iceAgentInitRelayCandidates (pIceAgent )), pIceAgent -> iceAgentProfileDiagnostics .relayCandidateSetUpTime ,
643- "Relay candidates setup time" );
642+ // Disable relay candidate gathering for STUN testing.
643+ // PROFILE_CALL_WITH_T_OBJ(CHK_STATUS(iceAgentInitRelayCandidates(pIceAgent)), pIceAgent->iceAgentProfileDiagnostics.relayCandidateSetUpTime,
644+ // "Relay candidates setup time");
644645
645646 // start listening for incoming data
646647 CHK_STATUS (connectionListenerStart (pIceAgent -> pConnectionListener ));
@@ -1105,6 +1106,11 @@ STATUS createIceCandidatePairs(PIceAgent pIceAgent, PIceCandidate pIceCandidate,
11051106 pCurrentIceCandidate = (PIceCandidate ) data ;
11061107 pCurNode = pCurNode -> pNext ;
11071108
1109+ // Skip forming pairs with local host candidates for STUN testing.
1110+ if (isRemoteCandidate && pCurrentIceCandidate -> iceCandidateType == ICE_CANDIDATE_TYPE_HOST ) {
1111+ continue ;
1112+ }
1113+
11081114 // https://tools.ietf.org/html/rfc8445#section-6.1.2.2
11091115 // pair local and remote candidates with the same family
11101116 if (pCurrentIceCandidate -> state == ICE_CANDIDATE_STATE_VALID && pCurrentIceCandidate -> ipAddress .family == pIceCandidate -> ipAddress .family ) {
@@ -1458,14 +1464,32 @@ STATUS iceAgentSendSrflxCandidateRequest(PIceAgent pIceAgent)
14581464 switch (pCandidate -> iceCandidateType ) {
14591465 case ICE_CANDIDATE_TYPE_SERVER_REFLEXIVE :
14601466 pIceServer = & (pIceAgent -> iceServers [pCandidate -> iceServerIndex ]);
1461- if (pIceServer -> ipAddress .family == pCandidate -> ipAddress .family ) {
1467+ if (pIceServer -> ipAddresses . ipv4Address .family == pCandidate -> ipAddress .family ) {
14621468 // update transactionId
14631469 CHK_STATUS (
14641470 iceUtilsGenerateTransactionId (pBindingRequest -> header .transactionId , ARRAY_SIZE (pBindingRequest -> header .transactionId )));
14651471
14661472 transactionIdStoreInsert (pIceAgent -> pStunBindingRequestTransactionIdStore , pBindingRequest -> header .transactionId );
14671473 checkSum = COMPUTE_CRC32 (pBindingRequest -> header .transactionId , ARRAY_SIZE (pBindingRequest -> header .transactionId ));
1468- CHK_STATUS (iceAgentSendStunPacket (pBindingRequest , NULL , 0 , pIceAgent , pCandidate , & pIceServer -> ipAddress ));
1474+
1475+ DLOGD ("[TEST] Sending STUN binding request to IPv4 STUN server: %u:%u" , pIceServer -> ipAddresses .ipv4Address .address , pIceServer -> ipAddresses .ipv4Address .port );
1476+
1477+ CHK_STATUS (iceAgentSendStunPacket (pBindingRequest , NULL , 0 , pIceAgent , pCandidate , & pIceServer -> ipAddresses .ipv4Address ));
1478+ if (pIceAgent -> pRtcIceServerDiagnostics [pCandidate -> iceServerIndex ] != NULL ) {
1479+ pIceAgent -> pRtcIceServerDiagnostics [pCandidate -> iceServerIndex ]-> totalRequestsSent ++ ;
1480+ CHK_STATUS (hashTableUpsert (pIceAgent -> requestTimestampDiagnostics , checkSum , GETTIME ()));
1481+ }
1482+ } else if (pIceServer -> ipAddresses .ipv6Address .family == pCandidate -> ipAddress .family ) {
1483+ // update transactionId
1484+ CHK_STATUS (
1485+ iceUtilsGenerateTransactionId (pBindingRequest -> header .transactionId , ARRAY_SIZE (pBindingRequest -> header .transactionId )));
1486+
1487+ transactionIdStoreInsert (pIceAgent -> pStunBindingRequestTransactionIdStore , pBindingRequest -> header .transactionId );
1488+ checkSum = COMPUTE_CRC32 (pBindingRequest -> header .transactionId , ARRAY_SIZE (pBindingRequest -> header .transactionId ));
1489+
1490+ DLOGD ("[TEST] Sending STUN binding request to IPv6 STUN server: %u:%u" , pIceServer -> ipAddresses .ipv6Address .address , pIceServer -> ipAddresses .ipv6Address .port );
1491+
1492+ CHK_STATUS (iceAgentSendStunPacket (pBindingRequest , NULL , 0 , pIceAgent , pCandidate , & pIceServer -> ipAddresses .ipv6Address ));
14691493 if (pIceAgent -> pRtcIceServerDiagnostics [pCandidate -> iceServerIndex ] != NULL ) {
14701494 pIceAgent -> pRtcIceServerDiagnostics [pCandidate -> iceServerIndex ]-> totalRequestsSent ++ ;
14711495 CHK_STATUS (hashTableUpsert (pIceAgent -> requestTimestampDiagnostics , checkSum , GETTIME ()));
@@ -1762,7 +1786,7 @@ STATUS iceAgentInitSrflxCandidate(PIceAgent pIceAgent)
17621786 if (pCandidate -> iceCandidateType == ICE_CANDIDATE_TYPE_HOST ) {
17631787 for (j = 0 ; j < pIceAgent -> iceServersCount ; j ++ ) {
17641788 pIceServer = & pIceAgent -> iceServers [j ];
1765- if (!pIceServer -> isTurn && pIceServer -> ipAddress .family == pCandidate -> ipAddress .family ) {
1789+ if (!pIceServer -> isTurn && ( pIceServer -> ipAddresses . ipv4Address . family == pCandidate -> ipAddress .family || pIceServer -> ipAddresses . ipv6Address . family == pCandidate -> ipAddress .family ) ) {
17661790 CHK ((pNewCandidate = (PIceCandidate ) MEMCALLOC (1 , SIZEOF (IceCandidate ))) != NULL , STATUS_NOT_ENOUGH_MEMORY );
17671791 generateJSONSafeString (pNewCandidate -> id , ARRAY_SIZE (pNewCandidate -> id ));
17681792 pNewCandidate -> isRemote = FALSE;
@@ -1794,18 +1818,19 @@ STATUS iceAgentInitSrflxCandidate(PIceAgent pIceAgent)
17941818 pCandidate = srflxCandidates [j ];
17951819 // TODO: IPv6 STUN is not supported at the moment. Remove this check if the support is added in the future
17961820 if (IS_IPV4_ADDR (& (pCandidate -> ipAddress ))) {
1797- // open up a new socket at host candidate's ip address for server reflex candidate.
1798- // the new port will be stored in pNewCandidate->ipAddress.port. And the Ip address will later be updated
1799- // with the correct ip address once the STUN response is received.
1800- CHK_STATUS (createSocketConnection (pCandidate -> ipAddress .family , KVS_SOCKET_PROTOCOL_UDP , & pCandidate -> ipAddress , NULL , (UINT64 ) pIceAgent ,
1801- incomingDataHandler , pIceAgent -> kvsRtcConfiguration .sendBufSize , & pCandidate -> pSocketConnection ));
1802- ATOMIC_STORE_BOOL (& pCandidate -> pSocketConnection -> receiveData , TRUE);
1803- // connectionListener will free the pSocketConnection at the end.
1804- CHK_STATUS (connectionListenerAddConnection (pIceAgent -> pConnectionListener , pCandidate -> pSocketConnection ));
1805-
1821+ DLOGW ("[TEST] IPv4 STUN candidate detected ...." );
18061822 } else {
1807- DLOGW ("IPv6 candidate detected, ignoring ...." );
1823+ DLOGW ("[TEST] IPv6 STUN candidate detected ...." );
18081824 }
1825+
1826+ // open up a new socket at host candidate's ip address for server reflex candidate.
1827+ // the new port will be stored in pNewCandidate->ipAddress.port. And the Ip address will later be updated
1828+ // with the correct ip address once the STUN response is received.
1829+ CHK_STATUS (createSocketConnection (pCandidate -> ipAddress .family , KVS_SOCKET_PROTOCOL_UDP , & pCandidate -> ipAddress , NULL , (UINT64 ) pIceAgent ,
1830+ incomingDataHandler , pIceAgent -> kvsRtcConfiguration .sendBufSize , & pCandidate -> pSocketConnection ));
1831+ ATOMIC_STORE_BOOL (& pCandidate -> pSocketConnection -> receiveData , TRUE);
1832+ // connectionListener will free the pSocketConnection at the end.
1833+ CHK_STATUS (connectionListenerAddConnection (pIceAgent -> pConnectionListener , pCandidate -> pSocketConnection ));
18091834 }
18101835
18111836CleanUp :
@@ -1898,7 +1923,7 @@ STATUS iceAgentInitRelayCandidate(PIceAgent pIceAgent, UINT32 iceServerIndex, KV
18981923 // open up a new socket without binding to any host address. The candidate Ip address will later be updated
18991924 // with the correct relay ip address once the Allocation success response is received. Relay candidate's socket is managed
19001925 // by TurnConnection struct.
1901- CHK_STATUS (createSocketConnection (KVS_IP_FAMILY_TYPE_IPV4 , protocol , NULL , & pIceAgent -> iceServers [iceServerIndex ].ipAddress ,
1926+ CHK_STATUS (createSocketConnection (KVS_IP_FAMILY_TYPE_IPV4 , protocol , NULL , & pIceAgent -> iceServers [iceServerIndex ].ipAddresses . ipv4Address ,
19021927 (UINT64 ) pNewCandidate , incomingRelayedDataHandler , pIceAgent -> kvsRtcConfiguration .sendBufSize ,
19031928 & pNewCandidate -> pSocketConnection ));
19041929 // connectionListener will free the pSocketConnection at the end.
0 commit comments