Skip to content
This repository was archived by the owner on Aug 9, 2021. It is now read-only.

Commit e6d7f42

Browse files
authored
Merge pull request #859 from 3box/fix/timeout-dag-get-link
fix: timeout links which dont resolve ipfs.dag.get
2 parents b50c8e4 + 1fcaa4b commit e6d7f42

3 files changed

Lines changed: 13 additions & 9 deletions

File tree

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"orbit-db-cache": "^0.3.0",
7171
"orbit-db-identity-provider": "^0.3.0",
7272
"orbit-db-storage-adapter": "^0.5.3",
73+
"p-timeout": "^3.2.0",
7374
"store": "^2.0.12",
7475
"tweetnacl": "^1.0.1",
7576
"tweetnacl-util": "^0.15.0"

src/replicator.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const path = require('path')
22
const EventEmitter = require('events')
33
const merge = require('lodash.merge')
4+
const pTimeout = require('p-timeout')
45
const multiaddr = require('multiaddr')
56
const OrbitDB = require('orbit-db')
67
const Pubsub = require('orbit-db-pubsub')
@@ -247,15 +248,17 @@ class Replicator {
247248
async getAddressLinks () {
248249
const entries = await this.rootstore.iterator({ limit: -1 }).collect()
249250
const linkEntries = entries.filter(e => e.payload.value.type === entryTypes.ADDRESS_LINK)
250-
const resolveLinks = linkEntries.map(async entry => {
251+
const resolveLinks = []
252+
253+
for (const entry of linkEntries) {
251254
const cid = entry.payload.value.data
252-
// TODO handle missing ipfs obj??, timeouts?
253-
const obj = (await this.ipfs.dag.get(cid)).value
254-
this.ipfs.pin.add(cid)
255-
obj.entry = entry
256-
return obj
257-
})
258-
return Promise.all(resolveLinks)
255+
try {
256+
const dag = await pTimeout(this.ipfs.dag.get(cid), 2500)
257+
resolveLinks.push(Object.assign(dag.value, { entry }))
258+
this.ipfs.pin.add(cid)
259+
} catch (e) { }
260+
}
261+
return resolveLinks
259262
}
260263

261264
async getAuthData () {

0 commit comments

Comments
 (0)