upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/btfrv.cpp
diff options
context:
space:
mode:
authorbitflash-maintainer <noreply@bitflash.invalid>2026-09-03 21:49:35 +0000
committerbitflash-maintainer <noreply@bitflash.invalid>2026-09-03 21:49:35 +0000
commitea8fe94658bf20d2b669b619231238f12e6bd8fc (patch)
tree02b8f4485d3e4a4117a3c16751af24a702037ce9 /src/btfrv.cpp
parent944f93f163cb560f095556834b6eb75bfde60c9c (diff)
parentca03f8e9416837acfac825f02a6c592e07e0c4df (diff)
merge: !8 fix/tunnel-retry into deploy/all-2026-08-24
Diffstat (limited to 'src/btfrv.cpp')
-rw-r--r--src/btfrv.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/btfrv.cpp b/src/btfrv.cpp
index 8ab735c..7d705ef 100644
--- a/src/btfrv.cpp
+++ b/src/btfrv.cpp
@@ -377,17 +377,29 @@ bool RvServiceWaitPaired(RvSocket s, int nTimeoutSecs)
377} 377}
378 378
379RvSocket RvClientConnect(const char* relay_host, unsigned short port, 379RvSocket RvClientConnect(const char* relay_host, unsigned short port,
380 const unsigned char target_pubkey[32]) 380 const unsigned char target_pubkey[32],
381 RvClientFail* pFail)
381{ 382{
383 if (pFail) *pFail = RVC_FAIL_DIAL;
382 if (!RvInit()) return RV_INVALID; 384 if (!RvInit()) return RV_INVALID;
383 SOCKET s = ConnectTo(relay_host, port); 385 SOCKET s = ConnectTo(relay_host, port);
384 if (s == INVALID_SOCKET) return RV_INVALID; 386 if (s == INVALID_SOCKET) return RV_INVALID;
387 if (pFail) *pFail = RVC_FAIL_PAIR;
385 unsigned char hdr[33]; 388 unsigned char hdr[33];
386 hdr[0] = (unsigned char)'C'; 389 hdr[0] = (unsigned char)'C';
387 memcpy(hdr + 1, target_pubkey, 32); 390 memcpy(hdr + 1, target_pubkey, 32);
388 if (!WriteN(s, hdr, 33)) { CLOSESOCK(s); return RV_INVALID; } 391 if (!WriteN(s, hdr, 33)) { CLOSESOCK(s); return RV_INVALID; }
389 unsigned char paired = 0; 392 unsigned char paired = 0;
390 if (!ReadN(s, &paired, 1) || paired != 0x01) { CLOSESOCK(s); return RV_INVALID; } 393 if (!ReadN(s, &paired, 1)) { CLOSESOCK(s); return RV_INVALID; }
394 if (paired != 0x01)
395 {
396 // The relay answered and declined: HandleIncoming writes 0x00 and
397 // closes when no service is parked under this pubkey right now.
398 if (pFail) *pFail = RVC_FAIL_REFUSED;
399 CLOSESOCK(s);
400 return RV_INVALID;
401 }
402 if (pFail) *pFail = RVC_FAIL_NONE;
391 return (RvSocket)s; 403 return (RvSocket)s;
392} 404}
393 405