Nim implementation of the e2e reliability protocol.
onMessageSent (message_sent in the C FFI) reports acknowledgment evidence
from an incoming message's causal history or bloom filter. Unacknowledged
messages removed after the configured sweep budget instead trigger the optional
onMessageExpired callback (message_expired), with messageId and channelId.
Expiry is not delivery confirmation.
The existing sweep timing and accounting are unchanged: after resendInterval,
the sweep increments resendAttempts and resets sendTime, or expires the
message if maxResendAttempts has been reached. The sweep does not transmit
retries; these counters currently measure elapsed intervals, not transmissions.
- Nix package manager
git clone https://github.com/logos-messaging/nim-sds.git
cd nim-sds
# Build the shared library
nix build '.#libsds'
# Run tests
nix develop --command nimble testnix build --print-out-paths '.#libsds'nix build --print-out-paths '.#libsds-android-arm64'
nix build --print-out-paths '.#libsds-android-amd64'
nix build --print-out-paths '.#libsds-android-x86'
nix build --print-out-paths '.#libsds-android-arm'nix build --print-out-paths '.#libsds-ios'With Nimble 0.26 or later, for the current platform:
nimble setup
nimble libsds # short for: nimble shell nim c library/libsds.nimThis builds the shared library into build/, with the headers libsds.h includes in
build/generated/. nimble shell runs the Nim that nimble.lock pins, and the root
config.nims passes it the locked dependencies. For a static library, add
--app:staticlib --out:build/libsds.a.
Development shell
Enter the dev shell:
nix developBuild for the current platform:
nim c library/libsds.nim # shared library
nim c --app:staticlib --out:build/libsds.a library/libsds.nim # static libraryRun tests:
nimble testThe built library is output to build/.
Android (without Nix)
Download the latest Android NDK:
cd ~
wget https://dl.google.com/android/repository/android-ndk-r27c-linux.zip
unzip android-ndk-r27c-linux.zipAdd to ~/.bashrc:
export ANDROID_NDK_ROOT=$HOME/android-ndk-r27c
export PATH=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATHThen pass the target to the build:
CC=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android28-clang
nim c -d:ffiOutputDir=$PWD/build/generated --app:lib --out:build/libsds.so --os:android --cpu:arm64 --cc:clang --clang.exe:$CC --clang.linkerexe:$CC library/libsds.nimThe API level comes from the compiler name, and the architecture from --cpu and the compiler name.
The library is output to build/libsds.so.
Dependency management
Dependencies are managed by Nimble and pinned via nimble.lock.
To set up dependencies locally:
nimble setup -lTo update dependencies:
nimble lockAfter updating nimble.lock, the Nix outputHash in nix/deps.nix must be recalculated
by running nix build and updating the hash from the error output.
Embedding libsds in another project
A project builds the library from the installed package with plain nim c, passing everything about the build except what the library needs itself, which is in library/config.nims: the target, the policy (--mm, --opt, log level), the app type, the outputs and the --path of every dependency from its own resolution:
nim c --skipParentCfg --noNimblePath <target> <policy> $(tr '\n' ' ' < nimble.paths) \
--app:lib --nimcache:out/nimcache -d:ffiOutputDir=$PWD/out/generated -o:out/libsds.so "$(nimble path sds)/library/libsds.nim"The C API is sds_*, declared in library/libsds.h, which includes generated/sds.h: nim-ffi writes it during the compile into the directory -d:ffiOutputDir names (build/generated in the checkout by default, so an embedder passes its own).
Licensed under either of Apache License, Version 2.0 or MIT license at your option.