upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/btfrv.h
diff options
context:
space:
mode:
authorbitflash-coin <bookofshamers@outlook.com>2026-08-04 06:34:32 -0700
committerbitflash-coin <bookofshamers@outlook.com>2026-08-04 06:34:32 -0700
commit5ce650382352c1503f40abf08129ada69402af55 (patch)
tree6a18198901f1e2c4933f1ac53c9365eec512bf63 /src/btfrv.h
parentf34113291da7e5e3dc7d2468d4f9c212c05c584b (diff)
public commit
Diffstat (limited to 'src/btfrv.h')
-rw-r--r--src/btfrv.h73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/btfrv.h b/src/btfrv.h
new file mode 100644
index 0000000..9cd7476
--- /dev/null
+++ b/src/btfrv.h
@@ -0,0 +1,73 @@
1// Copyright (c) 2026 Bitflash developers
2// Distributed under the MIT/X11 software license.
3//
4// Bitflash rendezvous transport -- the "meeting node" that lets two nodes behind
5// CGNAT connect without a public IP or port forwarding. Both sides connect OUT
6// to the relay (which HAS a public IP, e.g. the VPS); the relay pairs them by
7// `.btf` pubkey and forwards raw bytes between them. The endpoints then run the
8// echan end-to-end channel on top, so the relay sees only ciphertext and cannot
9// MITM (the client boxes to the service's STATIC key from its self-certified
10// descriptor -- a substituting relay just breaks the channel, never reads it).
11//
12// This is the server that runs on the VPS (headless, Layer 6 ports it to Linux)
13// plus the client/service helpers the desktop node uses.
14
15#ifndef BITFLASH_BTFRV_H
16#define BITFLASH_BTFRV_H
17
18#include <stdint.h>
19
20namespace btf
21{
22
23// A connected, paired rendezvous socket (opaque). Read/write raw bytes; the
24// caller layers echan on top. Close with RvClose.
25typedef intptr_t RvSocket;
26static const RvSocket RV_INVALID = (RvSocket)-1;
27
28// Initialize sockets (Winsock on Windows). Idempotent.
29bool RvInit();
30
31// ---- relay side (runs on the VPS) ----
32// Run the rendezvous relay forever on `port`, forwarding between paired peers.
33// Blocks; run it in a thread. Returns false if it can't bind/listen.
34bool RvRelayRun(unsigned short port);
35
36// Stop a running relay (signals RvRelayRun to return).
37void RvRelayStop();
38
39// ---- service side (the node being reached by its .btf address) ----
40// Register at the relay under `my_pubkey` (32 bytes). Returns as soon as the
41// relay has us listed, WITHOUT waiting for anyone to dial -- the caller needs
42// that moment to start advertising this relay as its meeting node. Waiting for
43// the dial was folded into this call before, which deadlocked discovery: a node
44// could not be advertised until it had been dialled, and could not be dialled
45// until it was advertised. Returns RV_INVALID on error.
46RvSocket RvServiceRegister(const char* relay_host, unsigned short port,
47 const unsigned char my_pubkey[32]);
48
49// Block on a registered service socket until a client is paired to us. Returns
50// false if the relay drops us or errors, in which case the caller should close
51// the socket and register again.
52// Blocks until a client is paired with us. Give it a timeout, in seconds, and
53// it returns false once that passes with nobody arriving -- which the caller
54// should treat as "register again", not as an error. Zero means wait forever,
55// which is what this used to do unconditionally and must not be used for a
56// registration socket: see the note on the implementation.
57bool RvServiceWaitPaired(RvSocket s, int nTimeoutSecs = 0);
58
59// ---- client side (the node dialing a .btf address) ----
60// Connect through the relay to the service registered under `target_pubkey`.
61// Returns the paired socket, or RV_INVALID on error.
62RvSocket RvClientConnect(const char* relay_host, unsigned short port,
63 const unsigned char target_pubkey[32]);
64
65// Blocking read/write of exactly n bytes over a rendezvous socket. Return false
66// on error/EOF.
67bool RvReadN(RvSocket s, void* buf, int n);
68bool RvWriteN(RvSocket s, const void* buf, int n);
69void RvClose(RvSocket s);
70
71} // namespace btf
72
73#endif