diff --git a/faithd/src/client/client.c b/faithd/src/client/client.c index 020dba3..6bb84b7 100644 --- a/faithd/src/client/client.c +++ b/faithd/src/client/client.c @@ -928,12 +928,12 @@ client_handle_disconnect(faith_client_t *client, const faith_envelope_t *envl) { return FAITH_OK; } - static faith_status_code_t client_send_ack_event(faith_client_t *client, uint64_t seq_num, faith_event_codec_type_t event_type) { - if(!client || seq_num == UINT64_MAX) return FAITH_ERR_INVALID; + if (!client || seq_num == UINT64_MAX) + return FAITH_ERR_INVALID; uint8_t body[FAITH_ENVL_CTS_EVENT_ACK_BODY_SIZE] = {0}; faith_body_size_t body_size = 0; @@ -955,8 +955,11 @@ client_send_ack_event(faith_client_t *client, uint64_t seq_num, return FAITH_OK; } -static faith_status_code_t client_handle_event_conversation_created(faith_client_t* client, const faith_envl_stc_event_t* event) { - if(!client || !event) return FAITH_ERR_INVALID; +static faith_status_code_t +client_handle_event_conversation_created(faith_client_t *client, + const faith_envl_stc_event_t *event) { + if (!client || !event) + return FAITH_ERR_INVALID; faith_event_conversation_created_t conv_created = {0}; _FH_CHECK_RETURN(faith_decode_event_conversation_created( @@ -969,10 +972,12 @@ static faith_status_code_t client_handle_event_conversation_created(faith_client return FAITH_OK; } static faith_status_code_t -client_dispatch_event(faith_client_t* client, const faith_envl_stc_event_t* event) { - if(!client || !event) return FAITH_ERR_INVALID; +client_dispatch_event(faith_client_t *client, + const faith_envl_stc_event_t *event) { + if (!client || !event) + return FAITH_ERR_INVALID; - switch(event->type) { + switch (event->type) { case FAITH_EVENT_CONVERSATION_CREATED: _FH_CHECK_RETURN(client_handle_event_conversation_created(client, event)); break; @@ -983,8 +988,10 @@ client_dispatch_event(faith_client_t* client, const faith_envl_stc_event_t* even return FAITH_OK; } -static faith_status_code_t client_ack_event(faith_client_t* client, const faith_envl_stc_event_t* event) { - if(!client || !event) return FAITH_ERR_INVALID; +static faith_status_code_t +client_ack_event(faith_client_t *client, const faith_envl_stc_event_t *event) { + if (!client || !event) + return FAITH_ERR_INVALID; /* duplicate event */ if (client->last_acked_ev_seq != UINT64_MAX) { @@ -1001,9 +1008,8 @@ static faith_status_code_t client_ack_event(faith_client_t* client, const faith_ return FAITH_OK; } -static faith_status_code_t -client_handle_event(faith_client_t *client, - const faith_envelope_t *envl) { +static faith_status_code_t client_handle_event(faith_client_t *client, + const faith_envelope_t *envl) { if (!client || !envl) return FAITH_ERR_INVALID; @@ -1399,10 +1405,11 @@ static faith_status_code_t faith_client_send_hello(faith_client_t *client) { _FH_CHECK_RETURN(faith_random_bytes((uint8_t *)&hello.client_nonce, sizeof(hello.client_nonce))); - uint8_t body[FAITH_ENVL_CTS_HELLO_BODY_SIZE] = {0}; + uint8_t body[FAITH_ENVL_CTS_HELLO_BODY_SIZE] = {0}; faith_body_size_t body_size = 0; - _FH_CHECK_RETURN(faith_encode_hello_body(body, &body_size, sizeof(body), &hello)); + _FH_CHECK_RETURN( + faith_encode_hello_body(body, &body_size, sizeof(body), &hello)); /* Store nonce in temporary client state */ client->nonce_tmp = hello.client_nonce; @@ -1760,7 +1767,6 @@ faith_status_code_t faith_client_init_global(int log_enable_tracing) { return FAITH_OK; } - static faith_status_code_t client_new_identity(client_side_identity_t *o_ident) { if (!o_ident) diff --git a/faithd/src/codec/events.h b/faithd/src/codec/events.h index 25220ad..1f7f866 100644 --- a/faithd/src/codec/events.h +++ b/faithd/src/codec/events.h @@ -50,7 +50,8 @@ typedef struct { faith_conversation_id_t conversation_id; } faith_event_conversation_created_t; -#define FAITH_EVENT_CONVERSATION_CREATED_DATA_SIZE _FAITH_BODY_SIZE(FAITH_CONVERSATION_ID_SIZE) +#define FAITH_EVENT_CONVERSATION_CREATED_DATA_SIZE \ + _FAITH_BODY_SIZE(FAITH_CONVERSATION_ID_SIZE) faith_status_code_t faith_encode_event_conversation_created( uint8_t *out_buf, faith_body_size_t *out_size, size_t buf_cap_in_bytes, diff --git a/faithd/src/codec/protocol.c b/faithd/src/codec/protocol.c index 059ba85..83ffdc5 100644 --- a/faithd/src/codec/protocol.c +++ b/faithd/src/codec/protocol.c @@ -698,7 +698,8 @@ faith_status_code_t faith_encode_event_body(uint8_t *out_buf, in->data_size); } - FAITH_ENCODE_EPILOGUE(FAITH_ENVL_STC_EVENT_BODY_SIZE_FIXED + in->data_size, !=); + FAITH_ENCODE_EPILOGUE(FAITH_ENVL_STC_EVENT_BODY_SIZE_FIXED + in->data_size, + !=); return FAITH_OK; } diff --git a/faithd/src/delivery/event_inbox.c b/faithd/src/delivery/event_inbox.c index 287309b..e38a007 100644 --- a/faithd/src/delivery/event_inbox.c +++ b/faithd/src/delivery/event_inbox.c @@ -3,8 +3,9 @@ #include "../../third_party/stb_ds.h" #include -void device_event_inbox_init(device_event_inbox_t* o_inbox) { - if(!o_inbox) return; +void device_event_inbox_init(device_event_inbox_t *o_inbox) { + if (!o_inbox) + return; o_inbox->events = NULL; o_inbox->last_acked_seq = UINT64_MAX; @@ -21,8 +22,10 @@ device_event_inbox_queue_event(device_event_inbox_t *inbox, return FAITH_OK; } -faith_status_code_t device_event_inbox_advance_seq(device_event_inbox_t *inbox) { - if(!inbox) return FAITH_ERR_INVALID; +faith_status_code_t +device_event_inbox_advance_seq(device_event_inbox_t *inbox) { + if (!inbox) + return FAITH_ERR_INVALID; /* Dont allow UINT64_MAX */ if (inbox->next_seq >= UINT64_MAX - 1) @@ -51,8 +54,7 @@ faith_status_code_t device_event_inbox_ack_seq(device_event_inbox_t *inbox, return FAITH_OK; } -faith_status_code_t -device_event_inbox_destroy(device_event_inbox_t *inbox) { +faith_status_code_t device_event_inbox_destroy(device_event_inbox_t *inbox) { if (!inbox) return FAITH_ERR_INVALID; diff --git a/faithd/src/delivery/event_inbox.h b/faithd/src/delivery/event_inbox.h index d051d2f..854633d 100644 --- a/faithd/src/delivery/event_inbox.h +++ b/faithd/src/delivery/event_inbox.h @@ -1,15 +1,14 @@ #pragma once -#include #include "../codec/events.h" - +#include typedef struct { uint64_t next_seq; uint64_t last_acked_seq; uint64_t last_sent_seq; - faith_envl_stc_event_t* events; + faith_envl_stc_event_t *events; } device_event_inbox_t; void device_event_inbox_init(device_event_inbox_t *o_inbox); diff --git a/faithd/src/delivery/events.c b/faithd/src/delivery/events.c index afe8c40..31573d6 100644 --- a/faithd/src/delivery/events.c +++ b/faithd/src/delivery/events.c @@ -5,20 +5,21 @@ #include "event_inbox.h" faith_status_code_t delivery_queue_event(server_state_t *s, client_conn_t *cl, - faith_event_codec_type_t type, - uint8_t *data, - faith_body_size_t data_size) { + faith_event_codec_type_t type, + uint8_t *data, + faith_body_size_t data_size) { if (!cl || (!data && data_size != 0) || (data && data_size == 0)) return FAITH_ERR_INVALID; - if(!cl->authorized) return FAITH_ERR_UNAUTHORIZED; + if (!cl->authorized) + return FAITH_ERR_UNAUTHORIZED; client_device_session_data_t *sess = NULL; _FH_CHECK_RETURN( sess_registry_get_session(&s->rt, &cl->auth_id, &cl->device_id, &sess)); - if(!sess) return FAITH_ERR_UNAUTHORIZED; - + if (!sess) + return FAITH_ERR_UNAUTHORIZED; faith_envl_stc_event_t event = {0}; event.type = type; @@ -51,7 +52,8 @@ faith_status_code_t delivery_queue_event(server_state_t *s, client_conn_t *cl, faith_status_code_t delivery_handle_event_acked(server_state_t *s, client_conn_t *cl, faith_envelope_t *envl) { - if(!s || !cl || !envl) return FAITH_ERR_INVALID; + if (!s || !cl || !envl) + return FAITH_ERR_INVALID; if (envl->type != FAITH_ENVELOPE_EVENT_ACK) return FAITH_ERR_BAD_ENVELOPE; @@ -63,7 +65,8 @@ faith_status_code_t delivery_handle_event_acked(server_state_t *s, _FH_CHECK_RETURN( sess_registry_get_session(&s->rt, &cl->auth_id, &cl->device_id, &sess)); - if(!sess) return FAITH_ERR_UNAUTHORIZED; + if (!sess) + return FAITH_ERR_UNAUTHORIZED; faith_envl_cts_event_ack_t ack = {0}; _FH_CHECK_RETURN( diff --git a/faithd/src/delivery/events.h b/faithd/src/delivery/events.h index 04741bd..a0006b0 100644 --- a/faithd/src/delivery/events.h +++ b/faithd/src/delivery/events.h @@ -5,9 +5,9 @@ #include "../server/server.h" faith_status_code_t delivery_queue_event(server_state_t *s, client_conn_t *cl, - faith_event_codec_type_t type, - uint8_t *data, - faith_body_size_t data_size); + faith_event_codec_type_t type, + uint8_t *data, + faith_body_size_t data_size); faith_status_code_t delivery_handle_event_acked(server_state_t *s, client_conn_t *cl, diff --git a/faithd/src/server/dispatch.c b/faithd/src/server/dispatch.c index 8ecfd78..47c5370 100644 --- a/faithd/src/server/dispatch.c +++ b/faithd/src/server/dispatch.c @@ -7,8 +7,8 @@ #include "../auth/device_link.h" #include "../auth/handshake.h" -#include "../delivery/routing.h" #include "../delivery/events.h" +#include "../delivery/routing.h" #include "../commands/dispatch.h" diff --git a/faithd/src/server/dispatch.h b/faithd/src/server/dispatch.h index 3321e06..4b1da13 100644 --- a/faithd/src/server/dispatch.h +++ b/faithd/src/server/dispatch.h @@ -5,4 +5,3 @@ faith_status_code_t server_dispatch_frame(server_state_t *s, client_conn_t *cl, faith_frame_t *frame); -