Skip to content

Commit f6ba55a

Browse files
nits
1 parent fd07405 commit f6ba55a

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

libudpard/udpard.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ typedef unsigned char byte_t; ///< For compatibility with platforms where byte s
6666
#define IPv4_MCAST_PREFIX 0xEF000000UL
6767
#define IPv4_MCAST_SUFFIX_MASK 0x007FFFFFUL
6868

69-
static udpard_udpip_ep_t make_topic_ep(const uint32_t subject_id)
70-
{
71-
return (udpard_udpip_ep_t){ .ip = IPv4_MCAST_PREFIX | (subject_id & IPv4_MCAST_SUFFIX_MASK), .port = UDP_PORT };
72-
}
73-
7469
static size_t smaller(const size_t a, const size_t b) { return (a < b) ? a : b; }
7570
static size_t larger(const size_t a, const size_t b) { return (a > b) ? a : b; }
7671
static int64_t min_i64(const int64_t a, const int64_t b) { return (a < b) ? a : b; }
@@ -121,6 +116,11 @@ static int32_t cavl_compare_fragment_end(const void* const user, const udpard_tr
121116
return 0; // clang-format on
122117
}
123118

119+
udpard_udpip_ep_t udpard_make_subject_endpoint(const uint32_t subject_id)
120+
{
121+
return (udpard_udpip_ep_t){ .ip = IPv4_MCAST_PREFIX | (subject_id & IPv4_MCAST_SUFFIX_MASK), .port = UDP_PORT };
122+
}
123+
124124
// NOLINTNEXTLINE(misc-no-recursion)
125125
void udpard_fragment_free_all(udpard_fragment_t* const frag, const udpard_mem_resource_t fragment_memory_resource)
126126
{
@@ -612,17 +612,17 @@ uint32_t udpard_tx_publish(udpard_tx_t* const self,
612612
.sender_uid = self->local_uid,
613613
.topic_hash = topic_hash,
614614
};
615-
out = tx_push(self, deadline, meta, make_topic_ep(subject_id), payload, user_transfer_reference);
615+
out = tx_push(self, deadline, meta, udpard_make_subject_endpoint(subject_id), payload, user_transfer_reference);
616616
}
617617
return out;
618618
}
619619

620620
uint32_t udpard_tx_p2p(udpard_tx_t* const self,
621621
const udpard_us_t now,
622622
const udpard_us_t deadline,
623+
const udpard_prio_t priority,
623624
const uint64_t remote_uid,
624625
const udpard_udpip_ep_t remote_ep,
625-
const udpard_prio_t priority,
626626
const uint64_t transfer_id,
627627
const udpard_bytes_t payload,
628628
const bool ack_required,

libudpard/udpard.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ typedef struct udpard_remote_t
197197
udpard_udpip_ep_t endpoints[UDPARD_NETWORK_INTERFACE_COUNT_MAX]; ///< Zeros in unavailable ifaces.
198198
} udpard_remote_t;
199199

200+
/// Returns the destination multicast UDP/IP endpoint for the given subject ID.
201+
/// The application may use this function when setting up subscription sockets.
202+
/// If the subject-ID exceeds the allowed range, the excessive bits are masked out.
203+
udpard_udpip_ep_t udpard_make_subject_endpoint(const uint32_t subject_id);
204+
200205
/// The semantics are similar to malloc/free.
201206
/// Consider using O1Heap: https://github.com/pavel-kirienko/o1heap. Alternatively, some applications may prefer to
202207
/// use a set of fixed-size block pool allocators (see the high-level overview for details); for example:
@@ -456,12 +461,13 @@ uint32_t udpard_tx_publish(udpard_tx_t* const self,
456461
/// Similar to udpard_tx_publish, but for P2P transfers between specific nodes.
457462
/// This can only be sent in a response to a published message; the RX pipeline will provide the discovered return
458463
/// endpoint for this particular remote node.
464+
/// The destination UID may seem redundant but it is needed to filter out incorrectly addressed transfers.
459465
uint32_t udpard_tx_p2p(udpard_tx_t* const self,
460466
const udpard_us_t now,
461467
const udpard_us_t deadline,
468+
const udpard_prio_t priority,
462469
const uint64_t remote_uid,
463470
const udpard_udpip_ep_t remote_ep,
464-
const udpard_prio_t priority,
465471
const uint64_t transfer_id,
466472
const udpard_bytes_t payload,
467473
const bool ack_required,

tests/src/test_intrusive_tx.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ static void test_tx_publish(void)
671671
TEST_ASSERT_EQUAL(2000000, frame->deadline);
672672
TEST_ASSERT_EQUAL(udpard_prio_nominal, frame->priority);
673673
// Verify the destination is the correct multicast endpoint
674-
const udpard_udpip_ep_t expected_ep = make_topic_ep(123);
674+
const udpard_udpip_ep_t expected_ep = udpard_make_subject_endpoint(123);
675675
TEST_ASSERT_EQUAL(expected_ep.ip, frame->destination.ip);
676676
TEST_ASSERT_EQUAL(expected_ep.port, frame->destination.port);
677677
udpard_tx_pop(&tx, frame);
@@ -692,9 +692,9 @@ static void test_tx_p2p(void)
692692
const uint32_t enqueued = udpard_tx_p2p(&tx,
693693
1000000, // now
694694
2000000, // deadline
695+
udpard_prio_high, // priority
695696
0xFEDCBA9876543210ULL, // remote_uid
696697
(udpard_udpip_ep_t){ .ip = 0xC0A80101, .port = 9999 },
697-
udpard_prio_high, // priority
698698
0x0BADC0DE0BADC0DEULL, // transfer_id
699699
(udpard_bytes_t){ .size = interstellar_war_size, .data = interstellar_war },
700700
true, // ack_required
@@ -800,9 +800,9 @@ static void test_tx_deadline_at_current_time(void)
800800
enqueued = udpard_tx_p2p(&tx,
801801
2000000, // now
802802
1999999, // deadline in the past
803+
udpard_prio_high,
803804
0xFEDCBA9876543210ULL,
804805
(udpard_udpip_ep_t){ .ip = 0xC0A80101, .port = 9999 },
805-
udpard_prio_high,
806806
0x0BADC0DE0BADC0DEULL,
807807
(udpard_bytes_t){ .size = test_payload_size, .data = test_payload },
808808
false,
@@ -870,9 +870,9 @@ static void test_tx_invalid_params(void)
870870
udpard_tx_p2p(&tx,
871871
1000000,
872872
2000000,
873+
udpard_prio_high,
873874
0, // remote_uid cannot be 0
874875
(udpard_udpip_ep_t){ .ip = 0xC0A80101, .port = 9999 },
875-
udpard_prio_high,
876876
0x0BADC0DE0BADC0DEULL,
877877
(udpard_bytes_t){ .size = 10, .data = "test" },
878878
false,
@@ -881,9 +881,9 @@ static void test_tx_invalid_params(void)
881881
udpard_tx_p2p(&tx,
882882
1000000,
883883
2000000,
884+
udpard_prio_high,
884885
0xFEDCBA9876543210ULL,
885886
(udpard_udpip_ep_t){ .ip = 0, .port = 9999 }, // ip cannot be 0
886-
udpard_prio_high,
887887
0x0BADC0DE0BADC0DEULL,
888888
(udpard_bytes_t){ .size = 10, .data = "test" },
889889
false,

0 commit comments

Comments
 (0)