Repository navigation
thrum-clients/c: the C client, with its primitives imported - #88
Merged
Merged
Conversation
C has no JSON and no crypto in its standard library, so the C client imports both instead of carrying them: libsodium for Ed25519, SHA-256 and randomness, cJSON for tones. Nothing is vendored and no primitive is hand-rolled. codegen emits only what is read from the Rust source for C: the registry (thrum/chi.h) and the views (thrum/protocol.h). The helpers are library calls and live with the client, so the generator carries no C logic. build.rs refreshes the pair and --check gates them. A bee enters through the hum CLI and signs its hello with one timestamp. Sends are one locked write per line. The hello's verdict is read the way humd gives it: the breath after the hello's own delivery ack admits, an echo with ok false under its rid refuses, and a refusal after admission ends the run loop. thrum_tone_undeclared names stray keys the way thrum_core::undeclared does. thrum.mk gives a hive the flags and the archive. The tests check the bee id and the hello signature byte for byte against hum_identity over the RFC 8032 seed, read the golden fixture through a real socket among junk lines, replay humd's admit, refuse, revoke, hang-up and silent hellos, and send from eight threads at once. They pass under ASan, UBSan and TSan, and on Ubuntu 24.04 with gcc. CI builds and tests the client against the distribution's packages.
…ncluder's goal
main made a sigil the session's own, sha256("sigil:<sid>"), the same on
every humd, so thrum_sigil takes the sid alone. The vectors are
thrum_core::sigil's, and the C sigil matches the one humd put on the
wire in a live run.
The regenerated views carry headroom on hello and pulse.
thrum.mk defined the archive before the includer defined anything, so
the archive became the default goal of every Makefile that included it,
the client's own among them, and a bare make built only libthrum.a. It
now puts the includer's default goal back.
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.
What this adds
The fifth reference client for the thrum wire, in C, and nothing else.
No hive rides along: this is what a C bee needs, so that dwarfstar (#85)
can shrink to the hive itself on top of it.
C has no JSON and no crypto in its standard library, so the client
imports both instead of carrying them:
Nothing is vendored and no primitive is hand-rolled. #85 carried a
vendored Ed25519 (5,019 lines), a vendored jsmn, a hand-written JSON tree
and a SHA-256 emitted by codegen; this replaces all of it with two
pkg-config dependencies.
What it touches in the core
source: the registry (
thrum/chi.h) and the views (thrum/protocol.h).The helpers are library calls and live with the client, so the
generator carries no C logic.
main.rsnow lets a target own the filesit owns rather than always three.
--checkgates them.cjob that installslibsodium-devandlibcjson-devand runs
make test.The client
thrum/client.cthrum/identity.chum bee enter --hive --as, loads the filed key, signs the hello with one timestampthrum/helpers.cthrum/spec.cthrum_tone_undeclared, the declared-key check humd runsthrum.mkexamples/echo_bee.cEntering goes through the hum CLI, as the TS bees do, so there is one
implementation of it.
The hello's verdict
humd acks every tone that has a
ridwithecho ok:trueas soon as itis delivered. The hello is admitted by the
breathafter its own ack andrefused by an
echo ok:falseunder itsrid.thrum_client_hellowaitsfor that (ten seconds by default), and
thrum_client_runreturns -1 if arefusal arrives after admission.
Reading it this way was not optional. The first version took the first
breathas admission, and a live humd admitted a forged key, because:breathon connect, before it has seen any hello.WIRE.md says the breath is the reply to the hello.
thrum_closeonly drops the clientfrom the registry. WIRE.md says the connection is closed. The Rust and
TS bees ignore
breathandecho, so a refused one sits connectedand never knows.
breathis sent, so arevoked bee is told it is in, then refused.
This PR does not change humd; those three are worth their own fix.
Proof
make test: 423 checks. The bee id and the hello signature matchhum_identity::BeeKeybyte for byte over the RFC 8032 test seed; thesigils are
thrum_core::sigil's. A thread plays humd over a real Unixsocket: the golden fixture in seven-byte pieces among junk lines, the
admit, refuse, revoke, hang-up and silent hellos, eight threads sending
at once.
423 of 423.
entered and nestled, a C asker's prompt came back as
chunkandfinishthrough humd, a hello signed by a key never entered wasrefused, and the C sigil matched the one humd put on the wire.
Building it