You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Worked examples of consuming nim-libp2p from C through the FFI bindings generated by [nim-ffi](https://github.com/logos-messaging/nim-ffi).
4
+
5
+
The bindings are a header-only C API over a C ABI. Every generated method is asynchronous: it takes a result callback and returns immediately, and the callback fires from the library's dispatch thread. Library-initiated events (incoming streams, pub/sub messages) arrive through `libp2p_ctx_add_on_…_listener` callbacks. The examples turn each async call back into a blocking step with the small helpers in `common.h`.
6
+
7
+
-`echo.c` — two TCP nodes; the server mounts a custom `/cbind/echo/1.0.0` protocol and echoes the bytes it reads, the client dials it and verifies the round-trip. The incoming-stream handler only hands the stream id to `main`, which serves it inline, since calling back into the library from the dispatch thread would deadlock.
8
+
9
+
## Build
10
+
11
+
From `cbind/`, produce the runtime library and the generated header first:
12
+
13
+
```sh
14
+
nimble setup
15
+
nimble buildffi # -> ../build/liblibp2p.so
16
+
nimble genbindings_c # -> c_bindings/libp2p.h
17
+
```
18
+
19
+
Then build the examples:
20
+
21
+
```sh
22
+
cd examples
23
+
cmake -S . -B build
24
+
cmake --build build
25
+
```
26
+
27
+
If the vendored TinyCBOR sources can't be located automatically, point CMake at them:
0 commit comments