Skip to content

chore(cbind): nim-ffi migration [4/9] — streams & custom protocols (+ echo example)#2775

Draft
gmelodie wants to merge 4 commits into
chore/cbind/ffi/03-connectivityfrom
chore/cbind/ffi/04-streams
Draft

chore(cbind): nim-ffi migration [4/9] — streams & custom protocols (+ echo example)#2775
gmelodie wants to merge 4 commits into
chore/cbind/ffi/03-connectivityfrom
chore/cbind/ffi/04-streams

Conversation

@gmelodie

@gmelodie gmelodie commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

nim-ffi cbind migration — PR train

  1. chore(cbind): nim-ffi migration [1/9] — deps + pinning scaffold #2772 — deps + pinning
  2. chore(cbind): nim-ffi migration [2/9] — new-library scaffold + CI #2773 — scaffold + CI
  3. chore(cbind): nim-ffi migration [3/9] — connectivity & identity #2774 — connectivity
  4. chore(cbind): nim-ffi migration [4/9] — streams & custom protocols (+ echo example) #2775 — streams (+ echo) ← this PR
  5. chore(cbind): nim-ffi migration [5/9] — pubsub / gossipsub (+ gossipsub example) #2776 — pubsub (+ gossipsub)
  6. chore(cbind): nim-ffi migration [6/9] — kademlia + CID + crypto #2777 — kad + CID + crypto
  7. chore(cbind): nim-ffi migration [7/9] — service discovery + extended peer records #2778 — service discovery
  8. chore(cbind): nim-ffi migration [8/9] — relay, peerstore, metrics (API parity) #2779 — relay / peerstore / metrics
  9. chore(cbind): nim-ffi migration [9/9] — flip to libp2p.nim, delete legacy cbind #2780 — flip + delete legacy

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

  • Stream ops over streamId handles: readExactly, readLp, write, writeLp, close, closeWithEof, release.
  • libp2pMountProtocol + the onIncomingStream {.ffiEvent.}, plus the full StreamRegistry release-waiter logic that keeps custom-protocol handlers alive across the FFI boundary.
  • validateReadLength hardening — rejects negative lengths, the MaxReadBytes ceiling, and values that would narrow-overflow a 32-bit int (matters for linux-i386 CI).
  • The echo C example plus the examples build harness: common.h, CMakeLists.txt, README.md, .clang-format, updated Makefile, and the examples nimble task.
  • Retires the clang-format linter step (the C files it guarded are rewritten here).

Review artifact: Header diff shows the stream/protocol entry points and the incoming-stream event.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (chore/cbind/ffi/03-connectivity@2704369). Learn more about missing BASE report.

Additional details and impacted files

Impacted file tree graph

@@                        Coverage Diff                         @@
##             chore/cbind/ffi/03-connectivity    #2775   +/-   ##
==================================================================
  Coverage                                   ?   81.15%           
==================================================================
  Files                                      ?      170           
  Lines                                      ?    31027           
  Branches                                   ?       12           
==================================================================
  Hits                                       ?    25180           
  Misses                                     ?     5847           
  Partials                                   ?        0           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gmelodie gmelodie mentioned this pull request Jul 7, 2026
2 tasks
@github-project-automation github-project-automation Bot moved this from new to In Progress in nim-libp2p Jul 7, 2026
@gmelodie gmelodie force-pushed the chore/cbind/ffi/03-connectivity branch 3 times, most recently from 543a063 to 021033a Compare July 8, 2026 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants