Peernet Whitepaper
A decentralized internet.
Version 0.10 — 2026-11-19
Abstract: Peernet is a new peer-to-peer network for sharing and discovering files. Peernet is neutral and data agnostic. The network is fully controlled and owned by its users. Data is shared freely.
Introduction
Peernet is a public peer-to-peer network. Each user holds their private key which gives them full control over their data. This private key manages the user's personal blockchain which stores metadata of shared files and folders, as well as the user's +1s and follows. Users may publish, share, and remove their data at their discretion. Content is not tied to a single host: peers that follow a peer may mirror its blockchain and files, so the data stays available while any of them is online.
The network hierarchy is organized in a Kademlia-like fashion. The Peer ID is the user's public key (Ed25519 is used). The distance between two peers is measured as XOR of their Peer IDs. Two Distributed Hash Tables (DHTs) are used: DHT A to discover peers, DHT B to discover who stores a blockchain. There is no central authority; each peer makes its own decisions on the extent to rely on and trust other peers.
At any time, the user is in control of what data he publishes and what data he consumes.
Terminology
| Term | Definition |
|---|---|
| Client | A client is a software program that participates in the Peernet. |
| Decentralized Internet | In this phrase, "internet" refers to application-level services recognized by a typical user. Peernet connects over the internet as well as LANs. |
| Root Peer | A peer operated by a known trusted entity. A root peer must be reachable directly by any peer. It has a public IP address and port that are not translated (no NAT, no port forwarding). They allow to speed up the network including discovery of peers and data. The chain of trust is established by hard coding such peers into the client. Users may choose to remove those peers from the trust list and add their own curated list. |
| User | Human. |
| Peer | An endpoint participating in the peer-to-peer network. Usually a Computer. |
| Peer ID | The peer's Ed25519 public key. It identifies the peer and is the root of its blockchain. |
| DHT A | The peer discovery DHT. Keyed by Peer ID, which is the peer's position in it; resolves a Peer ID to the peer's addresses. It serves no other purpose. |
| DHT B | The data storage DHT. Keyed by the Peer ID of a blockchain; resolves it to the peers that store a copy. |
| +1 | A signed reference in the user's blockchain to a specific piece of content (publisher key and File ID) marking it as valuable. |
| Follow | A signed reference in the user's blockchain to another peer, marking that peer's blockchain as one the user tracks. |
| Bootstrapping | The process of discovering the initial set of peers to connect to the network. |
| Message | A packet sent from one peer to another. |
| Offset and Size | In bytes unless otherwise specified. |
| Byte Order | Integers are encoded little-endian. |
Trust
Trust is decided by each peer. The protocol defines the trust signals, not their evaluation.
Root peers are trusted by default; the user may remove them from the trust list and add his own. Follow and +1 are signed records in the user's blockchain: a peer the user follows, or whose data the user has given a +1, is trusted by that user. A peer may record a blacklist entry in its blockchain marking another peer as spam. Since all blockchains are public via DHT B, any peer may read other peers' follows, +1s and blacklist entries and use them as input for its own trust decisions.
Neutrality
Peernet is neutral and data agnostic. The protocol transports and stores whatever data its users publish, in the same way that TCP/IP or HTTP carry any payload; the protocol does not inspect, classify, rank, promote or restrict data, and has no knowledge of its meaning.
Each user holds the private key that allows the user to extend his or her own blockchain – including deleting data by publishing a new version of the blockchain without it. The private key is the identity: there is no recovery mechanism, and a lost key means a lost identity and blockchain. Data is published by the user, under the user's key and by the user's decision; no other party can alter or remove it. Only the private key holder can remove data from his or her blockchain; a request to remove data, including a legal demand, can therefore be fulfilled by the key holder alone.
Which data a peer stores, mirrors, or displays is decided by that peer. Users may use content blacklists, peer blacklists and trust lists; their use is the user's decision.
Protocol
The functionality of the protocol is separated into:
- Peer discovery
- Bootstrapping
- DHT A for peer discovery, keyed by Peer ID.
- Metadata sharing
- DHT B to find who stores a blockchain (keyed by its Peer ID).
- File transfer
Peernet only uses UDP. The default port for exchanging packets is 'p' (112). UDT (UDP-based Data Transfer Protocol) is used for file transfer. If the default port is unavailable, a random port may be used. (The only reason for the default port is for initial discovery in isolated networks.)
Peers are identified via their Ed25519 public key (= Peer ID). At the same time, it is the root of the peers' blockchain. This allows anyone to verify the blockchain of that peer, and to send it a packet that only that peer can read. Blockchains are versioned, and if a newer version appears, the old one must be deleted. This allows to restructure a blockchain if it becomes too big and contains dead entries like deleted file descriptors.
The client software is identified via a User Agent which must include the software name and version number. Peers may have multiple IP addresses assigned at the same time. Public and private IPs are supported and IPv4/IPv6 dual stack is supported.
A local address is a private address (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, fc00::/7), a link-local address (169.254.0.0/16, fe80::/10) or a loopback address (127.0.0.0/8, ::1). A connection is local if the remote peer's address is a local address.
A peer shares the local address of another peer only over a local connection, and uses a local address it receives only if it arrived over a local connection. A link-local or loopback address of another peer is never shared, and is ignored when received. This applies to peer records in the Response message and to the addresses in the Traverse message. Where a local address may be shared, it is shared in preference to a public one, and the message carrying it is sent over that local connection.
An address in 100.64.0.0/10 (the shared address space of carrier-grade NAT, RFC 6598) is neither a local nor a public address. A connection from it is not a local connection, and the address of another peer in this range is never shared and is ignored when received.
Routing of peers follows the Kademlia protocol. Neighbors are discovered using the XOR distance between Peer IDs. Each peer keeps a routing table of 256 buckets, one for each bit of the Peer ID. Another peer belongs to the bucket of the first bit in which its Peer ID differs from the Peer ID of the peer that keeps the table. A bucket holds at most 20 peers (k = 20).
Any peer may store a copy of any blockchain and may announce it in DHT B. A peer announces a blockchain it stores by sending a B_STORE_BLOCKCHAIN request to the γ peers closest to the Peer ID of the blockchain (γ = 20), and repeats it every 12 hours. A peer that maintains a listing removes it 24 hours after the time in its blockchain record.
The peers that store a blockchain are found by a lookup in DHT B. It proceeds as the lookup in DHT A, with B_FIND_BLOCKCHAIN requests for the Peer ID of the blockchain. The lookup ends when the γ closest peers known have all answered, or when no peer is left to ask. A peer that does not answer is not counted among the γ. The peer that searches may end the lookup earlier.
Each peer may store any file. A file is found through the blockchain it is published in: the peers that store the file are among the peers that store that blockchain. Peers maintaining DHT B may randomly verify that the listed peers are alive and store the blockchain.
Packet Structure
Each UDP command packet has the following structure (see table below). The packet is encrypted and authenticated with a key that only the sender and the receiver can derive: each derives it from its own private key and the Peer ID of the other. There is no handshake and no session; any packet can be the first one between two peers. The scheme provides four properties:
- Only the sender and the receiver can read the command, the sequence and the payload of a packet.
- Traffic carries no plaintext structure and appears as random data. This defeats content-based traffic classification by ISPs and corporate firewalls, which are known to block or degrade peer-to-peer traffic.
- A packet is bound to one receiver. It cannot be redirected to or replayed against a different peer, since that peer derives a different key and fails to decrypt it.
- It protects against impersonation and tampering: the receiver accepts a packet only if it was created with the private key of the sender's Peer ID, and any modification invalidates the authentication tag.
Packets contain a random amount of garbage appended to the payload to prevent fingerprinting based on packet size.
| Offset | Size | Info | Encrypted (ChaCha20, key = receiver ID) | Encrypted and authenticated (ChaCha20-Poly1305, packet key) |
|---|---|---|---|---|
| 0 | 12 | Nonce | ||
| 12 | 32 | Sender's public key (= sender's Peer ID) | ✓ | |
| 44 | 1 | Protocol version = 0 | ✓ | |
| 45 | 1 | Command | ✓ | |
| 46 | 4 | Sequence | ✓ | |
| 50 | 2 | Size of payload data | ✓ | |
| 52 | ? | Payload | ✓ | |
| ? | Randomized garbage. Protects against fingerprinting of the traffic based on size of packet. | ✓ | ||
| 16 | Authentication tag (Poly1305) |
The packet key is derived from a key agreement between the sender and the receiver. Peer IDs are Ed25519 keys and are converted to X25519 keys (RFC 7748) for it: the public key is u = (1 + y) / (1 − y) mod 2^255 − 19, where y is the y-coordinate encoded in the Peer ID; the private key is the first 32 bytes of the SHA-512 hash of the 32-byte Ed25519 private key, as in the key generation of RFC 8032. The shared secret is the X25519 function of the peer's own private key and the public key of the other peer. The packet key is the blake3 hash of the shared secret followed by the sender's Peer ID and the receiver's Peer ID. Both peers derive the same packet key; the two directions between two peers use different packet keys. A packet is dropped if the sender's public key is not a valid Ed25519 public key or if the shared secret is all zero.
The nonce is 12 random bytes from a cryptographically secure random generator, generated for every packet. The sender's public key is encrypted with ChaCha20 (RFC 8439, initial block counter 0) using the receiver's Peer ID as key and the nonce. The fields from the protocol version to the randomized garbage are encrypted and authenticated with ChaCha20-Poly1305 (RFC 8439) using the packet key and the same nonce, with no additional authenticated data; the authentication tag is appended. The receiver decrypts the sender's public key with its own Peer ID, derives the packet key and verifies the authentication tag. A packet whose authentication tag does not verify is dropped.
Messages that are responses to a request must use the same sequence number. It allows to filter out unsolicited responses and protect against replay and poisoning attacks. Messages like Response that potentially return multiple replies have a flag SEQUENCE_LAST that indicates the last reply in the sequence. Single reply messages like Pong do not need such a flag.
The sender's Peer ID is not confidential: it is readable with the receiver's Peer ID, and Peer IDs are public by design. The size and the timing of a packet are visible. The packet key between two peers does not change; there are no session keys. A packet proves its sender to the receiver, not to a third party.
The scheme is versioned. Since the protocol version field is inside the encrypted part of the packet, a receiver cannot determine the version before decoding. Receivers therefore decode by trial: a packet is first decoded with the scheme defined here; if the authentication tag does not verify, the receiver tries any newer scheme it supports, in order. Every scheme must include an authentication check (such as the authentication tag) so that a wrong decoding is reliably rejected.
The target packet size shall, where possible, not exceed 508 bytes to prevent fragmentation and increase delivery probability: every IPv4 host accepts a datagram of 576 bytes, less the maximum IP header (60) and the UDP header (8). The next limit that should not be exceeded is 1232 bytes: the IPv6 minimum MTU (maximum transmission unit) of 1280 bytes, less the IPv6 header (40) and the UDP header (8). The hard cap is 65507 bytes, the largest UDP payload over IPv4.
The following commands exist. Responses may only be sent after receiving a corresponding request.
| # | Name | Info |
|---|---|---|
| 0 | Announcement | Message to a new peer to inform about self and to request information. Carries DHT A requests (find peers) and DHT B requests (find or announce stored blockchains). |
| 1 | Response | Response to the announcement. Carries DHT A and DHT B results. |
| 2 | Ping | Keep-alive message (no payload). |
| 3 | Pong | Response to ping (no payload). |
| 4 | Local Discovery | Local discovery. |
| 5 | Traverse | Help establish the initial connection between 2 remote peers. |
| 6 | Relay | Relay Announcement and Response messages between 2 peers that cannot establish a direct connection. |
| 7 | Get Block | Request blocks for specified blockchain. |
| 8 | Transfer | Start file transfer. |
| 9 | Search | Search for files. Response contains blocks or reference to blocks. |
Announcement
The announcement (command 0) is used for multiple purposes: initial connectivity (bootstrapping), (unsolicited) announcement of self, requesting peers close to a Peer ID (DHT A), requesting who stores a blockchain (DHT B), and informing about blockchains stored (DHT B). The request records are optional; an announcement without requests only announces the sender. It is up to the receiver whether to add the sender into its peer table, and whether to respond to some or all of the requests.
| Offset | Size | Info |
|---|---|---|
| 0 | 4 bits | Protocol version support. Might be a higher number than used for sending this packet. |
| 0.5 | 4 bits | For future use. |
| 1 | 1 | Feature bit array. Informs about what the sender supports. See below. |
| 2 | 8 | Sender's blockchain version. Any stored previous versions must be deleted, and the blocks must be requested again. |
| 10 | 8 | Sender's blockchain height. |
| 18 | 2 | Sender's internal listening port |
| 20 | 2 | Sender's external listening port, if known |
| 22 | 1 | Size of User Agent in bytes. Max 255. |
| 23 | ? | User Agent in the format "Software/Version number". Required in the initial announcement/bootstrap. Example: "Test Client/1.0". UTF-8 encoded. Must not contain null bytes. Max length is 255 bytes. |
| ? | 1 | Count of records that follow (7 bits). Bit 7 is the SEQUENCE_LAST flag: in a response it indicates that no further response messages follow for the announcement; in an announcement the bit is 0. |
| ? | ? | Records. See below. Request records in the announcement, response records in the response. |
Feature bit array:
| Bit | Feature | Info |
|---|---|---|
| 0 | IPv4_LISTEN | Sender listens on IPv4 |
| 1 | IPv6_LISTEN | Sender listens on IPv6 |
Each record has the below format. The type identifies the structure of the data. A receiver skips a record of an unknown type using its size and processes the remaining records.
| Offset | Size | Info |
|---|---|---|
| 0 | 1 | Type |
| 1 | 2 | Size of the data |
| 3 | ? | Data |
Request types:
| Type | Name | DHT | Request data | Info |
|---|---|---|---|---|
| 0 | A_FIND_SELF | A | none | Request closest peers to the sender |
| 1 | A_FIND_PEER | A | List of keys | Request closest peers to each Peer ID |
| 2 | B_FIND_BLOCKCHAIN | B | List of keys | Request peers that store the blockchain of each Peer ID |
| 3 | B_STORE_BLOCKCHAIN | B | List of blockchain records | Sender indicates storing the listed blockchains |
List of keys (A_FIND_PEER, B_FIND_BLOCKCHAIN). The number of keys follows from the size of the request data.
| Offset | Size | Info |
|---|---|---|
| 32 * n | 32 | Key = Peer ID |
List of blockchain records (B_STORE_BLOCKCHAIN). The number of records follows from the size of the request data.
| Offset | Size | Info |
|---|---|---|
| 116 * n + 0 | 32 | Peer ID of the blockchain |
| 116 * n + 32 | 8 | Blockchain version stored |
| 116 * n + 40 | 8 | Blockchain height stored |
| 116 * n + 48 | 4 | Time of the record, Unix time in seconds, UTC |
| 116 * n + 52 | 64 | Signature by the sender |
The height stored is the count of blocks stored from block 0 on, without a gap. The signature is computed over the ASCII text B_STORE_BLOCKCHAIN followed by the Peer ID of the blockchain, the version, the height and the time. A blockchain record is valid if its signature verifies against the Peer ID of the peer that stores the blockchain, and its time is at most 24 hours in the past and at most 1 hour in the future. A blockchain record that is not valid is ignored.
The store request (B_STORE_BLOCKCHAIN) informs other peers that the sender stores the listed blockchains. Receivers may choose to maintain that information in DHT B to inform others when requested (via B_FIND_BLOCKCHAIN). The protocol intentionally does NOT provide a push mechanism for data stored by 3rd party peers to prevent flooding and spam. The receiver may verify if the sender stores the data by requesting it. This can be done randomly to prevent unnecessary overhead. Store requests do not trigger a response.
Response
The response has the same format as the announcement. Its records are response records. A request with multiple keys is answered with one response record per key. Multiple response messages may be sent for a single announcement; the last one sets the SEQUENCE_LAST flag. A request that the receiver chooses not to answer has no response record.
Response types:
| Type | Name | Answers | Info |
|---|---|---|---|
| 0 | A_RESPONSE_SELF | A_FIND_SELF | Peers close to the sender |
| 1 | A_RESPONSE_PEER | A_FIND_PEER | Peers close to the requested Peer ID |
| 2 | B_RESPONSE_BLOCKCHAIN | B_FIND_BLOCKCHAIN | Peers that store the requested blockchain, and peers close to the key |
A response record of DHT A carries at most 5 peer records of peers close to the key (close to the sender in A_RESPONSE_SELF). The response records of B_RESPONSE_BLOCKCHAIN for one key carry at most γ peer records of peers close to the key in total: the lookup in DHT B reads the γ closest peers, so a response has to be able to report them. Storing peer records do not count towards these limits. Bit 7 of the first count in the response data below indicates the last result. Until it is set, further response records for the same request or key follow in later response messages. A requested key with zero peer records and bit 7 set was not found. Data after the counted peer records is ignored.
Response data for A_RESPONSE_SELF:
| Offset | Size | Info |
|---|---|---|
| 0 | 1 | Count of peer records that follow (7 bits). Bit 7 indicates the last result. |
| 1 | ? | Peer records of peers close to the sender |
Response data for A_RESPONSE_PEER:
| Offset | Size | Info |
|---|---|---|
| 0 | 32 | Requested key |
| 32 | 1 | Count of peer records that follow (7 bits). Bit 7 indicates the last result. |
| 33 | ? | Peer records of peers close to the key |
Response data for B_RESPONSE_BLOCKCHAIN:
| Offset | Size | Info |
|---|---|---|
| 0 | 32 | Requested key |
| 32 | 1 | Count of storing peer records that follow (7 bits). Bit 7 indicates the last result. |
| 33 | 1 | Count of peer records of peers close to the key that follow (7 bits). Bit 7 is 0. |
| 34 | ? | Storing peer records: each a peer record followed by the version (8), height (8), time (4) and signature (64) of the blockchain record of that peer |
| ? | ? | Peer records of peers close to the key |
Peer Record
The size of a peer record follows from its address counts. The announcement message uses the feature field (IPv4_LISTEN and IPv6_LISTEN) to indicate whether the response shall contain IPv4 and IPv6 addresses. A peer record carries at least one address, with one exception: a peer that stores the requested blockchain itself lists its own Peer ID as a storing peer record without an address. In B_RESPONSE_BLOCKCHAIN a peer record carries at most one IPv4 and one IPv6 address.
| Offset | Size | Info |
|---|---|---|
| 0 | 32 | Peer ID |
| 32 | 1 | Feature bit array. Same format as in Announcement message. |
| 33 | 1 | Address counts. Bits 0–1: count of IPv4 addresses. Bits 2–3: count of IPv6 addresses. Bits 4–7 are 0. |
| 34 | 10 * n | IPv4 addresses |
| ? | 22 * n | IPv6 addresses |
Each address has the below format. The IP address is 4 bytes for IPv4 and 16 bytes for IPv6.
| Offset | Size | Info |
|---|---|---|
| 0 | 4 / 16 | IP address |
| 4 / 16 | 2 | Port (actual one used for connection) |
| 6 / 18 | 2 | Internal port as reported by that peer. This can be used to identify whether the peer is potentially behind a NAT. |
| 8 / 20 | 2 | External port as reported by that peer. This is used in case of port forwarding (manual or automated). 0 if not known. |
Local Discovery
The local discovery message is used to discover peers over the local network. It is sent to UDP port 12912: on IPv4 to the limited broadcast address 255.255.255.255 and to the directed broadcast address of the local network, on IPv6 to the site-local multicast group ff05::112. It may not be sent via the internet. Since the broadcast/multicast targets unknown recipients, it cannot use the receiver's Peer ID for encryption. Instead, a fixed key pair takes the place of the receiver's key pair. Every peer uses its private key to decrypt the packet:
| Network | Public key (hex) | Private key (hex) |
|---|---|---|
| IPv4 broadcast | 7e1e727b62c6a791b0b3fdd18c957c985f24b53c2e23425f10de143469c7df7b | 5e27ecc8e54a24e71dca9ba84a9bf465400e27b8c46a977d34962d3d88558c8e |
| IPv6 multicast | cacfa174378dceb20bc46f314d4dc6ebbc9ccadc9961dadf0a0ba183ea1df23d | 016ad30bfb369926523bf18d136298b6c31d0817e9fb6c21feed89ae22cad788 |
Note that the local discovery feature with hard-coded keys is a tradeoff with deep packet inspection security. Since the private key is known to everyone, the packet does not authenticate its sender; the message carries a signature instead. The structure is the same as the announcement message without request records, followed by a 64-byte Ed25519 signature by the sender. The signature is computed over the fixed public key followed by all preceding bytes of the message. A receiver drops the message if the signature does not verify against the sender's public key of the packet. The local discovery message has no response; a receiver may send an Announcement to the sender.
Traverse
The traverse message helps 2 remote peers to establish a connection to each other. If Peer M sends Peer A the information of Peer B, A sends its first Announcement to B directly and, at the same time, in a Traverse message to M, which forwards it to B. A does this for every peer other than a root peer, without determining whether B is behind a NAT or a firewall, and for local addresses as well. The embedded packet must be an Announcement message; B drops the Traverse message otherwise. M forwards the message only if the sender of the embedded packet is the sender of the Traverse message; it decrypts the sender's public key of the embedded packet with the Peer ID of B and cannot read its other fields. Root peers are always contacted directly: A sends no Traverse message for a root peer, and M drops a Traverse message whose end receiver is a root peer. Every peer shall forward Traverse messages. A peer may limit the rate at which it forwards them; a message above the limit is dropped. M sets a local address of A only if both A and B are connected to M over a local connection; it then forwards the message to B over that local connection. When B receives the message, it processes the embedded packet as if it were sent from A directly.
In this case M acts as a proxy. Since A sends the Announcement message both directly to B and via the Traverse message through M, B is likely to receive it. When B sends back the Response message it should automatically open the port on B's NAT or firewall for further communication.
This UDP hole punching mechanism fails if one peer is behind a symmetric NAT and the other is behind a port-restricted or symmetric NAT. Such peers communicate through Relay messages.
| Offset | Size | Info |
|---|---|---|
| 0 | 32 | End receiver Peer ID |
| 32 | 4 | IPv4 address of the original sender. Set by the relay. |
| 36 | 2 | IPv4 port used for connection. |
| 38 | 2 | IPv4 external port as reported by the original sender. |
| 40 | 16 | IPv6 address of the original sender. Set by the relay. |
| 56 | 2 | IPv6 port used for connection. |
| 58 | 2 | IPv6 external port as reported by the original sender. |
| 60 | ? | Embedded packet. Its size follows from the size of the payload. |
The embedded packet has the packet structure without the randomized garbage. Its additional authenticated data is the Peer ID of M followed by the command number of the Traverse message (1 byte). It is therefore valid only inside a Traverse message sent by M, and not as a packet sent to B directly.
Relay
The relay message carries Announcement and Response messages between 2 peers that cannot establish a direct connection. If A receives no Response from B, neither to its direct Announcement nor to the one sent in a Traverse message, A sends the Announcement in a Relay message to R, a peer that has B in its peer list. R forwards it to B in a Relay message of its own. B processes the embedded packet as if it were sent from A directly, and sends its Response to A in a Relay message to R.
Every peer shall forward Relay messages. A peer may limit the rate at which it forwards them; a message above the limit is dropped. R forwards a Relay message only if the FORWARDED flag is not set and the peer named in it is in its peer list. It sets the FORWARDED flag, replaces the Peer ID in the message with the Peer ID of the sender and forwards the embedded packet unchanged; it cannot read it. R keeps no state for A and B.
The receiver of a Relay message with the FORWARDED flag set is the end receiver. The embedded packet must be an Announcement or a Response message; the end receiver drops the Relay message otherwise. Relay messages are not used for data transfer.
| Offset | Size | Info |
|---|---|---|
| 0 | 32 | Peer ID of the other peer: the end receiver when sent to the relay, the original sender when sent by the relay. |
| 32 | 1 | Flags. Bit 0: FORWARDED, set by the relay. Bits 1–7 are 0. |
| 33 | ? | Embedded packet. Its size follows from the size of the payload. |
The embedded packet has the packet structure without the sender's public key and without the randomized garbage. Its sender is the sender of the Relay message when sent to the relay, and the Peer ID in the Relay message when sent by the relay. Its additional authenticated data is the Peer ID of R followed by the command number of the Relay message (1 byte). It is therefore valid only inside a Relay message sent through R, and not as a packet sent to B directly.
Transfer
The transfer message initiates and continues a file transfer. For the purpose of clarity, the peer requesting a file is considered the client, and the peer serving the file the server. The client must know before the transfer that the server stores the file.
| Offset | Size | Info |
|---|---|---|
| 0 | 1 | Control (see below) |
| 1 | 1 | Transfer Protocol: 0 = UDT |
| 2 | 32 | File Hash |
| 34 | ? | Embedded protocol data |
Control values:
| Control | Info |
|---|---|
| 0 | Request start transfer (client → server). Data at byte 34 is offset and limit to read, each 8 bytes. |
| 1 | Not available (server → client) |
| 2 | Active transfer (server → client) |
| 3 | Terminate (both way) |
Blockchain Exchange
The get block message requests specified blocks for a blockchain from a remote peer. The blockchain might be the remote peer's own blockchain, or any other that the remote peer may cache. The actual transfer of the blocks is done via UDT.
Design Considerations
The design considerations for this protocol were:
- First packet must establish connection. This includes sending metadata and requests.
- Only the sender and the receiver can read a packet, and traffic appears as random data to third parties.
- Secure against message forgery.
- Secure against tampering and by extension bitflip.
- Small as possible to increase deliverability.
- TCP-like acknowledgment and resending are not desired due to the decentralized nature of the network and natural concurrency. The exception to this is file transfer.
Blockchain
The blockchain height and version number are 64-bits, which is the absolute limitation on the user's modifications of his blockchain. Adding files, removing them, renaming them, changing other metadata tags etc. produces additional blocks (and increasing the height). However, when there are many deletions or many small blocks, it makes sense to instead increase the version number and start the height at 0. This is beneficial to keep the blockchain small when many files are deleted, while at the same time increasing privacy.
A block is at most 32 KB (32,768 bytes), including the header and signature. A block that exceeds this size is invalid.
Block header:
| Offset | Size | Info |
|---|---|---|
| 0 | 64 | Signature of entire block by the blockchain owner |
| 64 | 32 | Hash (blake3) of last block. 0 for first one. |
| 96 | 8 | Blockchain version number |
| 104 | 8 | Block number |
| 112 | 4 | Size of entire block including this header |
| 116 | 2 | Count of records that follow |
Each block record that follows the block header has the below format. The record type identifies the structure of the data field and allows new record types to be defined in the future. To completely remove a record, the blockchain is rebuilt without that record and the version number increased; this is the only deletion mechanism, there is no delete record. A rebuilt blockchain must preserve the original order of the remaining records. All record types and the encoding of the data are defined in the reference implementation. Example records include profile data, files, and social interactions.
| Offset | Size | Info |
|---|---|---|
| 0 | 1 | Record type. |
| 1 | 8 | Date created, Unix time in seconds, UTC. This remains the same in case of block refactoring. |
| 9 | 4 | Size of data |
| 13 | ? | Data. Encoding depends on the record type. |
The encoding of profile data (record type 0) is 2 bytes the profile type followed by the profile data.
This is the encoding of files (record type 2):
| Offset | Size | Info |
|---|---|---|
| 0 | 32 | Hash blake3 of the file content |
| 32 | 16 | File ID (UUID version 7) |
| 48 | 32 | Merkle Root Hash |
| 80 | 8 | Fragment Size |
| 88 | 1 | File Type |
| 89 | 2 | File Format |
| 91 | 8 | File Size |
| 99 | 2 | Count of Tags |
| 101 | ? | Tags |
The File ID is a UUID version 7 (time-ordered), generated when the file is published. It identifies the file record, whereas the content hash identifies the content: the same content may be published more than once, each time with a new File ID. Because UUID version 7 embeds the creation time and blocks are appended in order of creation, File IDs are monotonic across a blockchain, which allows a very large blockchain to be searched for a File ID by binary search rather than a full scan.
Referencing Data in Other Blockchains
A file is referenced by the publisher's public key and the File ID. References never address a block position, since the publisher may rebuild the blockchain at any time. A reference may additionally carry the blockchain version and block number as a non-authoritative locator hint: a peer resolving the reference first fetches that single block and checks whether it contains the File ID; if not (for example after a rebuild), it falls back to the publisher's blockchain or its index. The hint is cheap and makes resolution effective at scale. A reference to data that the publisher has since deleted does not resolve, which is the intended behavior.
Peer Discovery
Initial peer discovery is done via bootstrapping: a hard-coded list of root peers for the internet, and the Local Discovery message (IPv4 broadcast, IPv6 multicast) for the LAN. Peernet does not use Multicast DNS due to its unreliability.
Ongoing peer discovery is accomplished by exchanging peer lists via the Announcement and Response messages (DHT A). Clients shall prioritize exchanging high quality peers. High quality can be determined by uptime, reach (for example, is the port forwarded), and other metrics such as connection speed and ping time.
A peer is found by a lookup in DHT A. The peer that searches starts with the peers closest to the Peer ID in its routing table and sends each an A_FIND_PEER request. The responses carry peers close to the Peer ID; those not yet asked are asked next, the closest first. Several peers are asked in parallel; their count α is chosen by the client, α = 5 is suggested. The lookup ends when the peer searched for answers, when the β closest peers known have all answered, or when no peer is left to ask. A peer that does not answer is not counted among the β. β is chosen by the client, β = 5 is suggested. If responses report different addresses for the peer searched for, each is tried.
File Transfer
Transfer of file data uses a forked (slightly trimmed down) version of UDT embedded in the Transfer message. It handles packet loss, congestion, and rearranging the packets into a continuous stream.
TODO
File Discovery
Peers may index files and associated metadata tags in a sanitized way and make it searchable.
TODO
URI
Outside Peernet, data is referenced by a URI. It names the publisher by Peer ID, followed by a format indicator that defines the structure of the remainder:
peer://[PEER ID]
peer://[PEER ID]/0/[FILE ID]
peer://[PEER ID]/1/folder/filename
[PEER ID] is the Peer ID hex encoded, 64 characters, case insensitive. A URI consisting of the Peer ID alone references the peer itself, that is its blockchain.
| Format | Remainder |
|---|---|
| 0 | The File ID in UUID text form, 36 characters, case insensitive. |
| 1 | Folder and file name, the file record's folder and name tags. |