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

@boranseckin/chord

v1.2.4

Published

An implementation of Chord network using TypeScript

Downloads

11

Readme

chord

npm (scoped) Dependencies Travis (.com) Docker Cloud Build Status Codecov

A Scalable Peer-to-peer Lookup Service for Internet Applications

This is an implementation of Chord network explained in this paper using TypeScript. All the communication between nodes is handled using UDP sockets and the code is written asynchronously using promises to facilitate the high traffic of requests. This project only uses pure NodeJS and is dependency-free.

Demo Video

Network

In the network, nodes constantly communicate with each other to make sure that their version of the network is up to date. Moreover, Chord network requires nodes to execute functions for other nodes remotely. This remote execution is essential for the network since every node only knows a few other nodes and they require other nodes to perform actions like lookups where they cannot reach.

Every node uses an IPv4 address and a port number to communicate with other nodes. All the messages are serialized and sent over UDP sockets. When a node sends a new message, it wraps it into a promise and passes a promise id that corresponds to the resolve/reject functions of the promise with the message. The receiver then can respond to this message using the supplied promise id and whether the response is positive or negative, the promise can be resolved or rejected. With this method, the network module never gets blocked and multiple messages can be sent to different nodes without waiting for a response.

Most of the functions are written to handle both local and remote execution. If a function was called with a remote executer argument, the function gets forwarded to that executer and a promise is returned instead. Once the remote node finishes the execution, it sends the return value back to the original node and the promise gets resolved (or rejected) with that value.

Visualizer

To see the network clearly and admire its dynamic structure, a different module is built called @boranseckin/chord-visualizer. Visualizer class inherits the node class to seamlessly send/receive messages. It is not a part of the network and it only uses the getInfo command to gather information about nodes.

Collected data is shown as a graph on a simple web page that is periodically updated to reflect the changes on the network. The visualizer requires an anchor node to start crawling a network. If the anchor node is lost, it will try to use a previously-found node to replace its place.

Docker

After a long struggle, this project is fully dockerized. Both boranseckin/chord and boranseckin/chord-visualizer can be run as standalone containers. Additionally, docker-compose file can be used to create and scale a fully functional Chord network (including a visualizer). When scaling, only make copies of the node service. There must be at most one flare and one visualizer services active at all times since they are staticly binded to specific ports.

Problems and Solutions

To create the network, a node must first enter and act as a flare to the rest.

Using the boranseckin/chord image create two different services. The first one (flare) uses a static configuration and becomes the flare. The second one (node) depends on the first one and scales the network using the configuration of the flare.

When adding a new node (automatically scaling), its IPv4 address is not known yet. So it can't be supplied as an environmental variable.

Do not specifiy the address and let the node find figure it out instead using os module. This is a workaround and only works if the interface is called eth0 like it is in docker containers.

NodeJS dgram module does not like Dynamic DNS as an address.

In a custom network, containers can use their names as DDNS to communicate with each other. Since dgram module requires IPv4 addresses, use dns module to lookup IPv4 equivalent of the DDNS.

Each node requires a unique ID but used IDs are not known during scaling.

When using docker-compose each new container is assigned a unique id as an extension to its name. However, for some reason, these names are not easily accessible from inside the container. To get container information, Docker Engine API must be exposed to each node. During startup, a shell script is run to digest the data and export an ID for the node. Exposing the API is sub-optimal but a necessity in this case.

References

Author

  • Boran Seckin

License

This project is licensed under the MIT License - see the LICENSE.md file for details.