Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcoap/forward_proxy: handle timeout case #20915

Merged
merged 1 commit into from
Oct 24, 2024
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
11 changes: 10 additions & 1 deletion sys/net/application_layer/gcoap/forward_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
ztimer_set(ZTIMER_MSEC, timer, timeout_ms);
}


Check warning on line 90 in sys/net/application_layer/gcoap/forward_proxy.c

View workflow job for this annotation

GitHub Actions / static-tests

too many consecutive empty lines
void gcoap_forward_proxy_init(void)
{
gcoap_register_listener(&forward_proxy_listener);
Expand Down Expand Up @@ -276,6 +276,9 @@
/* No harm done in removing a timer that's not active */
ztimer_remove(ZTIMER_MSEC, &cep->empty_ack_timer);
buf_len = coap_get_total_len(pdu);
assert(memo->state == GCOAP_MEMO_RESP ||
memo->state == GCOAP_MEMO_RESP_TRUNC ||
memo->state == GCOAP_MEMO_TIMEOUT);
if (memo->state == GCOAP_MEMO_RESP) {
uint8_t req_etag_len = _cep_get_req_etag_len(cep);

Expand Down Expand Up @@ -304,6 +307,7 @@
}
#endif
}
_set_response_type(pdu, _cep_get_response_type(cep));
/* we do not need to check if valid came from upstream as this is already automatically
* converted by the client-side to the cached response */
/* else forward the response packet as-is to the client */
Expand All @@ -315,8 +319,13 @@
assert(buf_len >= (sizeof(*pdu->hdr) + 4U));
gcoap_resp_init(pdu, (uint8_t *)pdu->hdr, buf_len, COAP_CODE_INTERNAL_SERVER_ERROR);
coap_opt_finish(pdu, COAP_OPT_FINISH_NONE);
_set_response_type(pdu, _cep_get_response_type(cep));
}
else if (memo->state == GCOAP_MEMO_TIMEOUT) {
/* send RST */
gcoap_resp_init(pdu, (uint8_t *)pdu->hdr, buf_len, COAP_CODE_EMPTY);
coap_opt_finish(pdu, COAP_OPT_FINISH_NONE);
}
_set_response_type(pdu, _cep_get_response_type(cep));
/* don't use buf_len here, in case the above `gcoap_resp_init`s changed `pdu` */
_dispatch_msg(pdu->hdr, coap_get_total_len(pdu), &cep->ep, &cep->proxy_ep);
_free_client_ep(cep);
Expand Down
4 changes: 3 additions & 1 deletion sys/net/application_layer/gcoap/gcoap.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#define NO_IMMEDIATE_REPLY (-1)

/* End of the range to pick a random timeout */
#define TIMEOUT_RANGE_END ((uint32_t)CONFIG_COAP_ACK_TIMEOUT_MS * CONFIG_COAP_RANDOM_FACTOR_1000 / 1000)

Check warning on line 56 in sys/net/application_layer/gcoap/gcoap.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters

/* Internal functions */
static void *_event_loop(void *arg);
Expand Down Expand Up @@ -399,7 +399,7 @@
/* but store the header to keep the token for Observe notifications */
memcpy(memo->msg.hdr_buf, hdr, sizeof(hdr));
/* no further retransmissions should be made and
gcoap_request_memo_get_hdr() has to know how to get the header for Observe notifications */

Check warning on line 402 in sys/net/application_layer/gcoap/gcoap.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
memo->send_limit = GCOAP_SEND_LIMIT_NON;
}
}
Expand Down Expand Up @@ -958,7 +958,7 @@
memo_pdu->hdr = gcoap_request_memo_get_hdr(memo);

/* verbose debug to catch bugs with request/response matching */
DEBUG("Seeking memo for remote=%s, tkn=0x%02x%02x%02x%02x%02x%02x%02x%02x, tkl=%"PRIuSIZE"\n",

Check warning on line 961 in sys/net/application_layer/gcoap/gcoap.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
ipv6_addr_to_str(_ipv6_addr_str, (ipv6_addr_t *)&remote->addr.ipv6,
IPV6_ADDR_MAX_STR_LEN),
token[0], token[1], token[2], token[3], token[4], token[5], token[6], token[7],
Expand Down Expand Up @@ -1045,7 +1045,9 @@
/* Pass response to handler */
if (memo->resp_handler) {
coap_pkt_t req;

memset(&req, 0, sizeof(req));
/* 0 means there is an observe option value */
coap_clear_observe(&req);
req.hdr = gcoap_request_memo_get_hdr(memo);
memo->resp_handler(memo, &req, NULL);
}
Expand Down Expand Up @@ -1664,7 +1666,7 @@
const coap_resource_t *resource = last_resource;

while (listener) {
if ((resource = _match_resource_path_iterator(listener, resource, (const uint8_t *)uri_path))) {

Check warning on line 1669 in sys/net/application_layer/gcoap/gcoap.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
*last_listener = listener;
return resource;
}
Expand Down Expand Up @@ -2091,4 +2093,4 @@
event_post(&_queue, arg);
}

/** @} */

Check warning on line 2096 in sys/net/application_layer/gcoap/gcoap.c

View workflow job for this annotation

GitHub Actions / static-tests

source file is too long
Loading