To a world without data-centers: an introduction of ZeroNet

Dynamic websites on a fully peer-to-peer network is a combination most people would find hard to believe, yet that's exactly what ZeroNet has achieved. This piece of software allows anyone to create and view peer-to-peer websites that are impossible to take down, based entirely on static files. Unlike other peer-to-peer website networks, ZeroNet can power websites with user-generated content like forums and wikis. This article will teach you the basics of how it works.

What's a zite?

All ZeroNet sites — also called zites — start with an address. These are, like onion addresses, cryptographic keys. More specifically, they are bitcoin addresses. When creating a new zite, you are actually creating a key pair, where the private key allows the owner to sign new content and the public key allows anyone to verify the validity of the zite's files, even if they originate from an untrusted peer.

Once you have a key pair, you can start adding files to your zite. Zites act like any regular static website: you can add HTML, CSS and JavaScript as needed. In order for other peers to download the new files, you have to sign them with your private key. The hash of each file is stored in a special file called content.json, which conveniently contains a signature of itself. The new content.json file will propagate through the network and peers will automatically request files they need to keep their local copy up-to-date.

Now, what actually goes on when someone tries to access a zite? The first step is to get a list of peers that have the zite's content.json file. Once our client gets hold of the file, it can start to request all other files from the peers it has a connection with. This process typically takes about a second, which makes it faster than a lot of websites out there.

The process is actually a bit more involved than this, as ZeroNet supports optional files (only downloaded when needed), big files (files above 10MB are split up into pieces) and databases, which I will talk about next.

From static to dynamic

The content.json file contains file hashes, but not exclusively. It has a few more options that help in making a website dynamic. One of these options is named user_contents. It describes a set of rules surrounding user-generated content, like who can add files and how much custom data a user can have. When this option is used, users will be able to publish files themselves in a sub-directory named after their public key.

To illustrate how this can be used, let's take the example of the forum zite ZeroTalk. When a user creates a new post, ZeroNet will transparently create a new JSON file inside their custom files directory. This file will house the contents of the user's post as well as some metadata. To ensure the file's authenticity, each user has a content.json file that, like the one for the zite, contains file hashes. We now have a system where anyone can publish content to a zite, on a peer-to-peer network.

To make accessing these files more efficient, ZeroNet creates an SQL database for every zite that needs it. It is up to the zite owner to configure the mapping between custom user JSON files and the SQL database. We end up with a system where files go in, database comes out. The database itself is local: every client modifies it based on the files it has access to, and will do its best to keep it updated as new files come in.

This system has made fully decentralized websites possible: forums, wikis, mailboxes, torrent trackers, IRC-like message boards and more.

Domain names with NameCoin

ZeroNet relies on NameCoin .bit domains to make human-readable addresses. Anyone can create their own domains and subdomains as long as they have some NameCoin in a wallet and that the domain isn't already taken. The price of a single domain name is only a few cents, which makes custom addresses quite affordable.

Wrapping it up

I hope I've been able to shed some light on how ZeroNet works and what makes it great. There is a lot more to be said though, like how ZeroNet handles identities and peer discovery, how the protocol works or how it integrates with the Tor network.

I suggest anyone to try out the software for themselves, to create a small zite, then to publish it and watch it still be online years later. More information about the inner workings of ZeroNet can be found in the documentation.