Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

ipfs-swarm-bind-shim

0.1.0 • Public • Published

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

Install

npm i ipfs-swarm-bind-shim

DownloadsWeekly Downloads

2

Version

0.1.0

License

MIT

Unpacked Size

5.72 kB

Total Files

5

Last publish

Collaborators

  • avatar