4 #ifndef __KINESIS_VIDEO_WEBRTC_CLIENT_TURN_CONNECTION__
5 #define __KINESIS_VIDEO_WEBRTC_CLIENT_TURN_CONNECTION__
14 #define TURN_REQUEST_TRANSPORT_UDP 17
15 #define TURN_REQUEST_TRANSPORT_TCP 6
16 #define DEFAULT_TURN_ALLOCATION_LIFETIME_SECONDS 600
18 #define TURN_PERMISSION_LIFETIME (300 * HUNDREDS_OF_NANOS_IN_A_SECOND)
19 #define DEFAULT_TURN_TIMER_INTERVAL_BEFORE_READY (50 * HUNDREDS_OF_NANOS_IN_A_MILLISECOND)
20 #define DEFAULT_TURN_TIMER_INTERVAL_AFTER_READY (1 * HUNDREDS_OF_NANOS_IN_A_SECOND)
21 #define DEFAULT_TURN_SEND_REFRESH_INVERVAL (1 * HUNDREDS_OF_NANOS_IN_A_SECOND)
24 #define DEFAULT_TURN_GET_CREDENTIAL_TIMEOUT (5 * HUNDREDS_OF_NANOS_IN_A_SECOND)
25 #define DEFAULT_TURN_ALLOCATION_TIMEOUT (5 * HUNDREDS_OF_NANOS_IN_A_SECOND)
26 #define DEFAULT_TURN_CREATE_PERMISSION_TIMEOUT (5 * HUNDREDS_OF_NANOS_IN_A_SECOND)
27 #define DEFAULT_TURN_BIND_CHANNEL_TIMEOUT (5 * HUNDREDS_OF_NANOS_IN_A_SECOND)
28 #define DEFAULT_TURN_CLEAN_UP_TIMEOUT (10 * HUNDREDS_OF_NANOS_IN_A_SECOND)
30 #define DEFAULT_TURN_ALLOCATION_REFRESH_GRACE_PERIOD (30 * HUNDREDS_OF_NANOS_IN_A_SECOND)
31 #define DEFAULT_TURN_PERMISSION_REFRESH_GRACE_PERIOD (30 * HUNDREDS_OF_NANOS_IN_A_SECOND)
33 #define MAX_TURN_CHANNEL_DATA_MESSAGE_SIZE 4 + 65536
34 #define DEFAULT_TURN_MESSAGE_SEND_CHANNEL_DATA_BUFFER_LEN MAX_TURN_CHANNEL_DATA_MESSAGE_SIZE
35 #define DEFAULT_TURN_MESSAGE_RECV_CHANNEL_DATA_BUFFER_LEN MAX_TURN_CHANNEL_DATA_MESSAGE_SIZE
36 #define DEFAULT_TURN_CHANNEL_DATA_BUFFER_SIZE 512
37 #define DEFAULT_TURN_MAX_PEER_COUNT 32
38 #define MAX_TURN_PROFILE_LOG_DESC_LEN 256
41 #define TURN_CHANNEL_BIND_CHANNEL_NUMBER_BASE (UINT16) 0x4000
44 #define TURN_DATA_CHANNEL_SEND_OVERHEAD 4
45 #define TURN_DATA_CHANNEL_MSG_FIRST_BYTE 0x40
47 #define TURN_STATE_MACHINE_NAME (PCHAR) "TURN"
49 #define TURN_STATE_NEW_STR (PCHAR) "TURN_STATE_NEW"
50 #define TURN_STATE_CHECK_SOCKET_CONNECTION_STR (PCHAR) "TURN_STATE_CHECK_SOCKET_CONNECTION"
51 #define TURN_STATE_GET_CREDENTIALS_STR (PCHAR) "TURN_STATE_GET_CREDENTIALS"
52 #define TURN_STATE_ALLOCATION_STR (PCHAR) "TURN_STATE_ALLOCATION"
53 #define TURN_STATE_CREATE_PERMISSION_STR (PCHAR) "TURN_STATE_CREATE_PERMISSION"
54 #define TURN_STATE_BIND_CHANNEL_STR (PCHAR) "TURN_STATE_BIND_CHANNEL"
55 #define TURN_STATE_READY_STR (PCHAR) "TURN_STATE_READY"
56 #define TURN_STATE_CLEAN_UP_STR (PCHAR) "TURN_STATE_CLEAN_UP"
57 #define TURN_STATE_FAILED_STR (PCHAR) "TURN_STATE_FAILED"
58 #define TURN_STATE_UNKNOWN_STR (PCHAR) "TURN_STATE_UNKNOWN"
#define STUN_MAX_NONCE_LEN
Definition: Include_i.h:81
#define STUN_MAX_REALM_LEN
Definition: Include_i.h:78
struct KvsIpAddress * PKvsIpAddress
KVS_SOCKET_PROTOCOL
Definition: Network.h:48
struct __SocketConnection * PSocketConnection
Definition: SocketConnection.h:48
STATUS turnConnectionGetLongTermKey(PCHAR, PCHAR, PCHAR, PBYTE, UINT32)
Definition: TurnConnection.c:1134
STATUS turnConnectionFreePreAllocatedPackets(PTurnConnection)
Definition: TurnConnection.c:907
STATUS turnConnectionAddPeer(PTurnConnection, PKvsIpAddress)
Definition: TurnConnection.c:669
STATUS(* RelayAddressAvailableFunc)(UINT64, PKvsIpAddress, PSocketConnection)
Definition: TurnConnection.h:60
TURN_CONNECTION_DATA_TRANSFER_MODE
Definition: TurnConnection.h:70
@ TURN_CONNECTION_DATA_TRANSFER_MODE_SEND_INDIDATION
Definition: TurnConnection.h:71
@ TURN_CONNECTION_DATA_TRANSFER_MODE_DATA_CHANNEL
Definition: TurnConnection.h:72
UINT64 turnConnectionGetTime(UINT64)
Definition: TurnConnection.c:85
TURN_PEER_CONNECTION_STATE
Definition: TurnConnection.h:63
@ TURN_PEER_CONN_STATE_FAILED
Definition: TurnConnection.h:67
@ TURN_PEER_CONN_STATE_BIND_CHANNEL
Definition: TurnConnection.h:65
@ TURN_PEER_CONN_STATE_READY
Definition: TurnConnection.h:66
@ TURN_PEER_CONN_STATE_CREATE_PERMISSION
Definition: TurnConnection.h:64
STATUS turnConnectionHandleChannelData(PTurnConnection, PBYTE, UINT32, PTurnChannelData, PUINT32, PUINT32)
Definition: TurnConnection.c:492
STATUS turnConnectionShutdown(PTurnConnection, UINT64)
Definition: TurnConnection.c:964
STATUS freeTurnConnection(PTurnConnection *)
Definition: TurnConnection.c:91
STATUS createTurnConnection(PIceServer, TIMER_QUEUE_HANDLE, TURN_CONNECTION_DATA_TRANSFER_MODE, KVS_SOCKET_PROTOCOL, PTurnConnectionCallbacks, PSocketConnection, PConnectionListener, PTurnConnection *)
Definition: TurnConnection.c:10
STATUS turnConnectionTimerCallback(UINT32, UINT64, UINT64)
Definition: TurnConnection.c:1099
STATUS turnConnectionStart(PTurnConnection)
Definition: TurnConnection.c:798
STATUS turnConnectionIncomingDataHandler(PTurnConnection, PBYTE, UINT32, PKvsIpAddress, PKvsIpAddress, PTurnChannelData, PUINT32)
Definition: TurnConnection.c:157
struct TurnProfileDiagnostics * PTurnProfileDiagnostics
BOOL turnConnectionGetRelayAddress(PTurnConnection, PKvsIpAddress)
Definition: TurnConnection.c:1013
STATUS(* TurnStateFailedFunc)(PSocketConnection, UINT64)
Definition: TurnConnection.h:61
VOID turnConnectionFatalError(PTurnConnection, STATUS)
Definition: TurnConnection.c:1218
STATUS turnConnectionRefreshPermission(PTurnConnection, PBOOL)
Definition: TurnConnection.c:873
PTurnPeer turnConnectionGetPeerWithIp(PTurnConnection, PKvsIpAddress)
Definition: TurnConnection.c:1204
STATUS checkTurnPeerConnections(PTurnConnection)
Definition: TurnConnection.c:1027
STATUS turnConnectionHandleStun(PTurnConnection, PBYTE, UINT32)
Definition: TurnConnection.c:207
struct TurnConnectionCallbacks * PTurnConnectionCallbacks
STATUS turnConnectionSendData(PTurnConnection, PBYTE, UINT32, PKvsIpAddress)
Definition: TurnConnection.c:720
struct TurnPeer * PTurnPeer
STATUS turnConnectionPackageTurnAllocationRequest(PCHAR, PCHAR, PBYTE, UINT16, UINT32, PStunPacket *)
Definition: TurnConnection.c:1155
STATUS turnConnectionHandleChannelDataTcpMode(PTurnConnection, PBYTE, UINT32, PTurnChannelData, PUINT32, PUINT32)
Definition: TurnConnection.c:566
PTurnPeer turnConnectionGetPeerWithChannelNumber(PTurnConnection, UINT16)
Definition: TurnConnection.c:1190
STATUS turnConnectionRefreshAllocation(PTurnConnection)
Definition: TurnConnection.c:837
STATUS turnConnectionUpdateNonce(PTurnConnection)
Definition: TurnConnection.c:935
struct TurnChannelData * PTurnChannelData
struct __TurnConnection * PTurnConnection
Definition: TurnConnection.h:187
STATUS turnConnectionHandleStunError(PTurnConnection, PBYTE, UINT32)
Definition: TurnConnection.c:368
BOOL turnConnectionIsShutdownComplete(PTurnConnection)
Definition: TurnConnection.c:1004
#define DEFAULT_TURN_MAX_PEER_COUNT
Definition: TurnConnection.h:37
Definition: ConnectionListener.h:19
Definition: IceUtils.h:53
Definition: Include_i.h:99
Definition: IceUtils.h:31
Definition: TurnConnection.h:75
UINT32 size
Definition: TurnConnection.h:77
PBYTE data
Definition: TurnConnection.h:76
KvsIpAddress senderAddr
Definition: TurnConnection.h:78
Definition: TurnConnection.h:81
RelayAddressAvailableFunc relayAddressAvailableFn
Definition: TurnConnection.h:83
UINT64 customData
Definition: TurnConnection.h:82
TurnStateFailedFunc turnStateFailedFn
Definition: TurnConnection.h:84
Definition: TurnConnection.h:87
TURN_PEER_CONNECTION_STATE connectionState
Definition: TurnConnection.h:96
UINT64 bindChannelTime
Definition: TurnConnection.h:108
KvsIpAddress xorAddress
Definition: TurnConnection.h:89
UINT16 channelNumber
Definition: TurnConnection.h:98
UINT64 createPermissionTime
Definition: TurnConnection.h:104
PTransactionIdStore pTransactionIdStore
Definition: TurnConnection.h:97
KvsIpAddress address
Definition: TurnConnection.h:88
BOOL ready
Definition: TurnConnection.h:100
UINT64 bindChannelStartTime
Definition: TurnConnection.h:107
BOOL firstTimeCreatePermReq
Definition: TurnConnection.h:101
UINT64 createPermissionStartTime
Definition: TurnConnection.h:103
BOOL firstTimeCreatePermResponse
Definition: TurnConnection.h:102
UINT64 permissionExpirationTime
Definition: TurnConnection.h:99
BOOL firstTimeBindChannelResponse
Definition: TurnConnection.h:106
BOOL firstTimeBindChannelReq
Definition: TurnConnection.h:105
Definition: TurnConnection.h:111
UINT64 getCredentialsStartTime
Definition: TurnConnection.h:112
UINT64 createAllocationStartTime
Definition: TurnConnection.h:114
UINT64 getCredentialsTime
Definition: TurnConnection.h:113
UINT64 createAllocationTime
Definition: TurnConnection.h:115
Definition: SocketConnection.h:25
Definition: TurnConnection.h:119
MUTEX sendLock
Definition: TurnConnection.h:144
UINT64 nextAllocationRefreshTime
Definition: TurnConnection.h:180
TurnConnectionCallbacks turnConnectionCallbacks
Definition: TurnConnection.h:167
PStateMachine pStateMachine
Definition: TurnConnection.h:185
PSocketConnection pControlChannel
Definition: TurnConnection.h:134
PStunPacket pTurnPacket
Definition: TurnConnection.h:153
UINT64 stateTimeoutTime
Definition: TurnConnection.h:149
MUTEX lock
Definition: TurnConnection.h:143
volatile ATOMIC_BOOL shutdownComplete
Definition: TurnConnection.h:122
UINT64 allocationExpirationTime
Definition: TurnConnection.h:179
BYTE turnNonce[STUN_MAX_NONCE_LEN]
Definition: TurnConnection.h:128
PStunPacket pTurnAllocationRefreshPacket
Definition: TurnConnection.h:156
PStunPacket pTurnChannelBindPacket
Definition: TurnConnection.h:155
STATUS errorStatus
Definition: TurnConnection.h:151
UINT64 currentTimerCallingPeriod
Definition: TurnConnection.h:182
CHAR turnRealm[STUN_MAX_REALM_LEN+1]
Definition: TurnConnection.h:127
PBYTE recvDataBuffer
Definition: TurnConnection.h:172
BYTE longTermKey[KVS_MD5_DIGEST_LENGTH]
Definition: TurnConnection.h:130
PBYTE completeChannelDataBuffer
Definition: TurnConnection.h:177
KvsIpAddress relayAddress
Definition: TurnConnection.h:160
volatile SIZE_T timerCallbackId
Definition: TurnConnection.h:124
PConnectionListener pConnectionListener
Definition: TurnConnection.h:162
UINT16 nonceLen
Definition: TurnConnection.h:129
BOOL relayAddressReported
Definition: TurnConnection.h:132
UINT32 recvDataBufferSize
Definition: TurnConnection.h:173
TURN_CONNECTION_DATA_TRANSFER_MODE dataTransferMode
Definition: TurnConnection.h:164
TurnPeer turnPeerList[32]
Definition: TurnConnection.h:136
UINT32 currRecvDataLen
Definition: TurnConnection.h:174
PStunPacket pTurnCreatePermissionPacket
Definition: TurnConnection.h:154
UINT32 dataBufferSize
Definition: TurnConnection.h:170
TIMER_QUEUE_HANDLE timerQueueHandle
Definition: TurnConnection.h:139
KvsIpAddress hostAddress
Definition: TurnConnection.h:158
CVAR freeAllocationCvar
Definition: TurnConnection.h:145
IceServer turnServer
Definition: TurnConnection.h:141
volatile ATOMIC_BOOL stopTurnConnection
Definition: TurnConnection.h:120
KVS_SOCKET_PROTOCOL protocol
Definition: TurnConnection.h:165
TurnProfileDiagnostics turnProfileDiagnostics
Definition: TurnConnection.h:184
BOOL credentialObtained
Definition: TurnConnection.h:131
BOOL deallocatePacketSent
Definition: TurnConnection.h:183
UINT32 turnPeerCount
Definition: TurnConnection.h:137
PBYTE sendDataBuffer
Definition: TurnConnection.h:169
UINT64 state
Definition: TurnConnection.h:147
volatile ATOMIC_BOOL hasAllocation
Definition: TurnConnection.h:123