ud3tn/components/bundle7/previousnode.c

62 lines
1.3 KiB
C
Raw Permalink Normal View History

// SPDX-License-Identifier: BSD-3-Clause OR Apache-2.0
#include "bundle7/bundle7.h"
#include "bundle7/eid.h"
#include "bundle7/previousnode.h"
#include "ud3tn/bundle.h"
#include "ud3tn/eid.h"
#include <stdlib.h>
Make EID a data structure - A new `struct eid` is introduced, which can represent EIDs in a scheme-based manner; specifically, this means that `ipn` EIDs are now represented as tuples of two 64-bit integers and the `dtn` null endpoint is now represented as a `NULL` pointer (similar to the CBOR representation in RFC 9171). - We assume that any `struct eid` instance has been validated before, e.g. by decoding a string via `eid_from_string`. - Note that the FIB is still using the (normalized) string format of node IDs. It performs a lookup in a hash table anyway and, later, we plan to support EID patterns (current IETF draft). - Changes to parsers and serializers: - The BPv7 parser validates EIDs separately from `eid_from_string`. This is intentional: No full normalizationis performed for incoming bundles; as long as the EID is valid, it is passed through, to prevent changes to the immutable (as per RFC9171) primary block. This means that, e.g., there are two representations of the null endpoint (`dtn:none` and `ipn:0.0`), which are kept as such now. - The BPv6 parser and serializer will rewrite the primary block of passing bundles -- they do this anyway as the "dictionary" is re-constructed by the serializer. - Dedicated string representations of the EIDs (`source_str`, etc.) are added to the bundle struct on reception (`cla_contact_tx_task`) and creation -- this is done for convenience when processing the bundle further (especially to still be able to print log messages referring to the EIDs in the BP and so on). We may remove it in the future to reduce the number of EID-to-string conversions. - Other changes: - Some terminology is cleaned up in the process: e.g., variables referring to the local administrative endpoint identifier are renamed as such. The previously-used terms "local node ID" or, worse, "local EID" are inaccurate -- according to the standards, any locally registered singleton EID is a node ID of the local bundle node. - In some places, log messages are harmonized (e.g. by always using quotes around EIDs and no quotes for agent sink IDs). Sometimes, EIDs were printed in logs which have been removed now to prevent an unnecessary EID-to-string conversion. - `aap2_agent`: the manual deallocation of string parts of the AAP2 message is now replaced by a less fragile `pb_release` in most cases. - `bundle.h`: `struct endpoint_list` is replaced in BPv6 by a `struct eid_list` containing the new `struct eid`; the DFCF ("compat") router still uses the old variant with strings - `init`: `preprocess_local_eid` is simplified and moved to `cmdline.c`. It now uses `eid_from_string`, which tolerates missing trailing slashes for `dtn`. Also, we do not support `ipn:x` without service number anymore on the command line, as it is an invalid format and only makes the coe more complex. It is recommended to review the changes to `ud3tn/eid.[c|h]` and the associated unit tests (`test_eid.c`) first, to get an overall idea of the added and adapted functionality plus the expected behaviors. Before reviewing the individual changes to all functions dealing with EIDs, it is also advisable to take a quick look at the other associated (following) commits. Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-11-13 08:48:10 +01:00
struct bundle_block_list *bundle7_previous_node_create_entry(const struct eid local_node_id)
{
struct bundle_block *const prev_node = bundle_block_create(
BUNDLE_BLOCK_TYPE_PREVIOUS_NODE
);
if (!prev_node)
return NULL;
struct bundle_block_list *const bbl_entry = bundle_block_entry_create(prev_node);
const size_t eid_len = bundle7_eid_sizeof(local_node_id);
if (!bbl_entry || eid_len == 0) {
bundle_block_free(prev_node);
return NULL;
}
void *const block_payload = malloc(eid_len);
if (!block_payload) {
bundle_block_entry_free(bbl_entry);
return NULL;
}
prev_node->data = block_payload;
const size_t serialized_len = bundle7_previous_node_serialize(
local_node_id,
block_payload,
eid_len
);
if (!serialized_len) {
bundle_block_entry_free(bbl_entry);
return NULL;
}
prev_node->length = serialized_len;
return bbl_entry;
}
Make EID a data structure - A new `struct eid` is introduced, which can represent EIDs in a scheme-based manner; specifically, this means that `ipn` EIDs are now represented as tuples of two 64-bit integers and the `dtn` null endpoint is now represented as a `NULL` pointer (similar to the CBOR representation in RFC 9171). - We assume that any `struct eid` instance has been validated before, e.g. by decoding a string via `eid_from_string`. - Note that the FIB is still using the (normalized) string format of node IDs. It performs a lookup in a hash table anyway and, later, we plan to support EID patterns (current IETF draft). - Changes to parsers and serializers: - The BPv7 parser validates EIDs separately from `eid_from_string`. This is intentional: No full normalizationis performed for incoming bundles; as long as the EID is valid, it is passed through, to prevent changes to the immutable (as per RFC9171) primary block. This means that, e.g., there are two representations of the null endpoint (`dtn:none` and `ipn:0.0`), which are kept as such now. - The BPv6 parser and serializer will rewrite the primary block of passing bundles -- they do this anyway as the "dictionary" is re-constructed by the serializer. - Dedicated string representations of the EIDs (`source_str`, etc.) are added to the bundle struct on reception (`cla_contact_tx_task`) and creation -- this is done for convenience when processing the bundle further (especially to still be able to print log messages referring to the EIDs in the BP and so on). We may remove it in the future to reduce the number of EID-to-string conversions. - Other changes: - Some terminology is cleaned up in the process: e.g., variables referring to the local administrative endpoint identifier are renamed as such. The previously-used terms "local node ID" or, worse, "local EID" are inaccurate -- according to the standards, any locally registered singleton EID is a node ID of the local bundle node. - In some places, log messages are harmonized (e.g. by always using quotes around EIDs and no quotes for agent sink IDs). Sometimes, EIDs were printed in logs which have been removed now to prevent an unnecessary EID-to-string conversion. - `aap2_agent`: the manual deallocation of string parts of the AAP2 message is now replaced by a less fragile `pb_release` in most cases. - `bundle.h`: `struct endpoint_list` is replaced in BPv6 by a `struct eid_list` containing the new `struct eid`; the DFCF ("compat") router still uses the old variant with strings - `init`: `preprocess_local_eid` is simplified and moved to `cmdline.c`. It now uses `eid_from_string`, which tolerates missing trailing slashes for `dtn`. Also, we do not support `ipn:x` without service number anymore on the command line, as it is an invalid format and only makes the coe more complex. It is recommended to review the changes to `ud3tn/eid.[c|h]` and the associated unit tests (`test_eid.c`) first, to get an overall idea of the added and adapted functionality plus the expected behaviors. Before reviewing the individual changes to all functions dealing with EIDs, it is also advisable to take a quick look at the other associated (following) commits. Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-11-13 08:48:10 +01:00
size_t bundle7_previous_node_serialize(const struct eid previous_node,
uint8_t *buffer, size_t length)
{
const int len = bundle7_eid_serialize(previous_node, buffer, length);
if (len < 0)
return 0;
return (size_t)len;
}