upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/btftunnel.h
diff options
context:
space:
mode:
authorbitflash-maintainer <noreply@bitflash.invalid>2026-08-09 02:43:44 +0000
committerbitflash-maintainer <noreply@bitflash.invalid>2026-08-19 22:48:26 +0000
commit82ac5bbc05a1de2be752e2f89110af1e424bc863 (patch)
tree4498fd222a5391130db055c66bc16526fecea4c7 /src/btftunnel.h
parent06bceb4d3e368bec47c4c2eaafdc1c1071625d30 (diff)
pool: wait to be paired before wrapping the rendezvous socket
Upstream #30 split rendezvous registration from waiting for a dial, so RvServiceRegister now returns as soon as the relay lists the service and no longer consumes the relay's 0x01 pairing byte. It updated its own caller in net.cpp and left this one behind. AcceptOneFn went straight from RvServiceRegister to BtfServiceWrap, so BtfServiceWrap read that 0x01 as the first byte of the miner's 32-byte ephemeral key and every byte after it was shifted by one. The X25519 handshake has no confirmation step, so it completed against a garbage shared secret, the tunnel was handed to the Stratum event loop, and nothing failed loudly: the pool logged a miner arriving and then dropped it as "never authorized", while the miner logged a pool that closed on it with gotSubscribeAck=0. Loopback miners were unaffected, which is exactly what made it look like a relay problem. Block in RvServiceWaitPaired before wrapping, and close and re-register if the relay drops us first. test_rvaccept.cpp covers both shapes against a real bitflashd on loopback: the pre-fix order establishes a tunnel that carries no bytes, the fixed order round-trips. Also corrects the btftunnel.h contract comment, which still described the pre-#30 behaviour and is what the old code was written against -- upstream's own test_relayproc.cpp, test_btftunnel.cpp and test_btfrv.cpp are still on that stale contract and fail the same way. (cherry picked from commit 3e3a36b2bf1e6ffb4861507089b743688619377f)
Diffstat (limited to 'src/btftunnel.h')
-rw-r--r--src/btftunnel.h13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/btftunnel.h b/src/btftunnel.h
index 1fa4f01..24a7509 100644
--- a/src/btftunnel.h
+++ b/src/btftunnel.h
@@ -10,8 +10,12 @@
10// caller), then BtfClientTunnel connects through the relay, runs the echan 10// caller), then BtfClientTunnel connects through the relay, runs the echan
11// handshake, and returns a local SOCKET to hand a new outbound CNode. 11// handshake, and returns a local SOCKET to hand a new outbound CNode.
12// 12//
13// Service side: after RvServiceRegister pairs us with a client, BtfServiceWrap 13// Service side: RvServiceRegister only registers -- callers must then block in
14// completes the echan handshake and returns a local SOCKET for an inbound CNode. 14// RvServiceWaitPaired until a client is actually paired to them. BtfServiceWrap
15// completes the echan handshake on that paired socket and returns a local
16// SOCKET for an inbound CNode. Wrapping a registered-but-unpaired socket reads
17// the relay's 0x01 pairing byte as the first byte of the client's ephemeral
18// key, which silently corrupts the tunnel instead of failing.
15 19
16#ifndef BITFLASH_BTFTUNNEL_H 20#ifndef BITFLASH_BTFTUNNEL_H
17#define BITFLASH_BTFTUNNEL_H 21#define BITFLASH_BTFTUNNEL_H
@@ -39,8 +43,9 @@ btf_socket_t BtfClientTunnel(const char* meeting_host, unsigned short port,
39 const unsigned char target_pubkey[32], 43 const unsigned char target_pubkey[32],
40 const unsigned char service_enc_pub[32]); 44 const unsigned char service_enc_pub[32]);
41 45
42// Service: wrap an already-paired rendezvous socket (from RvServiceRegister) 46// Service: wrap an already-paired rendezvous socket (RvServiceRegister followed
43// with echan using my static x25519 secret, returning a local plaintext SOCKET 47// by RvServiceWaitPaired -- the pairing byte MUST already be consumed) with
48// echan using my static x25519 secret, returning a local plaintext SOCKET
44// for an inbound CNode. Consumes `rv` (closed when the tunnel tears down). 49// for an inbound CNode. Consumes `rv` (closed when the tunnel tears down).
45btf_socket_t BtfServiceWrap(RvSocket rv, const unsigned char my_enc_sk[32]); 50btf_socket_t BtfServiceWrap(RvSocket rv, const unsigned char my_enc_sk[32]);
46 51