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

hashnet

v0.3.7

Published

Multi-hop rpc router

Downloads

21

Readme

hashnet

Multi-hop rpc router

Install

npm install --save hashnet

What

Hashnet (although the name was poorly chosen at the start of the project) handles routing of rpc calls within an overlay network.

What not

  • Peer discovery
  • Service discovery (maybe procedure listing in the future?)
  • Gateway into different networks

API

To load the core element of this package, include the following code:

const {Peer} = require('hashnet');

new Peer(options)

Returns a new peer which can act as a node within the network.

Options: | Name | Type | Default | Description | | -------------- | ------ | ------- | ---------------------------------------------------------------- | | id | string | null | Set the ID of the peer instead of generating one | | interval | number | 5000 | Interval to check connections with | | timeout | number | 2000 | Maximum time in milliseconds a procedure call is allowed to take | | maxConnections | number | 15 | Maximum amount of connections the peer is allowed to manage | | routeLabelSize | number | 32 | Route label size included in packages (must match the network) |

peer.addProcedure({ name, handler })

Adds a procedure handler locally. If multiple handlers are registered under the same name, the return value of the earlier handler is fed into the next handler.

Options: | Name | Type | Default | Description | | --------------------- | -------- | --------- | -------------------------------------------------- | | name | string | undefined | Name of the procedure to register under | | handler(data,message) | function | undefined | Function to call when the procedure is called upon |

peer.removeProcedure({ name, handler })

Removes the given handler from the named handler list.

Options: | Name | Type | Default | Description | | --------------------- | -------- | --------- | -------------------------------------------------- | | name | string | undefined | Name of the procedure to remove the handler from | | handler(data,message) | function | undefined | Function to not call anymore |

peer.addConnection(socket)

Adds a managed connection to the list of known connections.

The given socket must follow the same API as defined by simple-peer

peer.callProcedure({ peerId, procedure, data, getResponse })

Call a (remote) procedure within the network on the peer having the given peerId.

Options: | Name | Type | Default | Description | | ----------- | ------- | ------- | ------------------------------------------------- | | peerId | string | null | null = self ; The peer to call the procedure on | | procedure | string | null | Which procedure to call | | data | mixed | null | Data to pass into the procedure handler | | getResponse | boolean | true | Whether or not to retrieve the handler's response |

peer.shutdown()

Shut down the whole peer, closing all connections.

Internal API

The internal API is not intended for application use. This is documented for use within connection brokers, plugins & other non-application purposes.

peer._callProcedure({ routeLabel, connection, socket, procedure, data, getResponse })

Call a remote procedure, sending the request over the given socket with the given routeLabel.

Options: | Name | Type | Default | Description | | ----------- | ----------------- | --------- | ------------------------------------------------- | | routeLabel | string, BitBuffer | undefined | Which hops to follow towards the targetted peer | | connection | n/a | undefined | Internal representation of a connection | | socket | simple-peer | undefined | Socket to send the call over | | procedure | string | undefined | Which procedure to call on the targetted peer | | data | mixed | undefined | Data to pass into the handler of the procedure | | getResponse | boolean | true | Whether or not to retrieve the handler's response |

_findPeer(peerId)

Find the path to a peer with the given peer id.

Options: | Name | Type | Default | Description | | ------ | -------------- | --------- | ---------------------------------------------------- | | peerId | string, Buffer | undefined | A hex string or buffer representing the peer to find |