chore(cbind): nim-ffi migration [4/9] — streams & custom protocols (+ echo example)#2775
Merged
Conversation
This was referenced Jul 7, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2775 +/- ##
==========================================
- Coverage 81.07% 81.06% -0.02%
==========================================
Files 171 171
Lines 31135 31135
Branches 12 13 +1
==========================================
- Hits 25244 25240 -4
- Misses 5891 5895 +4 🚀 New features to boost your workflow:
|
2 tasks
vladopajic
approved these changes
Jul 7, 2026
gmelodie
force-pushed
the
chore/cbind/ffi/03-connectivity
branch
3 times, most recently
from
July 8, 2026 20:35
543a063 to
021033a
Compare
gmelodie
force-pushed
the
chore/cbind/ffi/04-streams
branch
3 times, most recently
from
July 10, 2026 19:16
f5eeca5 to
5e8e73c
Compare
gmelodie
force-pushed
the
chore/cbind/ffi/04-streams
branch
5 times, most recently
from
July 13, 2026 16:15
eba4827 to
4e4d51f
Compare
gmelodie
force-pushed
the
chore/cbind/ffi/04-streams
branch
from
July 13, 2026 16:40
4e4d51f to
a8a2b57
Compare
gmelodie
commented
Jul 13, 2026
Comment on lines
-172
to
-173
|
|
||
| static void event_handler(int callerRet, const char *msg, size_t len, |
Contributor
Author
There was a problem hiding this comment.
These and lines below got moved to common.h
gmelodie
marked this pull request as ready for review
July 13, 2026 16:43
gmelodie
enabled auto-merge
July 13, 2026 17:54
richard-ramos
approved these changes
Jul 13, 2026
| streams.release(streamId) | ||
| let releaseWaiter = | ||
| Future[void].Raising([CancelledError]).init("cbind custom protocol release") | ||
| streams.releaseWaiters[streamId] = releaseWaiter |
Member
There was a problem hiding this comment.
Should we do a stream_release on all releaseWaiters in libp2pStop / destroy?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
nim-ffi cbind migration — PR train
Part 4 of a 9-PR train that replaces the hand-rolled
cbind/C bindings with the generated nim-ffi codegen, landing it domain by domain so each PR stays reviewable and CI-green (build the FFI lib + generate bindings + build/run examples).Targets
chore/cbind/ffi/03-connectivity(stacked).This PR adds
streamIdhandles:readExactly,readLp,write,writeLp,close,closeWithEof,release.libp2pMountProtocol+ theonIncomingStream{.ffiEvent.}, plus theStreamRegistryrelease-waiter logic that keeps custom-protocol handlers alive across the FFI boundary until the host releases the stream.validateReadLengthhardening — rejects negative lengths and anything past theMaxReadBytes(64 MiB) DoS ceiling before it sizes an allocation.common.h,CMakeLists.txt,README.md, updatedMakefile, and theexamplesnimble task.Lifecycle procs now return
boollibp2pStart,libp2pStop,libp2pConnect, andlibp2pDisconnectreturnResult[bool, string]instead ofResult[void, string]. This is the first PR that compileslibp2p_ffi.nimin the always-onc-bindingsjob, and nim-ffi's async dispatch can't marshal avoidsuccess — its generated handler lambda unwraps the result value, which doesn't exist forvoid. A trivialboolgives every lifecycle call a uniformon_boolreply, which the echo example already consumes.Also
7ef58f4(latest master): picks up compile-time--nimMainPrefixvalidation (Fix/misc #116), the loud scalar-fast-path binding drop (Less confusing init patterns #120), and the shorter genbindings incantation (Disable new fragmentation tests #119). All are satisfied by the current build flags (--nimMainPrefix:liblibp2p) and the default CBOR ABI, so no binding source change was needed.buildffi/genbindings/examplesat the installedffiandcbor_serializationpackages via--path. Thec-bindingsjob runs under nimble's project-local deps mode, and those two packages aren't cbindrequires(not in the registry), sonimble setupleaves them offnimble.paths. Their transitive deps are libp2p deps already on the inherited root paths.Review artifact: the generated header diff shows the stream/protocol entry points and the incoming-stream event.