Expose secret-stream datagram C API#3
Merged
jjacke13 merged 2 commits intojjacke13:mainfrom Apr 26, 2026
Merged
Conversation
The existing C API only surfaced the reliable byte stream from
SecretStreamDuplex. Wire up the unreliable/datagram side too so
embedders that want UDP-like semantics (e.g. carrying raw IP
packets across hyperdht-routed peers) don't have to drop down
into C++.
Adds three new C entry points on hyperdht_stream_t:
* hyperdht_stream_set_on_udp_message — install a callback that
fires for each inbound UDP datagram (SecretStreamDuplex::
on_udp_message). If unset, datagrams are silently dropped.
* hyperdht_stream_send_udp — best-effort send via
SecretStreamDuplex::send_udp.
* hyperdht_stream_try_send_udp — non-blocking variant
that returns immediately if the path is congested.
ffi_internal.hpp gains storage for the callback + userdata, and
ffi_stream.cpp installs an on_udp_message dispatcher inside
hyperdht_stream_open so the C callback slot is always wired
once a stream is open.
No behavioural change for existing callers: the new callback
slot is opt-in and the send entry points are additive.
Made-with: Cursor
Use the same NS_SEND constant as @hyperswarm/secret-stream so unordered datagrams authenticate across the C++ and JS implementations. Made-with: Cursor
Owner
|
thanks for the fixes :) |
jjacke13
added a commit
that referenced
this pull request
Apr 26, 2026
- REMAINING-WORK.md: remove completed items (ESP32, aarch64 CI, Kotlin wrapper, Python smoke test, stream drain), update FFI count 76→84, note Luke Burns' PRs #1-#3 - rpc.cpp: add DHT_LOG in check_persistent() showing NAT classification (UNKNOWN/OPEN/CONSISTENT/RANDOM) — aids debugging persistent transition - test/js/test_node_queries.js: verifies a server's announcement on DHT - test/js/test_node_serves.js: verifies a node serves PING, FIND_NODE, FIND_PEER, LOOKUP when queried directly
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.
Summary
SecretStreamDuplex::send_udp/on_udp_messagefor encrypted unreliable packet delivery.NS_SENDnamespace constant to match@hyperswarm/secret-stream, so C++ and JS peers can authenticate unordered messages.Test plan
hyperdhtpeer and back.SecretStreamDuplexUDP round-trip is present.Made with Cursor