Networking

libp2p host, gossip, sync, and direct messaging

XE is a fully peer-to-peer network with no central servers. All node communication -- block propagation, consensus voting, synchronization, marketplace negotiation, and peer discovery -- happens over direct connections between nodes using libp2p.

#Components

ComponentPurposeProtocol / Mechanism
HostTCP transport, connection management, persistent identitylibp2p core
GossipSubBroadcast blocks, votes, marketplace, statechain, directorylibp2p GossipSub
SyncFrontier-based block synchronization/xe/sync/1.0.0 stream
MessagingRequest-response over streams/xe/msg/1.0.0 stream
DHTKademlia peer discovery/xe prefixed DHT

#Architecture Overview

diagram
┌──────────────────────────────────────────────────────────┐│                       Node                               ││                                                          ││  ┌─────────────┐  ┌─────────────┐  ┌─────────────────┐  ││  │   Ledger    │  │ State Chain │  │   Directory     │  ││  └──────┬──────┘  └──────┬──────┘  └───────┬─────────┘  ││         │                │                  │            ││  ┌──────┴────────────────┴──────────────────┴─────────┐  ││  │              Network Layer (net package)            │  ││  │                                                    │  ││  │  ┌──────────┐ ┌──────┐ ┌──────────┐ ┌───────────┐ │  ││  │  │ GossipSub│ │ Sync │ │Messenger │ │    DHT    │ │  ││  │  └────┬─────┘ └──┬───┘ └────┬─────┘ └─────┬─────┘ │  ││  └───────┼──────────┼──────────┼──────────────┼───────┘  ││          │          │          │              │           ││  ┌───────┴──────────┴──────────┴──────────────┴───────┐  ││  │           libp2p Host (TCP transport)              │  ││  └────────────────────────┬───────────────────────────┘  │└───────────────────────────┼──────────────────────────────┘                            │                       TCP / Internet

#How Data Flows

#Block Propagation

  1. A node creates a new block (send, receive, claim, lease, etc.)
  2. The block is added to the local ledger
  3. The block is published via GossipSub on the xe/blocks topic
  4. All subscribed peers receive the block, validate it, and add it to their ledgers
  5. If the block triggers a conflict, votes are broadcast on xe/votes

#Synchronization

When a new node joins or reconnects after downtime, it uses the sync protocol to catch up:

  1. On connection to a peer, the node sends its current frontiers (latest block per account)
  2. The peer compares frontiers and streams back any missing blocks
  3. A periodic re-sync every 10 seconds catches blocks missed during gossip

#Peer-to-Peer Messaging

The messaging protocol provides request-response semantics for targeted communication:

  • Marketplace negotiation (resource requests and offers)
  • State chain synchronization
  • Any typed message exchange between specific peers

#Discovery Mechanisms

Peers find each other through three mechanisms:

  1. mDNS -- Automatic local network discovery. Nodes on the same LAN find each other without configuration.
  2. Bootstrap peers -- Explicit peer addresses passed via the -dial flag. The node retries failed connections every 10 seconds.
  3. Kademlia DHT -- Distributed hash table for discovering peers by their peer ID. Used by the Messenger to locate peers not already in the peerstore.

#Security Properties

  • Transport encryption: libp2p provides encrypted connections by default (Noise or TLS 1.3)
  • Peer identity: Each node has a persistent Ed25519 identity key, giving it a stable peer ID across restarts
  • Message validation: GossipSub pre-validates field lengths before accepting messages
  • Rate limiting: Sync protocol enforces a 5-second cooldown per peer to prevent abuse
  • Size limits: All protocols enforce maximum message sizes to prevent memory exhaustion

#Source Code

The networking layer lives in the core/net/ package:

FileContents
host.goHost creation, mDNS discovery, peer dialing
gossip.goGossipSub for all broadcast topics
sync.goFrontier-based block synchronization
msg.goRequest-response messaging protocol
dht.goKademlia DHT setup
messages.goWire format types for all message types