first commig

This commit is contained in:
2021-03-31 11:09:26 +02:00
commit 0afb8ecb3e
5 changed files with 17065 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
node_modules
orbitdb

122
bug.js Normal file
View File

@@ -0,0 +1,122 @@
const IPFS = require("ipfs-core")
const OrbitDB = require("orbit-db")
const IpfsClient = require("ipfs-http-client")
var ipfs = undefined
const ipfs_config = {
preload: {
enabled: false
},
EXPERIMENTAL: {
pubsub: true
},
config: {
Addresses: {
API: '/ip4/127.0.0.1/tcp/0',
Swarm: ['/ip4/0.0.0.0/tcp/0'],
Gateway: '/ip4/0.0.0.0/tcp/0'
},
Bootstrap: [],
Discovery: {
MDNS: {
Enabled: true,
Interval: 0
},
webRTCStar: {
Enabled: false
}
}
}
}
const defaultIpfsConfig = {
preload: { enabled: false },
config: {
Addresses: {
Swarm: [
// Use IPFS dev signal server
// Websocket:
// '/dns4/ws-star-signal-1.servep2p.com/tcp/443/wss/p2p-websocket-star',
// '/dns4/ws-star-signal-2.servep2p.com/tcp/443/wss/p2p-websocket-star',
// '/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star',
// WebRTC:
// '/dns4/star-signal.cloud.ipfs.team/wss/p2p-webrtc-star',
'/dns4/wrtc-star1.par.dwebops.pub/tcp/443/wss/p2p-webrtc-star/',
'/dns4/wrtc-star2.sjc.dwebops.pub/tcp/443/wss/p2p-webrtc-star/',
'/dns4/webrtc-star.discovery.libp2p.io/tcp/443/wss/p2p-webrtc-star/',
// Use local signal server
// '/ip4/0.0.0.0/tcp/9090/wss/p2p-webrtc-star',
]
}
},
EXPERIMENTAL: {
pubsub: true
}
}
var orbitdb = undefined
async function init_ipfs() {
try {
ipfs = await IpfsClient({ host: 'localhost', port: '5001', protocol: 'http' })
await ipfs.config.getAll() // Necessary to do a call to make code throw in case of CORS error...
console.log("Succesfully connected to existing node.")
} catch (e) {
console.log("Error while trying to connect to local IPFS node.")
console.log("Now running js-ipfs node...")
try {
ipfs = await IPFS.create(ipfs_config)
} catch (e) {
console.log("Error initializing js-ipfs node.")
console.log(e)
}
}
}
async function init_orbitdb() {
try {
orbitdb = await OrbitDB.createInstance(ipfs)
} catch (e) {
console.log(e)
}
}
async function createDBs() {
let db1 = await orbitdb.feed("db1")
await db1.load()
let db2 = await orbitdb.feed("db2")
await db2.load()
return { db1: db1, db2: db2 }
}
async function openExternalDBs() {
await init_ipfs()
await init_orbitdb()
await createDBs()
let opendb1 = await orbitdb.feed("/orbitdb/zdpuAqiS16AGYXKY38ztDdmwu1JC9iyP6pEykypn5ZfRRQAYB/bamberibok-tweetDB")
await opendb1.load()
let opendb2 = await orbitdb.feed("/orbitdb/zdpuAvTaoM5kE95KW8MwmBkvDaDLobJaWgJwQiR24awocPJYG/testiebok-tweetDB")
await opendb2.load()
payload1 = await opendb1.iterator({ reverse: true, limit: -1 }).collect()
data1 = payload1.map(element => element.payload.value)
console.log("opendb1 data:")
console.log(data1)
payload2 = await opendb2.iterator({ reverse: true, limit: -1 }).collect()
data2 = payload2.map(element => element.payload.value)
console.log("opendb2 data:")
console.log(data2)
}
try {
openExternalDBs()
} catch (e) {
console.log(e)
}

16918
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

16
package.json Normal file
View File

@@ -0,0 +1,16 @@
{
"name": "orbitdbbug",
"version": "1.0.0",
"description": "",
"main": "bug.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"ipfs-core": "^0.5.4",
"ipfs-http-client": "^47.0.1",
"orbit-db": "^0.26.1"
}
}

7
readme.md Normal file
View File

@@ -0,0 +1,7 @@
npm init
Install packages:
npm install orbit-db
npm install ipfs-core
npm install ipfs-http-client