mirror of
https://gitlab.com/d3tn/ud3tn.git
synced 2026-08-20 13:28:22 +02:00
The Bundle Age block [...] contains the number of milliseconds that have elapsed between the time the bundle was created and time at which it was most recently forwarded. It is intended for use by nodes lacking access to an accurate clock, to aid in determining the time at which a bundle's lifetime expires. [...] If the bundle's creation time is zero, then the bundle MUST contain exactly one (1) occurrence of this type of block.[1] In this implementation the age block is only evaluated if the creation timestamp is 0. If a bundle age block exists, it will be updated according to the specification, but an age block will never be proactively inserted. [1]: https://tools.ietf.org/html/draft-ietf-dtn-bpbis-30#section-4.4.2 Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
45 lines
1.1 KiB
C
45 lines
1.1 KiB
C
#ifndef BUNDLE_AGE_H_INCLUDED
|
|
#define BUNDLE_AGE_H_INCLUDED
|
|
|
|
#include "ud3tn/bundle.h"
|
|
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
|
|
/**
|
|
* Parses the given CBOR-encoded data into a uint64_t value.
|
|
* This function can be used to parse the payload of a bundle age
|
|
* extension block.
|
|
*
|
|
* @param bundle_age Pointer for returning the result
|
|
* @param buffer CBOR-encoded data
|
|
* @param length CBOR data length
|
|
*/
|
|
bool bundle_age_parse(uint64_t *bundle_age, const uint8_t *buffer,
|
|
size_t length);
|
|
|
|
|
|
/**
|
|
* Maximum length of a CBOR-encoded bundle age
|
|
* - 5 Bit length information
|
|
* - 8 Byte uint64_t value
|
|
*/
|
|
#define BUNDLE_AGE_MAX_ENCODED_SIZE 9
|
|
|
|
|
|
/**
|
|
* Generates the CBOR-encoded version of the given bundle age in milliseconds
|
|
* and writes it into the passed buffer. The buffer must be at least be
|
|
* BUNDLE_AGE_MAX_ENCODED_SIZE bytes long
|
|
*
|
|
* @param bundle_age uint_64_t Bundle Age in milliseconds
|
|
* @param buffer Output buffer
|
|
* @param length Buffer length
|
|
* @return Number of bytes written into buffer
|
|
*/
|
|
size_t bundle_age_serialize(const uint64_t bundle_age, uint8_t *const buffer,
|
|
const size_t length);
|
|
|
|
#endif // BUNDLE_AGE_H_INCLUDED
|