aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authoreunhhu <[email protected]>2026-09-28 17:37:41 +0100
committereunhhu <[email protected]>2026-09-28 17:37:41 +0100
commit745efcd4f19b59bcfb131df2d127a3387a544e84 (patch)
tree3e001fdd0a695f9a9aaf567e07ad00415f3cf330 /core
parent502f70dbd66debcf1cb0328427831ec14926504b (diff)
downloadpure-745efcd4f19b59bcfb131df2d127a3387a544e84.tar.gz
pure-745efcd4f19b59bcfb131df2d127a3387a544e84.zip
Link two nodes without a connection over UDP (093, design 011's first stage)
pure-serve --send OUTPUT=pure://host:port/INPUT sends an output's saved sends to another node's --link-port with no handshake: the first packet carries records. Keys come from the two nodes' keys (X25519, HKDF-SHA256, AES-128-GCM), with a random run in each packet's header so no nonce repeats across restarts; nothing is stored for them. What lasts is the apps' own: the sender's outbox and the receiver's heard numbers (pure_app_heard, new). The sender detects losses as RFC 9002 says, with NewReno, and trims a send once the receiver says it stored it; the receiver hands the owner whole records in order, which it applies from the one after the source's last heard number, stopping at a gap, and answers how far it stored with every acknowledgment. Stored bytes are the bytes on the wire: an output and an input of one shape need no JSON. server_links_udp kills the receiver, the sender, then both (-9) while four clients buy: every saved order is applied once, with no handshake (five runs, 10k-11k orders each). server_links_udp_lossy does it again in a namespace of its own with the link's packets delayed, lost (3 %) and reordered (10 %) by netem (three runs, 11k-12k orders).
Diffstat (limited to 'core')
-rw-r--r--core/module.c6
-rw-r--r--core/module.h3
2 files changed, 9 insertions, 0 deletions
diff --git a/core/module.c b/core/module.c
index c03d188..45f67f7 100644
--- a/core/module.c
+++ b/core/module.c
@@ -2922,6 +2922,12 @@ PureResult pure_app_deliver(PureApp *app, uint32_t input, const char *source, ui
return saved == PURE_OK ? result : saved;
}
+uint64_t pure_app_heard(const PureApp *app, const char *source) {
+ for (unsigned i = 0; i < app->heard_count; ++i)
+ if (!strcmp(app->heard[i].source, source)) return app->heard[i].seq;
+ return 0;
+}
+
PureResult pure_app_reply(const PureApp *app, bool (*visit)(void *, PureSpan), void *context) {
if (!app->has_reply) return PURE_OK;
return visit_value(app, &app->arena, app->reply, visit, context);
diff --git a/core/module.h b/core/module.h
index e5556fe..e9e5dd3 100644
--- a/core/module.h
+++ b/core/module.h
@@ -428,6 +428,9 @@ void pure_app_trim(PureApp *, uint32_t output, uint64_t through);
* save fails. placed is as for pure_app_message_fields, or NULL. */
PureResult pure_app_deliver(PureApp *, uint32_t input, const char *source, uint64_t seq, PureSpan payload,
const uint32_t *placed);
+/* The last number heard from source (0 when none): a host that gets
+ * numbered messages out of order hands them over from the one after it. */
+uint64_t pure_app_heard(const PureApp *, const char *source);
/* Readers on other threads. Right after a save an app can make a snapshot of
* its saved states, for evaluating views anywhere while it keeps applying