From 0e094b5601b0991e6742f0b4acbb782709a80c0b Mon Sep 17 00:00:00 2001 From: Diogo Diniz Date: Fri, 26 Jun 2026 19:31:16 +0100 Subject: [PATCH] feat: Closer to full localhost cycle --- app/src/incphub/src/incphub_client.c | 15 ++++++++++----- app/src/incphub/src/incphub_shared.h | 6 ++++++ app/src/incphub/src/incphub_task.c | 25 ++++++++++++++++++++----- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/app/src/incphub/src/incphub_client.c b/app/src/incphub/src/incphub_client.c index 1f894fc..dd090eb 100644 --- a/app/src/incphub/src/incphub_client.c +++ b/app/src/incphub/src/incphub_client.c @@ -65,10 +65,15 @@ int incphub_send_local(incphub_cli_t *cli, uint8_t *buffer, size_t length, ntl_p int incphub_await_msg(incphub_cli_t *cli, uint8_t **buffer_ptr, size_t *length_ptr, incphub_addr_t *sender_ptr) { - (void)cli; - (void)buffer_ptr; - (void)length_ptr; - (void)sender_ptr; - //TODO: Implement + if (cli == NULL) + return INCPHUB_EINVAL; + if (buffer_ptr == NULL) + return INCPHUB_EINVAL; + if (length_ptr == NULL) + return INCPHUB_EINVAL; + if (sender_ptr == NULL) + return INCPHUB_EINVAL; + + //TODO: Implement (with await_message_dispatch) return INCPHUB_ERR; } diff --git a/app/src/incphub/src/incphub_shared.h b/app/src/incphub/src/incphub_shared.h index b2adb69..2dfc508 100644 --- a/app/src/incphub/src/incphub_shared.h +++ b/app/src/incphub/src/incphub_shared.h @@ -9,6 +9,8 @@ #include "nil/nil.h" #include "ntl/ntl.h" +#include "incphub/incphub.h" + struct incphub_cli_t { @@ -58,4 +60,8 @@ int enqueue_message_ingest(uint8_t *buffer, size_t length); /// @return INCPHUB_OK on success, an error otherwise int dequeue_message_ingest(uint8_t **buffer_ptr, size_t *length_ptr); +int do_message_dispatch(incphub_cli_t *cli, uint8_t *buffer, size_t length, incphub_addr_t source); + +int await_message_dispatch(uint8_t **buffer_ptr, size_t *length_ptr, incphub_addr_t *source_ptr); + #endif diff --git a/app/src/incphub/src/incphub_task.c b/app/src/incphub/src/incphub_task.c index 04f662c..da757b7 100644 --- a/app/src/incphub/src/incphub_task.c +++ b/app/src/incphub/src/incphub_task.c @@ -39,7 +39,7 @@ static StaticQueue_t _ingest_queue_static; static nil_packet_t *extract_nil_packet(uint8_t *buffer, size_t length); static ntl_packet_t *extract_ntl_packet(nil_packet_t *nil); static void handle_nil_packet(nil_packet_t *nil); -static void handle_ntl_packet(ntl_packet_t *ntl); +static void handle_ntl_packet(ntl_packet_t *ntl, nil_addr_t src_addr); @@ -123,7 +123,7 @@ static void handle_nil_packet(nil_packet_t *nil) return; } - handle_ntl_packet(ntl); + handle_ntl_packet(ntl, nil->header.src_addr); return; } @@ -131,8 +131,23 @@ static void handle_nil_packet(nil_packet_t *nil) return; } -static void handle_ntl_packet(ntl_packet_t *ntl) +static void handle_ntl_packet(ntl_packet_t *ntl, nil_addr_t src_addr) { - (void)ntl; - //TODO: Implement + ntl_port_t port = ntl_get_dst(&ntl->header); + + incphub_cli_t *client; + if (get_client_with_port(port, &client) != INCPHUB_OK) + { + //TODO: Error + return; + } + + incphub_addr_t sender = { .addr = src_addr, .port = ntl->header.src_port }; + if (do_message_dispatch(client, ntl->payload, ntl->header.len, sender) != INCPHUB_OK) + { + //TODO: Error + return; + } + + return; }