Proxy: Add in support for multiplexing Observe requests

Add in limited caching for multiple clients requesting an Observe subscription
for the same upstream session resource so that only a single observation request
is sent upstream and any unsolicited response is sent back to all the
requesting clients.

This requires a change in the recently added handler registered to
coap_register_proxy_response_handler(), which no longer should no longer call
coap_proxy_forward_response(), but just return a PDU for forwarding on.
This commit is contained in:
Jon Shallow authored and Jon Shallow committed 2025-05-05 09:46:53 +01:00
1 parent 2e8decf756
commit daa4e05e18
15 files changed
+629 -162

No files matched your search

+3 -2
View File
@@ -360,18 +360,19 @@ nack_handler(coap_session_t *session COAP_UNUSED,
coap_bin_const_t token = coap_pdu_get_token(sent);
if (coap_pdu_get_code(sent) != COAP_EMPTY_CODE && !track_check_token(&token)) {
coap_log_err("nack_handler: Unexpected token\n");
coap_show_pdu(0, sent);
coap_log_err("nack_handler: %d: Unexpected token\n", reason);
}
}
switch (reason) {
case COAP_NACK_NOT_DELIVERABLE:
case COAP_NACK_TLS_FAILED:
case COAP_NACK_TOO_MANY_RETRIES:
coap_log_err("cannot send CoAP pdu\n");
if (!reconnect_secs)
quit = 1;
break;
case COAP_NACK_TOO_MANY_RETRIES:
case COAP_NACK_WS_FAILED:
case COAP_NACK_TLS_LAYER_FAILED:
case COAP_NACK_WS_LAYER_FAILED:
+8 -8
View File
@@ -1099,12 +1099,12 @@ proxy_event_handler(coap_session_t *session COAP_UNUSED,
return 0;
}
static coap_response_t
reverse_response_handler(coap_session_t *rsp_session,
const coap_pdu_t *sent COAP_UNUSED,
const coap_pdu_t *received,
const coap_mid_t id COAP_UNUSED) {
return coap_proxy_forward_response(rsp_session, received, NULL);
static coap_pdu_t *
proxy_response_handler(coap_session_t *rsp_session COAP_UNUSED,
const coap_pdu_t *sent COAP_UNUSED,
coap_pdu_t *received,
coap_cache_key_t *cache_key COAP_UNUSED) {
return received;
}
static void
@@ -1141,7 +1141,7 @@ init_resources(coap_context_t *ctx) {
r = coap_resource_reverse_proxy_init(hnd_reverse_proxy_uri, 0);
coap_add_resource(ctx, r);
coap_register_event_handler(ctx, proxy_event_handler);
coap_register_proxy_response_handler(ctx, reverse_response_handler);
coap_register_proxy_response_handler(ctx, proxy_response_handler);
coap_register_nack_handler(ctx, proxy_nack_handler);
} else {
#endif /* COAP_PROXY_SUPPORT */
@@ -1206,7 +1206,7 @@ init_resources(coap_context_t *ctx) {
proxy_host_name_list, 0);
coap_add_resource(ctx, r);
coap_register_event_handler(ctx, proxy_event_handler);
coap_register_proxy_response_handler(ctx, reverse_response_handler);
coap_register_proxy_response_handler(ctx, proxy_response_handler);
coap_register_nack_handler(ctx, proxy_nack_handler);
}
#endif /* COAP_PROXY_SUPPORT */