Adding base for async with kong

This commit is contained in:
Granyaa
2026-01-14 11:55:00 +02:00
parent 5dfa150635
commit 175429e60b
9 changed files with 926 additions and 1 deletions

View File

@@ -20,6 +20,8 @@ add_library(
nano_attachment_thread.c nano_attachment_thread.c
nano_attachment_sender.c nano_attachment_sender.c
nano_attachment_sender_thread.c nano_attachment_sender_thread.c
nano_attachment_sender_async.c
nano_attachment_bucket.c
nano_attachment_metric.c nano_attachment_metric.c
nano_compression.c nano_compression.c
) )

View File

@@ -10,6 +10,7 @@
#include "nano_attachment_sender.h" #include "nano_attachment_sender.h"
#include "nano_attachment_metric.h" #include "nano_attachment_metric.h"
#include "nano_attachment_bucket.h"
#include "nano_initializer.h" #include "nano_initializer.h"
#include "nano_configuration.h" #include "nano_configuration.h"
#include "nano_utils.h" #include "nano_utils.h"
@@ -120,6 +121,15 @@ RestartAttachmentConfiguration(NanoAttachment *attachment)
return reset_attachment_config(attachment); return reset_attachment_config(attachment);
}; };
int
GetCommSocket(NanoAttachment *attachment)
{
if (attachment == NULL) {
return -1;
}
return attachment->comm_socket;
}
HttpSessionData * HttpSessionData *
InitSessionData(NanoAttachment *attachment, SessionID session_id) InitSessionData(NanoAttachment *attachment, SessionID session_id)
{ {
@@ -225,6 +235,74 @@ SendDataNanoAttachment(NanoAttachment *attachment, AttachmentData *data)
return response; return response;
} }
NanoCommunicationResult
SendDataNanoAttachmentAsync(NanoAttachment *attachment, AttachmentData *data)
{
switch (data->chunk_type) {
case HTTP_REQUEST_FILTER: {
return SendRequestFilterAsync(attachment, data);
}
case HTTP_REQUEST_METADATA: {
return SendMetadataAsync(attachment, data);
}
case HTTP_REQUEST_HEADER: {
return SendRequestHeadersAsync(attachment, data);
}
case HTTP_REQUEST_BODY: {
return SendRequestBodyAsync(attachment, data);
}
case HTTP_REQUEST_END: {
return SendRequestEndAsync(attachment, data);
}
case HTTP_RESPONSE_HEADER: {
return SendResponseHeadersAsync(attachment, data);
}
case HTTP_RESPONSE_BODY: {
return SendResponseBodyAsync(attachment, data);
}
case HTTP_RESPONSE_END: {
return SendResponseEndAsync(attachment, data);
}
default:
break;
}
return NANO_OK;
}
// TODO: Implement
// Check if the queue is empty, return true if yes - otherwise false.
bool
isQueueEmpty(NanoAttachment *attachment)
{
return false;
}
// TODO: Implement
// [hash on session id] -> [verdict+modification]
// Updating the table, and then return the session ID to the caller
SessionID
PopFromQueue(NanoAttachment *attachment)
{
return session_id;
}
// TODO: Implement
// given a sessionID return a verdict from the table.
AttachmentVerdictResponse
getAttachmentVerdictResponse(NanoAttachment *attachment, SessionID session_id)
{
(void)attachment;
(void)session_id;
return (AttachmentVerdictResponse) {
.verdict = ATTACHMENT_VERDICT_INSPECT,
.session_id = session_id,
.modifications = NULL
};
}
/// ///
/// @brief Connects to the keep-alive socket. /// @brief Connects to the keep-alive socket.
/// ///

View File

@@ -0,0 +1 @@
#include "nano_attachment_bucket.h"

View File

@@ -0,0 +1,8 @@
/// @file nano_attachment_bucket.h
#ifndef __NANO_ATTACHMENT_BUCKET_H__
#define __NANO_ATTACHMENT_BUCKET_H__
#include "nano_attachment_common.h"
#include "nano_initializer.h"
#endif // __NANO_ATTACHMENT_BUCKET_H__

View File

@@ -4,6 +4,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "nano_attachment_sender_thread.h" #include "nano_attachment_sender_thread.h"
#include "nano_attachment_sender_async.h"
#include "nano_attachment_thread.h" #include "nano_attachment_thread.h"
#include "nano_utils.h" #include "nano_utils.h"
#include "nano_attachment_metric.h" #include "nano_attachment_metric.h"
@@ -317,7 +318,7 @@ HandleDelayedVerdict(
sleep(attachment->hold_verdict_polling_time); sleep(attachment->hold_verdict_polling_time);
write_dbg(attachment, session_id, DBG_LEVEL_DEBUG, "spawn SendDelayedVerdictRequestThread"); write_dbg(attachment, session_id, DBG_LEVEL_DEBUG, "spawn SendDelayedVerdictRequestThread");
res = NanoRunInThreadTimeout( res = NanoRunInThreadTimeout(
attachment, attachment,
data, data,
SendDelayedVerdictRequestThread, SendDelayedVerdictRequestThread,
(void *)ctx, (void *)ctx,
@@ -783,6 +784,360 @@ SendResponseEnd(NanoAttachment *attachment, AttachmentData *data)
return FinalizeSuccessfulResponse(attachment, session_id, &ctx); return FinalizeSuccessfulResponse(attachment, session_id, &ctx);
} }
NanoCommunicationResult
SendRequestFilterAsync(NanoAttachment *attachment, AttachmentData *data)
{
if (attachment == NULL || data == NULL) {
return NANO_ERROR;
}
HttpSessionData *session_data_p = data->session_data;
if (session_data_p == NULL) {
return NANO_ERROR;
}
SessionID session_id = session_data_p->session_id;
HttpRequestFilterData *start_data = (HttpRequestFilterData*)data->data;
if (start_data == NULL) {
write_dbg(
attachment,
session_id,
DBG_LEVEL_WARNING,
"NULL start_data in SendRequestFilterAsync for session ID: %d",
session_id
);
return NANO_ERROR;
}
write_dbg(
attachment,
session_id,
DBG_LEVEL_DEBUG,
"Request filter handling session ID: %d",
session_id
);
if (handle_shmem_corruption(attachment) == NANO_ERROR) {
write_dbg(
attachment,
session_id,
DBG_LEVEL_WARNING,
"Failed to handle shmem corruption in session ID: %d",
session_id
);
return NANO_ERROR;
}
return SendRequestFilterAsyncImpl(attachment, session_data_p, start_data);
}
NanoCommunicationResult
SendMetadataAsync(NanoAttachment *attachment, AttachmentData *data)
{
if (attachment == NULL || data == NULL) {
return NANO_ERROR;
}
HttpSessionData *session_data_p = data->session_data;
if (session_data_p == NULL) {
return NANO_ERROR;
}
SessionID session_id = session_data_p->session_id;
HttpMetaData *metadata = (HttpMetaData*)data->data;
if (metadata == NULL) {
write_dbg(
attachment,
session_id,
DBG_LEVEL_WARNING,
"NULL metadata in SendMetadataAsync for session ID: %d",
session_id
);
return NANO_ERROR;
}
write_dbg(
attachment,
session_id,
DBG_LEVEL_DEBUG,
"Metadata handling session ID: %d",
session_id
);
if (handle_shmem_corruption(attachment) == NANO_ERROR) {
write_dbg(
attachment,
session_id,
DBG_LEVEL_WARNING,
"Failed to handle shmem corruption in session ID: %d",
session_id
);
return NANO_ERROR;
}
return SendMetadataAsyncImpl(attachment, session_data_p, metadata);
}
NanoCommunicationResult
SendRequestHeadersAsync(NanoAttachment *attachment, AttachmentData *data)
{
if (attachment == NULL || data == NULL) {
return NANO_ERROR;
}
HttpSessionData *session_data_p = data->session_data;
if (session_data_p == NULL) {
return NANO_ERROR;
}
SessionID session_id = session_data_p->session_id;
HttpHeaders *headers = (HttpHeaders*)data->data;
if (headers == NULL) {
write_dbg(
attachment,
session_id,
DBG_LEVEL_WARNING,
"NULL headers in SendRequestHeadersAsync for session ID: %d",
session_id
);
return NANO_ERROR;
}
write_dbg(
attachment,
session_id,
DBG_LEVEL_DEBUG,
"Request headers handling session ID: %d",
session_id
);
if (handle_shmem_corruption(attachment) == NANO_ERROR) {
write_dbg(
attachment,
session_id,
DBG_LEVEL_WARNING,
"Failed to handle shmem corruption in session ID: %d",
session_id
);
return NANO_ERROR;
}
return SendRequestHeadersAsyncImpl(attachment, session_data_p, headers);
}
NanoCommunicationResult
SendRequestBodyAsync(NanoAttachment *attachment, AttachmentData *data)
{
if (attachment == NULL || data == NULL) {
return NANO_ERROR;
}
HttpSessionData *session_data_p = data->session_data;
if (session_data_p == NULL) {
return NANO_ERROR;
}
SessionID session_id = session_data_p->session_id;
NanoHttpBody *bodies = (NanoHttpBody*)data->data;
if (bodies == NULL) {
write_dbg(
attachment,
session_id,
DBG_LEVEL_WARNING,
"NULL bodies in SendRequestBodyAsync for session ID: %d",
session_id
);
return NANO_ERROR;
}
write_dbg(
attachment,
session_id,
DBG_LEVEL_DEBUG,
"Request body handling session ID: %d",
session_id
);
if (handle_shmem_corruption(attachment) == NANO_ERROR) {
write_dbg(
attachment,
session_id,
DBG_LEVEL_WARNING,
"Failed to handle shmem corruption in session ID: %d",
session_id
);
return NANO_ERROR;
}
return SendRequestBodyAsyncImpl(attachment, session_data_p, bodies);
}
NanoCommunicationResult
SendRequestEndAsync(NanoAttachment *attachment, AttachmentData *data)
{
if (attachment == NULL || data == NULL) {
return NANO_ERROR;
}
HttpSessionData *session_data_p = data->session_data;
if (session_data_p == NULL) {
return NANO_ERROR;
}
SessionID session_id = session_data_p->session_id;
write_dbg(
attachment,
session_id,
DBG_LEVEL_DEBUG,
"Request end handling session ID: %d",
session_id
);
if (handle_shmem_corruption(attachment) == NANO_ERROR) {
write_dbg(
attachment,
session_id,
DBG_LEVEL_WARNING,
"Failed to handle shmem corruption in session ID: %d",
session_id
);
return NANO_ERROR;
}
return SendRequestEndAsyncImpl(attachment, session_data_p);
}
NanoCommunicationResult
SendResponseHeadersAsync(NanoAttachment *attachment, AttachmentData *data)
{
if (attachment == NULL || data == NULL) {
return NANO_ERROR;
}
HttpSessionData *session_data_p = data->session_data;
if (session_data_p == NULL) {
return NANO_ERROR;
}
SessionID session_id = session_data_p->session_id;
ResHttpHeaders *headers = (ResHttpHeaders*)data->data;
if (headers == NULL) {
write_dbg(
attachment,
session_id,
DBG_LEVEL_WARNING,
"NULL headers in SendResponseHeadersAsync for session ID: %d",
session_id
);
return NANO_ERROR;
}
write_dbg(
attachment,
session_id,
DBG_LEVEL_DEBUG,
"Response headers handling session ID: %d",
session_id
);
if (handle_shmem_corruption(attachment) == NANO_ERROR) {
write_dbg(
attachment,
session_id,
DBG_LEVEL_WARNING,
"Failed to handle shmem corruption in session ID: %d",
session_id
);
return NANO_ERROR;
}
return SendResponseHeadersAsyncImpl(attachment, session_data_p, headers);
}
NanoCommunicationResult
SendResponseBodyAsync(NanoAttachment *attachment, AttachmentData *data)
{
if (attachment == NULL || data == NULL) {
return NANO_ERROR;
}
HttpSessionData *session_data_p = data->session_data;
if (session_data_p == NULL) {
return NANO_ERROR;
}
SessionID session_id = session_data_p->session_id;
NanoHttpBody *bodies = (NanoHttpBody*)data->data;
if (bodies == NULL) {
write_dbg(
attachment,
session_id,
DBG_LEVEL_WARNING,
"NULL bodies in SendResponseBodyAsync for session ID: %d",
session_id
);
return NANO_ERROR;
}
write_dbg(
attachment,
session_id,
DBG_LEVEL_DEBUG,
"Response body handling session ID: %d",
session_id
);
if (handle_shmem_corruption(attachment) == NANO_ERROR) {
write_dbg(
attachment,
session_id,
DBG_LEVEL_WARNING,
"Failed to handle shmem corruption in session ID: %d",
session_id
);
return NANO_ERROR;
}
return SendResponseBodyAsyncImpl(attachment, session_data_p, bodies);
}
NanoCommunicationResult
SendResponseEndAsync(NanoAttachment *attachment, AttachmentData *data)
{
if (attachment == NULL || data == NULL) {
return NANO_ERROR;
}
HttpSessionData *session_data_p = data->session_data;
if (session_data_p == NULL) {
return NANO_ERROR;
}
SessionID session_id = session_data_p->session_id;
write_dbg(
attachment,
session_id,
DBG_LEVEL_DEBUG,
"Response end handling session ID: %d",
session_id
);
if (handle_shmem_corruption(attachment) == NANO_ERROR) {
write_dbg(
attachment,
session_id,
DBG_LEVEL_WARNING,
"Failed to handle shmem corruption in session ID: %d",
session_id
);
return NANO_ERROR;
}
return SendResponseEndAsyncImpl(attachment, session_data_p);
}
NanoCommunicationResult NanoCommunicationResult
SendMetricData(NanoAttachment *attachment) SendMetricData(NanoAttachment *attachment)
{ {

View File

@@ -124,6 +124,86 @@ AttachmentVerdictResponse SendRequestEnd(NanoAttachment *attachment, AttachmentD
/// ///
AttachmentVerdictResponse SendResponseEnd(NanoAttachment *attachment, AttachmentData *data); AttachmentVerdictResponse SendResponseEnd(NanoAttachment *attachment, AttachmentData *data);
///
/// @brief Sends request filter data to the nano service asynchronously.
///
/// @param attachment A pointer to the NanoAttachment structure.
/// @param data A pointer to AttachmentData structure containing the data to send and the session data.
///
/// @return A NanoCommunicationResult indicating the outcome of the operation.
///
NanoCommunicationResult SendRequestFilterAsync(NanoAttachment *attachment, AttachmentData *data);
///
/// @brief Sends start request data to the nano service asynchronously.
///
/// @param attachment A pointer to the NanoAttachment structure.
/// @param data A pointer to AttachmentData structure containing the data to send and the session data.
///
/// @return A NanoCommunicationResult indicating the outcome of the operation.
///
NanoCommunicationResult SendMetadataAsync(NanoAttachment *attachment, AttachmentData *data);
///
/// @brief Sends request headers to the nano service asynchronously.
///
/// @param attachment A pointer to the NanoAttachment structure.
/// @param data A pointer to AttachmentData structure containing the headers to send and the session data.
///
/// @return A NanoCommunicationResult indicating the outcome of the operation.
///
NanoCommunicationResult SendRequestHeadersAsync(NanoAttachment *attachment, AttachmentData *data);
///
/// @brief Sends response headers to the nano service asynchronously.
///
/// @param attachment A pointer to the NanoAttachment structure.
/// @param data A pointer to AttachmentData structure containing the headers to send and the session data.
///
/// @return A NanoCommunicationResult indicating the outcome of the operation.
///
NanoCommunicationResult SendResponseHeadersAsync(NanoAttachment *attachment, AttachmentData *data);
///
/// @brief Sends request body to the nano service asynchronously.
///
/// @param attachment A pointer to the NanoAttachment structure.
/// @param data A pointer to AttachmentData structure containing the body to send and the session data.
///
/// @return A NanoCommunicationResult indicating the outcome of the operation.
///
NanoCommunicationResult SendRequestBodyAsync(NanoAttachment *attachment, AttachmentData *data);
///
/// @brief Sends response body to the nano service asynchronously.
///
/// @param attachment A pointer to the NanoAttachment structure.
/// @param data A pointer to AttachmentData structure containing the body to send and the session data.
///
/// @return A NanoCommunicationResult indicating the outcome of the operation.
///
NanoCommunicationResult SendResponseBodyAsync(NanoAttachment *attachment, AttachmentData *data);
///
/// @brief Sends end request signal to the nano service asynchronously.
///
/// @param attachment A pointer to the NanoAttachment structure.
/// @param data A pointer to AttachmentData structure containing the necessery data to send and the session data.
///
/// @return A NanoCommunicationResult indicating the outcome of the operation.
///
NanoCommunicationResult SendRequestEndAsync(NanoAttachment *attachment, AttachmentData *data);
///
/// @brief Sends end response signal to the nano service asynchronously.
///
/// @param attachment A pointer to the NanoAttachment structure.
/// @param data A pointer to AttachmentData structure containing the necessery data to send and the session data.
///
/// @return A NanoCommunicationResult indicating the outcome of the operation.
///
NanoCommunicationResult SendResponseEndAsync(NanoAttachment *attachment, AttachmentData *data);
/// ///
/// @brief Sends metric data to the nano service and resets it on the attachment. /// @brief Sends metric data to the nano service and resets it on the attachment.
/// ///

View File

@@ -0,0 +1,148 @@
#include "nano_attachment_sender_async.h"
#include "nano_attachment_common.h"
#include "nano_initializer.h"
NanoCommunicationResult
RegistrationCommSocketAsyncImpl(
NanoAttachment *attachment,
HttpSessionData *session_data_p
)
{
(void)attachment;
(void)session_data_p;
return NANO_OK;
}
NanoCommunicationResult
RegistrationSocketAsyncImpl(
NanoAttachment *attachment,
HttpSessionData *session_data_p
)
{
(void)attachment;
(void)session_data_p;
return NANO_OK;
}
NanoCommunicationResult
SendRequestFilterAsyncImpl(
NanoAttachment *attachment,
HttpSessionData *session_data_p,
HttpRequestFilterData *start_data
)
{
(void)attachment;
(void)session_data_p;
(void)start_data;
return NANO_OK;
}
NanoCommunicationResult
SendMetadataAsyncImpl(
NanoAttachment *attachment,
HttpSessionData *session_data_p,
HttpMetaData *metadata
)
{
(void)attachment;
(void)session_data_p;
(void)metadata;
return NANO_OK;
}
NanoCommunicationResult
SendRequestHeadersAsyncImpl(
NanoAttachment *attachment,
HttpSessionData *session_data_p,
HttpHeaders *headers
)
{
(void)attachment;
(void)session_data_p;
(void)headers;
return NANO_OK;
}
NanoCommunicationResult
SendResponseHeadersAsyncImpl(
NanoAttachment *attachment,
HttpSessionData *session_data_p,
ResHttpHeaders *headers
)
{
(void)attachment;
(void)session_data_p;
(void)headers;
return NANO_OK;
}
NanoCommunicationResult
SendRequestBodyAsyncImpl(
NanoAttachment *attachment,
HttpSessionData *session_data_p,
NanoHttpBody *bodies
)
{
(void)attachment;
(void)session_data_p;
(void)bodies;
return NANO_OK;
}
NanoCommunicationResult
SendResponseBodyAsyncImpl(
NanoAttachment *attachment,
HttpSessionData *session_data_p,
NanoHttpBody *bodies
)
{
(void)attachment;
(void)session_data_p;
(void)bodies;
return NANO_OK;
}
NanoCommunicationResult
SendRequestEndAsyncImpl(
NanoAttachment *attachment,
HttpSessionData *session_data_p
)
{
(void)attachment;
(void)session_data_p;
return NANO_OK;
}
NanoCommunicationResult
SendResponseEndAsyncImpl(
NanoAttachment *attachment,
HttpSessionData *session_data_p
)
{
(void)attachment;
(void)session_data_p;
return NANO_OK;
}
NanoCommunicationResult
SendDelayedVerdictRequestAsyncImpl(
NanoAttachment *attachment,
HttpSessionData *session_data_p
)
{
(void)attachment;
(void)session_data_p;
return NANO_OK;
}
NanoCommunicationResult
SendMetricToServiceAsyncImpl(
NanoAttachment *attachment,
HttpSessionData *session_data_p
)
{
(void)attachment;
(void)session_data_p;
return NANO_OK;
}

View File

@@ -0,0 +1,203 @@
#ifndef __NANO_ATTACHMENT_SENDER_ASYNC_H__
#define __NANO_ATTACHMENT_SENDER_ASYNC_H__
#include "nano_attachment_common.h"
#include "nano_initializer.h"
///
/// @brief Connect attachment communication socket to the nano service.
///
/// @param attachment A pointer to a NanoAttachment structure.
/// @param session_data_p A pointer to HttpSessionData structure.
///
/// @return #NANO_OK on success.
///
NanoCommunicationResult RegistrationCommSocketAsyncImpl(
NanoAttachment *attachment,
HttpSessionData *session_data_p
);
///
/// @brief Connect attachment to registration socket to the nano service.
///
/// @param attachment A pointer to a NanoAttachment structure.
/// @param session_data_p A pointer to HttpSessionData structure.
///
/// @return #NANO_OK on success.
///
NanoCommunicationResult RegistrationSocketAsyncImpl(
NanoAttachment *attachment,
HttpSessionData *session_data_p
);
///
/// @brief Sends request start data to the nano service.
///
/// This async function sends metadata to start a request interaction with the nano service.
///
/// @param attachment A pointer to a NanoAttachment structure.
/// @param session_data_p A pointer to HttpSessionData structure.
/// @param metadata A pointer to HttpMetaData structure.
///
/// @return #NANO_OK on success.
///
NanoCommunicationResult SendMetadataAsyncImpl(
NanoAttachment *attachment,
HttpSessionData *session_data_p,
HttpMetaData *metadata
);
///
/// @brief Sends request headers to the nano service.
///
/// This async function sends request headers to the nano service. It updates the session data
/// and handles any errors that occur during the header sending process.
///
/// @param attachment A pointer to a NanoAttachment structure.
/// @param session_data_p A pointer to HttpSessionData structure.
/// @param headers A pointer to HttpHeaders structure.
///
/// @return #NANO_OK on success.
///
NanoCommunicationResult SendRequestHeadersAsyncImpl(
NanoAttachment *attachment,
HttpSessionData *session_data_p,
HttpHeaders *headers
);
///
/// @brief Sends response headers to the nano service.
///
/// This async function sends response headers to the nano service. It updates the session data
/// and handles any errors that occur during the header sending process.
///
/// @param attachment A pointer to a NanoAttachment structure.
/// @param session_data_p A pointer to HttpSessionData structure.
/// @param headers A pointer to ResHttpHeaders structure.
///
/// @return #NANO_OK on success.
///
NanoCommunicationResult SendResponseHeadersAsyncImpl(
NanoAttachment *attachment,
HttpSessionData *session_data_p,
ResHttpHeaders *headers
);
///
/// @brief Sends request body to the nano service.
///
/// This async function sends request body to the nano service. It updates the session data
/// and handles any errors that occur during the body sending process.
///
/// @param attachment A pointer to a NanoAttachment structure.
/// @param session_data_p A pointer to HttpSessionData structure.
/// @param bodies A pointer to NanoHttpBody structure.
///
/// @return #NANO_OK on success.
///
NanoCommunicationResult SendRequestBodyAsyncImpl(
NanoAttachment *attachment,
HttpSessionData *session_data_p,
NanoHttpBody *bodies
);
///
/// @brief Sends response body to the nano service.
///
/// This async function sends response body to the nano service. It updates the session data
/// and handles any errors that occur during the body sending process.
///
/// @param attachment A pointer to a NanoAttachment structure.
/// @param session_data_p A pointer to HttpSessionData structure.
/// @param bodies A pointer to NanoHttpBody structure.
///
/// @return #NANO_OK on success.
///
NanoCommunicationResult SendResponseBodyAsyncImpl(
NanoAttachment *attachment,
HttpSessionData *session_data_p,
NanoHttpBody *bodies
);
///
/// @brief Sends request end data to the nano service.
///
/// This async function sends signal to the nano service that the request has ended
/// and with it the whole session transaction.
///
/// @param attachment A pointer to a NanoAttachment structure.
/// @param session_data_p A pointer to HttpSessionData structure.
///
/// @return #NANO_OK on success.
///
NanoCommunicationResult SendRequestEndAsyncImpl(
NanoAttachment *attachment,
HttpSessionData *session_data_p
);
///
/// @brief Sends response end data to the nano service.
///
/// This async function sends signal to the nano service that the response has ended
/// and with it the whole session transaction.
///
/// @param attachment A pointer to a NanoAttachment structure.
/// @param session_data_p A pointer to HttpSessionData structure.
///
/// @return #NANO_OK on success.
///
NanoCommunicationResult SendResponseEndAsyncImpl(
NanoAttachment *attachment,
HttpSessionData *session_data_p
);
///
/// @brief Async function to send request filters.
///
/// This async function sends metadata, request headers and end request
/// to the nano service. It updates the session data and handles any errors
/// that occur during the header sending process.
///
/// @param attachment A pointer to a NanoAttachment structure.
/// @param session_data_p A pointer to HttpSessionData structure.
/// @param start_data A pointer to HttpRequestFilterData structure.
///
/// @return #NANO_OK on success.
///
NanoCommunicationResult SendRequestFilterAsyncImpl(
NanoAttachment *attachment,
HttpSessionData *session_data_p,
HttpRequestFilterData *start_data
);
///
/// @brief Send query for requesting delayed data verdict.
///
/// This async function sends a delayed data query to the service and waits for the response.
///
/// @param attachment A pointer to a NanoAttachment structure.
/// @param session_data_p A pointer to HttpSessionData structure.
///
/// @return #NANO_OK on success.
///
NanoCommunicationResult SendDelayedVerdictRequestAsyncImpl(
NanoAttachment *attachment,
HttpSessionData *session_data_p
);
///
/// @brief Send data metric to the service.
///
/// This async function sends data metric to the service and resets it.
///
/// @param attachment A pointer to a NanoAttachment structure.
/// @param session_data_p A pointer to HttpSessionData structure.
///
/// @return #NANO_OK on success.
///
NanoCommunicationResult SendMetricToServiceAsyncImpl(
NanoAttachment *attachment,
HttpSessionData *session_data_p
);
#endif // __NANO_ATTACHMENT_SENDER_ASYNC_H__

View File

@@ -40,6 +40,15 @@ void FiniNanoAttachment(NanoAttachment *attachment);
NanoCommunicationResult RestartAttachmentConfiguration(NanoAttachment *attachment); NanoCommunicationResult RestartAttachmentConfiguration(NanoAttachment *attachment);
///
/// @brief Retrieves the communication socket from a NanoAttachment.
///
/// @param attachment A pointer to the NanoAttachment structure.
///
/// @return The communication socket file descriptor, or -1 if attachment is NULL.
///
int GetCommSocket(NanoAttachment *attachment);
/// ///
/// @brief Initializes a HttpSessionData structure with default values. /// @brief Initializes a HttpSessionData structure with default values.
/// ///
@@ -100,6 +109,19 @@ void SendAccumulatedMetricData(NanoAttachment *attachment);
/// ///
AttachmentVerdictResponse SendDataNanoAttachment(NanoAttachment *attachment, AttachmentData *data); AttachmentVerdictResponse SendDataNanoAttachment(NanoAttachment *attachment, AttachmentData *data);
///
/// @brief Sends attachment data asynchronously to the appropriate handlers.
///
/// This function processes the attachment data based on its chunk type and sends
/// it to the appropriate async handler functions.
///
/// @param attachment A pointer to the NanoAttachment structure associated with the data.
/// @param data A pointer to the AttachmentData structure containing the data to be processed.
///
/// @return A NanoCommunicationResult indicating the success or failure of the operation.
///
NanoCommunicationResult SendDataNanoAttachmentAsync(NanoAttachment *attachment, AttachmentData *data);
/// ///
/// @brief Sends a keep-alive signal using a socket connection. /// @brief Sends a keep-alive signal using a socket connection.
/// ///
@@ -266,4 +288,32 @@ freeCompressedBody(
NanoHttpBody *bodies NanoHttpBody *bodies
); );
///
/// @brief Checks if the queue is empty.
///
/// @param attachment A pointer to the NanoAttachment structure.
///
/// @return Returns true if the queue is empty, false otherwise.
///
bool isQueueEmpty(NanoAttachment *attachment);
///
/// @brief Pops a session ID from the queue and updates the table.
///
/// @param attachment A pointer to the NanoAttachment structure.
///
/// @return The session ID that was popped from the queue.
///
SessionID PopFromQueue(NanoAttachment *attachment);
///
/// @brief Retrieves a verdict response for a given session ID from the table.
///
/// @param attachment A pointer to the NanoAttachment structure.
/// @param session_id The session ID to look up.
///
/// @return An AttachmentVerdictResponse structure containing the verdict for the session.
///
AttachmentVerdictResponse getAttachmentVerdictResponse(NanoAttachment *attachment, SessionID session_id);
#endif // __NANO_ATTACHMENT_H__ #endif // __NANO_ATTACHMENT_H__