aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-client/src/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-client/src/main.js')
-rw-r--r--packages/meshbay-client/src/main.js40
1 files changed, 38 insertions, 2 deletions
diff --git a/packages/meshbay-client/src/main.js b/packages/meshbay-client/src/main.js
index bfa9b48..24c1b6a 100644
--- a/packages/meshbay-client/src/main.js
+++ b/packages/meshbay-client/src/main.js
@@ -751,6 +751,7 @@ function registerBridge() {
{ signal: AbortSignal.timeout(3000) });
if (!r.ok) return null;
const status = await r.json();
+ if (status.status !== 'running') return null;
_nodeToken = token;
_nodePort = port;
return { pk_node_ed25519: status.pk_node_ed25519 || '' };
@@ -798,7 +799,7 @@ function registerBridge() {
provisionNode(opts.hubUrl, opts.username);
}
- const deadline = Date.now() + 15000;
+ const deadline = Date.now() + 60000;
const configFile = nodeConfigPath();
let launched = false;
@@ -851,13 +852,48 @@ function registerBridge() {
child.unref();
}
+ let keyLinked = false;
while (Date.now() < deadline) {
await new Promise((r) => setTimeout(r, 500));
+
+ // If the node's admin UI is up but hub auth is stuck, link the key now.
+ if (!keyLinked && opts && opts.token) {
+ try {
+ const nc = readNodeConfig();
+ const dd = nc ? nc.dataDir
+ : path.join(os.homedir(), '.local', 'share', 'meshbay');
+ const tk = readNodeToken(dd);
+ if (tk) {
+ const port = nc ? nc.uiPort : 18000;
+ const sr = await fetch(
+ `http://127.0.0.1:${port}/api/status?t=${tk}`,
+ { signal: AbortSignal.timeout(3000) });
+ if (sr.ok) {
+ const st = await sr.json();
+ if (st.pk_node_ed25519 &&
+ (st.status === 'waiting_for_node_key' ||
+ st.status === 'waiting_for_account')) {
+ const lr = await fetch(
+ `${opts.hubUrl}/v1/users/me/node_key`, {
+ method: 'PUT',
+ headers: { 'Content-Type': 'application/json',
+ 'Authorization': `Bearer ${opts.token}` },
+ body: JSON.stringify({
+ pk_node_ed25519: st.pk_node_ed25519 }),
+ signal: AbortSignal.timeout(5000),
+ });
+ if (lr.ok) keyLinked = true;
+ }
+ }
+ }
+ } catch { /* best effort */ }
+ }
+
const result = await probeNode();
if (result) return { started: true, ...result };
}
throw new Error(
- 'meshbay-node was started but did not become ready within 15 seconds');
+ 'meshbay-node was started but did not become ready within 60 seconds');
});
ipcMain.handle('node:call', async (_e, method, apiPath, body) => {