Skip to content

Commit 02f0c2f

Browse files
simplify
1 parent 536db18 commit 02f0c2f

File tree

4 files changed

+120
-173
lines changed

4 files changed

+120
-173
lines changed

.idea/dictionaries/project.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libudpard/udpard.c

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -617,20 +617,21 @@ bool udpard_tx_new(udpard_tx_t* const self,
617617
return ok;
618618
}
619619

620-
uint32_t udpard_tx_publish(udpard_tx_t* const self,
621-
const udpard_us_t now,
622-
const udpard_us_t deadline,
623-
const udpard_prio_t priority,
624-
const uint64_t topic_hash,
625-
const uint32_t subject_id,
626-
const uint64_t transfer_id,
627-
const udpard_bytes_t payload,
628-
const bool ack_required,
629-
void* const user_transfer_reference)
630-
{
631-
uint32_t out = 0;
632-
if ((self != NULL) && (deadline >= now) && (self->local_uid != 0) && (priority <= UDPARD_PRIORITY_MAX) &&
633-
((payload.data != NULL) || (payload.size == 0U))) {
620+
uint32_t udpard_tx_push(udpard_tx_t* const self,
621+
const udpard_us_t now,
622+
const udpard_us_t deadline,
623+
const udpard_prio_t priority,
624+
const uint64_t topic_hash,
625+
const udpard_udpip_ep_t remote_ep,
626+
const uint64_t transfer_id,
627+
const udpard_bytes_t payload,
628+
const bool ack_required,
629+
void* const user_transfer_reference)
630+
{
631+
uint32_t out = 0;
632+
const bool ok = (self != NULL) && (deadline >= now) && (self->local_uid != 0) && validate_ep(remote_ep) &&
633+
(priority <= UDPARD_PRIORITY_MAX) && ((payload.data != NULL) || (payload.size == 0U));
634+
if (ok) {
634635
self->errors_expiration += tx_purge_expired(self, now);
635636
const meta_t meta = {
636637
.priority = priority,
@@ -640,35 +641,6 @@ uint32_t udpard_tx_publish(udpard_tx_t* const self,
640641
.sender_uid = self->local_uid,
641642
.topic_hash = topic_hash,
642643
};
643-
out = tx_push(self, deadline, meta, udpard_make_subject_endpoint(subject_id), payload, user_transfer_reference);
644-
}
645-
return out;
646-
}
647-
648-
uint32_t udpard_tx_p2p(udpard_tx_t* const self,
649-
const udpard_us_t now,
650-
const udpard_us_t deadline,
651-
const udpard_prio_t priority,
652-
const uint64_t remote_uid,
653-
const udpard_udpip_ep_t remote_ep,
654-
const uint64_t transfer_id,
655-
const udpard_bytes_t payload,
656-
const bool ack_required,
657-
void* const user_transfer_reference)
658-
{
659-
uint32_t out = 0;
660-
if ((self != NULL) && (deadline >= now) && (self->local_uid != 0) && (remote_uid != 0) && (remote_ep.ip != 0) &&
661-
(remote_ep.port != 0) && (priority <= UDPARD_PRIORITY_MAX) &&
662-
((payload.data != NULL) || (payload.size == 0U))) {
663-
self->errors_expiration += tx_purge_expired(self, now);
664-
const meta_t meta = {
665-
.priority = priority,
666-
.flag_ack = ack_required,
667-
.transfer_payload_size = (uint32_t)payload.size,
668-
.transfer_id = transfer_id,
669-
.sender_uid = self->local_uid,
670-
.topic_hash = remote_uid,
671-
};
672644
out = tx_push(self, deadline, meta, remote_ep, payload, user_transfer_reference);
673645
}
674646
return out;

libudpard/udpard.h

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,16 @@
7474
/// |
7575
/// ... ---+
7676
///
77-
///
78-
/// Memory management
79-
///
8077
/// The library can be used either with a regular heap (preferably constant-time) or with a collection of fixed-size
8178
/// block pool allocators (in safety-certified systems). It is up to the application to choose the desired memory
8279
/// management strategy; the library is interfaced with the memory managers via a special memory resource abstraction.
8380
///
8481
/// Typically, if block pool allocators are used, the following block sizes should be served:
8582
///
86-
/// - MTU sized blocks for the TX and RX pipelines (usually less than 2048 bytes);
87-
/// - TX fragment item sized blocks for the TX pipeline (less than 128 bytes).
88-
/// - RX session object sized blocks for the RX pipeline (less than 512 bytes);
89-
/// - RX fragment handle sized blocks for the RX pipeline (less than 128 bytes).
90-
/// - udpard_remote_t sized blocks for the return path discovery.
83+
/// - MTU sized blocks for the TX and RX pipelines (typically at most 1.5 KB unless jumbo frames are used).
84+
/// - sizeof(udpard_tx_item_t) blocks for the TX pipeline.
85+
/// - sizeof(rx_session_t) blocks for the RX pipeline.
86+
/// - sizeof(udpard_fragment_t) blocks for the RX pipeline.
9187
///
9288
/// --------------------------------------------------------------------------------------------------------------------
9389
///
@@ -233,10 +229,10 @@ typedef struct udpard_mem_resource_t
233229
/// as well as the payload structure itself, assuming that it is also heap-allocated.
234230
/// The model is as follows:
235231
///
236-
/// (payload header) ---> udpard_fragment_t:
237-
/// next ---> udpard_fragment_t...
238-
/// origin ---> (the free()able payload data buffer)
239-
/// view ---> (somewhere inside the payload data buffer)
232+
/// udpard_fragment_t:
233+
/// next ---> udpard_fragment_t...
234+
/// origin ---> (the free()able payload data buffer)
235+
/// view ---> (somewhere inside the payload data buffer)
240236
///
241237
/// Payloads of received transfers are represented using this type, where each fragment corresponds to a frame.
242238
/// The application can either consume them directly or to copy the data into a contiguous buffer beforehand
@@ -427,6 +423,9 @@ bool udpard_tx_new(udpard_tx_t* const self,
427423
/// The MTU of the generated datagrams is dependent on the value of the MTU setting at the time when this function
428424
/// is invoked. The MTU setting can be changed arbitrarily between invocations.
429425
///
426+
/// The topic hash is not defined for P2P transfers since there are no topics involved; in P2P, this parameter
427+
/// is used to pass the destination node's UID instead.
428+
///
430429
/// The transfer_id parameter will be used to populate the transfer_id field of the generated datagrams.
431430
/// The caller shall increment the transfer-ID counter after each successful invocation of this function
432431
/// per redundant interface; the same transfer published over redundant interfaces shall have the same transfer-ID.
@@ -456,31 +455,16 @@ bool udpard_tx_new(udpard_tx_t* const self,
456455
///
457456
/// The time complexity is O(p + log e), where p is the amount of payload in the transfer, and e is the number of
458457
/// transfers (not frames) already enqueued in the transmission queue.
459-
uint32_t udpard_tx_publish(udpard_tx_t* const self,
460-
const udpard_us_t now,
461-
const udpard_us_t deadline,
462-
const udpard_prio_t priority,
463-
const uint64_t topic_hash,
464-
const uint32_t subject_id,
465-
const uint64_t transfer_id,
466-
const udpard_bytes_t payload,
467-
const bool ack_required,
468-
void* const user_transfer_reference);
469-
470-
/// Similar to udpard_tx_publish, but for P2P transfers between specific nodes.
471-
/// This can only be sent in a response to a published message; the RX pipeline will provide the discovered return
472-
/// endpoint for this particular remote node.
473-
/// The destination UID may seem redundant but it is needed to filter out incorrectly addressed transfers.
474-
uint32_t udpard_tx_p2p(udpard_tx_t* const self,
475-
const udpard_us_t now,
476-
const udpard_us_t deadline,
477-
const udpard_prio_t priority,
478-
const uint64_t remote_uid,
479-
const udpard_udpip_ep_t remote_ep,
480-
const uint64_t transfer_id,
481-
const udpard_bytes_t payload,
482-
const bool ack_required,
483-
void* const user_transfer_reference);
458+
uint32_t udpard_tx_push(udpard_tx_t* const self,
459+
const udpard_us_t now,
460+
const udpard_us_t deadline,
461+
const udpard_prio_t priority,
462+
const uint64_t topic_hash, // For P2P transfers, this is the destination's UID.
463+
const udpard_udpip_ep_t remote_ep,
464+
const uint64_t transfer_id,
465+
const udpard_bytes_t payload,
466+
const bool ack_required,
467+
void* const user_transfer_reference);
484468

485469
/// Purges all timed out items from the transmission queue automatically; returns the next item to be transmitted,
486470
/// if there is any, otherwise NULL. The returned item is not removed from the queue; use udpard_tx_pop() to do that.

0 commit comments

Comments
 (0)