upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/nostr.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/nostr.h
parentf34113291da7e5e3dc7d2468d4f9c212c05c584b (diff)
public commit
Diffstat (limited to 'src/nostr.h')
-rw-r--r--src/nostr.h116
1 files changed, 116 insertions, 0 deletions
diff --git a/src/nostr.h b/src/nostr.h
new file mode 100644
index 0000000..b5eb5e3
--- /dev/null
+++ b/src/nostr.h
@@ -0,0 +1,116 @@
1// Copyright (c) 2026 Bitflash developers
2// Distributed under the MIT/X11 software license.
3//
4// Peer discovery over Nostr relays -- replaces the old ThreadIRCSeed. Each
5// node publishes a replaceable event (NIP-78, kind 30078) containing its
6// "ip:port", signed with Schnorr/secp256k1 (BIP340, the same scheme used by
7// Nostr), and subscribes to receive the announcements of other nodes, feeding
8// them into the Bitflash address manager.
9
10#ifndef BITFLASH_NOSTR_H
11#define BITFLASH_NOSTR_H
12
13#include <string>
14#include <vector>
15#include <map>
16
17// Thread entry point (signature compatible with _beginthread)
18void ThreadNostrSeed(void* parg);
19void ThreadBtfPoolAnnouncer(void* parg);
20
21// Set to true to make ThreadBtfPoolAnnouncer publish immediately instead of
22// waiting for its ~60s sleep loop (e.g. right after the operator changes pool
23// name/fee/dashboard URL in Options). The announcer clears it after publishing.
24extern volatile bool gAnnounceNow;
25
26// Public relays used for discovery. Tunable.
27extern const char* pszNostrRelays[];
28extern const int nNostrRelays;
29
30// Rendezvous meeting relays ("host:port") this node can register its .btf
31// service at. It registers at the first reachable one and advertises that in
32// its descriptor; if the relay dies it fails over to another, so attacking a
33// single relay's IP can't take the network down. Overridable with /rvrelay.
34extern std::vector<std::string> vBtfMeetingRelays;
35// The relay this node is currently registered at (set by ThreadBtfAccept).
36extern std::string strBtfActiveRelay;
37// The relay we are registered at, or "" if registration hasn't succeeded yet.
38// Never guesses a seed: an unregistered node has no meeting node to advertise.
39std::string BtfActiveRelay();
40// Record the relay this node just registered its service at (thread-safe).
41void BtfSetActiveRelay(const std::string& relay);
42
43// If set (via /announcerelay=host:port), this node announces that relay on
44// Nostr so other nodes discover it automatically -- no manual seed-list edit.
45extern std::string strBtfAnnounceRelay;
46// Every relay to try: curated seeds + relays discovered from Nostr announcements.
47std::vector<std::string> BtfAllRelays();
48
49struct BtfPoolAnnouncement
50{
51 std::string btfAddress;
52 std::string poolName;
53 std::string dashboardUrl;
54 double feePercent;
55 int connectedMiners;
56 int blocksFound;
57 double hashRate;
58 int64 createdAt;
59
60 BtfPoolAnnouncement()
61 : feePercent(0.0), connectedMiners(0), blocksFound(0), hashRate(0.0), createdAt(0)
62 {
63 }
64};
65
66// Number of .btf peers discovered from Nostr relays (includes not-yet-connected).
67int GetDiscoveredPeerCount();
68
69// Current live pool announcements discovered from Nostr relays.
70void BtfGetPoolAnnouncements(std::vector<BtfPoolAnnouncement>& out);
71
72// Publish a live pool announcement on Nostr.
73bool BtfPublishPoolAnnouncement(const BtfPoolAnnouncement& ann);
74
75// Query the latest pool announcement for a specific .btf pool address.
76bool BtfQueryPoolAnnouncement(const std::string& poolBtfAddr, BtfPoolAnnouncement& out);
77
78// Copy this node's .btf identity (lazily loading or generating it): the x-only
79// pubkey (= the .btf address) and the x25519 secret for the end-to-end channel.
80bool BtfGetIdentity(unsigned char pubkey[32], unsigned char enc_sk[32]);
81
82// This node's printable .btf address, or "" if the identity failed to load.
83std::string BtfLocalAddress();
84
85// This node's own signed descriptor, ready to hand to a peer over the wire.
86// "" until ThreadBtfAccept has registered at a rendezvous.
87std::string BtfLocalDescriptor();
88
89// The shared secp256k1 context, for btf::VerifyDescriptor (which takes it as
90// void* to keep headers free of secp). NULL if the identity failed to load.
91void* BtfSecpContext();
92
93// Resolve a .btf address via the public discovery relays: fetch the owner's
94// self-certified descriptor and return its meeting node ("host:port") and
95// x25519 public key for the end-to-end channel.
96bool BtfResolve(const std::string& btfAddr, std::string& meetingHostPort,
97 unsigned char enc_pub[32]);
98
99// Result of resolving one .btf address via BtfResolveMany.
100struct BtfResolvedPeer
101{
102 std::string meetingHostPort;
103 unsigned char enc_pub[32];
104};
105
106// Resolve many .btf addresses at once. Batches all still-unresolved addresses
107// into a single Nostr REQ per relay (multiple "authors"), instead of opening
108// one relay connection per address like BtfResolve does. Use this whenever
109// resolving more than a handful of addresses in the same pass -- e.g. before
110// dialing several discovered peers in parallel -- to avoid hammering the
111// same few public relays with a burst of simultaneous connections. Returns
112// true if at least one address resolved; check `out` for which ones.
113bool BtfResolveMany(const std::vector<std::string>& btfAddrs,
114 std::map<std::string, BtfResolvedPeer>& out);
115
116#endif