OrbitDB can't replicate database on different peer

413 Views Asked by At

I have forced with problem in my p2p database orbitdb. Everything works fine while I did not move the database to another server.

const ipfsOptions = {
    repo: './ipfs'
}
const ipfs = await IPFS.create(ipfsOptions)
const orbitdb = await OrbitDB.createInstance(ipfs, { directory: './orbitdb' })

try {
    publicDB = await orbitdb.open("/orbitdb/zdpuB2kVAbJEk1aZBeeKcwz2ehfDaMWi3upkD3ZHwb15zesLF/hub")
    console.log(publicDB.get('hello'))
} catch (err) {
    console.log(err)
}

I created an orbit db on another computer and wanted to open from my computer, but it doesn't work, got TimeoutError: request timed out.

TimeoutError: request timed out
    at maybeThrowTimeoutError (D:\Source\iprs-node\node_modules\ipfs-core-utils\cjs\src\with-timeout-option.js:35:15)
    at D:\Source\iprs-node\node_modules\ipfs-core-utils\cjs\src\with-timeout-option.js:78:9
    at runNextTicks (internal/process/task_queues.js:60:5)
    at processTimers (internal/timers.js:497:9)
    at async Object.read (D:\Source\iprs-node\node_modules\orbit-db-io\index.js:59:17)
    at async OrbitDB.open (D:\Source\iprs-node\node_modules\orbit-db\src\OrbitDB.js:452:22)
    at async initOrbit (D:\Source\iprs-node\services\orbitdb\index.js:26:20)
    at async initAll (D:\Source\iprs-node\index.js:9:5) {
  code: 'ERR_TIMEOUT'
}

Does anyone know how to fix it? Or enlighten me, how this works?

1

There are 1 best solutions below

0
On

Let me share my previous code that is working well.

const Libp2pOptions = {
  peerDiscovery: [mdns()],
  addresses: {
    listen: ['/ip4/0.0.0.0/tcp/0'],
  },
  transports: [tcp()],
  connectionEncryption: [noise()],
  streamMuxers: [yamux()],
  services: {
    identify: identify(),
    pubsub: gossipsub({ allowPublishToZeroPeers: true, emitSelf: true }),
  },
};
const blockstore = new LevelBlockstore('./_ipfs');
const libp2p = await createLibp2p(Libp2pOptions);
const ipfs = await createHelia({ libp2p, blockstore });

const orbitdb = await createOrbitDB({ ipfs, directory: `./_orbitdb` });

const db = await orbitdb.open(config.OrbitDB.url);

// const db = await orbitdb.open('my-db', { type: 'keyvalue', AccessController: IPFSAccessController({ write: ['*'] }) });

Once you create database on a server, you should copy the ipfs and orbitdb folder on another server.