From 62ad921abbb91f442d4df9a4746df3a937bb1940 Mon Sep 17 00:00:00 2001 From: Andre Staltz Date: Thu, 20 Jul 2023 19:49:01 +0300 Subject: [PATCH] fix conn key conversion to shse.pubkey --- lib/ms-tunnel.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/ms-tunnel.js b/lib/ms-tunnel.js index f8e4697..5aa581f 100644 --- a/lib/ms-tunnel.js +++ b/lib/ms-tunnel.js @@ -33,7 +33,7 @@ const makeTunnelPlugin = (hubs, local) => (/** @type {any}} */ msConfig) => { pull.drain(async ({ address, key, details }) => { if (!key) return // TODO: once ssb-conn is replaced, we won't need this anymore: - const pubkey = bs58.encode(Buffer.from(key, 'base64')) + const pubkey = key.slice(1, -8) // not base64, it's @BASE58.ed25519 if (hubs.has(pubkey)) return if (!details?.rpc) return if (address.startsWith('tunnel:')) return @@ -61,7 +61,7 @@ const makeTunnelPlugin = (hubs, local) => (/** @type {any}} */ msConfig) => { pull.drain(({ key }) => { if (!key) return // TODO: once ssb-conn is replaced, we won't need this anymore: - const pubkey = bs58.encode(Buffer.from(key, 'base64')) + const pubkey = key.slice(1, -8) // not base64, it's @BASE58.ed25519 if (!hubs.has(pubkey)) return hubs.get(pubkey)?.close() hubs.delete(pubkey) @@ -95,6 +95,12 @@ const makeTunnelPlugin = (hubs, local) => (/** @type {any}} */ msConfig) => { let hubRPC = hubs.get(hub)?.rpc + // If no hub found, wait a second and try again + if (!hubRPC) { + await new Promise(resolve => setTimeout(resolve, 1000)) + hubRPC = hubs.get(hub)?.rpc + } + // If no hub found, look up hub in connDB and connect to it if (!hubRPC) { for (const [msaddr] of local.conn.db().entries()) {