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

njs-blocklist-merger

v0.1.4

Published

an HTTP server that downloads blocklists in p2p format and merges them on demand

Downloads

8

Readme

njs-blocklist-merger

An HTTP server written with NodeJS that downloads blocklists in p2p format and merges them on demand.

Introduction

Many network-related programs support blocking ranges of IP addresses from a text file that is periodically downloaded from a web server. Unfortunately, there are scenarios in which the desired IP ranges come from separated sources on the Internet, and some programs only allow for one source url to update their IP ranges.

njs-blocklist-merger is an HTTP server that can download multiple IP range files in p2p format (see http://sourceforge.net/p/peerguardian/wiki/dev-blocklist-format-p2p/) from the web simultaneously and merge them on demand. It is meant to be run locally (eg. on http://localhost:1337/) so that programs requiring a unique IP blocklist can query it to download IP ranges from many sources.

Sets of blocklist sources are arranged in text files and placed in a local folder. Then, njs-blocklist-merger will serve a merged version of all the blocklists in a given file when requested.

How it works

njs-blocklist-merger is a NodeJS script that setups an HTTP server listening on a configured port number and wait for GET requests in the form http://host:port/listname. Then it looks for a file named listname in local folder ./lists/. Each file in this folder must be encoded in UTF-8 and contains a list of urls specifying where to download the blocklists to merge. Empty lines and lines starting with # are ignored by njs-blocklist-merger. After such file is parsed, njs-blocklist-merger downloads specified blocklists in parallel. Each downloaded blocklist must be in p2p format, encoded in UTF-8 and served either in plain text or gzip format. When all requested data is available, njs-blocklist-merger merges them and responds to the HTTP request with a blocklist in p2p format encoded in UTF-8 and served in plain text with MIME type text/plain.

Kown bugs and limitations

  • Exceptions need to be handled in some parts of the code to keep the server live through some kinds of failures like problems accessing local list files, etc.
  • HTTP redirections are handled when downloading blocklists from the Internet, but the server is not protected from looping redirections (will probably cause a stack overflow).
  • Blocklist files are downloaded in parallel but the server waits for each request to complete before it merges the content and responds.
  • When the HTTP server responds, it does not provide the Content-Length header field so client programs will not be able to display progress as they download the merged blocklist from it.

Installation

  1. Install NodeJS on your system (see http://nodejs.org/).
  2. Install NPM on your system (see https://npmjs.org/).
  3. Place server.js in the folder of your choice.
  4. Use NPM to install the async module, either locally in the same folder as server.js, or globally (see https://github.com/caolan/async).
  5. Create a folder alongside server.js named lists.
  6. Place list files inside the lists folder in the format specified above.
  7. Run the server by executing the command:
node /path/to/folder/server.js host=localhost port=1337

You can customize the host and port numbers.

Then, any program can then request http://localhost:1337/mylist to download a merged version of the blocklists specified in file mylist.

Development

njs-blocklist-merger is written in TypeScript (see http://www.typescriptlang.org/). You need it installed (eg. as a NodeJS module) to be able to compile server.ts.

You can compile njs-blocklist-merger with the following command line:

tsc --sourcemap --target ES5 server.ts