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.
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:
Same as ssb-ebt's request method. priority
is optional and defaults to 0. The higher the number, the sooner it will be replicated.
Sets a new mode change threshold.
Sets a new maximum number of connections allowed when in limited mode.
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.
With npm installed, run
$ npm install ssb-replication-limiter
This project is funded by a grant from staltz for the manyverse project.
MIT