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
#define MAX_CANDIDATE_TYPE_LENGTH
Definition: Stats.h:76
ICE_CANDIDATE_PAIR_STATE
Indicates computing states in the checklist Reference: https://www.w3.org/TR/webrtc-stats/#rtcstatsic...
Definition: Stats.h:137
ICE_CANDIDATE_TYPE
Definition: Stats.h:97
#define MAX_ICE_SERVERS_COUNT
Definition: Include.h:622
#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:843
#define MAX_ICE_CONFIG_URI_LEN
Definition: Stats.h:30
#define MAX_PROTOCOL_LENGTH
Definition: Stats.h:60
#define MAX_CANDIDATE_ID_LENGTH
Definition: Stats.h:25
Definition: ConnectionListener.h:19
Definition: IceAgent.h:140
IceNewLocalCandidateFunc newLocalCandidateFn
Definition: IceAgent.h:144
IceInboundPacketFunc inboundPacketFn
Definition: IceAgent.h:142
UINT64 customData
Definition: IceAgent.h:141
IceServerSetIpFunc setStunServerIpFn
Definition: IceAgent.h:145
IceConnectionStateChangedFunc connectionStateChangedFn
Definition: IceAgent.h:143
Definition: IceAgent.h:188
UINT64 relayCandidateSetUpTime
Definition: IceAgent.h:192
UINT64 localCandidateGatheringTime
Definition: IceAgent.h:189
UINT64 candidateGatheringTime
Definition: IceAgent.h:195
UINT64 hostCandidateSetUpTime
Definition: IceAgent.h:190
UINT64 srflxCandidateSetUpTime
Definition: IceAgent.h:191
UINT64 iceAgentSetUpTime
Definition: IceAgent.h:196
UINT64 iceCandidatePairNominationTime
Definition: IceAgent.h:194
Definition: IceAgent.h:173
PTransactionIdStore pTransactionIdStore
Definition: IceAgent.h:180
UINT64 roundTripTime
Definition: IceAgent.h:183
PIceCandidate local
Definition: IceAgent.h:174
PHashTable requestSentTime
Definition: IceAgent.h:182
UINT64 responsesReceived
Definition: IceAgent.h:184
BOOL firstStunRequest
Definition: IceAgent.h:177
ICE_CANDIDATE_PAIR_STATE state
Definition: IceAgent.h:179
PIceCandidate remote
Definition: IceAgent.h:175
PRtcIceCandidatePairDiagnostics pRtcIceCandidatePairDiagnostics
Definition: IceAgent.h:185
UINT64 lastDataSentTime
Definition: IceAgent.h:181
BOOL nominated
Definition: IceAgent.h:176
UINT64 priority
Definition: IceAgent.h:178
Definition: IceAgent.h:148
PSocketConnection pSocketConnection
Definition: IceAgent.h:152
BOOL reported
Definition: IceAgent.h:168
UINT32 iceServerIndex
Definition: IceAgent.h:155
KvsIpAddress ipAddress
Definition: IceAgent.h:151
UINT32 priority
Definition: IceAgent.h:154
struct __TurnConnection * pTurnConnection
Definition: IceAgent.h:159
BOOL isRemote
Definition: IceAgent.h:150
KVS_SOCKET_PROTOCOL remoteProtocol
Definition: IceAgent.h:170
UINT32 foundation
Definition: IceAgent.h:156
PIceAgent pIceAgent
Definition: IceAgent.h:164
ICE_CANDIDATE_TYPE iceCandidateType
Definition: IceAgent.h:149
ICE_CANDIDATE_STATE state
Definition: IceAgent.h:153
Definition: IceUtils.h:53
KVS ICE Agent Collection of ICE agent related stats. Can be expanded in the future.
Definition: Include.h:1564
Definition: Include_i.h:99
Definition: Include.h:1166
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:1214
Definition: IceAgent.h:91
INT32 priority
Computed using the formula in https://tools.ietf.org/html/rfc5245#section-15.1.
Definition: IceAgent.h:97
INT32 port
Port number of the candidate.
Definition: IceAgent.h:98
Definition: IceAgent.h:102
BOOL nominated
Definition: IceAgent.h:106
UINT64 bytesReceived
Total number of bytes (minus header and padding) received on this candidate pair.
Definition: IceAgent.h:114
UINT64 bytesDiscardedOnSend
Total number of bytes for this candidate pair discarded due to socket errors.
Definition: IceAgent.h:137
ICE_CANDIDATE_PAIR_STATE state
State of checklist for the local-remote candidate pair.
Definition: IceAgent.h:105
UINT64 lastRequestTimestamp
Definition: IceAgent.h:120
UINT64 lastResponseTimestamp
Represents the timestamp at which the last STUN response was received on this particular candidate pa...
Definition: IceAgent.h:123
UINT64 lastPacketReceivedTimestamp
Definition: IceAgent.h:117
UINT64 requestsSent
The total number of connectivity check requests sent (without retransmissions).
Definition: IceAgent.h:134
NullableUint32 circuitBreakerTriggerCount
Definition: IceAgent.h:108
UINT64 bytesSent
Total number of bytes (minus header and padding) sent on this candidate pair.
Definition: IceAgent.h:113
DOUBLE availableOutgoingBitrate
Definition: IceAgent.h:129
DOUBLE currentRoundTripTime
Latest round trip time (seconds)
Definition: IceAgent.h:128
UINT64 requestsReceived
Total number of connectivity check requests received (including retransmission)
Definition: IceAgent.h:133
UINT64 lastPacketSentTimestamp
Definition: IceAgent.h:115
UINT32 packetsDiscardedOnSend
Total number of packets discarded for candidate pair due to socket errors,.
Definition: IceAgent.h:110
DOUBLE totalRoundTripTime
Definition: IceAgent.h:124
UINT64 packetsReceived
Total number of packets received on this candidate pair.
Definition: IceAgent.h:112
UINT64 responsesReceived
The total number of connectivity check responses received.
Definition: IceAgent.h:135
UINT64 firstRequestTimestamp
Represents the timestamp at which the first STUN request was sent on this particular candidate pair.
Definition: IceAgent.h:119
UINT64 packetsSent
Total number of packets sent on this candidate pair;.
Definition: IceAgent.h:111
DOUBLE availableIncomingBitrate
Definition: IceAgent.h:131
UINT64 responsesSent
The total number of connectivity check responses sent.
Definition: IceAgent.h:136
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:199
volatile ATOMIC_BOOL restart
Definition: IceAgent.h:204
volatile ATOMIC_BOOL agentStartGathering
Definition: IceAgent.h:200
ICE_TRANSPORT_POLICY iceTransportPolicy
Definition: IceAgent.h:265
KvsIpAddress localNetworkInterfaces[MAX_LOCAL_NETWORK_INTERFACE_COUNT]
Definition: IceAgent.h:253
UINT32 iceAgentStateTimerTask
Definition: IceAgent.h:235
UINT64 lastDataReceivedTime
Definition: IceAgent.h:261
TIMER_QUEUE_HANDLE timerQueueHandle
Definition: IceAgent.h:260
PStunPacket pBindingIndication
Definition: IceAgent.h:269
BOOL isControlling
Definition: IceAgent.h:229
UINT64 iceAgentState
Definition: IceAgent.h:240
PIceCandidatePair pDataSendingIceCandidatePair
Definition: IceAgent.h:246
BOOL detectedDisconnection
Definition: IceAgent.h:262
CHAR combinedUserName[(MAX_ICE_CONFIG_USER_NAME_LEN+1)<< 1]
the combination of remote user name and local user name.
Definition: IceAgent.h:213
PTransactionIdStore pStunBindingRequestTransactionIdStore
Definition: IceAgent.h:273
PDoubleList localCandidates
Definition: IceAgent.h:222
MUTEX lock
Definition: IceAgent.h:232
CHAR localPassword[MAX_ICE_CONFIG_CREDENTIAL_LEN+1]
Definition: IceAgent.h:210
UINT32 relayCandidateCount
Definition: IceAgent.h:258
volatile ATOMIC_BOOL shutdown
Definition: IceAgent.h:203
PDoubleList iceCandidatePairs
Definition: IceAgent.h:226
PRtcIceCandidateDiagnostics pRtcSelectedLocalIceCandidateDiagnostics
Definition: IceAgent.h:216
UINT32 keepAliveTimerTask
Definition: IceAgent.h:236
PStateMachine pStateMachine
Definition: IceAgent.h:242
PHashTable requestTimestampDiagnostics
Definition: IceAgent.h:220
PStackQueue triggeredCheckQueue
Definition: IceAgent.h:225
KvsRtcConfiguration kvsRtcConfiguration
Definition: IceAgent.h:266
volatile ATOMIC_BOOL addedRelayCandidate
Definition: IceAgent.h:206
volatile ATOMIC_BOOL processStun
Definition: IceAgent.h:205
UINT64 iceAgentStartTime
Definition: IceAgent.h:277
UINT32 foundationCounter
Definition: IceAgent.h:256
UINT64 tieBreaker
Definition: IceAgent.h:230
STATUS iceAgentStatus
Definition: IceAgent.h:243
CHAR remoteUsername[MAX_ICE_CONFIG_USER_NAME_LEN+1]
Definition: IceAgent.h:211
UINT64 disconnectionGracePeriodEndTime
Definition: IceAgent.h:263
volatile ATOMIC_BOOL stopGathering
Definition: IceAgent.h:207
PStunPacket pBindingRequest
Definition: IceAgent.h:270
UINT64 candidateGatheringProcessEndTime
Definition: IceAgent.h:276
PRtcIceCandidateDiagnostics pRtcSelectedRemoteIceCandidateDiagnostics
Definition: IceAgent.h:217
volatile ATOMIC_BOOL candidateGatheringFinished
Definition: IceAgent.h:202
IceAgentCallbacks iceAgentCallbacks
Definition: IceAgent.h:248
UINT64 stateEndTime
Definition: IceAgent.h:244
PDoubleList remoteCandidates
Definition: IceAgent.h:223
PConnectionListener pConnectionListener
Definition: IceAgent.h:228
UINT32 iceCandidateGatheringTimerTask
Definition: IceAgent.h:237
UINT64 candidateGatheringStartTime
Definition: IceAgent.h:275
UINT32 iceServersCount
Definition: IceAgent.h:251
IceAgentProfileDiagnostics iceAgentProfileDiagnostics
Definition: IceAgent.h:218
CHAR remotePassword[MAX_ICE_CONFIG_CREDENTIAL_LEN+1]
Definition: IceAgent.h:212
IceServer iceServers[MAX_ICE_SERVERS_COUNT]
Definition: IceAgent.h:250
UINT32 localNetworkInterfaceCount
Definition: IceAgent.h:254
volatile ATOMIC_BOOL remoteCredentialReceived
Definition: IceAgent.h:201
CHAR localUsername[MAX_ICE_CONFIG_USER_NAME_LEN+1]
Definition: IceAgent.h:209
PRtcIceServerDiagnostics pRtcIceServerDiagnostics[MAX_ICE_SERVERS_COUNT]
Definition: IceAgent.h:215
UINT64 candidateGatheringEndTime
Definition: IceAgent.h:245
Definition: SocketConnection.h:25
Definition: TurnConnection.h:119