Skip to content

Commit c843aa5

Browse files
committed
use data from reassembler in rxAcceptTransfer & update session on transfer acceptance
1 parent 3950b9e commit c843aa5

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

libserard/serard.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -626,29 +626,30 @@ SERARD_PRIVATE int8_t rxValidateHeader(struct SerardRx* const ins, struct Serard
626626
/// hand, while the wire compatibility is still guaranteed by the high-level requirements given in the specification.
627627
SERARD_PRIVATE bool rxSessionUpdate(struct SerardRx* const ins,
628628
struct SerardInternalRxSession* const rxs,
629-
const struct SerardRxTransfer* const transfer,
629+
struct SerardReassembler* const reassembler,
630630
const SerardMicrosecond transfer_id_timeout_usec)
631631
{
632632
SERARD_ASSERT(ins != NULL);
633633
SERARD_ASSERT(rxs != NULL);
634-
SERARD_ASSERT(transfer != NULL);
634+
SERARD_ASSERT(reassembler != NULL);
635635

636-
const struct SerardTransferMetadata* metadata = &transfer->metadata;
636+
const struct SerardTransferMetadata* metadata = &reassembler->metadata;
637637

638638
// Accept the transfer if the new transfer ID is greater than the previous.
639639
const bool tid_future = metadata->transfer_id > rxs->transfer_id;
640640

641641
// Accept (and restart the session) on transfer ID timeout.
642-
const bool tid_timed_out = (transfer->timestamp_usec > rxs->transfer_timestamp_usec) &&
643-
((transfer->timestamp_usec - rxs->transfer_timestamp_usec) > transfer_id_timeout_usec);
642+
const bool tid_timed_out = (reassembler->timestamp_usec > rxs->transfer_timestamp_usec) &&
643+
((reassembler->timestamp_usec - rxs->transfer_timestamp_usec) > transfer_id_timeout_usec);
644644

645645
// Accept if the transfer ID is at least TRANSFER_ID_DELTA counts less than
646646
// the previous one. This is used to hot-start the rx pipeline after a reboot.
647647
const bool wrap = !tid_future && ((rxs->transfer_id - metadata->transfer_id) >= TRANSFER_ID_DELTA);
648648

649-
if (tid_timed_out)
649+
if (tid_future || tid_timed_out || wrap)
650650
{
651651
rxs->transfer_id = metadata->transfer_id;
652+
rxs->transfer_timestamp_usec = reassembler->timestamp_usec;
652653
}
653654

654655
return tid_future || tid_timed_out || wrap;
@@ -663,7 +664,7 @@ SERARD_PRIVATE int8_t rxAcceptTransfer(struct SerardRx* const ins,
663664
SERARD_ASSERT(reassembler != NULL);
664665
SERARD_ASSERT(transfer != NULL);
665666

666-
const struct SerardTransferMetadata* const metadata = &transfer->metadata;
667+
const struct SerardTransferMetadata* const metadata = &reassembler->metadata;
667668
const struct SerardRxSubscription* const subscription = reassembler->sub;
668669

669670
const size_t payload_size = reassembler->counter - HEADER_SIZE;
@@ -689,7 +690,7 @@ SERARD_PRIVATE int8_t rxAcceptTransfer(struct SerardRx* const ins,
689690
sizeof(struct SerardInternalRxSession));
690691
if (rxs != NULL)
691692
{
692-
rxs->transfer_timestamp_usec = transfer->timestamp_usec;
693+
rxs->transfer_timestamp_usec = reassembler->timestamp_usec;
693694
rxs->source_node_id = metadata->remote_node_id;
694695
rxs->transfer_id = metadata->transfer_id;
695696
struct SerardTreeNode* node = cavl2_find_or_insert((struct SerardTreeNode**) &subscription->sessions,
@@ -708,7 +709,7 @@ SERARD_PRIVATE int8_t rxAcceptTransfer(struct SerardRx* const ins,
708709
}
709710
else
710711
{
711-
valid = valid && rxSessionUpdate(ins, rxs, transfer, subscription->transfer_id_timeout_usec);
712+
valid = valid && rxSessionUpdate(ins, rxs, reassembler, subscription->transfer_id_timeout_usec);
712713
ret = valid ? 1 : 0;
713714
}
714715
}

0 commit comments

Comments
 (0)