Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions faithd/src/client/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion faithd/src/codec/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion faithd/src/codec/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 8 additions & 6 deletions faithd/src/delivery/event_inbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
#include "../../third_party/stb_ds.h"
#include <stdint.h>

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;
Expand All @@ -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)
Expand Down Expand Up @@ -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;

Expand Down
5 changes: 2 additions & 3 deletions faithd/src/delivery/event_inbox.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#pragma once

#include <stdint.h>
#include "../codec/events.h"

#include <stdint.h>

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);
Expand Down
19 changes: 11 additions & 8 deletions faithd/src/delivery/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions faithd/src/delivery/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion faithd/src/server/dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
1 change: 0 additions & 1 deletion faithd/src/server/dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@

faith_status_code_t server_dispatch_frame(server_state_t *s, client_conn_t *cl,
faith_frame_t *frame);

Loading