Skip to content

Commit 7d52f88

Browse files
committed
fixup! unicoap: basic group communication support
Remove separate multicast timer. Use existing request timer instead.
1 parent 3635858 commit 7d52f88

3 files changed

Lines changed: 22 additions & 56 deletions

File tree

sys/net/application_layer/unicoap/client/client.c

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ static void _on_response_timeout(unicoap_scheduled_event_t* timeout) {
3535
unicoap_client_memo_free(unicoap_client_memo_of_timeout(timeout));
3636
}
3737

38-
static void _on_multicast_response_timeout(unicoap_scheduled_event_t* timeout)
39-
{
40-
_CLIENT_DEBUG("multicast window closed\n");
41-
unicoap_client_memo_free(unicoap_client_memo_of_multicast_timeout(timeout));
42-
}
43-
4438
int unicoap_client_callback_success(unicoap_client_memo_t* memo, const unicoap_packet_t* packet,
4539
unicoap_block_option_t block) {
4640
(void)block;
@@ -141,6 +135,18 @@ int unicoap_client_send_request_body(unicoap_message_t* request,
141135
.token_length = sizeof(token),
142136
} };
143137

138+
ipv6_addr_t ep_addr;
139+
memcpy(ep_addr.u8, endpoint->_tl_ep.addr.ipv6, 16);
140+
bool multicast = endpoint->_tl_ep.family == AF_INET6 && ipv6_addr_is_multicast(&ep_addr);
141+
142+
if (multicast) {
143+
if (flags && UNICOAP_CLIENT_FLAG_RELIABLE) {
144+
_CLIENT_DEBUG("error trying to send reliable datagram via multicast\n");
145+
return -EINVAL;
146+
}
147+
flags |= UNICOAP_CLIENT_FLAG_MULTICAST;
148+
}
149+
144150
if (unicoap_callback_is_present(callback)) {
145151
_CLIENT_DEBUG("need a memo\n");
146152
if (!(memo = unicoap_client_memo_create(endpoint))) {
@@ -150,26 +156,13 @@ int unicoap_client_send_request_body(unicoap_message_t* request,
150156
memo->callback_arg = callback_arg;
151157
memo->flags = flags;
152158

153-
unicoap_event_schedule(&memo->super.exchange.timeout, _on_response_timeout,
154-
CONFIG_UNICOAP_TIMEOUT_CLIENT_RESPONSE_MS);
155-
}
156-
157-
ipv6_addr_t addr;
158-
memcpy(addr.u8, endpoint->_tl_ep.addr.ipv6, 16);
159-
160-
if (endpoint->_tl_ep.family == AF_INET6 && ipv6_addr_is_multicast(&addr)) {
161-
flags |= UNICOAP_CLIENT_FLAG_MULTICAST;
162-
163-
if (memo && (CONFIG_UNICOAP_TIMEOUT_CLIENT_MULTICAST_RESPONSE_MS > 0)) {
164-
unicoap_event_schedule(&memo->super.multicast.timeout, _on_multicast_response_timeout,
159+
if (!multicast) {
160+
unicoap_event_schedule(&memo->super.exchange.timeout, _on_response_timeout,
161+
CONFIG_UNICOAP_TIMEOUT_CLIENT_RESPONSE_MS);
162+
} else if (CONFIG_UNICOAP_TIMEOUT_CLIENT_MULTICAST_RESPONSE_MS > 0) {
163+
unicoap_event_schedule(&memo->super.exchange.timeout, _on_response_timeout,
165164
CONFIG_UNICOAP_TIMEOUT_CLIENT_MULTICAST_RESPONSE_MS);
166165
}
167-
168-
if (flags == UNICOAP_CLIENT_FLAG_RELIABLE) {
169-
_CLIENT_DEBUG("error trying to send reliable datagram via multicastn");
170-
unicoap_client_callback_failure(memo, -EINVAL);
171-
goto error;
172-
}
173166
}
174167

175168
/* TODO: OSCORE */

sys/net/application_layer/unicoap/include/private/state.h

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,6 @@ typedef struct {
173173
} exchange;
174174

175175

176-
/**
177-
* @brief Multicast state
178-
*
179-
* State tracked by the request-response layer for multicast operations.
180-
*/
181-
struct {
182-
unicoap_scheduled_event_t timeout; /**< Timeout */
183-
} multicast;
184-
185176
/**
186177
* @brief Messaging state
187178
*
@@ -214,16 +205,6 @@ static inline unicoap_memo_t* unicoap_memo_of_timeout(unicoap_scheduled_event_t*
214205
return container_of(timeout, unicoap_memo_t, exchange.timeout);
215206
}
216207

217-
/**
218-
* @brief Returns memo of scheduled multicast timeout event
219-
* @param[in] timeout Scheduled multicast timeout event
220-
* @returns Common memo state object
221-
*/
222-
static inline unicoap_memo_t* unicoap_memo_of_multicast_timeout(unicoap_scheduled_event_t* timeout)
223-
{
224-
return container_of(timeout, unicoap_memo_t, multicast.timeout);
225-
}
226-
227208
/**
228209
* @brief Returns memo of scheduled event
229210
* @param[in] event Superclass event
@@ -399,15 +380,6 @@ static inline unicoap_client_memo_t* unicoap_client_memo_of_timeout(unicoap_sche
399380
return unicoap_client_memo_of_super(unicoap_memo_of_timeout(timeout));
400381
}
401382

402-
/**
403-
* @brief Returns client memo of scheduled multicast timeout event
404-
* @param[in] event Superclass timeout event
405-
* @returns Client memo state object
406-
*/
407-
static inline unicoap_client_memo_t* unicoap_client_memo_of_multicast_timeout(unicoap_scheduled_event_t* timeout) {
408-
return unicoap_client_memo_of_super(unicoap_memo_of_multicast_timeout(timeout));
409-
}
410-
411383
/**
412384
* @brief Invokes the the client callback
413385
*/

sys/net/application_layer/unicoap/state.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ static void _deinit_client(unicoap_client_memo_t* memo) {
120120
memo->callback._any = NULL;
121121
memo->callback_arg = NULL;
122122
memo->flags = 0;
123-
unicoap_event_cancel(&memo->super.exchange.timeout);
124-
unicoap_event_cancel(&memo->super.multicast.timeout);
125-
126123
#if IS_ACTIVE(CONFIG_UNICOAP_CLIENT_CANCELLABLE)
127124
memo->reference_id = 0;
128125
#endif
@@ -591,13 +588,17 @@ unicoap_preprocessing_result_t unicoap_exchange_preprocess(unicoap_packet_t* pac
591588
}
592589
}
593590

591+
if ((memo->flags && UNICOAP_CLIENT_FLAG_MULTICAST) == 0) {
592+
unicoap_event_cancel(&memo->super.exchange.timeout);
593+
}
594+
594595
if (truncated) {
595596
_CLIENT_DEBUG("truncated, not processing\n");
596597
unicoap_client_callback_failure(memo, -ENOBUFS);
597598
unicoap_client_memo_free(memo);
598599
return UNICOAP_PREPROCESSING_ERROR_TRUNCATED;
599600
}
600-
unicoap_event_cancel(&memo->super.exchange.timeout);
601+
601602
arg->client = memo;
602603
*flags = _messaging_flags_client(memo->flags);
603604
return UNICOAP_PREPROCESSING_SUCCESS_RESPONSE;

0 commit comments

Comments
 (0)