npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

swarm-manager

v1.0.2

Published

Manage swarming hypercores

Downloads

72

Readme

Swarm Manager

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.

Install

npm i swarm-manager

Usage

See example

API

const swarmManager = new SwarmManager(swarm)

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

Properties

swarmManager.keys

Get a list of all keys joined as either client or server.

swarmManager.requestedKeys

Get a list of all requested keys (joined as client). Does not include keys also joined as server.

swarmManager.servedKeys

Get a list of all served keys.

Methods

Note: the discovery key can be in any format (buffer, hex or z32).

swarmManager.serve(discoveryKey)

Increment the serve counter for the given discovery key. If it was 0 before, the core is now served.

swarmManager.request(discoveryKey)

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)

await swarmManager.unrequest(discoveryKey)

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.

await swarmManager.unserve(discoveryKey)

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.

await swarmManager.close()

Destroys the swarm and cleans up.