Skip to content
logos-messagingPublic

About

Nim implementation of the e2e reliability protocol

Resources

Stars

3 stars

Watchers

1 watching

Forks

Repository files navigation

nim-sds

Nim implementation of the e2e reliability protocol.

Outgoing message events

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.

Prerequisites

  • Nix package manager

Quick start

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 test

Building

Desktop

nix build --print-out-paths '.#libsds'

Android

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'

iOS

nix build --print-out-paths '.#libsds-ios'

Without Nix

With Nimble 0.26 or later, for the current platform:

nimble setup
nimble libsds    # short for: nimble shell nim c library/libsds.nim

This 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 develop

Build for the current platform:

nim c library/libsds.nim                                               # shared library
nim c --app:staticlib --out:build/libsds.a library/libsds.nim          # static library

Run tests:

nimble test

The 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.zip

Add to ~/.bashrc:

export ANDROID_NDK_ROOT=$HOME/android-ndk-r27c
export PATH=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH

Then 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.nim

The 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 -l

To update dependencies:

nimble lock

After 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).

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

About

Nim implementation of the e2e reliability protocol

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages