Previously the maximum waiting time was just over 24 days. In a DTN
setup we may want to wait longer, e.g., for contacts to occur. This
allows for waiting about 292 years. If the provided delay exceeds this
threshold, an infinite delay is assumed.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
The nanoseconds field in struct timespec must not exceed 1000 million,
i.e., one second. As we add to an absolute time we might exceed this in
some cases. Thus, we need to check for it and reflect the additional
second in the seconds field of struct timespec.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
We cannot easily support this on MacOS, but we do not use it except in
tests. Thus, remove it and make the tests only run on Linux and use
`sem_getvalue` directly.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
Unnamed semaphores are unsupported there, which is why we were seeing
segfaults.
See also: https://stackoverflow.com/a/27847103
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This removes all external functions currently unused in uD3TN.
We may re-introduce esp. JSON at a later point in time, but should
include updated libraries anyway.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
`hal_task_create` returned a reference to the new task allocated on the
heap via `malloc`. We commonly used the pattern to `free` this reference
from the new thread which, however, could result in race conditions and
other synchronization issues. We added a fix using a semaphore in the
application agent, but this would have been needed in other places (CLA,
...) as well. As we do not make use of the task reference anywhere
besides in the CLA for error handling, we can remove the heap-allocated
value altogether and replace it with an `enum ud3tn_result` to simplify
things and circumvent the named synchronization issues.
In the case of the CLA function `cla_link_init`, logic is introduced to
request the RX task to exit immediately in case the TX task cannot be
launched.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
The delete function should just deallocate the heap memory, termination
of the thread should be controlled by itself, to make it safe to call
`hal_task_delete()` from within the thread.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
`strerror()` is not thread-safe, thus, we have to use an alternative. If
we want to prevent allocating a temporary buffer (e.g., for
`strerror_r`), we need to use `perror()`. To allow writing stored
`errno` values, the function sets `errno` from an argument passed to it,
which should be safe according to the manual.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
As on the targeted platforms the scheduler is always running when the
program is launched, the function should simply pause indefinitely. It
did not do this, though, as a signal can interrupt `pause()`.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This removes some functions solely useful for the STM32, debugging and
error handling with these boards. When doing a future uC port, we should
move such functions to the platform-specific part.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
The static variables might be accessed at the same time. The name is not
really needed if we have a debugger available, which we probably always
do...
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This can lead to hard-to-debug errors as it would just increment the
semaphore further and then a double "locking" is needed to actually lock it.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
The previous polling method was not clean in that it left the semaphore
locked and did not return whether the operation was successful or not.
This adds a more descriptive and correct method to chieve the goal of
checking the semaphore's status.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This switches all log messages to `stderr`, which is intended for
diagnostic purposes (i.e., matches the intent of our log messages). This
makes it easy to distinguish the log output from actual output (which
the uD3TN daemon does not have, but a program based on libud3tn might).
This also flushes stderr after every log message (i.e., makes it
line-buffered) to prevent delays when outputting the logs.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
LOG() is not safe to be called inside signal handlers as it requires
malloc() and free() to work.
Detected by Clang's thread sanitizer.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
Do not return a reference to a non-thread-safe global variable:
ctime() is not thread safe. As we only use the function in logging, we
can directly print the return value, protected by a mutex.
This also adapts the tests and makes the initialization routine always
run. To use the system time again, UINT64_MAX can be passed.
Found by Clang's thread (data race) sanitizer.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
Former releases of uD3TN have included support for STM32/FreeRTOS.
Having this support from the first moment on was a good thing in
order to optimize for platforms with limited resources. As this
platform is not used in current uD3TN setups and as it results in quite
some maintenance work, it is removed with this commit. The removed parts
cover the implementation itself, tests, tools, documentation, parts of
the build/make scripts as well as licensing information.
Signed-off-by: Marius Feldmann <marius.feldmann@d3tn.com>
ud3tn is available under multiple licenses and we want to reflect this in
our source code. But which license information should appear first and how
can we manage this efficiently in the future? The Linux Kernel uses SPDX
expressions instead of boilerplate sections. This seems to be a great
approach, so we do the same here.
Signed-off-by: Georg Alexander Murzik <georg.murzik@d3tn.com>
As we are moving to `BSD-3-Clause OR Apache-2.0`, this needs to be
adapted as well. (We got the permission of Robert to publish his code
under the new licensing scheme.)
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This adds the array length of UD3TN_HASH_LENGTH to the function argument
as it is declared in the header file. By that, a new GCC warning is
fixed.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
The re-name to "enum ud3tn_result" broke the indentation in some
function signatures, which is fixed by this commit.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This is the initial commit for uD3TN. uD3TN is a fork of uPCN v0.8.0,
which will be developed and maintained in a public Git repository.
For questions concerning the history of and code provided with uPCN,
please get in touch with us via: contact <at> d3tn <dot> com
Signed-off-by: Felix Walter <felix.walter@d3tn.com>