diff options
| author | Bitflash <btf01@proton.me> | 2026-07-29 13:28:50 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-07-29 13:28:50 -0300 |
| commit | 997e511e120272e8f2ddd29716b486e597410f02 (patch) | |
| tree | 42c816df51d837bcac9f806864d677c2d9a9de0c /src/btfrv.h | |
| parent | 6e836ed5cb5f41391e335b4f508dc6c0e8915ba5 (diff) | |
rendezvous: register and wait for a dial as separate steps (#30)
A node could not become reachable. RvServiceRegister connected, sent its
'S'+pubkey header, and then blocked reading the relay's 0x01 byte -- which the
relay only writes when a client pairs with the service. So the call did not
return when the node was registered; it returned when somebody had already
dialled it.
ThreadBtfAccept called BtfSetActiveRelay after that. The result is a deadlock:
- to be dialled, a node must publish a descriptor naming its meeting node
- to publish, BtfActiveRelay() must be set
- it is only set once somebody has dialled
Before #26 this was masked. BtfActiveRelay() fell back to
vBtfMeetingRelays[0], so a node always published something, and ThreadBtfAccept
picks its relay at random -- so it worked whenever the two happened to match,
roughly one time in the number of relays. That is the flakiness this project has
been chasing: not a bad relay, an advertisement that usually named the wrong one.
#26 removed the fallback, which was right on its own terms and turned an
unreliable heuristic into a reliable deadlock. This is the other half of that
change and they belong together.
RvServiceRegister now returns as soon as the relay has the service listed.
RvServiceWaitPaired does the blocking read. ThreadBtfAccept registers, advertises,
then waits. RvClientConnect is untouched -- a dialer blocking until it is paired
is correct.
Registration failure also had no log line at all, which is why this stayed
invisible: a node that never registered looked identical to one waiting quietly
for a peer. There are now lines for registering, failing over, and being dropped.
Verified: a fresh node reports `registered at 90.156.222.107:8434, waiting for a
dial` and then self-resolves with `meeting_node=90.156.222.107:8434` -- the relay
it is actually on. Two nodes on one machine reach each other.
Diffstat (limited to 'src/btfrv.h')
| -rw-r--r-- | src/btfrv.h | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/btfrv.h b/src/btfrv.h index c776201..9d6756e 100644 --- a/src/btfrv.h +++ b/src/btfrv.h | |||
| @@ -37,11 +37,20 @@ bool RvRelayRun(unsigned short port); | |||
| 37 | void RvRelayStop(); | 37 | void RvRelayStop(); |
| 38 | 38 | ||
| 39 | // ---- service side (the node being reached by its .btf address) ---- | 39 | // ---- service side (the node being reached by its .btf address) ---- |
| 40 | // Register at the relay under `my_pubkey` (32 bytes) and block until a client is | 40 | // Register at the relay under `my_pubkey` (32 bytes). Returns as soon as the |
| 41 | // paired to us. Returns the paired socket, or RV_INVALID on error. | 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. | ||
| 42 | RvSocket RvServiceRegister(const char* relay_host, unsigned short port, | 46 | RvSocket RvServiceRegister(const char* relay_host, unsigned short port, |
| 43 | const unsigned char my_pubkey[32]); | 47 | const unsigned char my_pubkey[32]); |
| 44 | 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 | bool RvServiceWaitPaired(RvSocket s); | ||
| 53 | |||
| 45 | // ---- client side (the node dialing a .btf address) ---- | 54 | // ---- client side (the node dialing a .btf address) ---- |
| 46 | // Connect through the relay to the service registered under `target_pubkey`. | 55 | // Connect through the relay to the service registered under `target_pubkey`. |
| 47 | // Returns the paired socket, or RV_INVALID on error. | 56 | // Returns the paired socket, or RV_INVALID on error. |