ae6c80f0cd
* fixed rebase conflict with cargo.lock * shared cleanup * moved returncode to shared * first pass at Go binding structure * minor cleanup * working on custom type udl * trying to get LDFLAG script working * commit before changing alias -> proper types * converted CCallbacks from aliases to Struct * cleanup comments * temp * push to share * cleanup * trait Lift not implemented for *const i8 issue * test of refactor: * move c-specific var casting out of shared/ into cpp/ * error returning in go/ over ffi boundary with uniffi * _internal functions ffi wrapper agnostic * moved lang-specific type conversions to cpp / go bindings and out of shared * got send_message working in c/c++ & go * split out c/c++-specific types to mod * cont. with making _internal fns lang agnostic * working on final fn for C and shared (listening for incoming messages) * fixed return err on listen_for_incoming * got full example run running again after shared/ refactor * removed unused struct * code comments * got first runthrough of go example code * script cleanup * clean up readme instructions * clippy * removed unused imports * rustfmt * Update sdk/ffi/go/README.md with link to example file Co-authored-by: Mark Sinclair <14054343+mmsinclair@users.noreply.github.com> * updated readme with extra build and usage info * renamed binding outer directory for nicer path * moved example file from ffi/main.go -> ./example.go * updated README with new example file name --------- Co-authored-by: mfahampshire <mfahampshire@pm.me> Co-authored-by: Mark Sinclair <14054343+mmsinclair@users.noreply.github.com>
47 lines
2.6 KiB
Markdown
47 lines
2.6 KiB
Markdown
# 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](https://matrix.to/#/#dev:nymtech.chat).
|
|
|
|
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](#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](https://nymtech.net/docs/clients/addressing-system.html)
|
|
* 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](https://nymtech.net/docs/architecture/traffic-flow.html#private-replies-using-surbs)
|
|
* send a reply to yourself using SURBs
|
|
|
|
## Installation
|
|
Prerequisites:
|
|
* Rust
|
|
* C++
|
|
* [Boost](https://www.boost.org/) 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.
|
|
|
|
|