Comments (11)
Thanks. Just confirming #1163 ?
from orbitdb.
I've tried using a LevelDataStore but that doesn't solve the issue. I don't know if both issues are related.
from orbitdb.
@T00rk I will take a look at the script you have provided.
from orbitdb.
I have run the script and launched two nodes. The problem appears to be that neither peer finds the other and connects. Since USER2 can't find USER1, OrbitDB can't find the db in order to replicate it.
libp2pDefaults()
seems to be the cause of the issue. I suspect the problem is with the service settings (although I haven't tested enough to rule out other problems). I've also noticed that peer performance is degradated with default settings (I also notice the first peer eventually crashes with an unrelated libp2p error).
To solve the problem and get the two peers swapping db records, I added the following to the script:
config.services = {
identify: identify(),
pubsub: gossipsub({ allowPublishToZeroPeers: true })
}
config.addresses.listen = [`/ip4/0.0.0.0/tcp/${PORT}`]
config.peerDiscovery = [
mdns(),
bootstrap({
list: ["/ip4/127.0.0.1/tcp/8181", "/ip4/127.0.0.1/tcp/8282"],
})]
from orbitdb.
I've tried your solution. It doesn't work.
I've tried manual connection using libp2p dial method:
const { status } = await libp2p.dial(multiaddr("/ip4/127.0.0.1/tcp/8181"));
console.log("Connection", status);
It seems second node can connect to the first one as I get this output :
node server.js 8282 USER2 /orbitdb/zdpuAnwe1J3Y6oXHVxdvAMXVzn7tRrjKaHGmBdzDLfFXRMCEY
running with port:8282 and USER2
Connection open
from orbitdb.
Could you please provide the full script with my modifications?
from orbitdb.
EDIT:
I've added a LevelDataStore to Helia and it works.
import { gossipsub } from "@chainsafe/libp2p-gossipsub";
import { bootstrap } from "@libp2p/bootstrap";
import { identify } from "@libp2p/identify";
import { mdns } from "@libp2p/mdns";
import { multiaddr } from "@multiformats/multiaddr";
import { IPFSAccessController, createOrbitDB } from "@orbitdb/core";
import { LevelBlockstore } from "blockstore-level";
import { LevelDatastore } from "datastore-level";
import { createHelia, libp2pDefaults } from "helia";
import { createLibp2p } from "libp2p";
import { join } from "path";
const main = async () => {
if (process.argv.length < 4) process.exit(1);
const [, , PORT, DIRECTORY, DATABASE = "FOOBAR"] = process.argv;
const config = {
...libp2pDefaults(),
addresses: {
listen: [`/ip4/0.0.0.0/tcp/${PORT}`],
},
peerDiscovery: [
mdns(),
bootstrap({
list: ["/ip4/127.0.0.1/tcp/8181", "/ip4/127.0.0.1/tcp/8282"],
}),
],
services: {
pubsub: gossipsub({ allowPublishToZeroPeers: true }),
identify: identify(),
},
};
console.log(`running with port:${PORT} and ${DIRECTORY}`);
const ipfsBSDirectory = join("./", DIRECTORY, "helia", "BS");
const ipfsDSDirectory = join("./", DIRECTORY, "helia", "DS");
const orbitDirectory = join("./", DIRECTORY, "orbit");
const blockstore = new LevelBlockstore(ipfsBSDirectory);
const datastore = new LevelDatastore(ipfsDSDirectory);
const libp2p = await createLibp2p(config);
const ipfs = await createHelia({ libp2p, blockstore, datastore });
const id = +DIRECTORY.replace("USER", "");
if (id > 1) {
const { status } = await libp2p.dial(multiaddr("/ip4/127.0.0.1/tcp/8181"));
console.log("Connection", status);
}
const orbitdb = await createOrbitDB({
ipfs,
id: DIRECTORY,
directory: orbitDirectory,
});
const clientEventsDb = await orbitdb.open(DATABASE, {
type: "events",
syncAutomatically: true,
AccessController: IPFSAccessController({ write: ["*"] }),
});
console.log("clientEventsDb address", clientEventsDb.address);
console.log(await clientEventsDb.all());
let index = 0;
const sayHello = async () => {
await clientEventsDb.add(`hello from ${DIRECTORY} ${++index}`);
setTimeout(sayHello, 2000);
};
clientEventsDb.events.on("join", async (peerId, heads) => {
console.log("peer", peerId);
});
clientEventsDb.events.on("update", async (entry) => {
console.log("entry", entry.payload);
});
await sayHello();
process.on("SIGINT", async () => {
await clientEventsDb.close();
await orbitdb.stop();
await ipfs.stop();
process.exit();
});
};
main();
from orbitdb.
Good news and good to know about the DataStore.
I would change the following in your above script because I think the peer discovery services could be causing problems:
const config = {
...libp2pDefaults(),
addresses: {
listen: [`/ip4/0.0.0.0/tcp/${PORT}`],
},
peerDiscovery: [
mdns(),
bootstrap({
list: ["/ip4/127.0.0.1/tcp/8181", "/ip4/127.0.0.1/tcp/8282"],
}),
],
services: {
pubsub: gossipsub({ allowPublishToZeroPeers: true }),
identify: identify(),
},
};
To:
const config = libp2pDefaults()
config.services = {
identify: identify(),
pubsub: gossipsub({ allowPublishToZeroPeers: true })
}
config.addresses.listen = [`/ip4/0.0.0.0/tcp/${PORT}`]
config.peerDiscovery = [
mdns(),
bootstrap({
list: ["/ip4/127.0.0.1/tcp/8181", "/ip4/127.0.0.1/tcp/8282"],
})]
This means you don't have to explicitly dial the 2nd peer because mdns will help both peers discover each other (provided they are on the same local network).
from orbitdb.
I don't understand what is different in both examples.in my config, mdns is already set
const config = {
...libp2pDefaults(),
addresses: {
listen: [`/ip4/0.0.0.0/tcp/${PORT}`],
},
peerDiscovery: [
-> mdns(),
bootstrap({
list: ["/ip4/127.0.0.1/tcp/8181", "/ip4/127.0.0.1/tcp/8282"],
}),
],
services: {
pubsub: gossipsub({ allowPublishToZeroPeers: true }),
identify: identify(),
},
};
from orbitdb.
I just tried your config above and I'm able to get both nodes connecting to one another without explicitly dialling the first peer from the second one. I did have to delete USER1 and USER2 directories before re-running the nodes.
Using mdns() should ensure nodes can discover each other on a local network so I'm not sure why dial
needs to be called explicitly. It could be something to do with the libp2pDefaults().
Anyway, if you are satisfied with the outcome then we can assume this as solved.
from orbitdb.
@haydenyoung I have had the same problem when I was trying to connect two peers on two different ubuntu linux 24.04 systems across the local area network on the 192.168.0.x subnet on a home router.
I dont know how mdns works, or if this is a better issue for libp2p, and if bootstrap nodes are required, because I was to some degree hoping it wasn't necessary for peers to discover each other with dht, but i will do some more research into the problem tomorrow.
from orbitdb.
Related Issues (20)
- Recover from [AggregateError: All promises were rejected] Error: Want for xyz aborted HOT 4
- Uncaught Error: Could not append entry: although write access is granted HOT 7
- Error: fetching raw block for CID HOT 4
- TS7016: Could not find a declaration file for module @orbitdb/core. HOT 3
- Error: No native build was found for platform=darwin arch=arm64 runtime=node abi=115 uv=1 armv=8 libc=glibc node=20.11.0 webpack=true HOT 1
- Log Entries created on remote/other Peers are not Pinned Locally HOT 5
- database record limits for acceptable lookup performance HOT 7
- Sync only to N entries. HOT 1
- Issue with GETTING_STARTED.md LevelBlockstore HOT 2
- Issue with GETTING_STARTED.md page HOT 4
- Can't open existing database HOT 6
- When put data, tell me 'PublishError.NoPeersSubscribedToTopic' error. How can i fix this? THX HOT 3
- OrbitDB can't be opened - AggregateError: All promises were rejected HOT 5
- Update config to use `allowPublishToZeroTopicPeers` HOT 2
- Altering protection to prevent changing data of other users HOT 2
- Unable to Index Documents with Custom IPFSBlockStorage (pure browser environment)
- Integration Issue with Helia: Custom Service Configuration Disables Peer Discovery in Browser Environment HOT 3
- Code Sample Issues in OrbitDB Documentation for Access Controllers HOT 2
- issue trying to get multiple nodejs peers to sync HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from orbitdb.