diff options
| -rw-r--r-- | names/server.js | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/names/server.js b/names/server.js index e17ca05..a40cff6 100644 --- a/names/server.js +++ b/names/server.js @@ -178,13 +178,35 @@ async function sendWelcome(pubkey, linkedKeys = []) { // clients with an endless stream of his own welcome message. const [, toPeer] = wrapManyEvents(WELCOME.sk, [{ publicKey: pubkey }], WELCOME.message); const inbox = await inboxRelaysOf(pubkey); - await Promise.allSettled(pool.publish([...new Set([...inbox, ...LNURL_RELAYS])], toPeer)); - log(`welcome DM sent to ${pubkey.slice(0, 12)}`); + const relays = [...new Set([...inbox, ...LNURL_RELAYS])]; + // Count acknowledgements, not attempts: a socket that died under the + // pool (the home uplink drops every connection at once) swallows a + // publish without a word, and four welcomes on 2026-10-07 went nowhere + // while the log said "sent". Nobody heard it → drop those sockets and + // try again on fresh ones, then say what really happened. + let acked = await publishAcked(relays, toPeer); + for (let i = 1; !acked.length && i <= 3; i++) { + try { pool.close(relays); } catch {} + await new Promise((r) => setTimeout(r, 5000 * i)); + acked = await publishAcked(relays, toPeer); + } + if (acked.length) log(`welcome DM sent to ${pubkey.slice(0, 12)} (${acked.join(', ')})`); + else { + for (const k of keys) delete state.welcomed[k]; persist(); // undelivered: the next claim may try again + log(`welcome DM to ${pubkey.slice(0, 12)} FAILED: no relay accepted it`); + } } catch (e) { log('welcome DM failed: ' + e.message); } } +// Publish and return the relays that answered OK within the time limit. +async function publishAcked(relays, ev, ms = 10000) { + const timeout = new Promise((_, j) => setTimeout(() => j(new Error('timeout')), ms)); + const res = await Promise.allSettled(pool.publish(relays, ev).map((p) => Promise.race([p, timeout]))); + return relays.filter((_, i) => res[i].status === 'fulfilled').map((r) => r.replace(/^wss:\/\//, '')); +} + const lnurlMeta = (address) => JSON.stringify([ ['text/plain', `Paying ${address}`], ['text/identifier', address], |
