4 #ifndef __KINESIS_VIDEO_WEBRTC_CLIENT_ICE_AGENT__
5 #define __KINESIS_VIDEO_WEBRTC_CLIENT_ICE_AGENT__
13 #define KVS_ICE_MAX_CANDIDATE_PAIR_COUNT 1024
14 #define KVS_ICE_MAX_REMOTE_CANDIDATE_COUNT 100
15 #define KVS_ICE_MAX_LOCAL_CANDIDATE_COUNT 100
16 #define KVS_ICE_GATHER_REFLEXIVE_AND_RELAYED_CANDIDATE_TIMEOUT (10 * HUNDREDS_OF_NANOS_IN_A_SECOND)
17 #define KVS_ICE_CONNECTIVITY_CHECK_TIMEOUT \
18 (12 * HUNDREDS_OF_NANOS_IN_A_SECOND)
20 #define KVS_ICE_CANDIDATE_NOMINATION_TIMEOUT \
21 (12 * HUNDREDS_OF_NANOS_IN_A_SECOND)
23 #define KVS_ICE_SEND_KEEP_ALIVE_INTERVAL (15 * HUNDREDS_OF_NANOS_IN_A_SECOND)
24 #define KVS_ICE_TURN_CONNECTION_SHUTDOWN_TIMEOUT (1 * HUNDREDS_OF_NANOS_IN_A_SECOND)
25 #define KVS_ICE_DEFAULT_TIMER_START_DELAY (3 * HUNDREDS_OF_NANOS_IN_A_MILLISECOND)
26 #define KVS_ICE_SHORT_CHECK_DELAY (50 * HUNDREDS_OF_NANOS_IN_A_MILLISECOND)
29 #define KVS_ICE_CONNECTION_CHECK_POLLING_INTERVAL (50 * HUNDREDS_OF_NANOS_IN_A_MILLISECOND)
30 #define KVS_ICE_STATE_READY_TIMER_POLLING_INTERVAL (1 * HUNDREDS_OF_NANOS_IN_A_SECOND)
32 #define KVS_ICE_GATHER_CANDIDATE_TIMER_POLLING_INTERVAL (50 * HUNDREDS_OF_NANOS_IN_A_MILLISECOND)
35 #define KVS_ICE_ENTER_STATE_DISCONNECTION_GRACE_PERIOD (2 * KVS_ICE_SEND_KEEP_ALIVE_INTERVAL)
36 #define KVS_ICE_ENTER_STATE_FAILED_GRACE_PERIOD (15 * HUNDREDS_OF_NANOS_IN_A_SECOND)
38 #define STUN_HEADER_MAGIC_BYTE_OFFSET 4
40 #define KVS_ICE_MAX_RELAY_CANDIDATE_COUNT 4
41 #define KVS_ICE_MAX_NEW_LOCAL_CANDIDATES_TO_REPORT_AT_ONCE 10
44 #define ICE_PRIORITY_HOST_CANDIDATE_TYPE_PREFERENCE 126
45 #define ICE_PRIORITY_SERVER_REFLEXIVE_CANDIDATE_TYPE_PREFERENCE 100
46 #define ICE_PRIORITY_PEER_REFLEXIVE_CANDIDATE_TYPE_PREFERENCE 110
47 #define ICE_PRIORITY_RELAYED_CANDIDATE_TYPE_PREFERENCE 0
48 #define ICE_PRIORITY_LOCAL_PREFERENCE 65535
50 #define IS_STUN_PACKET(pBuf) (getInt32(*(PUINT32) ((pBuf) + STUN_HEADER_MAGIC_BYTE_OFFSET)) == STUN_HEADER_MAGIC_COOKIE)
51 #define GET_STUN_PACKET_SIZE(pBuf) ((UINT32) getInt16(*(PINT16) ((pBuf) + SIZEOF(UINT16))))
53 #define IS_CANN_PAIR_SENDING_FROM_RELAYED(p) ((p)->local->iceCandidateType == ICE_CANDIDATE_TYPE_RELAYED)
55 #define KVS_ICE_DEFAULT_TURN_PROTOCOL KVS_SOCKET_PROTOCOL_TCP
57 #define ICE_HASH_TABLE_BUCKET_COUNT 100
58 #define ICE_HASH_TABLE_BUCKET_LENGTH 2
60 #define ICE_CANDIDATE_ID_LEN 8
62 #define STATS_NOT_APPLICABLE_STR (PCHAR) "N/A"
64 #define ICE_STATE_MACHINE_NAME (PCHAR) "ICE"
STATUS iceAgentGatherCandidateTimerCallback(UINT32, UINT64, UINT64)
Definition: IceAgent.c:1594
STATUS iceAgentSendKeepAliveTimerCallback(UINT32, UINT64, UINT64)
Definition: IceAgent.c:1552
struct IceAgentCallbacks * PIceAgentCallbacks
STATUS iceAgentInitRelayCandidate(PIceAgent, UINT32, KVS_SOCKET_PROTOCOL)
Definition: IceAgent.c:1878
STATUS iceAgentConnectedStateSetup(PIceAgent)
Definition: IceAgent.c:2080
STATUS iceAgentSendPacket(PIceAgent, PBYTE, UINT32)
Definition: IceAgent.c:664
STATUS pruneUnconnectedIceCandidatePair(PIceAgent)
Definition: IceAgent.c:1267
VOID(* IceConnectionStateChangedFunc)(UINT64, UINT64)
Definition: IceAgent.h:73
STATUS freeIceAgent(PIceAgent *)
Definition: IceAgent.c:169
UINT64 computeCandidatePairPriority(PIceCandidatePair, BOOL)
Definition: IceAgent.c:2895
struct RtcIceServerDiagnostics * PRtcIceServerDiagnostics
STATUS iceCandidatePairCheckConnection(PStunPacket, PIceAgent, PIceCandidatePair)
Definition: IceAgent.c:1300
ICE_CANDIDATE_STATE
Definition: IceAgent.h:66
@ ICE_CANDIDATE_STATE_INVALID
Definition: IceAgent.h:69
@ ICE_CANDIDATE_STATE_NEW
Definition: IceAgent.h:67
@ ICE_CANDIDATE_STATE_VALID
Definition: IceAgent.h:68
STATUS iceAgentInvalidateCandidatePair(PIceAgent)
Definition: IceAgent.c:2349
STATUS iceAgentShutdown(PIceAgent)
Definition: IceAgent.c:782
#define ICE_CANDIDATE_ID_LEN
Definition: IceAgent.h:60
STATUS iceAgentSendCandidateNomination(PIceAgent)
Definition: IceAgent.c:1696
STATUS iceCandidateSerialize(PIceCandidate, PCHAR, PUINT32)
Definition: IceAgent.c:2456
STATUS incomingDataHandler(UINT64, PSocketConnection, PBYTE, UINT32, PKvsIpAddress, PKvsIpAddress)
Definition: IceAgent.c:2402
STATUS iceAgentPopulateSdpMediaDescriptionCandidates(PIceAgent, PSdpMediaDescription, UINT32, PUINT32)
Definition: IceAgent.c:742
STATUS getIceAgentStats(PIceAgent, PKvsIceAgentMetrics)
Definition: IceAgent.c:2932
STATUS iceAgentValidateKvsRtcConfig(PKvsRtcConfiguration)
Definition: IceAgent.c:292
STATUS updateCandidateAddress(PIceCandidate, PKvsIpAddress)
Definition: IceAgent.c:2845
STATUS iceAgentReadyStateSetup(PIceAgent)
Definition: IceAgent.c:2193
STATUS freeIceCandidatePair(PIceCandidatePair *)
Definition: IceAgent.c:1173
STATUS findCandidateWithIp(PKvsIpAddress, PDoubleList, PIceCandidate *)
Definition: IceAgent.c:1005
struct IceAgentProfileDiagnostics * PIceAgentProfileDiagnostics
VOID(* IceInboundPacketFunc)(UINT64, PBYTE, UINT32)
Definition: IceAgent.h:72
UINT32 computeCandidatePriority(PIceCandidate)
Definition: IceAgent.c:2861
VOID iceAgentLogNewCandidate(PIceCandidate)
Definition: IceAgent.c:2817
VOID(* IceNewLocalCandidateFunc)(UINT64, PCHAR)
Definition: IceAgent.h:74
struct RtcIceCandidatePairDiagnostics * PRtcIceCandidatePairDiagnostics
STATUS iceAgentCheckConnectionStateSetup(PIceAgent)
Definition: IceAgent.c:1965
struct IceCandidatePair * PIceCandidatePair
STATUS findIceCandidatePairWithLocalSocketConnectionAndRemoteAddr(PIceAgent, PSocketConnection, PKvsIpAddress, BOOL, PIceCandidatePair *)
Definition: IceAgent.c:1230
STATUS createIceAgent(PCHAR, PCHAR, PIceAgentCallbacks, PRtcConfiguration, TIMER_QUEUE_HANDLE, PConnectionListener, PIceAgent *)
Definition: IceAgent.c:24
struct IceCandidate * PIceCandidate
STATUS iceAgentInitRelayCandidates(PIceAgent)
Definition: IceAgent.c:1830
STATUS updateSelectedLocalRemoteCandidateStats(PIceAgent)
Definition: IceAgent.c:2068
STATUS insertIceCandidatePair(PDoubleList, PIceCandidatePair)
Definition: IceAgent.c:1195
STATUS iceAgentSendSrflxCandidateRequest(PIceAgent)
Definition: IceAgent.c:1434
STATUS findCandidateWithSocketConnection(PSocketConnection, PDoubleList, PIceCandidate *)
Definition: IceAgent.c:1040
STATUS iceAgentStateTransitionTimerCallback(UINT32, UINT64, UINT64)
Definition: IceAgent.c:1409
STATUS iceAgentStartGathering(PIceAgent)
Definition: IceAgent.c:619
STATUS iceAgentInitSrflxCandidate(PIceAgent)
Definition: IceAgent.c:1736
struct __IceAgent * PIceAgent
Definition: IceAgent.h:77
PCHAR iceAgentGetCandidateTypeStr(ICE_CANDIDATE_TYPE)
Definition: IceAgent.c:2911
STATUS iceAgentInitHostCandidate(PIceAgent)
Definition: IceAgent.c:494
STATUS createIceCandidatePairs(PIceAgent, PIceCandidate, BOOL)
Definition: IceAgent.c:1075
STATUS iceAgentSendStunPacket(PStunPacket, PBYTE, UINT32, PIceAgent, PIceCandidate, PKvsIpAddress)
Definition: IceAgent.c:1350
STATUS iceAgentFatalError(PIceAgent, STATUS)
Definition: IceAgent.c:2803
STATUS handleStunPacket(PIceAgent, PBYTE, UINT32, PSocketConnection, PKvsIpAddress, PKvsIpAddress)
Definition: IceAgent.c:2497
STATUS iceAgentAddRemoteCandidate(PIceAgent, PCHAR)
Definition: IceAgent.c:352
STATUS iceAgentNominatingStateSetup(PIceAgent)
Definition: IceAgent.c:2150
STATUS iceAgentCheckCandidatePairConnection(PIceAgent)
Definition: IceAgent.c:1497
STATUS incomingRelayedDataHandler(UINT64, PSocketConnection, PBYTE, UINT32, PKvsIpAddress, PKvsIpAddress)
Definition: IceAgent.c:2378
STATUS iceAgentStartAgent(PIceAgent, PCHAR, PCHAR, BOOL)
Definition: IceAgent.c:571
STATUS iceAgentCheckPeerReflexiveCandidate(PIceAgent, PKvsIpAddress, UINT32, BOOL, PSocketConnection)
Definition: IceAgent.c:2745
UINT64 iceAgentGetCurrentTime(UINT64)
Definition: IceAgent.c:2926
struct RtcIceCandidateDiagnostics * PRtcIceCandidateDiagnostics
STATUS iceAgentRestart(PIceAgent, PCHAR, PCHAR)
Definition: IceAgent.c:862
STATUS iceAgentReportNewLocalCandidate(PIceAgent, PIceCandidate)
Definition: IceAgent.c:328
STATUS iceAgentNominateCandidatePair(PIceAgent)
Definition: IceAgent.c:2290
STATUS(* IceServerSetIpFunc)(UINT64, PCHAR, PKvsIpAddress)
Definition: Include_i.h:111
#define MAX_LOCAL_NETWORK_INTERFACE_COUNT
Definition: Network.h:13
KVS_SOCKET_PROTOCOL
Definition: Network.h:48
#define KVS_IP_ADDRESS_STRING_BUFFER_LEN
Definition: Network.h:18
CHAR DOMString[255U+1]
DOMString type is used to store strings of size 256 bytes (inclusive of '\0' character.
Definition: Stats.h:73
ICE_CANDIDATE_PAIR_STATE
Indicates computing states in the checklist Reference: https://www.w3.org/TR/webrtc-stats/#rtcstatsic...
Definition: Stats.h:126
ICE_CANDIDATE_TYPE
Definition: Stats.h:86
#define MAX_ICE_SERVERS_COUNT
Definition: Include.h:627
#define MAX_ICE_CONFIG_CREDENTIAL_LEN
Definition: Include.h:456
#define MAX_ICE_CONFIG_USER_NAME_LEN
Definition: Include.h:450
ICE_TRANSPORT_POLICY
ICE_TRANSPORT_POLICY restrict which ICE candidates are used in a session.
Definition: Include.h:848
#define MAX_STATS_STRING_LENGTH
Definition: Stats.h:65
#define MAX_CANDIDATE_ID_LENGTH
Definition: Stats.h:25
Definition: ConnectionListener.h:19
Definition: IceAgent.h:141
IceNewLocalCandidateFunc newLocalCandidateFn
Definition: IceAgent.h:145
IceInboundPacketFunc inboundPacketFn
Definition: IceAgent.h:143
UINT64 customData
Definition: IceAgent.h:142
IceServerSetIpFunc setStunServerIpFn
Definition: IceAgent.h:146
IceConnectionStateChangedFunc connectionStateChangedFn
Definition: IceAgent.h:144
Definition: IceAgent.h:189
UINT64 relayCandidateSetUpTime
Definition: IceAgent.h:193
UINT64 localCandidateGatheringTime
Definition: IceAgent.h:190
UINT64 candidateGatheringTime
Definition: IceAgent.h:196
UINT64 hostCandidateSetUpTime
Definition: IceAgent.h:191
UINT64 srflxCandidateSetUpTime
Definition: IceAgent.h:192
UINT64 iceAgentSetUpTime
Definition: IceAgent.h:197
UINT64 iceCandidatePairNominationTime
Definition: IceAgent.h:195
Definition: IceAgent.h:174
PTransactionIdStore pTransactionIdStore
Definition: IceAgent.h:181
UINT64 roundTripTime
Definition: IceAgent.h:184
PIceCandidate local
Definition: IceAgent.h:175
PHashTable requestSentTime
Definition: IceAgent.h:183
UINT64 responsesReceived
Definition: IceAgent.h:185
BOOL firstStunRequest
Definition: IceAgent.h:178
ICE_CANDIDATE_PAIR_STATE state
Definition: IceAgent.h:180
PIceCandidate remote
Definition: IceAgent.h:176
PRtcIceCandidatePairDiagnostics pRtcIceCandidatePairDiagnostics
Definition: IceAgent.h:186
UINT64 lastDataSentTime
Definition: IceAgent.h:182
BOOL nominated
Definition: IceAgent.h:177
UINT64 priority
Definition: IceAgent.h:179
Definition: IceAgent.h:149
PSocketConnection pSocketConnection
Definition: IceAgent.h:153
BOOL reported
Definition: IceAgent.h:169
UINT32 iceServerIndex
Definition: IceAgent.h:156
KvsIpAddress ipAddress
Definition: IceAgent.h:152
UINT32 priority
Definition: IceAgent.h:155
struct __TurnConnection * pTurnConnection
Definition: IceAgent.h:160
BOOL isRemote
Definition: IceAgent.h:151
KVS_SOCKET_PROTOCOL remoteProtocol
Definition: IceAgent.h:171
UINT32 foundation
Definition: IceAgent.h:157
PIceAgent pIceAgent
Definition: IceAgent.h:165
ICE_CANDIDATE_TYPE iceCandidateType
Definition: IceAgent.h:150
ICE_CANDIDATE_STATE state
Definition: IceAgent.h:154
Definition: IceUtils.h:53
KVS ICE Agent Collection of ICE agent related stats. Can be expanded in the future.
Definition: Include.h:1569
Definition: Include_i.h:99
Definition: Include.h:1171
Custom data type to allow setting UINT32 data type to NULL since C does not support setting basic dat...
Definition: NullableDefs.h:105
The Configuration defines a set of parameters to configure how the peer-to-peer communication establi...
Definition: Include.h:1219
Definition: IceAgent.h:91
DOMString url
For local candidates this is the URL of the ICE server from which the candidate was obtained.
Definition: IceAgent.h:92
DOMString relayProtocol
Definition: IceAgent.h:96
INT32 priority
Computed using the formula in https://tools.ietf.org/html/rfc5245#section-15.1.
Definition: IceAgent.h:98
INT32 port
Port number of the candidate.
Definition: IceAgent.h:99
DOMString candidateType
Type of local/remote ICE candidate.
Definition: IceAgent.h:100
DOMString protocol
Valid values: UDP, TCP.
Definition: IceAgent.h:95
Definition: IceAgent.h:103
BOOL nominated
Definition: IceAgent.h:107
UINT64 bytesReceived
Total number of bytes (minus header and padding) received on this candidate pair.
Definition: IceAgent.h:115
UINT64 bytesDiscardedOnSend
Total number of bytes for this candidate pair discarded due to socket errors.
Definition: IceAgent.h:138
ICE_CANDIDATE_PAIR_STATE state
State of checklist for the local-remote candidate pair.
Definition: IceAgent.h:106
UINT64 lastRequestTimestamp
Definition: IceAgent.h:121
UINT64 lastResponseTimestamp
Represents the timestamp at which the last STUN response was received on this particular candidate pa...
Definition: IceAgent.h:124
UINT64 lastPacketReceivedTimestamp
Definition: IceAgent.h:118
UINT64 requestsSent
The total number of connectivity check requests sent (without retransmissions).
Definition: IceAgent.h:135
NullableUint32 circuitBreakerTriggerCount
Definition: IceAgent.h:109
UINT64 bytesSent
Total number of bytes (minus header and padding) sent on this candidate pair.
Definition: IceAgent.h:114
DOUBLE availableOutgoingBitrate
Definition: IceAgent.h:130
DOUBLE currentRoundTripTime
Latest round trip time (seconds)
Definition: IceAgent.h:129
UINT64 requestsReceived
Total number of connectivity check requests received (including retransmission)
Definition: IceAgent.h:134
UINT64 lastPacketSentTimestamp
Definition: IceAgent.h:116
UINT32 packetsDiscardedOnSend
Total number of packets discarded for candidate pair due to socket errors,.
Definition: IceAgent.h:111
DOUBLE totalRoundTripTime
Definition: IceAgent.h:125
UINT64 packetsReceived
Total number of packets received on this candidate pair.
Definition: IceAgent.h:113
UINT64 responsesReceived
The total number of connectivity check responses received.
Definition: IceAgent.h:136
UINT64 firstRequestTimestamp
Represents the timestamp at which the first STUN request was sent on this particular candidate pair.
Definition: IceAgent.h:120
UINT64 packetsSent
Total number of packets sent on this candidate pair;.
Definition: IceAgent.h:112
DOUBLE availableIncomingBitrate
Definition: IceAgent.h:132
UINT64 responsesSent
The total number of connectivity check responses sent.
Definition: IceAgent.h:137
Definition: IceAgent.h:82
UINT64 totalRoundTripTime
Sum of RTTs of all the requests for which response has been received.
Definition: IceAgent.h:88
UINT64 totalResponsesReceived
Total number of responses received from the server.
Definition: IceAgent.h:87
UINT64 totalRequestsSent
Total amount of requests that have been sent to the server.
Definition: IceAgent.h:86
INT32 port
Port number used by client.
Definition: IceAgent.h:85
Definition: IceUtils.h:31
Definition: IceAgent.h:200
volatile ATOMIC_BOOL restart
Definition: IceAgent.h:205
volatile ATOMIC_BOOL agentStartGathering
Definition: IceAgent.h:201
ICE_TRANSPORT_POLICY iceTransportPolicy
Definition: IceAgent.h:266
KvsIpAddress localNetworkInterfaces[MAX_LOCAL_NETWORK_INTERFACE_COUNT]
Definition: IceAgent.h:254
UINT32 iceAgentStateTimerTask
Definition: IceAgent.h:236
UINT64 lastDataReceivedTime
Definition: IceAgent.h:262
TIMER_QUEUE_HANDLE timerQueueHandle
Definition: IceAgent.h:261
PStunPacket pBindingIndication
Definition: IceAgent.h:270
BOOL isControlling
Definition: IceAgent.h:230
UINT64 iceAgentState
Definition: IceAgent.h:241
PIceCandidatePair pDataSendingIceCandidatePair
Definition: IceAgent.h:247
BOOL detectedDisconnection
Definition: IceAgent.h:263
CHAR combinedUserName[(MAX_ICE_CONFIG_USER_NAME_LEN+1)<< 1]
the combination of remote user name and local user name.
Definition: IceAgent.h:214
PTransactionIdStore pStunBindingRequestTransactionIdStore
Definition: IceAgent.h:274
PDoubleList localCandidates
Definition: IceAgent.h:223
MUTEX lock
Definition: IceAgent.h:233
CHAR localPassword[MAX_ICE_CONFIG_CREDENTIAL_LEN+1]
Definition: IceAgent.h:211
UINT32 relayCandidateCount
Definition: IceAgent.h:259
volatile ATOMIC_BOOL shutdown
Definition: IceAgent.h:204
PDoubleList iceCandidatePairs
Definition: IceAgent.h:227
PRtcIceCandidateDiagnostics pRtcSelectedLocalIceCandidateDiagnostics
Definition: IceAgent.h:217
UINT32 keepAliveTimerTask
Definition: IceAgent.h:237
PStateMachine pStateMachine
Definition: IceAgent.h:243
PHashTable requestTimestampDiagnostics
Definition: IceAgent.h:221
PStackQueue triggeredCheckQueue
Definition: IceAgent.h:226
KvsRtcConfiguration kvsRtcConfiguration
Definition: IceAgent.h:267
volatile ATOMIC_BOOL addedRelayCandidate
Definition: IceAgent.h:207
volatile ATOMIC_BOOL processStun
Definition: IceAgent.h:206
UINT64 iceAgentStartTime
Definition: IceAgent.h:278
UINT32 foundationCounter
Definition: IceAgent.h:257
UINT64 tieBreaker
Definition: IceAgent.h:231
STATUS iceAgentStatus
Definition: IceAgent.h:244
CHAR remoteUsername[MAX_ICE_CONFIG_USER_NAME_LEN+1]
Definition: IceAgent.h:212
UINT64 disconnectionGracePeriodEndTime
Definition: IceAgent.h:264
volatile ATOMIC_BOOL stopGathering
Definition: IceAgent.h:208
PStunPacket pBindingRequest
Definition: IceAgent.h:271
UINT64 candidateGatheringProcessEndTime
Definition: IceAgent.h:277
PRtcIceCandidateDiagnostics pRtcSelectedRemoteIceCandidateDiagnostics
Definition: IceAgent.h:218
volatile ATOMIC_BOOL candidateGatheringFinished
Definition: IceAgent.h:203
IceAgentCallbacks iceAgentCallbacks
Definition: IceAgent.h:249
UINT64 stateEndTime
Definition: IceAgent.h:245
PDoubleList remoteCandidates
Definition: IceAgent.h:224
PConnectionListener pConnectionListener
Definition: IceAgent.h:229
UINT32 iceCandidateGatheringTimerTask
Definition: IceAgent.h:238
UINT64 candidateGatheringStartTime
Definition: IceAgent.h:276
UINT32 iceServersCount
Definition: IceAgent.h:252
IceAgentProfileDiagnostics iceAgentProfileDiagnostics
Definition: IceAgent.h:219
CHAR remotePassword[MAX_ICE_CONFIG_CREDENTIAL_LEN+1]
Definition: IceAgent.h:213
IceServer iceServers[MAX_ICE_SERVERS_COUNT]
Definition: IceAgent.h:251
UINT32 localNetworkInterfaceCount
Definition: IceAgent.h:255
volatile ATOMIC_BOOL remoteCredentialReceived
Definition: IceAgent.h:202
CHAR localUsername[MAX_ICE_CONFIG_USER_NAME_LEN+1]
Definition: IceAgent.h:210
PRtcIceServerDiagnostics pRtcIceServerDiagnostics[MAX_ICE_SERVERS_COUNT]
Definition: IceAgent.h:216
UINT64 candidateGatheringEndTime
Definition: IceAgent.h:246
Definition: SocketConnection.h:25
Definition: TurnConnection.h:119