### Start Basic go-libp2p Node Source: https://libp2p.io/docs/getting-started-go Create a main.go file to start a libp2p node with default settings, print its listening addresses, and then shut it down. This is the foundational node setup. ```go package main import ( "fmt" "github.com/libp2p/go-libp2p" ) func main() { // start a libp2p node with default settings node, err := libp2p.New() if err != nil { panic(err) } // print the node's listening addresses fmt.Println("Listen addresses:", node.Addrs()) // shut the node down if err := node.Close(); err != nil { panic(err) } } ``` -------------------------------- ### Clone the libp2p-webrtc-guide repository Source: https://libp2p.io/docs/webrtc-browser-connectivity Clone the repository to get started with the guide. This is the initial step to access the project files. ```bash git clone https://github.com/libp2p/libp2p-webrtc-guide ``` -------------------------------- ### Install npm dependencies Source: https://libp2p.io/docs/webrtc-browser-connectivity Navigate into the cloned repository and install the necessary npm dependencies for the project. This step is crucial before running any part of the guide. ```bash cd libp2p-webrtc-guide npm install ``` -------------------------------- ### Install go-libp2p Dependencies Source: https://libp2p.io/docs/webrtc-browser-connectivity Navigate to the go-relay directory and install the necessary Go dependencies. ```bash cd go-relay go get . ``` -------------------------------- ### Install libp2p Module Source: https://libp2p.io/docs/getting-started-javascript Install the core libp2p module to your project. ```bash npm install libp2p ``` -------------------------------- ### Install Dependencies on Windows (WSL) Source: https://libp2p.io/docs/local-testing-strategies Sets up the testing environment within WSL Ubuntu, including installing common utilities and yq. Assumes Docker Desktop integration or direct WSL Docker installation. ```bash # Install WSL2 with Ubuntu wsl --install -d Ubuntu # Inside WSL Ubuntu sudo apt update sudo apt install -y bash docker.io git curl patch wget zip unzip # Install yq sudo wget https://github.com/mikefarah/yq/releases/download/v4.35.1/yq_linux_amd64 \ -O /usr/local/bin/yq && sudo chmod +x /usr/local/bin/yq # Configure Docker (ensure Docker Desktop WSL integration is enabled) # Or install Docker in WSL directly # Clone unified-testing git clone https://github.com/libp2p/unified-testing.git cd unified-testing ``` -------------------------------- ### Start and Stop libp2p Node Source: https://libp2p.io/docs/getting-started-javascript Demonstrates the full lifecycle of a libp2p node, including starting it, logging listening addresses, and subsequently stopping it. Ensure you have configured transports, encryption, and stream multiplexers before starting. ```javascript import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { noise } from '@chainsafe/libp2p-noise' import { yamux } from '@chainsafe/libp2p-yamux' const main = async () => { const node = await createLibp2p({ addresses: { // add a listen address (localhost) to accept TCP connections on a random port listen: ['/ip4/127.0.0.1/tcp/0'] }, transports: [tcp()], connectionEncrypters: [noise], streamMuxers: [yamux()] }) // start libp2p await node.start() console.log('libp2p has started') // print out listening addresses console.log('listening on addresses:') node.getMultiaddrs().forEach((addr) => { console.log(addr.toString()) }) // stop libp2p await node.stop() console.log('libp2p has stopped') } main().then().catch(console.error) ``` -------------------------------- ### Start a Listening libp2p Node Source: https://libp2p.io/docs/getting-started-go Run this command in a terminal to start a libp2p node that listens for incoming connections. No command-line arguments are needed. ```bash ./libp2p-node lbp2p node address: /ip4/192.0.2.0/tcp/61790/ipfs/QmZKjsGJ6ukXVRXVEcExx9GhiyWoJC97onYpzBwCHPWqpL ``` -------------------------------- ### Install TCP Transport Module Source: https://libp2p.io/docs/getting-started-javascript Install the @libp2p/tcp module for establishing network connections. ```bash npm install @libp2p/tcp ``` -------------------------------- ### Start Frontend Development Server Source: https://libp2p.io/docs/webrtc-browser-connectivity Execute this command to launch the frontend development server for the browser peer. ```bash npm run start ``` -------------------------------- ### Check Go Version Source: https://libp2p.io/docs/getting-started-go Verify that your Go installation is version 1.20 or higher. This is a prerequisite for the tutorial. ```bash $ go version go version go1.20 darwin/arm64 ``` -------------------------------- ### Install Noise Connection Encryption Module Source: https://libp2p.io/docs/getting-started-javascript Install the @chainsafe/libp2p-noise module for encrypting connections. ```bash npm install @chainsafe/libp2p-noise ``` -------------------------------- ### Install yq from GitHub Releases Source: https://libp2p.io/docs/local-testing-strategies Install the `yq` command-line YAML processor by downloading the binary directly from GitHub releases. This ensures you are using the correct version and avoids conflicts with snap packages. ```bash sudo wget https://github.com/mikefarah/yq/releases/download/v4.35.1/yq_linux_amd64 \ -O /usr/local/bin/yq && sudo chmod +x /usr/local/bin/yq ``` -------------------------------- ### Build and Run go-libp2p Node Source: https://libp2p.io/docs/getting-started-go Compile the Go program into an executable and run it. This will start the libp2p node and display its listening addresses. ```bash $ go build -o libp2p-node $ ./libp2p-node Listen addresses: [/ip6/::1/tcp/57666 /ip4/192.0.2.0/tcp/57665 /ip4/198.51.100.0/tcp/57665] ``` -------------------------------- ### Configure libp2p Node with Yamux Source: https://libp2p.io/docs/getting-started-javascript Initialize a libp2p node with TCP transport, Noise encryption, and Yamux stream multiplexing. This setup is a common starting point for libp2p applications. ```javascript import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { noise } from '@chainsafe/libp2p-noise' import { yamux } from '@chainsafe/libp2p-yamux' const node = await createLibp2p({ transports: [tcp()], connectionEncrypters: [noise()], streamMuxers: [yamux()] }) ``` -------------------------------- ### Start Node.js Relay Source: https://libp2p.io/docs/webrtc-browser-connectivity Run this command in your terminal to start the Node.js relay server. ```bash npm run start:relay ``` -------------------------------- ### Install Dependencies for Ping Pong Source: https://libp2p.io/docs/getting-started-javascript Install the necessary packages for multiaddr parsing and the libp2p ping service. ```bash npm install multiaddr @libp2p/ping ``` -------------------------------- ### Test Metadata Example Source: https://libp2p.io/docs/write-a-perf-test-app The `perf/lib/run-signle-test.sh` script adds metadata to the results file. This example shows the format of the metadata, including test details, transport, and status. ```yaml test: rust-v0.56 x rust-v0.56 (quic-v1) dialer: rust-v0.56 listener: rust-v0.56 transport: quic-v1 secureChannel: null muxer: null status: pass ``` -------------------------------- ### Install Dependencies on macOS Source: https://libp2p.io/docs/local-testing-strategies Installs required tools using Homebrew and verifies the bash version. Includes cloning the unified-testing repository and running a check with the Homebrew bash executable. ```bash # Using Homebrew brew install bash docker yq git # Start Docker Desktop open -a Docker # Verify bash version (must be 4.0+) /opt/homebrew/bin/bash --version # Clone unified-testing git clone https://github.com/libp2p/unified-testing.git cd unified-testing # Run with Homebrew bash (macOS ships with bash 3.x) /opt/homebrew/bin/bash perf/run.sh --check-deps ``` -------------------------------- ### Install Yamux Stream Multiplexer Source: https://libp2p.io/docs/getting-started-javascript Install the Yamux stream multiplexer package using npm. This is a recommended step for efficient connection management in libp2p. ```bash npm install @chainsafe/libp2p-yamux ``` -------------------------------- ### Install Dependencies on Linux (Debian 13) Source: https://libp2p.io/docs/local-testing-strategies Installs necessary packages like bash, docker, git, and yq on Debian-based systems. Includes steps for adding the user to the docker group and cloning the unified-testing repository. ```bash # Ubuntu/Debian sudo apt update sudo apt install -y bash docker.io git curl patch wget zip unzip # Install yq sudo wget https://github.com/mikefarah/yq/releases/download/v4.35.1/yq_linux_amd64 \ -O /usr/local/bin/yq && sudo chmod +x /usr/local/bin/yq # Install Docker Compose v2 (if not included with docker.io) sudo apt install docker-compose-plugin # Add user to docker group sudo usermod -aG docker $USER newgrp docker # Clone unified-testing git clone https://github.com/libp2p/unified-testing.git cd unified-testing ``` -------------------------------- ### Dependency Checker Output Source: https://libp2p.io/docs/local-testing-strategies Example output from the `./run.sh --check-deps` command, showing successful verification of versioned tools, required utilities, Docker services, and optional dependencies. ```text ╔╦╦╗ ╔═╗ ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ║╠╣╚╦═╬╝╠═╗ ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ═══════════════════════ ║║║║║║║╔╣║║ ════════════════════════ ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ ╚╩╩═╣╔╩═╣╔╝ ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ ╚╝ ╚╝ ╲ Checking dependencies... ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ → Checking versioned tools... → bash... [OK] 5.2 → docker... [OK] 29.1.5 → yq... [OK] 4.48.1 → git... [OK] 2.47.3 → Checking required utilities... → patch... [OK] → wget... [OK] → zip... [OK] → unzip... [OK] → cut... [OK] → bc... [OK] → sha256sum... [OK] → timeout... [OK] → flock... [OK] → tar... [OK] → gzip... [OK] → awk... [OK] → sed... [OK] → grep... [OK] → sort... [OK] → head... [OK] → tail... [OK] → wc... [OK] → tr... [OK] → paste... [OK] → cat... [OK] → mkdir... [OK] → cp... [OK] → mv... [OK] → rm... [OK] → chmod... [OK] → find... [OK] → xargs... [OK] → basename... [OK] → dirname... [OK] → mktemp... [OK] → date... [OK] → sleep... [OK] → uname... [OK] → hostname... [OK] → ps... [OK] → Checking Docker services... → docker daemon... [OK] → docker compose... [OK] using 'docker compose' → Checking optional dependencies... → gnuplot... [OK] 6.0 → pandoc... [OK] ✓ All required dependencies are satisfied ``` -------------------------------- ### WebSocket Upgrade Request Example Source: https://libp2p.io/docs/browser-connectivity This is an example of an HTTP request used to initiate a WebSocket upgrade. The browser sends this request to the server to establish a WebSocket connection. ```http GET /chat HTTP/1.1 Host: server.example.com Upgrade: websocket Connection: Upgrade ``` -------------------------------- ### Example Generated docker-compose.yaml Source: https://libp2p.io/docs/write-a-transport-test-app This is an example of a docker-compose.yaml file generated by the transport test suite. It defines the services for a listener and a dialer, including their Docker images, container names, network configurations, and environment variables. ```yaml name: rust-v0_56_x_rust-v0_56__quic-v1_ networks: transport-network: external: true services: listener: image: transport-rust-v0.56 container_name: rust-v0_56_x_rust-v0_56__quic-v1__listener init: true networks: - transport-network environment: - IS_DIALER=false - REDIS_ADDR=transport-redis:6379 - TEST_KEY=a5b50d5e - TRANSPORT=quic-v1 - LISTENER_IP=0.0.0.0 - DEBUG=false dialer: image: transport-rust-v0.56 container_name: rust-v0_56_x_rust-v0_56__quic-v1__dialer depends_on: - listener networks: - transport-network environment: - IS_DIALER=true - REDIS_ADDR=transport-redis:6379 - TEST_KEY=a5b50d5e - TRANSPORT=quic-v1 - LISTENER_IP=0.0.0.0 - DEBUG=false ``` -------------------------------- ### Run Libp2p Node Without Arguments Source: https://libp2p.io/docs/getting-started-javascript Execute the script without any arguments to start a libp2p node that listens for incoming connections and logs its listening addresses. This is the first step in establishing peer communication. ```bash > node src/index.js ``` -------------------------------- ### Verify Dependencies with run.sh Source: https://libp2p.io/docs/local-testing-strategies Executes the dependency checker script for the unified-testing framework. This command verifies that all necessary tools and services are correctly installed and configured. ```bash cd perf ./run.sh --check-deps ``` -------------------------------- ### Configure Bootstrap Peer for Relay Source: https://libp2p.io/docs/webrtc-browser-connectivity Configure js-libp2p to automatically connect to the relay peer by adding it to the bootstrap list. Replace the example multiaddr with your actual relay multiaddr. ```javascript import { bootstrap } from '@libp2p/bootstrap' const libp2p = await createLibp2p({ addresses: { listen: [ '/p2p-circuit', ], }, transports: [ webSockets(), webTransport(), webRTC(), circuitRelayTransport(), ], connectionEncrypters: [noise()], streamMuxers: [yamux()], connectionGater: { // Allow private addresses for local testing denyDialMultiaddr: async () => false, }, peerDiscovery: [ bootstrap({ // replace with your relay multiaddr list: ['/ip4/127.0.0.1/tcp/9001/ws/p2p/12D3KooWQtCgYCZ7JZQoe7Ao6KP5CDMnmEiURqMoarfBgJwbnCPQ'], }), ], services: { identify: identify(), }, }) ``` -------------------------------- ### Example Generated Docker Compose Configuration Source: https://libp2p.io/docs/write-a-perf-test-app This configuration defines the services, networks, and environment variables for running libp2p performance tests using Docker Compose. It sets up listener and dialer services with specified images and network configurations. ```yaml name: rust-v0_56_x_rust-v0_56__quic-v1_ networks: perf-network: external: true services: listener: image: perf-rust-v0.56 container_name: rust-v0_56_x_rust-v0_56__quic-v1__listener init: true networks: - perf-network environment: - IS_DIALER=false - REDIS_ADDR=perf-redis:6379 - TEST_KEY=a5b50d5e - TRANSPORT=quic-v1 - LISTENER_IP=0.0.0.0 dialer: image: perf-rust-v0.56 container_name: rust-v0_56_x_rust-v0_56__quic-v1__dialer depends_on: - listener networks: - perf-network environment: - IS_DIALER=true - REDIS_ADDR=perf-redis:6379 - TEST_KEY=a5b50d5e - TRANSPORT=quic-v1 - UPLOAD_BYTES=1073741824 - DOWNLOAD_BYTES=1073741824 - UPLOAD_ITERATIONS=null - DOWNLOAD_ITERATIONS=null - LATENCY_ITERATIONS=100 - DURATION=20 ``` -------------------------------- ### Create and Initialize npm Project Source: https://libp2p.io/docs/getting-started-javascript Create a new directory for your project, initialize it as an npm project, and set the entry point to src/index.js. ```bash mkdir hello-libp2p mkdir hello-libp2p/src cd hello-libp2p git init . npm init es6 ``` -------------------------------- ### Circuit Relay Multiaddress Example Source: https://libp2p.io/docs/addressing This multiaddress demonstrates a circuit relay setup, combining multiple peer identities and transport addresses. ```plaintext /ip4/198.51.100.0/tcp/4242/p2p/QmRelay/p2p-circuit/p2p/QmRelayedPeer ``` -------------------------------- ### Initialize Go Module Source: https://libp2p.io/docs/getting-started-go Create a new directory and initialize it as a Go module. This sets up the project structure for your libp2p application. ```bash mkdir -p /tmp/go-libp2p-tutorial cd /tmp/go-libp2p-tutorial go mod init github.com/user/go-libp2p-tutorial ``` -------------------------------- ### Navigate to Project Directory Source: https://libp2p.io/docs/webrtc-browser-connectivity Change to the cloned repository directory to access project files. ```bash cd libp2p-webrtc-guide ``` -------------------------------- ### List Available Implementations Source: https://libp2p.io/docs/local-testing-strategies Displays a list of all available implementations that can be used for testing. ```bash # List available implementations ./run.sh --list-images ``` -------------------------------- ### Import go-libp2p Module Source: https://libp2p.io/docs/getting-started-go Add the go-libp2p module to your project dependencies. This command fetches the necessary library. ```bash go get github.com/libp2p/go-libp2p ``` -------------------------------- ### Run go-libp2p Relay Source: https://libp2p.io/docs/webrtc-browser-connectivity Compile and run the go-libp2p relay from the go-relay folder. The output will display the PeerID and listening multiaddrs. ```bash go run . ``` -------------------------------- ### Import libp2p Packages Source: https://libp2p.io/docs/getting-started-go Import necessary packages for libp2p functionality, including the core library and the ping protocol. ```go import ( ... "github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p/p2p/protocol/ping" ) ``` -------------------------------- ### Performance Test Results Schema Example Source: https://libp2p.io/docs/write-a-perf-test-app This is an example of a valid results report that your test application must print to stdout in YAML format. It includes measurements for upload, download, and latency tests, along with raw samples. ```yaml # Measurements from dialer upload: iterations: 10 min: 2.04 q1: 2.05 median: 2.06 q3: 2.06 max: 2.07 outliers: [2.02] samples: [2.02, 2.04, 2.05, 2.05, 2.05, 2.06, 2.06, 2.06, 2.06, 2.07] unit: Gbps download: iterations: 10 min: 2.05 q1: 2.06 median: 2.06 q3: 2.07 max: 2.08 outliers: [] samples: [2.05, 2.05, 2.06, 2.06, 2.06, 2.06, 2.07, 2.07, 2.08, 2.08] unit: Gbps latency: iterations: 100 min: 0.523 q1: 0.609 median: 0.634 q3: 0.671 max: 0.754 outliers: [0.473, 0.784, 0.803] samples: [0.473, 0.523, 0.551, 0.572, 0.576, 0.577, 0.581, 0.584, 0.589, 0.590, 0.590, 0.592, 0.593, 0.593, 0.594, 0.595, 0.598, 0.598, 0.602, 0.603, 0.604, 0.606, 0.606, 0.607, 0.607, 0.610, 0.610, 0.611, 0.611, 0.612, 0.614, 0.615, 0.616, 0.616, 0.617, 0.618, 0.619, 0.619, 0.621, 0.623, 0.625, 0.625, 0.625, 0.625, 0.626, 0.626, 0.627, 0.627, 0.629, 0.633, 0.635, 0.635, 0.636, 0.637, 0.638, 0.639, 0.640, 0.640, 0.640, 0.641, 0.645, 0.647, 0.647, 0.651, 0.651, 0.651, 0.654, 0.654, 0.660, 0.660, 0.660, 0.661, 0.667, 0.667, 0.670, 0.673, 0.674, 0.676, 0.677, 0.681, 0.684, 0.687, 0.690, 0.691, 0.692, 0.695, 0.695, 0.699, 0.700, 0.704, 0.707, 0.709, 0.714, 0.714, 0.720, 0.733, 0.740, 0.754, 0.784, 0.803] unit: ms ``` -------------------------------- ### Example IPv4 and UDP Multiaddress Source: https://libp2p.io/docs/addressing This multiaddress combines IPv4 addressing with a UDP port. ```plaintext /ip4/192.0.2.0/udp/1234 ``` -------------------------------- ### Rebuild and Run Configured Node Source: https://libp2p.io/docs/getting-started-go Recompile the application after configuring the listen address and run it. The output will show the explicitly configured listening address. ```bash $ go build -o libp2p-node $ ./libp2p-node Listening addresses: [/ip4/192.0.2.0/tcp/2000] ``` -------------------------------- ### Compare Multiple Implementation Versions Source: https://libp2p.io/docs/local-testing-strategies Run tests that compare two or more libp2p implementation versions. ```bash ./run.sh --impl-select "rust-v0.55|rust-v0.56" ``` -------------------------------- ### Example Peer Identity Multiaddress Source: https://libp2p.io/docs/addressing This multiaddress identifies a libp2p node using its Peer ID. ```plaintext /p2p/QmYyQSo1c1Ym7orWxLYvCrM2EmxFTANf8wXmmE7DWjhx5N ``` -------------------------------- ### Example Peer ID String Source: https://libp2p.io/docs/peers A Peer ID is represented as a base58-encoded multihash string. This format is standard for libp2p. ```text QmYyQSo1c1Ym7orWxLYvCrM2EmxFTANf8wXmmE7DWjhx5N ``` -------------------------------- ### Example TCP/IP Multiaddress Source: https://libp2p.io/docs/listen-and-dial This multiaddress specifies an IPv4 address and a TCP port. It is a common format for network communication. ```plaintext /ip4/198.51.100.0/tcp/6543 ``` -------------------------------- ### Import Peer and Multiaddr Packages Source: https://libp2p.io/docs/getting-started-go Import packages for handling peer information and multiaddr for network address manipulation. ```go import ( ... "github.com/libp2p/go-libp2p" peerstore "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/p2p/protocol/ping" multiaddr "github.com/multiformats/go-multiaddr" ) ``` -------------------------------- ### Clone and Checkout Implementation Repository Source: https://libp2p.io/docs/local-testing-strategies Clones the source repository for an implementation and checks out a specific version to prepare for local modifications. ```bash cd images/rust/v0.55 git clone https://github.com/libp2p/rust-libp2p . git checkout v0.55.0 ``` -------------------------------- ### Test Metadata Example Source: https://libp2p.io/docs/write-a-hole-punch-test-app The hole-punch script prepends metadata to the dialer's stdout results. This includes test configuration and status. ```yaml test: rust-v0.56 x rust-v0.56 (tcp, noise, yamux) [dr: linux, rly: rust-v0.56, lr: linux] dialer: rust-v0.56 listener: rust-v0.56 dialerRouter: linux listenerRouter: linux relay: rust-v0.56 transport: tcp secureChannel: noise muxer: yamux status: pass ``` -------------------------------- ### Display Go Module File Source: https://libp2p.io/docs/getting-started-go View the contents of the go.mod file after initialization. It shows the module name and the Go version being used. ```bash $ cat go.mod module github.com/user/go-libp2p-tutorial go 1.20 ``` -------------------------------- ### Example Multiaddress with PeerId Source: https://libp2p.io/docs/listen-and-dial This multiaddress includes a PeerId, which uniquely identifies the remote peer. This is used for establishing secure communication channels. ```plaintext /ip4/192.0.2.0/tcp/4321/p2p/QmcEPrat8ShnCph8WjkREzt5CPXF2RwhYxYBALDcLC1iV6 ``` -------------------------------- ### Initialize libp2p Node with Custom Ping Handler Source: https://libp2p.io/docs/getting-started-go Configure a libp2p node to listen on a random local TCP port and disable the default ping protocol to manually set up a custom ping service. ```go func main() { ... // start a libp2p node that listens on a random local TCP port, // but without running the built-in ping protocol node, err := libp2p.New( libp2p.ListenAddrStrings("/ip4/192.0.2.0/tcp/0"), libp2p.Ping(false), ) if err != nil { panic(err) } // configure our own ping protocol pingService := &ping.PingService{Host: node} node.SetStreamHandler(ping.ID, pingService.PingHandler) ... } ``` -------------------------------- ### Listener Environment Variable Example Source: https://libp2p.io/docs/write-a-transport-test-app When running in listener mode, the test application receives specific environment variables. LISTENER_IP is always set to '0.0.0.0' to bind to all interfaces. ```bash LISTENER_IP=0.0.0.0 ``` -------------------------------- ### Configure and Run Libp2p Ping Pong Service Source: https://libp2p.io/docs/getting-started-javascript This script sets up a libp2p node with TCP transport, noise encryption, and yamux stream multiplexing. It includes the ping service and can optionally ping a remote peer provided as a command-line argument. ```javascript import process from 'node:process' import { createLibp2p } from 'libp2p' import { tcp } from '@libp2p/tcp' import { noise } from '@chainsafe/libp2p-noise' import { yamux } from '@chainsafe/libp2p-yamux' import { multiaddr } from 'multiaddr' import { ping } from '@libp2p/ping' const node = await createLibp2p({ addresses: { // add a listen address (localhost) to accept TCP connections on a random port listen: ['/ip4/127.0.0.1/tcp/0'] }, transports: [tcp()], connectionEncrypters: [noise()], streamMuxers: [yamux()], services: { ping: ping({ protocolPrefix: 'ipfs', // default }), }, }) // start libp2p await node.start() console.log('libp2p has started') // print out listening addresses console.log('listening on addresses:') node.getMultiaddrs().forEach((addr) => { console.log(addr.toString()) }) // ping peer if received multiaddr if (process.argv.length >= 3) { const ma = multiaddr(process.argv[2]) console.log(`pinging remote peer at ${process.argv[2]}`) const latency = await node.services.ping.ping(ma) console.log(`pinged ${process.argv[2]} in ${latency}ms`) } else { console.log('no remote peer address given, skipping ping') } const stop = async () => { // stop libp2p await node.stop() console.log('libp2p has stopped') process.exit(0) } process.on('SIGTERM', stop) process.on('SIGINT', stop) ```