Last active
November 15, 2022 00:42
-
-
Save tabcat/8fc26a03a58617ebea0e8ff4d261fcb3 to your computer and use it in GitHub Desktop.
issue with ipfs-core pubsub when starting using existing repo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
first time running should be fine. ipfs nodes are able to become pubsub peers. | |
second time running should not be fine. ipfs nodes are able to swarm connect but do not pubsub peer. | |
*/ | |
import * as IPFS from 'ipfs-core' | |
const localIpfsOptions = (repo) => ({ | |
repo, | |
config: { | |
Addresses: { | |
Swarm: ['/ip4/127.0.0.1/tcp/0'], | |
Announce: [], | |
NoAnnounce: [], | |
Delegates: [] | |
}, | |
Bootstrap: [], | |
Pubsub: { | |
Router: 'gossipsub', | |
Enabled: true | |
} | |
} | |
}) | |
const ipfs1 = await IPFS.create(localIpfsOptions('./scratch/1/ipfs')) | |
const ipfs2 = await IPFS.create(localIpfsOptions('./scratch/2/ipfs')) | |
const id1 = await ipfs1.id() | |
const id2 = await ipfs2.id() | |
// uncomment for successful pubsub re-peering | |
// await ipfs1.libp2p.peerStore.delete(id2.id) | |
// get `Error: The dial request has no valid addresses` error if no timeout | |
await new Promise(resolve => setTimeout(resolve, 2000)) | |
await ipfs1.swarm.connect(id2.id) | |
await ipfs2.swarm.connect(id1.id) | |
await ipfs1.pubsub.subscribe('topic') | |
await ipfs2.pubsub.subscribe('topic') | |
const getPeers = async (pubsub) => await pubsub.peers('topic') | |
await new Promise(resolve => setTimeout(resolve, 1000)) | |
console.log(await getPeers(ipfs1.pubsub)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment