Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const libp2p = await createLibp2p({
- datastore,
- ...(savedPeerId ? { peerId: savedPeerId } : {}),
- addresses: {
- listen: [
- '/ip4/0.0.0.0/tcp/4001',
- '/ip4/0.0.0.0/tcp/9001/ws',
- ...relayListenAddrs,
- ],
- announce: [
- `/ip4/${myPublicIP}/tcp/4001`,
- `/ip4/${myPublicIP}/tcp/9001/ws`,
- ...relayListenAddrs, // I have no idea what I'm doing
- ],
- }, transports: [tcp(), webSockets()],
- connectionManager: {
- maxConnections: 300,
- minConnections: 50,
- },
- connectionGater: {
- denyDialMultiaddr: async () => false,
- },
- connectionEncryption: [noise()],
- streamMuxers: [yamux(), mplex()],
- peerDiscovery: [
- // mdns({
- // interval: 2000,
- // }),
- bootstrap({
- list: [
- '/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ',
- ...bootstrapAddrs,
- ],
- }),
- ],
- services: {
- identify: identify(),
- dcutr: dcutr(),
- //autoNAT: autoNAT(),
- //pubsub: gossipsub(),
- //delegatedRouting: () => delegatedClient,
- aminoDHT: kadDHT({
- protocol: '/ipfs/kad/1.0.0',
- //pingTimeout: 10000,
- //pingConcurrency: 10,
- //kBucketSize: 20,
- peerInfoMapper: removePrivateAddressesMapper,
- //clientMode: true,
- validators: {
- ipns: ipnsValidator,
- },
- selectors: {
- ipns: ipnsSelector,
- },
- }),
- },
- })
- libp2p.addEventListener('peer:connect', (evt) => {
- const peerId = evt.detail
- //console.log(`Connected to ${peerId.toString()}`)
- })
- libp2p.addEventListener('peer:disconnect', (evt) => {
- const peerId = evt.detail
- //console.log(`Disconnected from ${peerId.toString()}`)
- })
- libp2p.addEventListener('peer:discovery', (evt) => {
- const peerInfo = evt.detail
- console.log('Discovered:', peerInfo.id.toString())
- })
- console.log('PeerId:', JSON.stringify(libp2p.peerId, null, 2))
- await writePeerId(libp2p.peerId)
- return await createHelia({
- libp2p,
- datastore,
- blockstore,
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement