awmuncy / libp2p-bundle

Basic libp2p bundle with settings that match js-ipfs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

libp2p-bundle

GitHub license GitHub package.json version npm (scoped) Release standard-readme compliant

Tests

Basic libp2p bundle with settings that match js-ipfs.

Table of Contents

Background

This package provides a zero-config setup to make it easy to include a fully-configured libp2p host in any application. It is almost directly copied from js-ipfs, so you can be confident the settings are compatible. It also allows more nuanced access to the underlying libp2p settings.

Install

npm i @nullify/libp2p-bundle

Usage

import create from "@nullify/libp2p-bundle";

const run = async () => {
  const node = await create({
    multiaddrs: ["/ip4/0.0.0.0/tcp/4007", "/ip4/0.0.0.0/tcp/4008/ws"],
  });

  const p = new Promise((resolve) => {
    // Promise resolves on first discovered peer
    node.on("peer:discovery", (peerId) => {
      resolve(peerId);
    });
  });

  await node.start();

  const listenAddrs = node.transportManager.getAddrs();
  console.log("listening on: ", listenAddrs);

  const peerId = await p;
  console.log(`Discovered: ${peerId.toB58String()}`);
  await node.stop();
  process.exit();
};

run();

API

Functions

create(options)Promise.<Libp2p>

Typedefs

Repo : object
Libp2pConfig : module:libp2p~Libp2pConfig
Libp2p : module:libp2p
Options : object

create(options) ⇒ Promise.<Libp2p>

Kind: global function
Returns: Promise.<Libp2p> -

A properly configured libp2p host.

ParamTypeDescription
optionsOptions

The set of options to control bundle creation.

Repo : object

Kind: global typedef
Properties

NameTypeDescription
[datastore]module:interface-datastore~Datastore

Input datastore.

[keys]module:interface-datastore~Datastore

Input keystore

Libp2pConfig : module:libp2p~Libp2pConfig

Kind: global typedef

Libp2p : module:libp2p

Kind: global typedef

Options : object

Kind: global typedef
Properties

NameTypeDescription
[options]any

IPFS options.

[peerId]PeerId

Input PeerID object.

[multiaddrs]Array.<string>

Set of multiaddrs to listen on.

[repo]Repo

Input repo config.

[keychainConfig]Object

Input keychain config.

[config]Libp2pConfig

Libp2p options.

Maintainers

@carsonfarmer

Contributing

PRs accepted.

Small note: If editing the README, please conform to the standard-readme specification.

License

MIT © 2021 Carson Farmer

About

Basic libp2p bundle with settings that match js-ipfs

License:MIT License


Languages

Language:JavaScript 100.0%