Skip to content

Commit

Permalink
Create state machines with names (#1894)
Browse files Browse the repository at this point in the history
* Create state machines with names

* Add turn object in logs
  • Loading branch information
disa6302 authored Jan 5, 2024
1 parent feba4d3 commit 9e344ed
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/source/Ice/IceAgent.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ STATUS createIceAgent(PCHAR username, PCHAR password, PIceAgentCallbacks pIceAge
pIceAgent->lock = MUTEX_CREATE(TRUE);

// Create the state machine
CHK_STATUS(createStateMachine(ICE_AGENT_STATE_MACHINE_STATES, ICE_AGENT_STATE_MACHINE_STATE_COUNT, (UINT64) pIceAgent, iceAgentGetCurrentTime,
(UINT64) pIceAgent, &pIceAgent->pStateMachine));
CHK_STATUS(createStateMachineWithName(ICE_AGENT_STATE_MACHINE_STATES, ICE_AGENT_STATE_MACHINE_STATE_COUNT, (UINT64) pIceAgent,
iceAgentGetCurrentTime, (UINT64) pIceAgent, ICE_STATE_MACHINE_NAME, &pIceAgent->pStateMachine));
pIceAgent->iceAgentStatus = STATUS_SUCCESS;
pIceAgent->iceAgentStateTimerTask = MAX_UINT32;
pIceAgent->keepAliveTimerTask = MAX_UINT32;
Expand Down
3 changes: 3 additions & 0 deletions src/source/Ice/IceAgent.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ extern "C" {
#define ICE_CANDIDATE_ID_LEN 8

#define STATS_NOT_APPLICABLE_STR (PCHAR) "N/A"

#define ICE_STATE_MACHINE_NAME (PCHAR) "ICE"

typedef enum {
ICE_CANDIDATE_STATE_NEW,
ICE_CANDIDATE_STATE_VALID,
Expand Down
6 changes: 4 additions & 2 deletions src/source/Ice/TurnConnection.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ STATUS createTurnConnection(PIceServer pTurnServer, TIMER_QUEUE_HANDLE timerQueu
ENTERS();
STATUS retStatus = STATUS_SUCCESS;
PTurnConnection pTurnConnection = NULL;
CHAR turnStateMachineName[MAX_STATE_MACHINE_NAME_LENGTH];

CHK(pTurnServer != NULL && ppTurnConnection != NULL && pTurnSocket != NULL, STATUS_NULL_ARG);
CHK(IS_VALID_TIMER_QUEUE_HANDLE(timerQueueHandle), STATUS_INVALID_ARG);
Expand Down Expand Up @@ -62,8 +63,9 @@ STATUS createTurnConnection(PIceServer pTurnServer, TIMER_QUEUE_HANDLE timerQueu
pTurnConnection->nextAllocationRefreshTime = 0;
pTurnConnection->currentTimerCallingPeriod = DEFAULT_TURN_TIMER_INTERVAL_BEFORE_READY;

CHK_STATUS(createStateMachine(TURN_CONNECTION_STATE_MACHINE_STATES, TURN_CONNECTION_STATE_MACHINE_STATE_COUNT, (UINT64) pTurnConnection,
turnConnectionGetTime, (UINT64) pTurnConnection, &pTurnConnection->pStateMachine));
SNPRINTF(turnStateMachineName, MAX_STATE_MACHINE_NAME_LENGTH, "%s-%p", TURN_STATE_MACHINE_NAME, (PVOID) pTurnConnection);
CHK_STATUS(createStateMachineWithName(TURN_CONNECTION_STATE_MACHINE_STATES, TURN_CONNECTION_STATE_MACHINE_STATE_COUNT, (UINT64) pTurnConnection,
turnConnectionGetTime, (UINT64) pTurnConnection, turnStateMachineName, &pTurnConnection->pStateMachine));

CleanUp:

Expand Down
2 changes: 2 additions & 0 deletions src/source/Ice/TurnConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ extern "C" {
#define TURN_DATA_CHANNEL_SEND_OVERHEAD 4
#define TURN_DATA_CHANNEL_MSG_FIRST_BYTE 0x40

#define TURN_STATE_MACHINE_NAME (PCHAR) "TURN"

#define TURN_STATE_NEW_STR (PCHAR) "TURN_STATE_NEW"
#define TURN_STATE_CHECK_SOCKET_CONNECTION_STR (PCHAR) "TURN_STATE_CHECK_SOCKET_CONNECTION"
#define TURN_STATE_GET_CREDENTIALS_STR (PCHAR) "TURN_STATE_GET_CREDENTIALS"
Expand Down
2 changes: 1 addition & 1 deletion src/source/Ice/TurnConnectionStateMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ STATUS stepTurnConnectionStateMachine(PTurnConnection pTurnConnection)
}

if (oldState != pTurnConnection->state) {
DLOGD("Turn connection state changed from %s to %s.", turnConnectionGetStateStr(oldState),
DLOGD("[%p] Turn connection state changed from %s to %s.", (PVOID) pTurnConnection, turnConnectionGetStateStr(oldState),
turnConnectionGetStateStr(pTurnConnection->state));
} else {
// state machine retry is not used. resetStateMachineRetryCount just to avoid
Expand Down
7 changes: 4 additions & 3 deletions src/source/Signaling/Signaling.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ STATUS createSignalingSync(PSignalingClientInfoInternal pClientInfo, PChannelInf
CHK_STATUS(configureRetryStrategyForSignalingStateMachine(pSignalingClient));

// Create the state machine
CHK_STATUS(createStateMachine(SIGNALING_STATE_MACHINE_STATES, SIGNALING_STATE_MACHINE_STATE_COUNT,
CUSTOM_DATA_FROM_SIGNALING_CLIENT(pSignalingClient), signalingGetCurrentTime,
CUSTOM_DATA_FROM_SIGNALING_CLIENT(pSignalingClient), &pSignalingClient->pStateMachine));
CHK_STATUS(createStateMachineWithName(SIGNALING_STATE_MACHINE_STATES, SIGNALING_STATE_MACHINE_STATE_COUNT,
CUSTOM_DATA_FROM_SIGNALING_CLIENT(pSignalingClient), signalingGetCurrentTime,
CUSTOM_DATA_FROM_SIGNALING_CLIENT(pSignalingClient), SIGNALING_STATE_MACHINE_NAME,
&pSignalingClient->pStateMachine));

// Prepare the signaling channel protocols array
pSignalingClient->signalingProtocols[PROTOCOL_INDEX_HTTPS].name = HTTPS_SCHEME_NAME;
Expand Down
2 changes: 2 additions & 0 deletions src/source/Signaling/Signaling.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ extern "C" {

#define DEFAULT_CREATE_SIGNALING_CLIENT_RETRY_ATTEMPTS 7

#define SIGNALING_STATE_MACHINE_NAME (PCHAR) "SIGNALING"

static const ExponentialBackoffRetryStrategyConfig DEFAULT_SIGNALING_STATE_MACHINE_EXPONENTIAL_BACKOFF_RETRY_CONFIGURATION = {
/* Exponential wait times with this config will look like following -
************************************
Expand Down

0 comments on commit 9e344ed

Please sign in to comment.