Files
mfahampshire cf3fd00350 Max/crates io prep v2 (#6270)
* - standardise versions for all nym-sdk workspace dependencies
- prepend sqlx-pool-guard with 'nym-'

* Test remove nym-api from deps

* Add oneliner to client_pool doc comments

* Add note to commented out docs.rs link in sdk

* remove nym-api from script

* add publishing file

* bring non-binary / contract / tools into workspace version

* added more info to publishing.md

* make deps workspace version

* remove uploaded sphinx-types crate from script

* remove erroueously included ignore-defaults

* add zeroise to feature

* chore: Release

* add topology to batch

* more cargo versioning

* more cargo versioning - wasm utils

* more cargo versioning - wasm utils

* Add publish=false to manifest for cargo workspaces / crates.io
publishing exclusion

* remove script now switched to manifest based exclusion

* rename import based on rename of contracts-common dep

* Making workspace versions for publication + removing unnecessary crates
from publication

* Remove OOD info from publishing sdk guide

* rename contract imports + remove package

* temp commit: continuing with removal of path from cargo manifest and
replacing with workspace version import for publication

* continuing with cargo.toml updates

* dryrun only erroring on known version problem crates

* remove old published-crates file

* Minor comment change

* remove default features warning

* Additional info on workspace dep comment re publish list

* Add missing description to cargo.toml

* Fix missing feature flags

* Add missing descriptions

* Fix remaining path import

* Add workspace repo / homepage / documentation links to cargo.toml files

* remove workspace version from excluded crate

* Remove todo descriptions

* Minor comment change

* add homepage etc

* move from bls git import to nym_bls_fork crate

* Modify rest of imports from path to workspace import, excluding binaries

* add directory/homepage info

* fix cargo fmt

* add notes to gitignore

* better solution to contracts/ experiment

* wasm -> nym_wasm crate renaming

* fix fatfinger

* add metadata to ecash cargo.toml

* stub publishing guide

* fix misrevolved netlink- version

* Fixes and block publication of rebase re: LP

* first pass @ workflows
2026-01-19 13:19:45 +00:00
..
2024-01-24 15:05:59 +00:00
2026-01-19 13:19:45 +00:00

C++ FFI

⚠️ This is an initial version of this library in order to give developers something to experiment with. If you use this code to begin testing out Mixnet integration and run into issues, errors, or have feedback, please feel free to open an issue; feedback from developers trying to use it will help us improve it. If you have questions feel free to reach out via our Matrix channel.

This repo contains:

  • lib.rs: an initial version of bindings for interacting with the Mixnet via the Rust SDK from C++. These are essentially match statements wrapping imported functions from the nym-ffi-shared lib allowing for nicer error handling.
  • main.cpp: an example of using this library, relying on Boost for threads.

The example .cpp file is a simple example flow of:

  • setting up Nym client logging
  • creating an ephemeral Nym client (no key storage / persistent address - this will come in a future iteration)
  • getting its Nym address
  • using that address to send a message to yourself via the Mixnet
  • listen for and parse the incoming message for the sender_tag used for anonymous replies with SURBs
  • send a reply to yourself using SURBs

Unlike the Go FFI code, this code does not yet have bindings for the TcpProxyClient/Server. This will happen in the future.

Installation

Prerequisites:

  • Rust
  • C++
  • Boost which can be installed with:
# Arch / Manjaro
yay -S boost boost-libs

# Debian / Ubuntu
sudo apt install libboost-all-dev

Usage

The build.sh script in the root of the repository speeds up the task of building and linking the Rust and C++ code.

  • if want to quickly recompile your code run it as-is with ./build.sh
  • if you want to clean build both the Rust and C++ code after removing existing compiled binaries run it with the optional clean argument: ./build.sh clean.

Make sure to run the script from the root of the project directory.

This script will:

  • (optionally if called with clean argument) remove existing Rust and C++ artifacts
  • build lib.rs with the --release flag
  • compile main.cpp, linking lib.rs
  • set value of LD_LIBRARY_PATH to the Rust code in target/release/
  • run the compiled main

Error Handling

When calling a function across the FFI boundary (e.g.) reply, the Rust code is matching the output of an _internal function - Res or Err - to a member of the StatusCode enum. This allows for both Rust-style error handling and the ease of returning a c_int across the FFI boundary, which can be used by C++ for its own error handling / conditional logic.