upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/bitflashd.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bitflashd.cpp')
-rw-r--r--src/bitflashd.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/bitflashd.cpp b/src/bitflashd.cpp
new file mode 100644
index 0000000..d4ced77
--- /dev/null
+++ b/src/bitflashd.cpp
@@ -0,0 +1,45 @@
1// Copyright (c) 2026 Bitflash developers
2// Distributed under the MIT/X11 software license.
3//
4// bitflashd -- the headless Bitflash rendezvous relay (the "meeting node").
5// Runs on a machine with a public IP (a cheap VPS) and lets nodes behind CGNAT
6// reach each other: both sides connect OUT to this relay, which pairs them by
7// `.btf` pubkey and forwards ciphertext (it holds no keys and reads nothing).
8//
9// Build on the VPS (Linux):
10// g++ -std=gnu++14 -O2 -pthread bitflashd.cpp btfrv.cpp -o bitflashd
11// Run:
12// ./bitflashd 8434 # or any port you open in the firewall
13//
14// Cross-builds unchanged on Windows (for local testing):
15// g++ -std=gnu++14 -O2 -pthread bitflashd.cpp btfrv.cpp -lws2_32 -o bitflashd.exe
16
17#include "btfrv.h"
18#include <cstdio>
19#include <cstdlib>
20#include <cstring>
21
22int main(int argc, char* argv[])
23{
24 unsigned short port = 8434;
25 if (argc >= 2)
26 port = (unsigned short)atoi(argv[1]);
27
28 printf("bitflashd -- Bitflash rendezvous relay\n");
29 printf("listening on 0.0.0.0:%u (open this port in your firewall)\n", port);
30 fflush(stdout);
31
32 if (!btf::RvInit())
33 {
34 fprintf(stderr, "bitflashd: socket init failed\n");
35 return 1;
36 }
37
38 // Blocks forever, forwarding between paired peers.
39 if (!btf::RvRelayRun(port))
40 {
41 fprintf(stderr, "bitflashd: could not bind/listen on port %u\n", port);
42 return 1;
43 }
44 return 0;
45}