Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { createLibp2p } from 'libp2p'
- import { webSockets } from '@libp2p/websockets'
- import { noise } from '@chainsafe/libp2p-noise'
- import { mplex } from '@libp2p/mplex'
- /*
- This file is used to configure and run the relay node.
- The relay node is used to listen/accept incoming connections.
- This relay does not use the HOP feture, because it is used to advertise the relay address.
- */
- async function main ()
- {
- const myNode = await createLibp2p({
- addresses: { listen: ['/ip4/0.0.0.0/tcp/0/ws'] },
- transports: [ webSockets() ],
- connectionEncryption: [ noise() ],
- streamMuxers: [ mplex() ]
- })
- await myNode.start()
- .then(() => console.log("Node ID: " + myNode.peerId.toString())) // Display the Node ID
- .then(() =>
- {
- console.log("Listening:") // Display the listening addresses.
- myNode.getMultiaddrs().forEach((ma) => console.log("\t" + ma.toString()))
- })
- .catch((err) => console.error(err))
- /*
- let ID = "12D3KooWCMpg35Foh1JMKgZrTWJeja5ojrHxtNgcjZYKf3CovSjj";
- let addr = "/ip4/192.168.65.103/tcp/4001/ws/p2p/" + ID;
- const conn = await myNode.dial(addr)
- .then(() => console.log("Connected to " + ID))
- .catch((err) => console.error(err))
- */
- }
- main().then(r => console.log(r)).catch(e => console.error(e))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement