From 0f585daa9134efd20a2431a921260f87a9ce292c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kyle=20=F0=9F=90=86?= Date: Tue, 6 Oct 2026 00:17:56 -0400 Subject: [PATCH] End send at a NIP-77 reply and flush each line --- src/main.zig | 12 ++++++++---- tests/integration_relay.sh | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main.zig b/src/main.zig index 935f8f9..890f8bf 100644 --- a/src/main.zig +++ b/src/main.zig @@ -17,7 +17,7 @@ const usage = \\ relay Print the NIP-11 relay information document \\ sync [filters..] NIP-77 reconcile src's events into dst \\ send [--sec --auth] Send one raw client message, print replies - \\ until EOSE/CLOSED/COUNT/OK/NOTICE (--auth answers NIP-42) + \\ until EOSE/CLOSED/COUNT/OK/NOTICE/NEG-MSG/NEG-ERR (--auth answers NIP-42) \\ decode Decode a NIP-19 entity (npub/nsec/note/nevent/naddr/nprofile) \\ verify [event-json] Verify an event's id and signature (reads stdin if no arg) \\ @@ -536,9 +536,10 @@ fn cmdReq(io: Io, arena: Allocator, out: *Io.Writer, args: []const [:0]const u8) } // Sends one raw client message and prints every relay reply verbatim until the -// reply that ends it (EOSE, CLOSED, COUNT, OK, or NOTICE). With --auth, a NIP-42 -// challenge is answered and the message re-sent once authenticated, and the -// auth-required rejection that preceded it is not printed. +// reply that ends it (EOSE, CLOSED, COUNT, OK, NOTICE, NEG-MSG or NEG-ERR). +// With --auth, a NIP-42 challenge is answered and the message re-sent once +// authenticated, and the auth-required rejection that preceded it is not +// printed. fn cmdSend(env_sec: ?[]const u8, io: Io, arena: Allocator, out: *Io.Writer, args: []const [:0]const u8) !void { var url: ?[]const u8 = null; var json: ?[]const u8 = null; @@ -622,9 +623,12 @@ fn cmdSend(env_sec: ?[]const u8, io: Io, arena: Allocator, out: *Io.Writer, args if (auth_rejection) continue; } try printSanitized(io, out, msg.raw); + try out.flush(); switch (msg.msg_type) { .eose, .closed, .count, .ok => break, .notice => if (!waiting) break, + // NIP-77 replies, which the relay client does not classify. + .unknown => if (std.mem.startsWith(u8, msg.raw, "[\"NEG-MSG\"") or std.mem.startsWith(u8, msg.raw, "[\"NEG-ERR\"")) break, else => {}, } } diff --git a/tests/integration_relay.sh b/tests/integration_relay.sh index 90525f2..2026926 100755 --- a/tests/integration_relay.sh +++ b/tests/integration_relay.sh @@ -53,6 +53,8 @@ chk "send prints the matching EVENT" 1 "$(echo "$SENT" | grep -c "^\[\"EVENT\",\ chk "send stops at EOSE" '["EOSE","raw"]' "$(echo "$SENT" | tail -1)" chk "send prints a COUNT reply" 1 "$(timeout 10 $NOZ send "$R" "[\"COUNT\",\"c\",{\"ids\":[\"$ID\"]}]" 2>/dev/null | grep -c '"count":1')" +chk "send ends at a NIP-77 reply" 1 "$(timeout 10 $NOZ send "$R" '["NEG-OPEN","n",{},"6100"]' 2>/dev/null | grep -cE '^\["NEG-(MSG|ERR)","n"')" + # --- A fetched event survives verify end to end --- EV=$(timeout 10 $NOZ req -i "$ID" "$R" 2>/dev/null | head -1) chk "fetched event passes verify" valid "$(echo "$EV" | $NOZ verify)"