Skip to content

Commit ff3f140

Browse files
committed
Cleanup
1 parent 5964366 commit ff3f140

File tree

6 files changed

+36
-42
lines changed

6 files changed

+36
-42
lines changed

samples/Common.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,8 @@ STATUS initializePeerConnection(PSampleConfiguration pSampleConfiguration, PRtcP
375375
if (STRSTR(pSampleConfiguration->channelInfo.pRegion, "cn-")) {
376376
pKinesisVideoStunUrlPostFix = KINESIS_VIDEO_STUN_URL_POSTFIX_CN;
377377
}
378-
// SNPRINTF(configuration.iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, KINESIS_VIDEO_STUN_URL, pSampleConfiguration->channelInfo.pRegion,
379-
// pKinesisVideoStunUrlPostFix);
380-
SNPRINTF(configuration.iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, "stun:stun.l.google.com:19302");
381-
DLOGI("STUN server URL: %s", configuration.iceServers[0].urls);
378+
SNPRINTF(configuration.iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, KINESIS_VIDEO_STUN_URL, pSampleConfiguration->channelInfo.pRegion,
379+
pKinesisVideoStunUrlPostFix);
382380

383381
if (pSampleConfiguration->useTurn) {
384382
// Set the URIs from the configuration
@@ -509,7 +507,7 @@ STATUS createSampleStreamingSession(PSampleConfiguration pSampleConfiguration, P
509507

510508
// Flag to enable/disable SDK calculations of selected ice server, local, remote and candidate pair stats.
511509
// Note: enableIceStats only has an effect if compiler flag ENABLE_STATS_CALCULATION_CONTROL is defined.
512-
pSampleConfiguration->enableIceStats = TRUE;
510+
pSampleConfiguration->enableIceStats = FALSE;
513511

514512
CHK_STATUS(initializePeerConnection(pSampleConfiguration, &pSampleStreamingSession->pPeerConnection));
515513
CHK_STATUS(peerConnectionOnIceCandidate(pSampleStreamingSession->pPeerConnection, (UINT64) pSampleStreamingSession, onIceCandidateHandler));
@@ -889,7 +887,7 @@ STATUS createSampleConfiguration(PCHAR channelName, SIGNALING_CHANNEL_ROLE_TYPE
889887
pSampleConfiguration->channelInfo.pTags = NULL;
890888
pSampleConfiguration->channelInfo.channelType = SIGNALING_CHANNEL_TYPE_SINGLE_MASTER;
891889
pSampleConfiguration->channelInfo.channelRoleType = roleType;
892-
pSampleConfiguration->channelInfo.cachingPolicy = SIGNALING_API_CALL_CACHE_TYPE_NONE;
890+
pSampleConfiguration->channelInfo.cachingPolicy = SIGNALING_API_CALL_CACHE_TYPE_FILE;
893891
pSampleConfiguration->channelInfo.cachingPeriod = SIGNALING_API_CALL_CACHE_TTL_SENTINEL_VALUE;
894892
pSampleConfiguration->channelInfo.asyncIceServerConfig = TRUE; // has no effect
895893
pSampleConfiguration->channelInfo.retry = TRUE;

src/source/Ice/IceAgent.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -639,9 +639,8 @@ STATUS iceAgentStartGathering(PIceAgent pIceAgent)
639639
"Srflx candidates setup time");
640640
}
641641

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");
642+
PROFILE_CALL_WITH_T_OBJ(CHK_STATUS(iceAgentInitRelayCandidates(pIceAgent)), pIceAgent->iceAgentProfileDiagnostics.relayCandidateSetUpTime,
643+
"Relay candidates setup time");
645644

646645
// start listening for incoming data
647646
CHK_STATUS(connectionListenerStart(pIceAgent->pConnectionListener));
@@ -1106,11 +1105,6 @@ STATUS createIceCandidatePairs(PIceAgent pIceAgent, PIceCandidate pIceCandidate,
11061105
pCurrentIceCandidate = (PIceCandidate) data;
11071106
pCurNode = pCurNode->pNext;
11081107

1109-
// Skip forming pairs with local host candidates for STUN testing.
1110-
if (isRemoteCandidate && pCurrentIceCandidate->iceCandidateType == ICE_CANDIDATE_TYPE_HOST) {
1111-
continue;
1112-
}
1113-
11141108
// https://tools.ietf.org/html/rfc8445#section-6.1.2.2
11151109
// pair local and remote candidates with the same family
11161110
if (pCurrentIceCandidate->state == ICE_CANDIDATE_STATE_VALID && pCurrentIceCandidate->ipAddress.family == pIceCandidate->ipAddress.family) {
@@ -1816,11 +1810,10 @@ STATUS iceAgentInitSrflxCandidate(PIceAgent pIceAgent)
18161810
// Create and start the connection listener outside of the locks
18171811
for (j = 0; j < srflxCount; j++) {
18181812
pCandidate = srflxCandidates[j];
1819-
// TODO: IPv6 STUN is not supported at the moment. Remove this check if the support is added in the future
18201813
if (IS_IPV4_ADDR(&(pCandidate->ipAddress))) {
1821-
DLOGW("[TEST] IPv4 STUN candidate detected ....");
1814+
DLOGI("Initializing an IPv4 STUN candidate...");
18221815
} else {
1823-
DLOGW("[TEST] IPv6 STUN candidate detected ....");
1816+
DLOGI("Initializing an IPv6 STUN candidate...");
18241817
}
18251818

18261819
// open up a new socket at host candidate's ip address for server reflex candidate.

src/source/Ice/IceUtils.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,10 @@ STATUS iceUtilsSendStunPacket(PStunPacket pStunPacket, PBYTE password, UINT32 pa
176176
CHK(pDest != NULL, STATUS_NULL_ARG);
177177
switch (pStunPacket->header.stunMessageType) {
178178
case STUN_PACKET_TYPE_BINDING_REQUEST:
179-
// Need to format properly for IPv6.
180-
// DLOGD("Sending BINDING_REQUEST to ip:%u.%u.%u.%u, port:%u", pDest->address[0], pDest->address[1], pDest->address[2], pDest->address[3],
181-
// (UINT16) getInt16(pDest->port));
182179
DLOGD("Sending BINDING_REQUEST to ip:%s, port:%u",ipAddrStr,(UINT16) getInt16(pDest->port));
183-
184180
break;
185181
case STUN_PACKET_TYPE_BINDING_RESPONSE_SUCCESS:
186-
// DLOGD("Sending BINDING_RESPONSE_SUCCESS to ip:%u.%u.%u.%u, port:%u", pDest->address[0], pDest->address[1], pDest->address[2],
187-
// pDest->address[3], (UINT16) getInt16(pDest->port));
188182
DLOGD("Sending BINDING_RESPONSE_SUCCESS to ip:%s, port:%u",ipAddrStr,(UINT16) getInt16(pDest->port));
189-
190183
break;
191184
default:
192185
break;
@@ -230,8 +223,8 @@ STATUS parseIceServer(PIceServer pIceServer, PCHAR url, PCHAR username, PCHAR cr
230223
STATUS retStatus = STATUS_SUCCESS;
231224
PCHAR separator = NULL, urlNoPrefix = NULL, paramStart = NULL;
232225
UINT32 port = ICE_STUN_DEFAULT_PORT;
233-
CHAR addressResolved[KVS_IP_ADDRESS_STRING_BUFFER_LEN + 1] = {'\0'};
234-
CHAR addressResolved2[KVS_IP_ADDRESS_STRING_BUFFER_LEN + 1] = {'\0'};
226+
CHAR addressResolvedIPv4[KVS_IP_ADDRESS_STRING_BUFFER_LEN + 1] = {'\0'};
227+
CHAR addressResolvedIPv6[KVS_IP_ADDRESS_STRING_BUFFER_LEN + 1] = {'\0'};
235228

236229
// username and credential is only mandatory for turn server
237230
CHK(url != NULL && pIceServer != NULL, STATUS_NULL_ARG);
@@ -289,12 +282,12 @@ STATUS parseIceServer(PIceServer pIceServer, PCHAR url, PCHAR username, PCHAR cr
289282

290283
DLOGD("Setting port to %u", port);
291284
pIceServer->ipAddresses.ipv4Address.port = (UINT16) getInt16((INT16) port);
292-
getIpAddrStr(&pIceServer->ipAddresses.ipv4Address, addressResolved, ARRAY_SIZE(addressResolved));
293-
DLOGP("ICE Server IPv4 address for %s: %s", pIceServer->url, addressResolved);
285+
getIpAddrStr(&pIceServer->ipAddresses.ipv4Address, addressResolvedIPv4, ARRAY_SIZE(addressResolvedIPv4));
286+
DLOGP("ICE Server IPv4 address for %s: %s", pIceServer->url, addressResolvedIPv4);
294287

295288
pIceServer->ipAddresses.ipv6Address.port = (UINT16) getInt16((INT16) port);
296-
getIpAddrStr(&pIceServer->ipAddresses.ipv6Address, addressResolved2, ARRAY_SIZE(addressResolved));
297-
DLOGP("ICE Server IPv6 address for %s: %s", pIceServer->url, addressResolved2);
289+
getIpAddrStr(&pIceServer->ipAddresses.ipv6Address, addressResolvedIPv6, ARRAY_SIZE(addressResolvedIPv6));
290+
DLOGP("ICE Server IPv6 address for %s: %s", pIceServer->url, addressResolvedIPv6);
298291

299292

300293
CleanUp:

src/source/Ice/Network.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,14 +439,12 @@ STATUS getIpWithHostName(PCHAR hostname, PDualKvsIpAddresses destIps)
439439
// TODO: Should also init port to 0, or no (we do in the threadpool-enabled version of this call for STUN)?
440440
MEMCPY(destIps->ipv4Address.address, &ipv4Addr->sin_addr, IPV4_ADDRESS_LENGTH);
441441
ipv4Resolved = TRUE;
442-
// ipv6Resolved = TRUE;
443442
} else if (rp->ai_family == AF_INET6) {
444443
DLOGD("Found an IPv6 ICE server addresss");
445444
ipv6Addr = (struct sockaddr_in6*) rp->ai_addr;
446445
destIps->ipv6Address.family = KVS_IP_FAMILY_TYPE_IPV6;
447446
MEMCPY(destIps->ipv6Address.address, &ipv6Addr->sin6_addr, IPV6_ADDRESS_LENGTH);
448447
ipv6Resolved = TRUE;
449-
// ipv4Resolved = TRUE;
450448
} else {
451449
DLOGD("Found an invalid ICE server addresss family type - must be IPv4 or IPv6.");
452450
}

src/source/Include_i.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ typedef struct {
103103
BOOL isPointToPoint;
104104
} KvsIpAddress, *PKvsIpAddress;
105105

106-
// This structure stores both an IPv4 and IPv6 address (if applicable) for a peer/server.
106+
// This structure stores both an IPv4 and IPv6 address (if applicable).
107107
typedef struct {
108108
KvsIpAddress ipv4Address;
109109
KvsIpAddress ipv6Address;

src/source/PeerConnection/PeerConnection.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -814,8 +814,7 @@ STATUS getStunAddr(PStunIpAddrContext pStunIpAddrCtx)
814814
// # if not defined (USE_DUAL_STACK_CANDIDATES)
815815
// ipv6Resolved = TRUE;
816816

817-
DLOGD("Resolving STUN address...");
818-
817+
DLOGD("Resolving STUN server address for hostname: %s", pStunIpAddrCtx->hostname);
819818

820819
errCode = getaddrinfo(pStunIpAddrCtx->hostname, NULL, NULL, &res);
821820
if (errCode != 0) {
@@ -824,21 +823,21 @@ STATUS getStunAddr(PStunIpAddrContext pStunIpAddrCtx)
824823
} else {
825824
for (rp = res; rp != NULL && !(ipv4Resolved && ipv6Resolved); rp = rp->ai_next) {
826825
if (!ipv4Resolved && rp->ai_family == AF_INET) {
827-
DLOGD("Found an IPv4 STUN addresss");
826+
DLOGD("Found an IPv4 STUN addresss for hostname: %s", pStunIpAddrCtx->hostname);
828827
ipv4Addr = (struct sockaddr_in*) rp->ai_addr;
829828
pStunIpAddrCtx->kvsIpAddresses.ipv4Address.family = KVS_IP_FAMILY_TYPE_IPV4;
830829
pStunIpAddrCtx->kvsIpAddresses.ipv4Address.port = 0;
831830
MEMCPY(pStunIpAddrCtx->kvsIpAddresses.ipv4Address.address, &ipv4Addr->sin_addr, IPV4_ADDRESS_LENGTH);
832831
ipv4Resolved = TRUE;
833832
} else if (!ipv6Resolved && rp->ai_family == AF_INET6) {
834-
DLOGD("Found an IPv6 STUN addresss");
833+
DLOGD("Found an IPv6 STUN addresss for hostname: %s", pStunIpAddrCtx->hostname);
835834
ipv6Addr = (struct sockaddr_in6*) rp->ai_addr;
836835
pStunIpAddrCtx->kvsIpAddresses.ipv6Address.family = KVS_IP_FAMILY_TYPE_IPV6;
837836
pStunIpAddrCtx->kvsIpAddresses.ipv6Address.port = 0;
838837
MEMCPY(pStunIpAddrCtx->kvsIpAddresses.ipv6Address.address, &ipv6Addr->sin6_addr, IPV6_ADDRESS_LENGTH);
839838
ipv6Resolved = TRUE;
840839
} else {
841-
DLOGD("Invalid family STUN addresss");
840+
DLOGD("Invalid family STUN addresss for hostname: %s", pStunIpAddrCtx->hostname);
842841
}
843842
}
844843
freeaddrinfo(res);
@@ -884,6 +883,7 @@ STATUS onSetStunServerIp(UINT64 customData, PCHAR url, PDualKvsIpAddresses pIpAd
884883
CHK_ERR(getStunAddr(pWebRtcClientContext->pStunIpAddrCtx) == STATUS_SUCCESS, retStatus, "Failed to resolve after cache expiry");
885884
}
886885
MEMCPY(pIpAddresses, &pWebRtcClientContext->pStunIpAddrCtx->kvsIpAddresses.ipv4Address, SIZEOF(pWebRtcClientContext->pStunIpAddrCtx->kvsIpAddresses.ipv4Address));
886+
MEMCPY(pIpAddresses, &pWebRtcClientContext->pStunIpAddrCtx->kvsIpAddresses.ipv6Address, SIZEOF(pWebRtcClientContext->pStunIpAddrCtx->kvsIpAddresses.ipv6Address));
887887
} else {
888888
DLOGE("Initialization failed");
889889
}
@@ -906,7 +906,8 @@ PVOID resolveStunIceServerIp(PVOID args)
906906
UNUSED_PARAM(args);
907907
PWebRtcClientContext pWebRtcClientContext = getWebRtcClientInstance();
908908
BOOL locked = FALSE;
909-
CHAR addressResolved[KVS_IP_ADDRESS_STRING_BUFFER_LEN + 1] = {'\0'};
909+
CHAR addressResolvedIPv4[KVS_IP_ADDRESS_STRING_BUFFER_LEN + 1] = {'\0'};
910+
CHAR addressResolvedIPv6[KVS_IP_ADDRESS_STRING_BUFFER_LEN + 1] = {'\0'};
910911
PCHAR pRegion;
911912
PCHAR pHostnamePostfix;
912913
UINT64 stunDnsResolutionStartTime = 0;
@@ -932,9 +933,20 @@ PVOID resolveStunIceServerIp(PVOID args)
932933
KINESIS_VIDEO_STUN_URL_WITHOUT_PORT, pRegion, pHostnamePostfix);
933934
stunDnsResolutionStartTime = GETTIME();
934935
if (getStunAddr(pWebRtcClientContext->pStunIpAddrCtx) == STATUS_SUCCESS) {
935-
getIpAddrStr(&pWebRtcClientContext->pStunIpAddrCtx->kvsIpAddresses.ipv4Address, addressResolved, ARRAY_SIZE(addressResolved));
936-
DLOGI("ICE Server address for %s with getaddrinfo: %s", pWebRtcClientContext->pStunIpAddrCtx->hostname, addressResolved);
937-
pWebRtcClientContext->pStunIpAddrCtx->isIpInitialized = TRUE;
936+
if(pWebRtcClientContext->pStunIpAddrCtx->kvsIpAddresses.ipv4Address.family == KVS_IP_FAMILY_TYPE_IPV4) {
937+
// If IP family is set, then there must have been an IPv4 address resolved.
938+
getIpAddrStr(&pWebRtcClientContext->pStunIpAddrCtx->kvsIpAddresses.ipv4Address, addressResolvedIPv4, ARRAY_SIZE(addressResolvedIPv4));
939+
DLOGI("ICE Server address for %s with getaddrinfo: %s", pWebRtcClientContext->pStunIpAddrCtx->hostname, addressResolvedIPv4);
940+
pWebRtcClientContext->pStunIpAddrCtx->isIpInitialized = TRUE;
941+
}
942+
if(pWebRtcClientContext->pStunIpAddrCtx->kvsIpAddresses.ipv6Address.family == KVS_IP_FAMILY_TYPE_IPV4) {
943+
// If IP family is set, then there must have been an IPv6 address resolved.
944+
getIpAddrStr(&pWebRtcClientContext->pStunIpAddrCtx->kvsIpAddresses.ipv6Address, addressResolvedIPv6, ARRAY_SIZE(addressResolvedIPv6));
945+
DLOGI("ICE Server address for %s with getaddrinfo: %s", pWebRtcClientContext->pStunIpAddrCtx->hostname, addressResolvedIPv6);
946+
pWebRtcClientContext->pStunIpAddrCtx->isIpInitialized = TRUE;
947+
948+
}
949+
938950
} else {
939951
DLOGE("Failed to resolve %s", pWebRtcClientContext->pStunIpAddrCtx->hostname);
940952
}

0 commit comments

Comments
 (0)