Replies: 1 comment
-
They won't necessarily discover each other automatically. This is partly because it's a security hole - if I tell you the peers I am connected to, and you attack those peers, you can influence the behaviour of my node. The node doing the lookup has to know the peer id of the peer it wants to discover, then it can do a
import { createLibp2p } from 'libp2p'
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { tcp } from '@libp2p/tcp'
import { identify, identifyPush } from '@libp2p/identify'
import { kadDHT, removePublicAddressesMapper} from '@libp2p/kad-dht'
import { writeFileSync } from 'node:fs'
const node = await createLibp2p({
addresses: {
listen: [
'/ip4/0.0.0.0/tcp/0'
]
},
connectionEncrypters: [
noise()
],
streamMuxers: [
yamux()
],
transports: [
tcp()
],
services: {
identify: identify(),
identifyPush: identifyPush(),
kadDHT: kadDHT({
protocol: '/ipfs/lan/kad-dht/1.0.0',
clientMode: false,
peerInfoMapper: removePublicAddressesMapper
})
}
})
writeFileSync('./bootstrapper.json', JSON.stringify(node.getMultiaddrs()))
import { createLibp2p } from 'libp2p'
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { tcp } from '@libp2p/tcp'
import { identify, identifyPush } from '@libp2p/identify'
import { kadDHT, removePublicAddressesMapper } from '@libp2p/kad-dht'
import { bootstrap } from '@libp2p/bootstrap'
import { writeFileSync, readFileSync } from 'node:fs'
const bootstrapList = JSON.parse(readFileSync('bootstrapper.json'))
const node = await createLibp2p({
addresses: {
listen: [
'/ip4/0.0.0.0/tcp/0'
]
},
connectionEncrypters: [
noise()
],
streamMuxers: [
yamux()
],
transports: [
tcp()
],
services: {
identify: identify(),
identifyPush: identifyPush(),
kadDHT: kadDHT({
protocol: '/ipfs/lan/kad-dht/1.0.0',
clientMode: false,
peerInfoMapper: removePublicAddressesMapper
}),
bootstrap: bootstrap({
list: bootstrapList
})
}
})
writeFileSync('./peer1.json', JSON.stringify(node.peerId.toString()))
import { createLibp2p } from 'libp2p'
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { tcp } from '@libp2p/tcp'
import { identify, identifyPush } from '@libp2p/identify'
import { kadDHT, removePublicAddressesMapper } from '@libp2p/kad-dht'
import { bootstrap } from '@libp2p/bootstrap'
import { peerIdFromString } from '@libp2p/peer-id'
import { readFileSync } from 'node:fs'
const bootstrapList = JSON.parse(readFileSync('bootstrapper.json'))
const peer1 = JSON.parse(readFileSync('peer1.json'))
const node = await createLibp2p({
addresses: {
listen: [
'/ip4/0.0.0.0/tcp/0'
]
},
connectionEncrypters: [
noise()
],
streamMuxers: [
yamux()
],
transports: [
tcp()
],
services: {
identify: identify(),
identifyPush: identifyPush(),
kadDHT: kadDHT({
protocol: '/ipfs/lan/kad-dht/1.0.0',
clientMode: false,
peerInfoMapper: removePublicAddressesMapper
}),
bootstrap: bootstrap({
list: bootstrapList
})
}
})
console.info(await node.peerRouting.findPeer(peerIdFromString(peer1))) |
Beta Was this translation helpful? Give feedback.
-
Hello, I have a listener and dialer .js files that both use bootstrap list, that list has one address which belongs to another locally running node.
now the listener is connected to the local bootstrap node ... and when I run the dialer it also connects to the bootstrap, but can't find the listener to open connect to it and open a chat stream in the terminal.
it works with mDNS, but I want to do it using bootstrap, can somebody please help me understand what's missing?
this is the node creation in all three files
What I am trying to do is to somehow in the dialer find the listener and connect to it:
Thanks in advance :)
Beta Was this translation helpful? Give feedback.
All reactions