Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including ipfs-swarm-bind-shim with all npm packages installed. Try it out:

var ipfsSwarmBindShim = require("ipfs-swarm-bind-shim")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

ipfs-swarm-bind-shim v0.1.0

A poor mans shim for a missing swarm.bind command

ipfs-swarm-bind-shim

Build Status dependencies Status JavaScript Style Guide

A poor mans shim for a missing swarm.bind command

Stay connected to a minimum number of peers. Periodically checks for connectivity and if not connected to the minimum it'll (re)connect.

⚠️ No tests yet! Might not even work!

Install

npm install ipfs-swarm-bind-shim

Usage

const swarmBind = require('ipfs-swarm-bind-shim')

Example

// addresses of peers we want to stay connected to
// n.b. must include peer ID!
const addrs = [
  '/ip4/127.0.0.1/tcp/63372/p2p/QmXGb4JumMVSFc66Fz6q3XiUQbGdyU4WCHjrLykQD9p8SQ',
  '/ip4/127.0.0.1/tcp/63362/p2p/QmeqriW5H3G7KBo41U3pTyNdCq5iE19SH4oVeuxAQ3iHz2',
  '/ip4/127.0.0.1/tcp/63391/p2p/QmbtWfdGpeT9YVWZ4gajg2c4hA1UVrgqiFuLF2CgJmGv23'
]

const cancel = await swarmBind(ipfs, addrs, {
  minConnections: 1, // minimum number of peers from the list this node should be connected to (default addrs.length)
  checkInterval: 1000 * 60 // (ms) time between connectivity checks
})

// ipfs will now be connected to minConnections peers
// and will monitor and re-connect.

// later...

cancel() // unbind (stop checking and connecting)

Contribute

Feel free to dive in! Open an issue or submit PRs.

License

MIT © Alan Shaw

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free