MANDALA मण्डल

Mesh Architecture for Network Distribution & Layered Aggregation

Sacred geometry of interconnected nodes.

v3.5.10

The Sacred Geometry of Connection

In Buddhist and Hindu traditions, a mandala represents the cosmos— a sacred geometric pattern symbolizing the universe's structure. Concentric circles radiate from a central point, with each layer representing different realms of existence.

The MANDALA protocol embodies this sacred geometry: nodes form a self-organizing mesh with hub nodes at the center, peer connections radiating outward, and message flows traversing the cosmic web of interconnection.

Overview

MANDALA (Mesh Architecture for Network Distribution & Layered Aggregation) provides peer-to-peer mesh networking for the Yakmesh network. It handles node discovery, connection management, message routing, and topology maintenance— creating the underlying fabric that connects all network participants.

Protocol Family

Protocol Himalayan Name Purpose
Gossip MANTRA Epidemic message propagation
Broadcast STUPA Priority-based broadcasting
Consensus LAMA Distributed agreement
Time MANI Temporal synchronization
Trust KARMA Reputation management
Mesh MANDALA Network topology

Message Types

MANDALA defines a set of message types that flow through the sacred geometry, each serving a specific purpose in maintaining the cosmic web:

HELLO

Initial greeting when nodes first connect. Introduces the node to its peer.

{ type: 'HELLO', nodeId, capabilities, version }

WELCOME

Response to HELLO, confirming the connection and sharing peer information.

{ type: 'WELCOME', nodeId, peerList, networkState }

GOSSIP

Epidemic message propagation via MANTRA protocol. Spreads information to peers.

{ type: 'GOSSIP', mantraId, payload, ttl }

SYNC

State synchronization request. Reconciles data between nodes.

{ type: 'SYNC', vectorClock, dataRange }

PING/PONG

Heartbeat messages to maintain connection liveness and measure latency.

{ type: 'PING', timestamp, nonce }

BYE

Graceful disconnection notification. Allows clean peer list updates.

{ type: 'BYE', reason, reconnectHint }

Core Components

MandalaNetwork

The main mesh networking engine—the cosmic web of interconnection:

import { MandalaNetwork, MandalaMessageTypes } from 'yakmesh/mesh/network';

// Initialize the mandala mesh (identity first, config second)
const mandala = new MandalaNetwork(identity, {
  wsPort: 9001,                    // WebSocket listen port (auto-retries +10)
  pingInterval: 30000,             // Peer ping cadence
  maxConcurrentHandshakes: 50,     // Sybil gate — connected peers are unbounded
  holdTimeoutMs: 30000,            // SAMUHA HOLD queue wait
  holdQueueMax: 10,                // HOLD queue depth
});

await mandala.start();

// Listen for events
mandala.on('peer-registered', (peerId) => {
  console.log(`🌐 New connection in the mandala: ${peerId}`);
});

mandala.on('gossip', (payload, fromNodeId) => {
  console.log(`📨 Gossip received from ${fromNodeId}`);
});

// Connect to a peer
await mandala.connect('ws://peer.example.com:9001');

// Broadcast to all peers
mandala.broadcast({
  type: MandalaMessageTypes.GOSSIP,
  payload: { content: 'Hello Mandala!' }
});

Connection Lifecycle

Each connection follows a sacred journey through the mandala:

1 CONNECT WebSocket established
→
2 HELLO Introduce ourselves
→
3 WELCOME Acknowledge & share peers
→
4 ACTIVE Full message exchange
→
5 BYE Graceful disconnect

Network Topology

The MANDALA forms a self-organizing mesh topology, with nodes naturally clustering into a sacred geometry pattern:

                    ┌───────┐
                    │ Edge  │
                    │ Node  │
                    └───┬───┘
                        │
          ┌─────────────┼─────────────┐
          │             │             │
      ┌───┴───┐    ┌────┴────┐    ┌───┴───┐
      │ Outer │    │   Hub   │    │ Outer │
      │ Ring  │────│  Node   │────│ Ring  │
      └───┬───┘    └────┬────┘    └───┬───┘
          │             │             │
          └─────────────┼─────────────┘
                        │
                    ┌───┴───┐
                    │ Peer  │
                    └───────┘

        Legend:
        ─── Primary connection (low latency)
        ··· Secondary connection (backup)
        

Connection States

CONNECTING WebSocket handshake in progress
HANDSHAKING HELLO/WELCOME exchange
ACTIVE Full duplex communication
⏳ DRAINING Graceful shutdown in progress
CLOSED Connection terminated

Configuration

const mandala = new MandalaNetwork(identity, {
  // Listener
  wsPort: 9001,                  // WebSocket listen port
  portRetries: 10,               // Sequential ports tried on bind failure
  
  // Handshake gate (Sybil defense — connected peers stay unbounded)
  maxConcurrentHandshakes: 50,   // Simultaneous HELLO/WELCOME exchanges
  
  // SAMUHA HOLD queue
  holdTimeoutMs: 30000,          // Wait for slot before REDIRECT
  holdQueueMax: 10,              // HOLD queue depth
  
  // Peer maintenance
  pingInterval: 30000,           // PING interval (ms)
  reconnectMaxDelay: 60000,      // Maximum backoff (ms)
  
  // Identity & upgrades
  networkFingerprint: hex,       // Expected network fingerprint
  tribhujRotation: {...},        // Tribhuj key-rotation cadence
  tribhujGrace: {...},           // Grace window for rotated keys
  publicHost: 'host:port',       // Advertised endpoint for inbound peers
});

Integration with Other Protocols

MANDALA serves as the foundation layer, integrating with all other Himalayan protocols:

Protocol Integration
MANTRA GOSSIP messages propagate through MANDALA connections
STUPA Broadcasts use MANDALA for peer selection and delivery
LAMA Consensus votes travel via MANDALA message routing
MANI Time synchronization beacons flow through MANDALA
KARMA Trust scores influence MANDALA peer prioritization
SHERPA Discovery adds new peers to the MANDALA topology

Metrics

// Get network statistics
const stats = mandala.getStats();

console.log(`Connected peers: ${stats.connectedPeers}`);
console.log(`Messages sent: ${stats.messagesSent}`);
console.log(`Messages received: ${stats.messagesReceived}`);
console.log(`Average latency: ${stats.averageLatency}ms`);
console.log(`Uptime: ${stats.uptime}s`);

Related Protocols

Provenance full version history →

Introduced in v1.0.2 — MandalaNetwork mesh core.

  • v3.0.0 — Unified wiring in mega release