ssb-replication-limiter

1.0.5 • Public • Published

Build Status

ssb-replication-limiter

Limit and prioritise ebt replication for ssb.

ssb-ebt only exposes an api to stop or start replication of a feed. This module enhances it so you can control the maximum number of simultaneous downloads and prioritise who gets replicated first.

The limiter has two modes: unlimited and limited. In unlimited mode the module doesn't really do anything, it's just ordinary ebt replication.

In limited mode, only a certain number of feeds are allowed to be replicating at once.

This module tracks how far behind all feeds are. If your local copies are a long way behind then you have to do a lot of downloading to do. If a feed is more than threshold (modeChangeThreshold) behind, the module changes mode to limited mode.

In limited mode, only a set number (maxNumConnections) of feeds will be replicated simultaneously.

It's also possible to prioritise which feeds are replicated first in limited mode. See the third argument of the request function.

API

Init

var ReplicationLimiter = require('ssb-replication-limiter')
var replicationLimiter = ReplicationLimiter(opts)

Takes an opts object of shape:

{
  peerStatus: <function> (required)
  request: <function> (required)

  maxNumConnections: <num>,
  modeChangeThreshold: <num>,
}

replicationLimiter has four methods:

replicationLimiter.request(feedId, isReplicationEnabled, [priority])

Same as ssb-ebt's request method. priority is optional and defaults to 0. The higher the number, the sooner it will be replicated.

replicationLimiter.setModeChangeThreshold(threshold)

Sets a new mode change threshold.

replicationLimiter.setMaxNumConnections(max)

Sets a new maximum number of connections allowed when in limited mode.

replicationLimiter.isReplicationEnabled()

isReplicationEnabled is an observable

Sets listener-function as a new observer of isReplicationEnabled

listener-function will be called with a boolean when the mode changes.

Install

With npm installed, run

$ npm install ssb-replication-limiter

Acknowledgments

This project is funded by a grant from staltz for the manyverse project.

See Also

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.5
    1
    • latest

Version History

Package Sidebar

Install

npm i ssb-replication-limiter

Weekly Downloads

1

Version

1.0.5

License

MIT

Unpacked Size

34.7 kB

Total Files

14

Last publish

Collaborators

  • pietgeursen