WHAT VEILID IS
Veilid is an open-source peer-to-peer application framework, written in Rust and maintained by the Veilid Foundation. Veilid gives an application three services: encrypted transport between nodes, shared storage for data, and private routing. In private routing, a safety route hides the sender’s network address from the receiver, and a private route hides the receiver’s network address from the sender. Each node on a route sees the network addresses of the nodes with which it exchanges traffic.
NODES AND RELAYS
Every Veilid node runs the same software. Together, the nodes carry the data and traffic of applications. A node that accepts incoming connections from the internet also relays traffic for nodes that cannot accept them. The same node runs a reachability test for any node that asks. In the test, a helper sends a message to the requesting node’s public address. The message arrives only if the requesting node accepts incoming connections. Two kinds of node are reached through one of their relays: a node behind a router or firewall that blocks incoming traffic, and a node running in a browser. Such a node does not relay for other nodes. The Veilid Foundation’s Networking page covers public address detection, network classes, and relays.
A running network keeps working as nodes come and go. Capacity and redundancy fall when nodes leave and recover when nodes rejoin.
Finding the first peer
A node that joins for the first time learns about at least one peer from a source outside the network. The node then verifies that information. By default that source is DNS, because nearly every device can make a DNS lookup. The node looks up bootstrap-v1.veilid.net and verifies the signed records it receives against three keys held by the Veilid Foundation. First contact therefore depends on the domain’s registrar, the domain’s DNS operator, and the Foundation. A node can also start from the direct address of a peer that serves bootstrap records, or from signed records placed in the node’s own configuration. In both cases, the node still looks up any host names that the records contain.
WHERE THE DATA LIVES
Veilid’s shared storage is a . Each record has a key. The key determines which nodes are responsible for holding the record. Any node can ask any other node for a record by the record’s key. Because the key says where to look, each node holds only its share of the table.
Each node keeps its share in an encrypted database on disk. The Foundation’s Cryptography page describes that store and its device key. What the encryption protects depends on where the node keeps the device key. A record is a key plus numbered subkeys. Each subkey holds up to 32 KiB, and the whole record holds up to 1 MiB. A record is therefore closer to a small set of rows than to a file. Data larger than one record is split across several records by the software that stores the data.
A GetValue operation asks a node for a subkey. A SetValue operation sends a subkey to a node. Each node keeps two stores, divided by the origin of each operation:
| Store | What is in it |
|---|---|
| Local | Records your node opened or created for its own use. |
| Remote | Records other nodes wrote to you. Your node accepts a copy only when your node is among the nodes closest to the record’s key. Only this store answers an inbound GetValue, and the same closeness test applies first. |
Closeness is a calculation on identifiers. A record key is a , and a node identifier is the node’s . Both are 256-bit values in the same space. The distance between two identifiers is their . The routing table keeps peers in buckets by that distance. This distance measure is the model, which most distributed hash tables share. The lookup also follows Kademlia: a node queries several peers in parallel and runs each step of the search itself. On top of the Kademlia model, Veilid adds signed records, schemas, and a : several matching answers drawn from a wider set of candidates. A node configured without the DHT capability does not store or serve records for other nodes. The DHT chapter of the Foundation’s developer book describes records and schemas from the application side.
WHAT HAPPENS WHEN YOU READ
When an application asks for a record, the node takes these steps:
| Step | What happens |
|---|---|
| 1. Look at home | The node may answer from its local store. If the node finds the record there and the application has not forced a refresh, the operation ends. An application that needs the current value forces a refresh. The read then accepts only versions at least as new as the local copy. |
| 2. Ask the network | The node asks the known peers that are nearest the record’s key. |
| 3. Seek agreement | By default, the node seeks three matching answers from the ten closest nodes it can reach. When a node times out or gives an invalid answer, the reading node replaces that node with the next closest node. |
| 4. Verify | Each answer carries a over the value. The node checks the signature against a key that the record’s descriptor authorizes for that subkey. That key belongs to the owner, or to a listed member of a multi-writer record. A reader without the descriptor asks a peer for a copy and checks the copy against the record key. |
| 5. Keep it | A verified value newer than the local copy is written into the local store. On a forced refresh, a different value at the same version also replaces the local copy. The exception is when the node has its own write still waiting to reach the network. |
Step four detects altered values, because only a key that the descriptor authorizes can produce a valid signature. The signature shows who wrote a value. The sequence number shows how recent the value is. A node can still decline to answer, or can send an older version that the writer signed. A higher sequence number from any candidate restarts the agreement. A replayed old version therefore wins only when it is the newest among the answers that arrive before the read stops. A party that runs many nodes near a record’s key can block reads of that record, or cause a read to settle on an older signed version.
Reading keeps data alive
The remote store is bounded and evicts the least recently used record first. The bounds are a record count and a storage budget. As of Veilid 0.5.8, veilid-server defaults to 65,536 remote records and about 10 GB where the disk has room. When an application embeds veilid-core without a DHT configuration, the node gets 128 records and 256 MB. In a browser, the node gets 64 records and 128 MB. Records do not expire on a timer. Serving a read moves a record to the most recently used end of the order. A restart rebuilds the order without counting reads. The local store is unbounded, so what you read stays until you delete it.
A node keeps its own copy of each subkey it has read or written. When the node reopens a record, it counts how many nodes still store each subkey. By default, a write aims to store each one on five nodes. When fewer nodes store a subkey, the node writes its copy out again in the background. The stored value carries the writer’s signature, so the rewrite works without the writer’s key. Veilid calls this process rehydration. A record that has fallen off the network can return when a node holding a copy opens the record again. A newer version on the network wins. As of Veilid 0.5.8, reopening a record runs the check at most once every five minutes per record. The check skips records that the node created since the node started. An application can turn the check off whenever the application opens a record.
Veilid leaves scheduled refreshing to applications. A process can re-read particular records on a schedule and force a refresh on each read, so that each read reaches the storing nodes. Such a process keeps those records recently used, so the storing nodes evict records read less recently first, and can also restore subkeys that have fallen off. Such a process needs only the record key string, which includes the encryption key if the record is encrypted.
LIMITS
Storage is best effort
When a node reaches its storage or record-count limit, the node evicts records. Data that must be kept needs a copy held by someone who has agreed to keep that copy.
Agreement covers one subkey
A blockchain keeps one ledger that orders events across the whole network. A read in Veilid seeks agreement on one subkey at a time. In step three, the node looks for a quorum of nodes that return the same stored bytes for that subkey. When the read runs out of candidates or time before reaching a quorum, the node compares the answers with its local copy and returns the newest version.
Record encryption
Encryption protects data in transit between nodes. When a record is created, Veilid mints a fresh per-record key. The record’s values are stored as ciphertext under that key on every node that holds a copy. The record’s address is separate from the encryption key. A record is stored under a hash of the crypto kind, the owner key, and the schema. The encryption key travels beside that hash in the record key string. If an application opens a record by the bare hash and then writes to the record, the record stores plaintext instead. A reader holding only the bare hash of an encrypted record gets an error. Anyone who holds the encryption key can read the values. The application decides who receives that key.
VNS, QX9’s proposed naming system, puts the content key inside the signed manifest, so anyone who can resolve the address can read the site. An application that needs confidentiality gives the record’s encryption key, or a key of its own, only to the intended readers. The Foundation’s VeilidChat, in public beta, works this way.
Both kinds of encryption leave a record’s metadata visible. A node that stores a record sees the owner public key, the signing key and size of each value, and the times when values change. A record kept for one person can therefore link that person’s activity over time and identify that person to anyone who knows the owner key. An application that holds restricted data also cannot rely on a record disappearing. As of veilid-core 0.5.8, a node holding a copy in its own store can send the values back when that node reopens the record.
RELATED PROJECTS
Veilid Foundation
The project itself: source, documentation, and the community that maintains it. Veilid is public and usable today, independently of anything on this site.
Intersect
Intersect, by Evelyn-H, describes itself as “a decentralised platform for sharing notes privately”. A note is stored in the distributed hash table and shared by link. Opening the link reads the note directly from the table.
Cypher Page
Cypher Page publishes a small Markdown page as a single record in the distributed hash table. The address of each page is the record key with the record’s encryption key attached, so a reader fetches the content from the table with the address alone. The owner can update the page without changing the address.
VNS, a proposed naming system
A naming system in which the address is the public key itself, so only the keyholder can publish at that address. VNS is designed to hold small static sites and single Markdown pages, each in one content record of the distributed hash table. A guardian is a process that re-reads the records on a schedule. A guardian can keep the records resident. The design follows Intersect in reading the table directly and in carrying the content key inside the reference that leads to the content. The specification and its reference implementation are not published.