1.0.0 • Published 2 years ago

@savid/libp2p-peeper v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@savid/libp2p-peeper

Discover libp2p peers with the Node Discovery Protocol v5.

This package is adapted from the @chainsafe/discv5 project.

Requirements

  • NodeJS v18+
  • ESM only

Install

npm install --save @savid/libp2p-peeper

Usage

Add bootnodes to begin;

import peeper from '@savid/libp2p-peeper';

const bootnodes = [
  'enr:-Iq4QMCTfIMXnow27baRUb35Q8iiFHSIDBJh6hQM5Axohhf4b6Kr_cOCu0htQ5WvVqKvFgY28893DHAg8gnBAXsAVqmGAX53x8JggmlkgnY0gmlwhLKAlv6Jc2VjcDI1NmsxoQK6S-Cii_KmfFdUJL2TANL3ksaKUnNXvTCv1tLwXs0QgIN1ZHCCIyk',
];

try {
  for await (const { error, enr } of peeper({ bootnodes })) {
    if (error) throw error;
    // https://ethereum.org/en/developers/docs/networking-layer/network-addresses/#enr
    if (enr) console.log(enr);
  }
} catch (error) {
  console.error(error);
}

API

async function* peeper(options: {
  // list of EIP-778: Ethereum Node Records (ENR) bootnodes
  bootnodes: string[];
  // min number of candidate peers to retrieve from DNS records when attempting to discover new nodes
  minConnections?: number;
  // max number of candidate peers to retrieve from DNS records when attempting to discover new nodes
  maxConnections?: number;
}): AsyncGenerator<{
  enr?: string | undefined;
  error?: Error | undefined;
}>;

License

MIT