Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

planktos

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

planktos

Easily serve static website assets over bittorrent

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8
increased by166.67%
Maintainers
1
Weekly downloads
 
Created
Source

planktos Planktos

npm version

Planktos enables websites to serve their static content over bittorrent from the users of the website. This allows site owners to offset declining ad revenue by utilizing the user's bandwidth and scale easier since downloads get faster with more peers. Planktos works in vanilla Chrome and Firefox by using service workers to intercept http requests, and webtorrent to download the requested files from other users over bittorrent. Installing planktos into a website is as simple as registering the planktos service worker and creating a torrent that holds the static assets (or the entire site if it's completely static).

Setup

The planktos command line tool copies the neccessary library files, and it packages the website's files into a torrent. To install the tool run:

npm install -g planktos

Now change your current working directory to the directory you want to be served by planktos. The library files and service worker file need to be copied into this directory which can be done by running:

planktos --lib-only

The service worker needs to be registered which can be done by including this script:

<script src="/planktos/install.js"></script>

The final step is packaging the files into a torrent so it can be served over bittorrent which is done by running:

planktos [directories or files...]

If no files or directories are passed, planktos includes everything in the current working directory. Everything is setup now, and to test that everything is working open up the dev tools in look in the network tab. After modifying the website's files, the torrent can be repackaged by running the above command again.

There are a few things to keep in mind when using planktos:

  • The site must be served over https (or http on localhost) since service workers have restrictions on which types of sites can register them.
  • The web server must support the Range header since the server is used as a webseed. Most serves support this but python's simplehttpserver is a common one that doesn't.

How it works

Once the planktos service worker is installed, it intercepts all http requests made by the browser. When a fetch request is intercepted, planktos looks to see if the requested file is in the torrent for the website. If it is, planktos responds with the file's data it retreived over bittorrent. If the requested file is not in the torrent, the request goes to the webserver over http like it would without planktos installed. Planktos uses the awesome webtorrent project for everything bittorrent. One gotcha you may have noticed is that webtorrent relies on WebRTC for it's peer connections, and the WebRTC api is not accessible from within service workers. Planktos gets around this by injecting a downloader script in the initial webpage request which handles all the webtorrent downloading and seeding operations since this cannot be done in a service worker currently. See the W3C issue for more info on WebRTC in web workers.

If the browser does not have service worker support than everything goes over http like it would without planktos.

Planktos is still early on in developement, and is not recomended for production use yet. Some issues that are holding back production use are:

  • Cannot selectively download files within a torrent; the entire torrent is downloaded. This is fine for small sites but this will get out of hand quick with larger sites.
  • No streaming support. The requested file must be downloaded in it's entirety before it can be displayed to the user. Currently only chrome supports streaming from the service worker while Firefox has an open issue for it.

License

MIT. Copyright (c) Austin Middleton.

Keywords

FAQs

Package last updated on 16 Dec 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc