Skip to content

Commit 52fa5e6

Browse files
author
Tero Heinonen
committed
Renamed session_start_timestamp to last_contact_time.
Renamed SECURE_SESSION_ALERT_SENT to SECURE_SESSION_CLOSED.
1 parent 451d773 commit 52fa5e6

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

source/coap_connection_handler.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
typedef enum session_state_e {
1919
SECURE_SESSION_HANDSHAKE_ONGOING = 0,
2020
SECURE_SESSION_OK,
21-
SECURE_SESSION_ALERT_SENT
21+
SECURE_SESSION_CLOSED
2222
}session_state_t;
2323

2424
typedef struct internal_socket_s {
@@ -67,7 +67,7 @@ typedef struct secure_session {
6767
secure_timer_t timer;
6868

6969
session_state_t session_state;
70-
uint32_t session_start_timestamp;
70+
uint32_t last_contact_time;
7171
ns_list_link_t link;
7272
} secure_session_t;
7373

@@ -117,8 +117,8 @@ static secure_session_t *secure_session_create(internal_socket_t *parent, uint8_
117117
// Seek & destroy oldest session where close notify have been sent
118118
secure_session_t *to_be_removed = NULL;
119119
ns_list_foreach(secure_session_t, cur_ptr, &secure_session_list) {
120-
if(cur_ptr->session_state == SECURE_SESSION_ALERT_SENT){
121-
if(!to_be_removed || cur_ptr->session_start_timestamp < to_be_removed->session_start_timestamp){
120+
if(cur_ptr->session_state == SECURE_SESSION_CLOSED){
121+
if(!to_be_removed || cur_ptr->last_contact_time < to_be_removed->last_contact_time){
122122
to_be_removed = cur_ptr;
123123
}
124124
}
@@ -444,7 +444,7 @@ static void secure_recv_sckt_msg(void *cb_res)
444444
tr_err("secure_recv_sckt_msg session creation failed - OOM");
445445
return;
446446
}
447-
session->session_start_timestamp = coap_service_get_internal_timer_ticks();
447+
session->last_contact_time = coap_service_get_internal_timer_ticks();
448448
// Start handshake
449449
if( !session->sec_handler->_is_started ){
450450
uint8_t *pw = (uint8_t *)ns_dyn_mem_alloc(64);
@@ -545,7 +545,7 @@ int coap_connection_handler_virtual_recv(coap_conn_handler_t *handler, uint8_t a
545545
return -1;
546546
}
547547

548-
session->session_start_timestamp = coap_service_get_internal_timer_ticks();
548+
session->last_contact_time = coap_service_get_internal_timer_ticks();
549549

550550
if( !session->sec_handler->_is_started ){
551551
uint8_t *pw = (uint8_t *)ns_dyn_mem_alloc(64);
@@ -651,8 +651,8 @@ void connection_handler_close_secure_connection( coap_conn_handler_t *handler, u
651651
secure_session_t *session = secure_session_find( handler->socket, destination_addr_ptr, port);
652652
if( session ){
653653
coap_security_send_close_alert( session->sec_handler );
654-
session->session_state = SECURE_SESSION_ALERT_SENT;
655-
session->session_start_timestamp = coap_service_get_internal_timer_ticks();
654+
session->session_state = SECURE_SESSION_CLOSED;
655+
session->last_contact_time = coap_service_get_internal_timer_ticks();
656656
}
657657
}
658658
}
@@ -706,7 +706,7 @@ int coap_connection_handler_send_data(coap_conn_handler_t *handler, ns_address_t
706706
if( !session ){
707707
return -1;
708708
}
709-
session->session_start_timestamp = coap_service_get_internal_timer_ticks();
709+
session->last_contact_time = coap_service_get_internal_timer_ticks();
710710
memcpy( handler->socket->dest_addr.address, dest_addr->address, 16 );
711711
handler->socket->dest_addr.identifier = dest_addr->identifier;
712712
handler->socket->dest_addr.type = dest_addr->type;
@@ -731,7 +731,7 @@ int coap_connection_handler_send_data(coap_conn_handler_t *handler, ns_address_t
731731
}
732732
}else if( session->session_state == SECURE_SESSION_OK ){
733733
if( coap_security_handler_send_message(session->sec_handler, data_ptr, data_len ) > 0 ){
734-
session->session_start_timestamp = coap_service_get_internal_timer_ticks();
734+
session->last_contact_time = coap_service_get_internal_timer_ticks();
735735
return 0;
736736
}
737737
}
@@ -780,14 +780,14 @@ void coap_connection_handler_exec(uint32_t time)
780780
if(ns_list_count(&secure_session_list)){
781781
// Seek & destroy old sessions where close notify have been sent
782782
ns_list_foreach(secure_session_t, cur_ptr, &secure_session_list) {
783-
if(cur_ptr->session_state == SECURE_SESSION_ALERT_SENT ||
783+
if(cur_ptr->session_state == SECURE_SESSION_CLOSED ||
784784
cur_ptr->session_state == SECURE_SESSION_HANDSHAKE_ONGOING){
785-
if((cur_ptr->session_start_timestamp + CLOSED_SECURE_SESSION_TIMEOUT) <= time){
785+
if((cur_ptr->last_contact_time + CLOSED_SECURE_SESSION_TIMEOUT) <= time){
786786
secure_session_delete(cur_ptr);
787787
}
788788
}
789789
if(cur_ptr->session_state == SECURE_SESSION_OK){
790-
if((cur_ptr->session_start_timestamp + OPEN_SECURE_SESSION_TIMEOUT) <= time){
790+
if((cur_ptr->last_contact_time + OPEN_SECURE_SESSION_TIMEOUT) <= time){
791791
secure_session_delete(cur_ptr);
792792
}
793793
}

0 commit comments

Comments
 (0)