Skip to content

Commit 6721601

Browse files
authored
Merge pull request #9 from SovereignEdgeEU-COGNIT/mateuszkobak/fix-http
Mateuszkobak/fix http
2 parents f67f50c + bbfa114 commit 6721601

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

cognit/src/cognit_frontend_cli.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ int cfc_cli_upload_function_to_daas(cognit_frontend_cli_t* pt_cfc_cli, char* bis
317317
else
318318
{
319319
COGNIT_LOG_TRACE("JSON received size: %ld", t_http_config.t_http_response.size);
320-
cfc_set_has_connection(pt_cfc_cli, false);
320+
cfc_set_has_connection(pt_cfc_cli, true);
321321

322322
// Copy the response json to the response struct
323323
fc_id = atoi((char*)t_http_config.t_http_response.ui8_response_data_buffer);

cognit/src/device_runtime_state_machine.c

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ static void handle_init_state(device_runtime_sm_t* pt_dr_sm)
4242
if (!is_token_empty(pt_dr_sm))
4343
{
4444
dr_state_machine_execute_transition(pt_dr_sm, SUCCESS_AUTH);
45+
4546
}
4647
else
4748
{
@@ -111,6 +112,8 @@ static void handle_get_ecf_address_state(device_runtime_sm_t* pt_dr_sm)
111112
{
112113
COGNIT_LOG_DEBUG("Cognit Frontend Client disconnected, re-authenticating...");
113114
dr_state_machine_execute_transition(pt_dr_sm, TOKEN_NOT_VALID_ADDRESS);
115+
dr_state_machine_execute_transition(pt_dr_sm, TOKEN_UPDATED);
116+
114117
}
115118
}
116119

@@ -188,18 +191,10 @@ e_status_code_t dr_sm_offload_function(device_runtime_sm_t* pt_dr_sm, faas_t* pt
188191

189192
COGNIT_LOG_DEBUG("State is not READY. Handling transitions...");
190193
handle_transitions(pt_dr_sm);
191-
if (pt_dr_sm->current_state == READY)
194+
195+
if (pt_dr_sm->current_state != READY)
192196
{
193-
COGNIT_LOG_DEBUG("Retrying function offload after state transitions...");
194-
e_status_code_t ret = exec_offload_func(pt_dr_sm, pt_faas, pt_exec_response);
195-
if (ret != E_ST_CODE_SUCCESS)
196-
{
197-
COGNIT_LOG_DEBUG("Offload failed, re-authenticating...");
198-
dr_state_machine_execute_transition(pt_dr_sm, TOKEN_NOT_VALID_READY);
199-
dr_state_machine_execute_transition(pt_dr_sm, TOKEN_UPDATED);
200-
if (pt_dr_sm->current_state == READY)
201-
exec_offload_func(pt_dr_sm, pt_faas, pt_exec_response);
202-
}
197+
return E_ST_CODE_ERROR;
203198
}
204199

205200
COGNIT_LOG_DEBUG("Retrying function offload after state transitions...");
@@ -278,6 +273,19 @@ static int success_auth_condition(device_runtime_sm_t* pt_dr_sm)
278273
}
279274
}
280275

276+
static int token_updated_condition(device_runtime_sm_t* pt_dr_sm)
277+
{
278+
if (!is_token_empty(pt_dr_sm) && is_cfc_connected(pt_dr_sm) && pt_dr_sm->app_req_id != 0)
279+
{
280+
return 1;
281+
}
282+
else
283+
{
284+
return 0;
285+
}
286+
}
287+
288+
281289
static int repeat_auth_condition(device_runtime_sm_t* pt_dr_sm)
282290
{
283291
if (is_token_empty(pt_dr_sm))
@@ -419,7 +427,7 @@ sm_transition_t transitions[] = {
419427
{ GET_ECF_ADDRESS, ADDRESS_UPDATE_REQUIREMENTS, SEND_INIT_REQUEST, address_update_requirements_condition },
420428
{ INIT, SUCCESS_AUTH, SEND_INIT_REQUEST, success_auth_condition },
421429
{ INIT, REPEAT_AUTH, INIT, repeat_auth_condition },
422-
{ INIT, TOKEN_UPDATED, READY, success_auth_condition },
430+
{ INIT, TOKEN_UPDATED, READY, token_updated_condition },
423431
{ READY, RESULT_GIVEN, READY, result_given_condition },
424432
{ READY, TOKEN_NOT_VALID_READY, INIT, token_not_valid_ready_condition },
425433
{ READY, TOKEN_NOT_VALID_READY_2, INIT, token_not_valid_ready_2_condition },
@@ -568,6 +576,13 @@ static bool check_reqs(const scheduling_t* old_reqs, const scheduling_t* new_req
568576
return true;
569577
}
570578

579+
if (old_reqs->provider == NULL && new_reqs->provider == NULL) {
580+
return false; // los consideramos iguales
581+
}
582+
else if (old_reqs->provider == NULL || new_reqs->provider == NULL) {
583+
return true; // uno NULL y el otro no -> distintos
584+
}
585+
571586
if (strcmp(old_reqs->provider, new_reqs->provider) != 0)
572587
{
573588
return true;

0 commit comments

Comments
 (0)