Warpnet Protocol

This document describes the peer-to-peer communication layer of Warpnet, including transport channels, routing logic, and delivery semantics. It focuses on how nodes exchange encrypted messages over libp2p.

1. Transport Protocols

Warpnet uses libp2p as its networking layer. Communication between nodes occurs over authenticated and encrypted channels using the Noise protocol and a shared PSK.

What is a libp2p stream?

A libp2p stream is:

  • A logical connection, established between two peers on top of an existing libp2p connection

  • Identified by a protocol ID string, such as /private/post/tweet/0.0.0

  • Multiplexed: multiple streams can share a single physical connection (e.g., TCP + Noise)

  • Bidirectional: both peers can read and write from/to the stream

  • Automatically encrypted and authenticated using the Noise protocol + PSK

How streams are used in Warpnet

Every operation between two Warpnet nodes uses a distinct libp2p stream. For example:

  • A timeline post opens a stream using protocol /private/post/tweet/0.0.0

  • A request to fetch the user's timeline opens a stream /private/get/timeline/0.0.0

  • A public message broadcast to a peer opens a stream /public/post/message/0.0.0

Each stream is:

  1. Opened by the initiating node

  2. Processed by the recipient’s stream handler, which is registered per protocol route

  3. Closed once the operation is complete

Stream-level Isolation

  • Stream operations are sandboxed by protocol

  • Each handler in the node is registered to a specific protocol path

  • Streams are subject to authorization middleware, especially for private routes (see 4. Stream Authentication Middleware)

All WarpNet protocols follow a structured URI-style format that encodes access level, operation type, resource domain, and version. This convention is used to route and dispatch messages between peers, and also to enforce access boundaries.

>>> /{visibility}/{operation}/{domain}/{version}

Where:

Segment Meaning Example visibility public or private access /private/... operation get, post, delete, etc. /post/... domain Logical entity (e.g., tweet, message, user) /tweet/, /chat/ version Semantic version of protocol /0.0.0

This makes the protocol self-descriptive and extensible without breaking compatibility. Example:

>>> /private/post/tweet/0.0.0

A private POST call to submit a new tweet using protocol version 0.0.0

Benefits of Structured Protocols

  • Self-documenting: Each protocol clearly communicates its purpose

  • Modular dispatch: Handlers can be dynamically mapped via URI parsing

  • Access control: Easy to enforce public/private rules by prefix

  • Versionable: Future changes can use semantic versions without breaking older clients

All application-layer messages are serialized as raw JSON (or binary encoding TBD), and transmitted over multiplexed libp2p streams.

Stream Format

All stream payloads are currently:

  • Serialized as JSON objects (subject to change)

  • Encapsulated per stream: no interleaving, each stream handles a single logical operation

  • Length-prefixed (handled by libp2p's stream muxer)

2. Message Routing

When a message arrives at the node, it is routed based on its type:

  • Public timeline post → sent to all known friends via public/post/timeline/0.0.0

  • Private message → dialed directly to recipient via /private/get/chat/0.0.0

Routing logic is implemented in the client node, while message storage and broadcast happens in the main node.

3. Delivery Semantics

Warpnet operates under best-effort, eventually-consistent delivery:

  • No strict delivery guarantees are provided

  • Duplicate messages are allowed and must be filtered locally

  • Each message includes a unique identifier and timestamp

  • Timeline merge is deterministic per node based on user ID and timestamp

There is no centralized queue or acknowledgment mechanism. All reliability must be handled by retry or idempotent storage.

WarpNet Peer Discovery

WarpNet uses a modular discovery service to locate, connect to, and validate other peers in the network. It supports multiple discovery backends simultaneously, and uses a unified handler (HandlePeerFound) to process and validate incoming peer information.

Core Mechanism: HandlePeerFound

The central function of the discovery pipeline is discoveryService.HandlePeerFound

This handler is passed to all major discovery backends:

  • PubSub service (receives peer hints from gossip messages)

  • mDNS (local peer discovery via multicast DNS)

  • DHT (peer exchange via the distributed hash table)

  • Strean get info handler (invoked explicitly during connection requests)

All inbound peer discovery events, regardless of source, go through this unified pipeline.

Discovery Pipeline

Each discovered peer passes through several layers:

  1. Rate limiting – using internal token limiter

  2. Duplicate filtering – skip self and known peers

  3. Blocklist check – ignore banned peers

  4. Connect attempt – initiate encrypted Noise stream with PSK validation

  5. NodeInfo request – fetch metadata (/public/get/info)

  6. PSK validation – reject peers from other networks

  7. User sync – download and store peer user profile

This ensures that only authenticated, PSK-valid, non-malicious peers are admitted.

Discovery Backends

1. PubSub-based Discovery

Peers learn about others by observing message gossip in subscribed channels. When a message from an unknown peer is received, its identity is passed to HandlePeerFound.

2. Multicast DNS (mDNS)

Used for LAN-based peer discovery. Each peer announces itself periodically. When a new local peer is found, mDNS passes its address info to the same handler.

3. DHT

WarpNet supports Kademlia-like routing tables. As peers join or query, addresses are learned. DHT internally invokes HandlePeerFound for each new contact.

4. Stream

When a peer explicitly connects and requests node info, its address is passed through the discovery service.

User Synchronization

Upon successful connection, the discovery service:

  1. Fetches the peer's user metadata (OwnerID)

  2. Verifies node integrity and PSK, stores new peer in a peerstore

  3. Stores or updates the user in the local database

This allows WarpNet to maintain a decentralized but consistent view of the network's users.

Bootstrap Peer Handling

If the discovered peer is identified as a bootstrap node:

  • It's marked as a relay candidate

  • No user is synced (bootstraps don't carry profiles)

  • It's added to the routing layer

Summary

  • Discovery is multi-source but centrally handled

  • All discovered peers are validated cryptographically

  • Only peers with a matching PSK are accepted

  • Each peer is queried for metadata and user info

  • Duplicate or blocklisted nodes are rejected

  • Users are synced once per unique node ID

WarpNet discovery is designed for resilience, modularity, and zero-trust-by-default peer authentication.