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-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/btftunnel.h
parentf34113291da7e5e3dc7d2468d4f9c212c05c584b (diff)
public commit
Diffstat (limited to 'src/btftunnel.h')
-rw-r--r--src/btftunnel.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/btftunnel.h b/src/btftunnel.h
new file mode 100644
index 0000000..1fa4f01
--- /dev/null
+++ b/src/btftunnel.h
@@ -0,0 +1,49 @@
1// Copyright (c) 2026 Bitflash developers
2// Distributed under the MIT/X11 software license.
3//
4// Transparent anonymous tunnel. Gives the existing CNode a plain local socket
5// while, behind it, a pair of pump threads bridge plaintext <-> echan <->
6// rendezvous. CNode reads/writes normally and never knows its bytes travel
7// end-to-end encrypted through a meeting node (the Itzal `wrap()` pattern).
8//
9// Client side: resolve a `.btf` -> meeting node + service enc key (done by the
10// caller), then BtfClientTunnel connects through the relay, runs the echan
11// handshake, and returns a local SOCKET to hand a new outbound CNode.
12//
13// Service side: after RvServiceRegister pairs us with a client, BtfServiceWrap
14// completes the echan handshake and returns a local SOCKET for an inbound CNode.
15
16#ifndef BITFLASH_BTFTUNNEL_H
17#define BITFLASH_BTFTUNNEL_H
18
19#include "btfrv.h"
20
21#ifdef _WIN32
22#include <winsock2.h>
23typedef SOCKET btf_socket_t;
24#else
25typedef int btf_socket_t;
26#define INVALID_SOCKET (-1)
27#endif
28
29namespace btf
30{
31
32// Initialize (sockets + libsodium). Idempotent.
33bool TunnelInit();
34
35// Client: dial the service registered under `target_pubkey` at the meeting node
36// (host:port), box to its static x25519 `service_enc_pub`, and return a local
37// plaintext SOCKET tunneled end-to-end to the service. INVALID_SOCKET on error.
38btf_socket_t BtfClientTunnel(const char* meeting_host, unsigned short port,
39 const unsigned char target_pubkey[32],
40 const unsigned char service_enc_pub[32]);
41
42// Service: wrap an already-paired rendezvous socket (from RvServiceRegister)
43// with echan using my static x25519 secret, returning a local plaintext SOCKET
44// 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]);
46
47} // namespace btf
48
49#endif