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

ssb-conn-hub

v1.2.1

Published

Module that manages active connections to SSB peers

Downloads

303

Readme

ssb-conn-hub

Module that manages active connections to peers. For use with the SSB CONN family of modules.

Visual metaphor: a network switch managing connections to other peers, capable of starting or stopping connections.

hub.png

Usage

Prerequisites:

  • Requires Node.js 6.5 or higher
  • Requires secret-stack@^6.3.0

This module is only used to create an SSB CONN plugin, not used directly by applications. A ConnHub instance should be available on the CONN plugin, with the following API:

API

  • connHub.connect(address, data?): connect to a peer known by its address (string, must conform to the multiserver address convention). The second argument data is optional, and allows you to attach additional metadata, that can be read later when this connection data is retrieved. Returns a Promise, with the three possible outcomes:
    • Resolves with an RPC object that represents the successfully connected peer
    • Resolves with false when the connect was unnecessary, therefore not performed
    • Rejects with an error indicating why the connection failed
  • connHub.disconnect(address): disconnect from a peer known by its address (string, must conform to the multiserver address convention). Returns a Promise, with the three possible outcomes:
    • Resolves with true when disconnected successfully
    • Resolves with false when the disconnect was unnecessary, therefore not performed
    • Rejects with an error indicating why the disconnection failed
  • connHub.update(address, data): update the metadata of a peer currently in connection with us, where the peer is known by its address and the new data is in data. If the peer is not registered in ConnHub, this method performs no operations and returns false. Returns true if the update has succeeded.
  • connHub.reset(): closes all connections, basically resetting this instance as if it had just been started
  • connHub.entries(): returns a new Iterator object that gives [address, data] pairs, where data has the state and key of the peer
  • connHub.liveEntries(): returns a pull-stream that emits an array of entries (like connHub.entries(), but an array instead of an Iterator) everytime there are updates to connections.
  • connDB.listen(): returns a pull stream that notifies of connection events, as an object {type, address, key, details} where:
    • type is either 'connecting', 'connecting-failed', 'connected', 'disconnecting', 'disconnecting-failed', 'disconnected'
    • address is the original address used for connecting
    • (maybe present) key is the cryptographic public id
    • (maybe present, see below) details is an object with additional info
      • Present when when type === 'connected' and contains details.rpc (the MuxRPC object for the remote peer) and details.isClient (boolean indicating whether we are the client)
      • Does not exist when type === 'disconnecting'
      • Does not exist when type === 'disconnected'
      • Does not exist when type === 'connecting'
      • Present when type === 'connecting-failed' and details is the error object for the connection failure
      • Present when type === 'disconnecting-failed' and details is the error object for the connection failure
  • connHub.getState(address): returns undefined if the peer for that address is disconnected, otherwise returns one of 'connecting', 'connected', or 'disconnecting'
  • connHub.close(): terminates any used resources and listeners, in preparation to destroy this instance.

Recipes

How can I get the RPC object for the remote peer connected with me?

Assuming you're access ConnHub from ssb-conn, listen to connection events on ConnHub, filter for 'connected' events, and they should contain the RPC object on the event's details field:

pull(
  ssb.conn.hub().listen(),
  pull.filter(event => event.type === 'connected'),
  pull.drain(event => {
    const rpc = event.details.rpc
    // `rpc` object has public methods such as `rpc.createHistoryStream()`
  })
)

License

MIT