Skip to content

Commit

Permalink
Set session_id for peer endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielius1922 authored and Daniel Adam committed Aug 6, 2024
1 parent a758685 commit c4588fb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
3 changes: 2 additions & 1 deletion api/cloud/oc_cloud.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ cloud_ep_session_event_handler(const oc_endpoint_t *endpoint,
OC_CLOUD_DBG("ep(%" PRId64 ") ep_state: %d (current: %d)", session_id,
(int)state, (int)ctx->cloud_ep_state);
#endif /* OC_DBG_IS_ENABLED */
if (ctx->cloud_ep->session_id == 0 && state == OC_SESSION_CONNECTED) {
if (state == OC_SESSION_CONNECTED && (ctx->cloud_ep->flags & TCP) != 0 &&
ctx->cloud_ep->session_id == 0) {
OC_CLOUD_DBG("session_id set to %" PRIu32, endpoint->session_id);
ctx->cloud_ep->session_id = endpoint->session_id;
}
Expand Down
18 changes: 8 additions & 10 deletions security/oc_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -2182,6 +2182,12 @@ oc_tls_add_new_peer(oc_tls_new_peer_params_t params)
return NULL;
}

#ifdef OC_TCP
if (((peer->endpoint.flags & TCP) != 0) && (peer->endpoint.session_id == 0)) {
peer->endpoint.session_id = oc_tcp_get_new_session_id();
}
#endif /* OC_TCP */

#ifdef OC_PKI
oc_tls_peer_pki_init(peer, params.user_data, params.verify_certificate);
#endif /* OC_PKI */
Expand Down Expand Up @@ -2715,15 +2721,8 @@ oc_tls_init_connection(oc_message_t *message)
return;
}

#ifdef OC_TCP
if ((peer->endpoint.flags & TCP) != 0) {
#ifndef OC_HAS_FEATURE_TCP_ASYNC_CONNECT
if (peer->endpoint.session_id == 0) {
peer->endpoint.session_id = oc_tcp_get_new_session_id();
}
#endif /* !OC_HAS_FEATURE_TCP_ASYNC_CONNECT */

#ifdef OC_HAS_FEATURE_TCP_ASYNC_CONNECT
if ((peer->endpoint.flags & TCP) != 0) {
oc_tcp_connect_result_t res =
oc_tcp_connect_to_endpoint(&peer->endpoint, oc_tls_on_tcp_connect, NULL);
if (res.state == OC_TCP_SOCKET_STATE_CONNECTED ||
Expand All @@ -2747,9 +2746,8 @@ oc_tls_init_connection(oc_message_t *message)
oc_tls_free_peer(peer, false, false, true);
oc_message_unref(message);
return;
#endif /* OC_HAS_FEATURE_TCP_ASYNC_CONNECT */
}
#endif /* OC_TCP */
#endif /* OC_HAS_FEATURE_TCP_ASYNC_CONNECT */
oc_tls_handshake(peer);
oc_message_unref(message);
}
Expand Down

0 comments on commit c4588fb

Please sign in to comment.