From 2445e9388c2c9f544bd1c9fbf4c64f95979d2334 Mon Sep 17 00:00:00 2001 From: geolffrey Date: Sat, 3 Apr 2021 18:30:01 -0600 Subject: [PATCH] fix: allow find providers --- src/main/core/ipfs/node/index.js | 1 + src/main/core/node.js | 20 +++++++++++--------- src/main/core/provs/index.js | 17 ++++++----------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/main/core/ipfs/node/index.js b/src/main/core/ipfs/node/index.js index 557f32c24..384bed6fd 100644 --- a/src/main/core/ipfs/node/index.js +++ b/src/main/core/ipfs/node/index.js @@ -25,6 +25,7 @@ const forceKill = async (isInstance) => { } catch (e) { // Gateway stop await forceKill(isInstance) + throw new Error('Fail starting node') } }, startRunning = async () => { diff --git a/src/main/core/node.js b/src/main/core/node.js index c629593cf..d0777c0da 100644 --- a/src/main/core/node.js +++ b/src/main/core/node.js @@ -46,10 +46,13 @@ module.exports = class Node extends EventEmitter { } async getIngestKey() { - const rawAddress = this.rawIngestKey - const resolveKey = await this.resolveKey(rawAddress) - if (!resolveKey) return false; - return key.sanitizedKey(resolveKey) + return await this.resolveKey( + this.rawIngestKey + ) + } + + sanitizeKey(address) { + return key.sanitizedKey(address) } get rawIngestKey() { @@ -147,16 +150,15 @@ module.exports = class Node extends EventEmitter { */ log.info('Node ready'); log.info('Loading db..'); - const address = await this.getIngestKey(); - if (!address) return false // Avoid move forward - const rawAddress = this.rawIngestKey - + const raw = await this.getIngestKey(); + if (!raw) return false // Avoid move forward + const address = this.sanitizeKey(raw) // Get orbit instance and next line connect providers // Serve as provider too :) this.orbit = await this.instanceOB(); this.emit('node-step', 'Connecting') await this.run(address, res); - await provider.findProv(this.node, rawAddress); + await provider.findProv(this.node, raw); } diff --git a/src/main/core/provs/index.js b/src/main/core/provs/index.js index 278d99474..38160b504 100644 --- a/src/main/core/provs/index.js +++ b/src/main/core/provs/index.js @@ -14,30 +14,25 @@ module.exports = class Providers { } } - static getProvidersFromKey(node, key) { - return node.dht.findProvs( - key, {numProviders: 10} - ) - } - static async findProv(node, key) { /*** - * This module find provs to orbit address and connect with them + * This module find providers to orbit address + * and connect with them * @param key * @return {Promise} */ - if (!node.dht) - return; - try { - for await (const cid of this.getProvidersFromKey(node, key)) { + for await (const cid of node.dht.findProvs( + key, {numProviders: 10} + )) { log.info('Connecting to:', cid.id) // Sanitize addresses to valid multi address format const mAddr = cid.addrs.map((m) => `${m.toString()}/p2p/${cid.id}`) await Providers.connect(node, mAddr) } } catch (e) { + log.error(e) // pass }