Manage swarming hypercores by keeping track of when to start and stop swarming them.
For example, requesting a hypercore twice and unrequesting it once will mean it remains requested. Likewise, requesting and serving a hypercore and later unrequesting it will mean it remains served.
npm i swarm-manager
See example
Create a new swarm manager.
Note: the Hyperswarm's lifecycle is managed by the swarm manager.
Note: this module is not concerned with setting up replication. You will need to set up an on('connection')
handler on the passed-in swarm
Get a list of all keys joined as either client or server.
Get a list of all requested keys (joined as client). Does not include keys also joined as server.
Get a list of all served keys.
Note: the discovery key can be in any format (buffer, hex or z32).
Increment the serve counter for the given discovery key. If it was 0 before, the core is now served.
Increment the request counter for the given discovery key.
If it was 0 before, the core is now requested.
Note: if the core was already being served, nothing changes (serving already implies it is requested)
Decrement the request counter for the given discovery key. If it is now 0 and the serve counter is 0 too, then the core will no longer be requested.
Decrement the serve counter for the given discovery key. If it is now 0, the core is no longer served.
Note that even when no longer served, the core will remain requested if its request counter is higher than 0.
Destroys the swarm and cleans up.