Skip to content

Commit 877feee

Browse files
p2p
1 parent 950e22a commit 877feee

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

libudpard/udpard.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ static void tx_send_ack(udpard_rx_t* const rx,
11881188

11891189
bool udpard_tx_new(udpard_tx_t* const self,
11901190
const uint64_t local_uid,
1191-
const uint64_t p2p_transfer_id_base_seed,
1191+
const uint64_t p2p_transfer_id_seed,
11921192
const size_t enqueued_frames_limit,
11931193
const udpard_tx_mem_resources_t memory,
11941194
const udpard_tx_vtable_t* const vtable)
@@ -1199,7 +1199,7 @@ bool udpard_tx_new(udpard_tx_t* const self,
11991199
mem_zero(sizeof(*self), self);
12001200
self->vtable = vtable;
12011201
self->local_uid = local_uid;
1202-
self->p2p_transfer_id_base = hash_pair_u64(p2p_transfer_id_base_seed, local_uid);
1202+
self->p2p_transfer_id = hash_pair_u64(p2p_transfer_id_seed, local_uid);
12031203
self->ack_baseline_timeout = UDPARD_TX_ACK_BASELINE_TIMEOUT_DEFAULT_us;
12041204
self->enqueued_frames_limit = enqueued_frames_limit;
12051205
self->enqueued_frames_count = 0;
@@ -1264,7 +1264,7 @@ bool udpard_tx_push_p2p(udpard_tx_t* const self,
12641264
.priority = priority,
12651265
.kind = (feedback != NULL) ? frame_msg_reliable : frame_msg_best,
12661266
.transfer_payload_size = (uint32_t)bytes_scattered_size(payload),
1267-
.transfer_id = remote.uid + self->p2p_transfer_id_base++, // Preserve monotonicity.
1267+
.transfer_id = self->p2p_transfer_id++, // Shared for all remotes, hence no ack ambiguity.
12681268
.sender_uid = self->local_uid,
12691269
};
12701270
if (out_transfer_id != NULL) {

libudpard/udpard.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,8 @@ struct udpard_tx_t
398398
uint64_t local_uid;
399399

400400
/// A random-initialized counter for outgoing P2P transfers. Must not be changed by the application.
401-
uint64_t p2p_transfer_id_base;
401+
/// The shared counter for all P2P transfers ensures uniqueness of the transfer-ID per remote node.
402+
uint64_t p2p_transfer_id;
402403

403404
/// The maximum number of Cyphal transfer payload bytes per UDP datagram. See UDPARD_MTU_*.
404405
/// The Cyphal/UDP header is added to this value to obtain the total UDP datagram payload size.
@@ -474,7 +475,7 @@ struct udpard_tx_t
474475
/// True on success, false if any of the arguments are invalid.
475476
bool udpard_tx_new(udpard_tx_t* const self,
476477
const uint64_t local_uid,
477-
const uint64_t p2p_transfer_id_base_seed,
478+
const uint64_t p2p_transfer_id_seed,
478479
const size_t enqueued_frames_limit,
479480
const udpard_tx_mem_resources_t memory,
480481
const udpard_tx_vtable_t* const vtable);
@@ -488,6 +489,7 @@ bool udpard_tx_new(udpard_tx_t* const self,
488489
/// such that it is likely to be distinct per application startup (embedded systems can use noinit memory sections,
489490
/// hash uninitialized SRAM, use timers or ADC noise, etc). It is essential to provide a monotonic contiguous
490491
/// counter per topic to allow remotes to recover the original publication order and detect lost messages.
492+
/// The random starting point will ensure global uniqueness across topics.
491493
/// Related thread on random transfer-ID init: https://forum.opencyphal.org/t/improve-the-transfer-id-timeout/2375
492494
///
493495
/// The user context value is carried through to the callbacks. It must contain enough context to allow subject-ID

0 commit comments

Comments
 (0)