Skip to content

Commit

Permalink
fix: allow find providers
Browse files Browse the repository at this point in the history
  • Loading branch information
geolffreym committed Apr 4, 2021
1 parent 4c9a72c commit 2445e93
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/main/core/ipfs/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const forceKill = async (isInstance) => {
} catch (e) {
// Gateway stop
await forceKill(isInstance)
throw new Error('Fail starting node')
}

}, startRunning = async () => {
Expand Down
20 changes: 11 additions & 9 deletions src/main/core/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);

}

Expand Down
17 changes: 6 additions & 11 deletions src/main/core/provs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>}
*/

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
}

Expand Down

0 comments on commit 2445e93

Please sign in to comment.