This commit is contained in:
haad 2023-02-02 14:07:14 +02:00
parent 40494246e1
commit f576795c3e
8 changed files with 263 additions and 116 deletions

2
dist/ipfslog.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -40,11 +40,10 @@ const Database = async ({ OpLog, ipfs, identity, databaseId, accessController, s
const sync = async (bytes) => {
const entry = await Entry.decode(bytes)
events.emit('sync', entry)
await log.joinEntry(entry)
// const updated = await log.joinEntry(entry)
// if (updated) {
events.emit('update', entry)
// }
const updated = await log.joinEntry(entry)
if (updated) {
events.emit('update', entry)
}
}
const close = async () => {

View File

@ -54,7 +54,7 @@ const KeyValuePersisted = async ({ KeyValue, OpLog, Database, ipfs, identity, da
const drop = async () => {
events.off('update', updateIndex(index))
await index.clear()
await keyValueStore.clear()
await keyValueStore.drop()
}
// Listen for update events from the database and update the index on every update

View File

@ -424,15 +424,15 @@ const Log = async (identity, { logId, logHeads, access, storage, stateStorage, s
clock,
heads,
values,
access,
identity,
storage,
get,
append,
join,
joinEntry,
traverse,
iterator
iterator,
access,
identity,
storage
}
}
@ -442,7 +442,7 @@ const Log = async (identity, { logId, logHeads, access, storage, stateStorage, s
* Finds entries that are the heads of this collection,
* ie. entries that are not referenced by other entries.
*
* This function is provate and not exposed in the Log API
* This function is private and not exposed in the Log API
*
* @param {Array<Entry>} entries Entries to search heads from
* @returns {Array<Entry>}

View File

@ -1,4 +1,4 @@
import { deepStrictEqual, strictEqual, notStrictEqual } from 'assert'
import { deepStrictEqual, strictEqual } from 'assert'
import rimraf from 'rimraf'
import * as Log from '../src/log.js'
import IdentityProvider from 'orbit-db-identity-provider'
@ -8,7 +8,8 @@ import EventStore from '../src/events.js'
import Database from '../src/database.js'
// Test utils
import { config, testAPIs, startIpfs, stopIpfs, getIpfsPeerId, connectPeers, waitForPeers } from 'orbit-db-test-utils'
import { config, testAPIs, startIpfs, stopIpfs, getIpfsPeerId, waitForPeers } from 'orbit-db-test-utils'
import connectPeers from './utils/connect-nodes.js'
import { identityKeys, signingKeys } from './fixtures/orbit-db-identity-keys.js'
const { sync: rmrf } = rimraf
@ -59,9 +60,11 @@ Object.keys(testAPIs).forEach((IPFS) => {
afterEach(async () => {
if (kv1) {
await kv1.drop()
await kv1.close()
}
if (kv2) {
await kv2.drop()
await kv2.close()
}
})
@ -91,9 +94,9 @@ Object.keys(testAPIs).forEach((IPFS) => {
})
describe('using database', () => {
it.skip('returns all entries in the database', async () => {
let error
it('returns all entries in the database', async () => {
let updateCount = 0
let syncCount = 0
const accessController = {
canAppend: (entry) => entry.identity.id === testIdentity1.id
@ -102,8 +105,10 @@ Object.keys(testAPIs).forEach((IPFS) => {
const onUpdate = (entry) => {
updateCount++
}
const onError = (err) => {
error = err
const onSync = (entry) => {
syncCount++
}
const onError = () => {
}
kv1 = await EventStore({ OpLog: Log, Database, ipfs: ipfs1, identity: testIdentity1, databaseId, accessController })
@ -111,14 +116,16 @@ Object.keys(testAPIs).forEach((IPFS) => {
kv1.events.on('update', onUpdate)
kv2.events.on('update', onUpdate)
kv1.events.on('sync', onSync)
kv2.events.on('sync', onSync)
kv1.events.on('error', onError)
kv2.events.on('error', onError)
strictEqual(kv1.type, 'events')
strictEqual(kv2.type, 'events')
// await waitForPeers(ipfs1, [peerId2], databaseId)
// await waitForPeers(ipfs2, [peerId1], databaseId)
await waitForPeers(ipfs1, [peerId2], databaseId)
await waitForPeers(ipfs2, [peerId1], databaseId)
// send a garbage message to pubsub to test onError firing
// await ipfs1.pubsub.publish(databaseId, Uint8Array.from([1, 2, 3, 4, 5]))
@ -130,7 +137,8 @@ Object.keys(testAPIs).forEach((IPFS) => {
await kv1.add(12345)
await kv1.add('empty')
await kv1.add('')
const hash = await kv1.add('friend33')
await kv1.add('friend33')
// const hash = await kv1.add('friend33')
// await kv1.set('init', true)
// await kv1.set('hello', 'friend')
// await kv1.del('hello')
@ -139,7 +147,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
// await kv1.set('empty', '')
// await kv1.del('empty')
// const hash = await kv1.set('hello', 'friend3')
const lastEntry = await kv1.get(hash)
// const lastEntry = await kv1.get(hash)
// const sleep = (time) => new Promise((resolve) => {
// setTimeout(() => {
@ -148,24 +156,35 @@ Object.keys(testAPIs).forEach((IPFS) => {
// })
// await sleep(5000) // give some time for ipfs peers to sync
const waitForAllUpdates = async () => {
return new Promise((resolve) => {
const interval = setInterval(() => {
if (updateCount >= 8 * 2 || syncCount >= 8) {
clearInterval(interval)
resolve()
}
}, 100)
})
}
await waitForAllUpdates()
// sync() test
console.time('sync')
await kv2.sync(lastEntry.bytes)
console.timeEnd('sync')
// console.time('sync')
// await kv2.sync(lastEntry.bytes)
// console.timeEnd('sync')
// await sleep(1000) // give some time for ipfs peers to sync
// // write access test
let errorMessage
try {
await kv2.set('hello', 'friend4')
} catch (e) {
errorMessage = e.message
} finally {
const valueNotUpdated = await kv2.get('hello')
strictEqual(valueNotUpdated, 'friend3')
notStrictEqual(errorMessage, undefined)
strictEqual(errorMessage.startsWith('Could not append entry:\nKey'), true)
}
// let errorMessage
// try {
// await kv2.set('hello', 'friend4')
// } catch (e) {
// errorMessage = e.message
// } finally {
// const valueNotUpdated = await kv2.get('hello')
// strictEqual(valueNotUpdated, 'friend3')
// notStrictEqual(errorMessage, undefined)
// strictEqual(errorMessage.startsWith('Could not append entry:\nKey'), true)
// }
// all() test
const all2 = []
@ -198,23 +217,38 @@ Object.keys(testAPIs).forEach((IPFS) => {
])
// onError test
notStrictEqual(error, undefined)
strictEqual(error.message, 'CBOR decode error: too many terminals, data makes no sense')
// notStrictEqual(error, undefined)
// strictEqual(error.message, 'CBOR decode error: too many terminals, data makes no sense')
// onUpdate test
strictEqual(updateCount, 8 * 2)
})
})
describe('load database', () => {
describe.skip('load database', () => {
it('returns all entries in the database', async () => {
let updateCount = 0
let syncCount = 0
const accessController = {
canAppend: (entry) => entry.identity.id === testIdentity1.id
}
const onUpdate = (entry) => {
++updateCount
}
const onSync = (entry) => {
++syncCount
}
kv1 = await EventStore({ OpLog: Log, Database, ipfs: ipfs1, identity: testIdentity1, databaseId, accessController })
kv2 = await EventStore({ OpLog: Log, Database, ipfs: ipfs2, identity: testIdentity2, databaseId, accessController })
kv1.events.on('update', onUpdate)
kv2.events.on('update', onUpdate)
kv1.events.on('sync', onSync)
kv2.events.on('sync', onSync)
await waitForPeers(ipfs1, [peerId2], databaseId)
await waitForPeers(ipfs2, [peerId1], databaseId)
@ -229,25 +263,34 @@ Object.keys(testAPIs).forEach((IPFS) => {
// const hash = await kv1.add('friend33')
// const lastEntry = await kv1.log.get(hash)
const sleep = (time) => new Promise((resolve) => {
setTimeout(() => {
resolve()
}, time)
})
await sleep(10000) // give some time for ipfs peers to sync
// const sleep = (time) => new Promise((resolve) => {
// setTimeout(() => {
// resolve()
// }, time)
// })
// await sleep(10000) // give some time for ipfs peers to sync
const waitForAllUpdates = async () => {
return new Promise((resolve) => {
const interval = setInterval(() => {
if (updateCount >= 8 * 2 || syncCount >= 8) {
clearInterval(interval)
resolve()
}
}, 100)
})
}
await waitForAllUpdates()
// sync() test
// console.time('sync')
// await kv2.sync(lastEntry.bytes)
// console.timeEnd('sync')
await kv1.close()
await kv2.close()
// await kv1.close()
// await kv2.close()
// await sleep(1000) // give some time for ipfs peers to sync
kv1 = await EventStore({ OpLog: Log, Database, ipfs: ipfs1, identity: testIdentity1, databaseId, accessController })
kv2 = await EventStore({ OpLog: Log, Database, ipfs: ipfs2, identity: testIdentity2, databaseId, accessController })
// kv1 = await EventStore({ OpLog: Log, Database, ipfs: ipfs1, identity: testIdentity1, databaseId, accessController })
// kv2 = await EventStore({ OpLog: Log, Database, ipfs: ipfs2, identity: testIdentity2, databaseId, accessController })
// all() test
const all2 = []

View File

@ -1,4 +1,4 @@
import { deepStrictEqual, strictEqual, notStrictEqual } from 'assert'
import { deepStrictEqual, strictEqual } from 'assert'
import rimraf from 'rimraf'
import * as Log from '../src/log.js'
import IdentityProvider from 'orbit-db-identity-provider'
@ -8,7 +8,8 @@ import Feed from '../src/feed.js'
import Database from '../src/database.js'
// Test utils
import { config, testAPIs, getIpfsPeerId, waitForPeers, startIpfs, stopIpfs, connectPeers } from 'orbit-db-test-utils'
import { config, testAPIs, getIpfsPeerId, waitForPeers, startIpfs, stopIpfs } from 'orbit-db-test-utils'
import connectPeers from './utils/connect-nodes.js'
import { identityKeys, signingKeys } from './fixtures/orbit-db-identity-keys.js'
const { sync: rmrf } = rimraf
@ -16,7 +17,7 @@ const { createIdentity } = IdentityProvider
Object.keys(testAPIs).forEach((IPFS) => {
describe('Feed Database (' + IPFS + ')', function () {
this.timeout(config.timeout)
this.timeout(config.timeout * 2)
let ipfsd1, ipfsd2
let ipfs1, ipfs2
@ -59,9 +60,11 @@ Object.keys(testAPIs).forEach((IPFS) => {
afterEach(async () => {
if (kv1) {
await kv1.drop()
await kv1.close()
}
if (kv2) {
await kv2.drop()
await kv2.close()
}
})
@ -91,19 +94,21 @@ Object.keys(testAPIs).forEach((IPFS) => {
})
describe('using database', () => {
it.skip('returns all entries in the database', async () => {
let error
it('returns all entries in the database', async () => {
let updateCount = 0
let syncCount = 0
const accessController = {
canAppend: (entry) => entry.identity.id === testIdentity1.id
}
const onUpdate = (entry) => {
updateCount++
++updateCount
}
const onError = (err) => {
error = err
const onSync = (entry) => {
++syncCount
}
const onError = () => {
}
kv1 = await Feed({ OpLog: Log, Database, ipfs: ipfs1, identity: testIdentity1, databaseId, accessController })
@ -111,11 +116,13 @@ Object.keys(testAPIs).forEach((IPFS) => {
kv1.events.on('update', onUpdate)
kv2.events.on('update', onUpdate)
kv1.events.on('sync', onSync)
kv2.events.on('sync', onSync)
kv1.events.on('error', onError)
kv2.events.on('error', onError)
strictEqual(kv1.type, 'events')
strictEqual(kv2.type, 'events')
strictEqual(kv1.type, 'feed')
strictEqual(kv2.type, 'feed')
await waitForPeers(ipfs1, [peerId2], databaseId)
await waitForPeers(ipfs2, [peerId1], databaseId)
@ -134,12 +141,23 @@ Object.keys(testAPIs).forEach((IPFS) => {
// const hash = await kv1.add('friend33')
// const lastEntry = await kv1.get(hash)
const sleep = (time) => new Promise((resolve) => {
setTimeout(() => {
resolve()
}, time)
})
await sleep(10000) // give some time for ipfs peers to sync
// const sleep = (time) => new Promise((resolve) => {
// setTimeout(() => {
// resolve()
// }, time)
// })
// await sleep(10000) // give some time for ipfs peers to sync
const waitForAllUpdates = async () => {
return new Promise((resolve) => {
const interval = setInterval(() => {
if (updateCount >= 8 * 2 || syncCount >= 8) {
clearInterval(interval)
resolve()
}
}, 100)
})
}
await waitForAllUpdates()
// // sync() test
// console.time('sync')
@ -191,23 +209,42 @@ Object.keys(testAPIs).forEach((IPFS) => {
])
// onError test
notStrictEqual(error, undefined)
strictEqual(error.message, 'CBOR decode error: too many terminals, data makes no sense')
// notStrictEqual(error, undefined)
// strictEqual(error.message, 'CBOR decode error: too many terminals, data makes no sense')
// onUpdate test
strictEqual(updateCount, 8 * 2)
})
})
describe('load database', () => {
describe.skip('load database', () => {
it('returns all entries in the database', async () => {
let updateCount = 0
let syncCount = 0
const accessController = {
canAppend: (entry) => entry.identity.id === testIdentity1.id
}
const onUpdate = (entry) => {
++updateCount
}
const onSync = (entry) => {
++syncCount
}
const onError = () => {
}
kv1 = await Feed({ OpLog: Log, Database, ipfs: ipfs1, identity: testIdentity1, databaseId, accessController })
kv2 = await Feed({ OpLog: Log, Database, ipfs: ipfs2, identity: testIdentity2, databaseId, accessController })
kv1.events.on('update', onUpdate)
kv2.events.on('update', onUpdate)
kv1.events.on('sync', onSync)
kv2.events.on('sync', onSync)
kv1.events.on('error', onError)
kv2.events.on('error', onError)
await waitForPeers(ipfs1, [peerId2], databaseId)
await waitForPeers(ipfs2, [peerId1], databaseId)
@ -225,25 +262,36 @@ Object.keys(testAPIs).forEach((IPFS) => {
// const hashX = await kv1.del(hash)
// const lastEntry = await kv1.log.get(hashX)
const sleep = (time) => new Promise((resolve) => {
setTimeout(() => {
resolve()
}, time)
})
await sleep(5000) // give some time for ipfs peers to sync
// const sleep = (time) => new Promise((resolve) => {
// setTimeout(() => {
// resolve()
// }, time)
// })
// await sleep(10000) // give some time for ipfs peers to sync
const waitForAllUpdates = async () => {
return new Promise((resolve) => {
const interval = setInterval(() => {
if (updateCount >= 8 * 2 || syncCount >= 8) {
clearInterval(interval)
resolve()
}
}, 100)
})
}
await waitForAllUpdates()
// sync() test
// console.time('sync')
// await kv2.sync(lastEntry.bytes)
// console.timeEnd('sync')
await kv1.close()
await kv2.close()
// await kv1.close()
// await kv2.close()
// await sleep(1000) // give some time for ipfs peers to sync
// // await sleep(1000) // give some time for ipfs peers to sync
kv1 = await Feed({ OpLog: Log, Database, ipfs: ipfs1, identity: testIdentity1, databaseId, accessController })
kv2 = await Feed({ OpLog: Log, Database, ipfs: ipfs2, identity: testIdentity2, databaseId, accessController })
// kv1 = await Feed({ OpLog: Log, Database, ipfs: ipfs1, identity: testIdentity1, databaseId, accessController })
// kv2 = await Feed({ OpLog: Log, Database, ipfs: ipfs2, identity: testIdentity2, databaseId, accessController })
// all() test
const all2 = []

View File

@ -5,11 +5,12 @@ import IdentityProvider from 'orbit-db-identity-provider'
import Keystore from '../src/Keystore.js'
import KeyValueStore from '../src/kv.js'
// import KeyValueStorePersisted from '../src/kv-persisted.js'
import KeyValueStorePersisted from '../src/kv-persisted.js'
import Database from '../src/database.js'
// Test utils
import { config, testAPIs, getIpfsPeerId, waitForPeers, startIpfs, stopIpfs, connectPeers } from 'orbit-db-test-utils'
import { config, testAPIs, getIpfsPeerId, waitForPeers, startIpfs, stopIpfs } from 'orbit-db-test-utils'
import connectPeers from './utils/connect-nodes.js'
import { identityKeys, signingKeys } from './fixtures/orbit-db-identity-keys.js'
const { sync: rmrf } = rimraf
@ -17,7 +18,7 @@ const { createIdentity } = IdentityProvider
Object.keys(testAPIs).forEach((IPFS) => {
describe('KeyValue Database (' + IPFS + ')', function () {
this.timeout(config.timeout)
this.timeout(config.timeout * 2)
let ipfsd1, ipfsd2
let ipfs1, ipfs2
@ -84,9 +85,11 @@ Object.keys(testAPIs).forEach((IPFS) => {
afterEach(async () => {
if (kv1) {
await kv1.drop()
await kv1.close()
}
if (kv2) {
await kv2.drop()
await kv2.close()
}
})
@ -111,10 +114,10 @@ Object.keys(testAPIs).forEach((IPFS) => {
// error = err
}
kv1 = await KeyValueStore({ KeyValue: KeyValueStore, OpLog: Log, Database, ipfs: ipfs1, identity: testIdentity1, databaseId, accessController })
kv2 = await KeyValueStore({ KeyValue: KeyValueStore, OpLog: Log, Database, ipfs: ipfs2, identity: testIdentity2, databaseId, accessController })
// kv1 = await KeyValueStorePersisted({ KeyValue: KeyValueStore, OpLog: Log, Database, ipfs: ipfs1, identity: testIdentity1, databaseId, accessController })
// kv2 = await KeyValueStorePersisted({ KeyValue: KeyValueStore, OpLog: Log, Database, ipfs: ipfs2, identity: testIdentity2, databaseId, accessController })
// kv1 = await KeyValueStore({ KeyValue: KeyValueStore, OpLog: Log, Database, ipfs: ipfs1, identity: testIdentity1, databaseId, accessController })
// kv2 = await KeyValueStore({ KeyValue: KeyValueStore, OpLog: Log, Database, ipfs: ipfs2, identity: testIdentity2, databaseId, accessController })
kv1 = await KeyValueStorePersisted({ KeyValue: KeyValueStore, OpLog: Log, Database, ipfs: ipfs1, identity: testIdentity1, databaseId, accessController })
kv2 = await KeyValueStorePersisted({ KeyValue: KeyValueStore, OpLog: Log, Database, ipfs: ipfs2, identity: testIdentity2, databaseId, accessController })
kv1.events.on('update', onUpdate)
kv2.events.on('update', onUpdate)
@ -126,8 +129,8 @@ Object.keys(testAPIs).forEach((IPFS) => {
strictEqual(kv1.type, 'kv')
strictEqual(kv2.type, 'kv')
// await waitForPeers(ipfs1, [peerId2], databaseId)
// await waitForPeers(ipfs2, [peerId1], databaseId)
await waitForPeers(ipfs1, [peerId2], databaseId)
await waitForPeers(ipfs2, [peerId1], databaseId)
// send a garbage message to pubsub to test onError firing
// await ipfs1.pubsub.publish(databaseId, Uint8Array.from([1, 2, 3, 4, 5]))
@ -143,12 +146,23 @@ Object.keys(testAPIs).forEach((IPFS) => {
// const hash = await kv1.set('hello', 'friend3')
// const lastEntry = await kv1.database.log.get(hash)
const sleep = (time) => new Promise((resolve) => {
setTimeout(() => {
resolve()
}, time)
})
await sleep(1000) // give some time for ipfs peers to sync
// const sleep = (time) => new Promise((resolve) => {
// setTimeout(() => {
// resolve()
// }, time)
// })
// await sleep(10000) // give some time for ipfs peers to sync
const waitForAllUpdates = async () => {
return new Promise((resolve) => {
const interval = setInterval(() => {
if (updateCount >= 8 * 2 || syncCount >= 8) {
clearInterval(interval)
resolve()
}
}, 100)
})
}
await waitForAllUpdates()
// sync() test
// console.time('sync')
@ -223,25 +237,35 @@ Object.keys(testAPIs).forEach((IPFS) => {
})
})
describe('load database', () => {
describe.skip('load database', () => {
it('returns all entries in the database', async () => {
let updateCount = 0
let syncCount = 0
const accessController = {
canAppend: (entry) => entry.identity.id === testIdentity1.id
}
kv1 = await KeyValueStore({ KeyValue: KeyValueStore, OpLog: Log, Database, ipfs: ipfs1, identity: testIdentity1, databaseId, accessController })
kv2 = await KeyValueStore({ KeyValue: KeyValueStore, OpLog: Log, Database, ipfs: ipfs2, identity: testIdentity2, databaseId, accessController })
// kv1 = await KeyValueStorePersisted({ KeyValue: KeyValueStore, OpLog: Log, Database, ipfs: ipfs1, identity: testIdentity1, databaseId, accessController })
// kv2 = await KeyValueStorePersisted({ KeyValue: KeyValueStore, OpLog: Log, Database, ipfs: ipfs2, identity: testIdentity2, databaseId, accessController })
const onUpdate = (entry) => {
updateCount++
}
const onSync = (entry) => {
syncCount++
}
// kv1 = await KeyValueStore({ KeyValue: KeyValueStore, OpLog: Log, Database, ipfs: ipfs1, identity: testIdentity1, databaseId, accessController })
// kv2 = await KeyValueStore({ KeyValue: KeyValueStore, OpLog: Log, Database, ipfs: ipfs2, identity: testIdentity2, databaseId, accessController })
kv1 = await KeyValueStorePersisted({ KeyValue: KeyValueStore, OpLog: Log, Database, ipfs: ipfs1, identity: testIdentity1, databaseId, accessController })
kv2 = await KeyValueStorePersisted({ KeyValue: KeyValueStore, OpLog: Log, Database, ipfs: ipfs2, identity: testIdentity2, databaseId, accessController })
kv1.events.on('update', onUpdate)
kv2.events.on('update', onUpdate)
kv1.events.on('sync', onSync)
kv2.events.on('sync', onSync)
await waitForPeers(ipfs1, [peerId2], databaseId)
await waitForPeers(ipfs2, [peerId1], databaseId)
let syncCount = 0
kv2.events.on('sync', (entry) => {
++syncCount
})
await kv1.set('init', true)
await kv1.set('hello', 'friend')
await kv1.del('hello')
@ -253,23 +277,34 @@ Object.keys(testAPIs).forEach((IPFS) => {
// const hash = await kv1.set('hello', 'friend3')
// const lastEntry = await kv1.log.get(hash)
const sleep = (time) => new Promise((resolve) => {
setTimeout(() => {
resolve()
}, time)
})
await sleep(1000) // give some time for ipfs peers to sync
// const sleep = (time) => new Promise((resolve) => {
// setTimeout(() => {
// resolve()
// }, time)
// })
// await sleep(10000) // give some time for ipfs peers to sync
const waitForAllUpdates = async () => {
return new Promise((resolve) => {
const interval = setInterval(() => {
if (updateCount >= 8 * 2 || syncCount >= 8) {
clearInterval(interval)
resolve()
}
}, 100)
})
}
await waitForAllUpdates()
// sync() test
// console.time('sync')
// await kv2.sync(lastEntry.bytes)
// console.timeEnd('sync')
await kv1.close()
await kv2.close()
// await kv1.close()
// await kv2.close()
kv1 = await KeyValueStore({ KeyValue: KeyValueStore, OpLog: Log, Database, ipfs: ipfs1, identity: testIdentity1, databaseId, accessController })
kv2 = await KeyValueStore({ KeyValue: KeyValueStore, OpLog: Log, Database, ipfs: ipfs2, identity: testIdentity2, databaseId, accessController })
// kv1 = await KeyValueStore({ KeyValue: KeyValueStore, OpLog: Log, Database, ipfs: ipfs1, identity: testIdentity1, databaseId, accessController })
// kv2 = await KeyValueStore({ KeyValue: KeyValueStore, OpLog: Log, Database, ipfs: ipfs2, identity: testIdentity2, databaseId, accessController })
// kv1 = await KeyValueStorePersisted({ KeyValue: KeyValueStore, OpLog: Log, Database, ipfs: ipfs1, identity: testIdentity1, databaseId, accessController })
// kv2 = await KeyValueStorePersisted({ KeyValue: KeyValueStore, OpLog: Log, Database, ipfs: ipfs2, identity: testIdentity2, databaseId, accessController })

View File

@ -0,0 +1,22 @@
'use strict'
const defaultFilter = () => true
const connectIpfsNodes = async (ipfs1, ipfs2, options = {
filter: defaultFilter
}) => {
const id1 = await ipfs1.id()
const id2 = await ipfs2.id()
const addresses1 = id1.addresses.filter(options.filter)
const addresses2 = id2.addresses.filter(options.filter)
for (const a2 of addresses2) {
await ipfs1.swarm.connect(a2)
}
for (const a1 of addresses1) {
await ipfs2.swarm.connect(a1)
}
}
export default connectIpfsNodes