/* eslint-disable no-console */ 'use strict' const Libp2p = require('../../') const TCP = require('libp2p-tcp') const Mplex = require('libp2p-mplex') const SECIO = require('libp2p-secio') const PeerInfo = require('peer-info') const KadDHT = require('libp2p-kad-dht') const delay = require('delay') const createNode = async () => { const peerInfo = await PeerInfo.create() peerInfo.multiaddrs.add('/ip4/0.0.0.0/tcp/0') const node = await Libp2p.create({ peerInfo, modules: { transport: [TCP], streamMuxer: [Mplex], connEncryption: [SECIO], dht: KadDHT }, config: { dht: { enabled: true } } }) await node.start() return node } ;(async () => { const [node1, node2, node3] = await Promise.all([ createNode(), createNode(), createNode() ]) await Promise.all([ node1.dial(node2.peerInfo), node2.dial(node3.peerInfo) ]) // The DHT routing tables need a moment to populate await delay(100) const peer = await node1.peerRouting.findPeer(node3.peerInfo.id) console.log('Found it, multiaddrs are:') peer.multiaddrs.forEach((ma) => console.log(ma.toString())) })();