-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20454 from mariemC/mariem/coap-coaps-forward-proxy
gcoap: add coaps forward proxy
- Loading branch information
Showing
6 changed files
with
211 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (C) 2024 ML!PA Consulting GmbH | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @{ | ||
* | ||
* @file | ||
* @brief Forward Proxy Thread | ||
* | ||
* @author Mariem Charrada <mariem.charrada@ml-pa.com> | ||
* @} | ||
*/ | ||
|
||
#include "msg.h" | ||
#include "net/gcoap.h" | ||
#include "net/gcoap/forward_proxy.h" | ||
#include "thread.h" | ||
|
||
#include "forward_proxy_internal.h" | ||
|
||
#define ENABLE_DEBUG 0 | ||
#include "debug.h" | ||
|
||
static char _forward_proxy_thread[GCOAP_PROXY_STACK_SIZE]; | ||
kernel_pid_t forward_proxy_pid = KERNEL_PID_UNDEF; | ||
|
||
static void *_forward_proxy_thread_start(void *arg) | ||
{ | ||
(void)arg; | ||
|
||
msg_t _forward_proxy_msg_queue[CONFIG_GCOAP_REQ_WAITING_MAX]; | ||
msg_init_queue(_forward_proxy_msg_queue, ARRAY_SIZE(_forward_proxy_msg_queue)); | ||
|
||
msg_t msg; | ||
|
||
while (1) { | ||
msg_receive(&msg); | ||
client_ep_t *cep = (client_ep_t *)msg.content.ptr; | ||
switch (msg.type) { | ||
case GCOAP_FORWARD_PROXY_MSG_SEND: { | ||
gcoap_forward_proxy_req_send(cep); | ||
break; | ||
} | ||
default: | ||
DEBUG_PUTS("_forward_proxy_thread_start: unknown message type\n"); | ||
break; | ||
} | ||
} | ||
return NULL; | ||
} | ||
|
||
void gcoap_forward_proxy_thread_init(void) | ||
{ | ||
forward_proxy_pid = thread_create(_forward_proxy_thread, sizeof(_forward_proxy_thread), | ||
THREAD_PRIORITY_MAIN - 1, THREAD_CREATE_STACKTEST, | ||
_forward_proxy_thread_start, NULL, "gcoap proxy"); | ||
if (forward_proxy_pid <= KERNEL_PID_UNDEF) { | ||
DEBUG_PUTS("gcoap_forward_proxy_thread_init(): thread_create failed\n"); | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
sys/net/application_layer/gcoap/include/forward_proxy_internal.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright (C) 2024 ML!PA Consulting GmbH | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser General | ||
* Public License v2.1. See the file LICENSE in the top level directory for | ||
* more details. | ||
*/ | ||
|
||
/** | ||
* @defgroup net_gcoap_forward_proxy_thread GCoAP Forward Proxy Thread | ||
* @ingroup net_gcoap | ||
* @brief Forward proxy thread implementation for GCoAP | ||
* | ||
* @{ | ||
* | ||
* @file | ||
* @brief Definitions for the GCoAP forward proxy internal communication | ||
* | ||
* @author Mariem Charrada <mariem.charrada@ml-pa.com> | ||
*/ | ||
|
||
#ifndef FORWARD_PROXY_INTERNAL_H | ||
#define FORWARD_PROXY_INTERNAL_H | ||
|
||
#include <stdint.h> | ||
#include "net/coap.h" | ||
#include "net/gcoap.h" | ||
#include "net/sock/udp.h" | ||
#include "ztimer.h" | ||
#include "event.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* @brief client ep structure | ||
*/ | ||
typedef struct { | ||
coap_pkt_t pdu; /**< forward CoAP PDU */ | ||
sock_udp_ep_t server_ep; /**< forward Server endpoint */ | ||
sock_udp_ep_t ep; /**< client endpoint */ | ||
uint16_t mid; /**< message ID */ | ||
uint8_t flags; /**< client flags */ | ||
#if IS_USED(MODULE_NANOCOAP_CACHE) | ||
uint8_t req_etag[COAP_ETAG_LENGTH_MAX]; /**< request ETag */ | ||
#endif | ||
ztimer_t empty_ack_timer; /**< empty ACK timer */ | ||
event_t event; /**< client event */ | ||
} client_ep_t; | ||
|
||
/** | ||
* @brief Stack size for the forward proxy thread | ||
* | ||
*/ | ||
#ifndef GCOAP_PROXY_STACK_SIZE | ||
#define GCOAP_PROXY_STACK_SIZE (THREAD_STACKSIZE_DEFAULT + DEBUG_EXTRA_STACKSIZE \ | ||
+ sizeof(coap_pkt_t) + GCOAP_DTLS_EXTRA_STACKSIZE) | ||
#endif | ||
|
||
/** | ||
* @brief Definition of forward proxy thread msgs. | ||
*/ | ||
enum { | ||
GCOAP_FORWARD_PROXY_MSG_SEND, | ||
}; | ||
|
||
/** | ||
* @brief Initialize the forward proxy thread | ||
*/ | ||
void gcoap_forward_proxy_thread_init(void); | ||
|
||
/** | ||
* @brief Forward the CoAP request to the server | ||
* The client endpoint is passed as an argument | ||
* and freed if the send failed. | ||
* | ||
* @param[in] cep client endpoint | ||
* @return @ref gcoap_req_send | ||
*/ | ||
int gcoap_forward_proxy_req_send(client_ep_t *cep); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* FORWARD_PROXY_INTERNAL_H */ | ||
/** | ||
* @} | ||
*/ |