/
host.js
48 lines (36 loc) · 1 KB
/
host.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const data = require('./data.json')
const IPFS = require('ipfs')
const OrbitDB = require('orbit-db')
const ipfsOptions = {
start: true,
EXPERIMENTAL: {
pubsub: true,
},
config: {
Addresses: {
Swarm: [
'/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star'
]
},
}
}
const ipfs = new IPFS(ipfsOptions)
ipfs.on('error', (e) => console.error(e))
ipfs.on('ready', async () => {
const orbitdb = new OrbitDB(ipfs)
const db = await orbitdb.docs('trainingdata', {
create: true,
overwrite: true,
localOnly: false,
write: ['*'], // ALLOW ALL WRITE
})
await db.load()
console.log('OrbitDB address:')
console.log(db.address.toString())
// async forEach withon the IPFS on ready is problematic, put manually
await db.put( { _id: 'x', array: data.x })
await db.put( { _id: 'y', array: data.y })
// Remove this line if you do not have ground truth
await db.put( { _id: 't', array: data.t })
// Do not close connection to remain a host
})