Skip to content

antharmaya/shop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

38 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿœ SHOP Protocol

Rust Docker License Version

A Bio-Mimetic, Self-Healing P2P Mesh Network

SHOP (Self-Healing Overlay Protocol) is a decentralized networking protocol inspired by Ant Colony Optimization. Nodes communicate using virtual pheromones, enabling emergent routing intelligence without central coordination.


โœจ Key Features

Feature Description
๐Ÿง  Stigmergy Pheromone-based routing โ€” successful paths strengthen automatically
๐Ÿ” Hybrid Discovery mDNS (LAN) + Kademlia DHT (WAN) for zero-config peering
๐ŸŒ WAN Connectivity NAT traversal via Circuit Relay v2 + DCUtR hole punching
๐Ÿ’พ Crash-Safe Persistence sled embedded DB with zstd compression and versioned schemas
๐Ÿ›ก๏ธ DoS Protection Token auth, SSE rate limiting, input sanitization
๐Ÿ“Š Real-Time Dashboard Cyberpunk-styled network visualizer with live pheromone updates
๐Ÿณ Production-Ready Docker Compose deployment with health checks

๐Ÿ—๏ธ Architecture

graph TB
    subgraph Node["๐Ÿœ SHOP Node"]
        CLI["shop-cli"]
        subgraph Actors["Actor System"]
            NA["NetworkActor<br/>๐ŸŒ libp2p Swarm"]
            CA["ColonyActor<br/>๐Ÿง  Bio-Engine"]
            AA["ApiActor<br/>๐Ÿ–ฅ๏ธ HTTP API"]
        end
        subgraph Storage["Persistence"]
            Sled["sled DB<br/>๐Ÿ’พ Identity + Graph"]
        end
    end

    subgraph Network["P2P Network"]
        mDNS["mDNS<br/>๐Ÿ“ก LAN Discovery"]
        Kad["Kademlia DHT<br/>๐ŸŒ WAN Routing"]
        Gossip["Gossipsub<br/>๐Ÿ“ข Pheromone Broadcast"]
        Relay["Relay Servers<br/>๐Ÿ”„ NAT Traversal"]
    end

    CLI --> NA
    NA <--> CA
    CA <--> AA
    CA --> Sled
    NA <--> mDNS
    NA <--> Kad
    NA <--> Gossip
    NA <-.-> Relay
Loading

๐Ÿš€ Quick Start

Option 0: SRE Orchestrator (Quickest)

The easiest way to see the swarm in action (requires Linux/Mac):

# Runs 5 nodes, primes the network, and starts generating traffic
./scripts/simulate_swarm.sh

Note: This simulates on one machine. For real devices (Pi, servers, IoT), see DEPLOYMENT.md.

Option 1: Docker Compose (Recommended)

# Clone and enter directory
git clone https://github.com/your-org/shop-protocol.git
cd shop-protocol/shop

# Start 1 bootnode + 4 workers
docker compose up --build -d

# View logs
docker compose logs -f bootnode

# Open Dashboard
open http://localhost:3000

Option 2: Cargo (Development)

# Install Rust (if needed)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Clone and build
git clone https://github.com/your-org/shop-protocol.git
cd shop-protocol/shop
cargo build --release

# Run a node
cargo run -p shop-cli -- --api-port 3000

# Run additional nodes (in separate terminals)
cargo run -p shop-cli -- --api-port 3001
cargo run -p shop-cli -- --api-port 3002

๐ŸŒ Real-World Deployment

The quick start options above are for local testing. For deploying SHOP across real devices (Raspberry Pi, VPS, IoT devices, etc.), see:

๐Ÿ“˜ DEPLOYMENT.md - Comprehensive guide covering:

  • โœ… Platform support (Linux, macOS, Windows, Raspberry Pi, Docker, Kubernetes)
  • โœ… LAN vs WAN deployment strategies
  • โœ… NAT traversal configuration
  • โœ… Production readiness assessment
  • โœ… Troubleshooting common issues
  • โš ๏ธ Current limitations and gaps

TL;DR:

  • LAN (Same Network): Just run the binary, nodes auto-discover via mDNS
  • WAN (Internet): Need a bootnode with public IP + relay configuration
  • Production: Use Docker with persistent volumes and structured logging

๐Ÿ“ก API Reference

Dashboard

Endpoint Description
GET / Cyberpunk network visualizer
GET /api/v1/graph JSON graph state
GET /api/v1/events SSE stream of updates

Control Plane

Endpoint Auth Description
POST /dispatch x-shop-token Send packet to peer
POST /api/v1/control x-shop-token Update PID parameters

Example: Dispatch a Packet

curl -X POST http://localhost:3000/dispatch \
  -H "Content-Type: application/json" \
  -H "x-shop-token: shop-secret" \
  -d '{"destination": "12D3KooW...", "payload": "hello"}'

๐Ÿ—‚๏ธ Project Structure

shop/
โ”œโ”€โ”€ crates/
โ”‚   โ”œโ”€โ”€ shop-cli/       # CLI entry point
โ”‚   โ”œโ”€โ”€ shop-node/      # Core node (actors, API, storage)
โ”‚   โ”œโ”€โ”€ shop-core/      # Shared types and math
โ”‚   โ””โ”€โ”€ shop-proto/     # Protobuf definitions
โ”œโ”€โ”€ Dockerfile          # Multi-stage production build
โ”œโ”€โ”€ docker-compose.yml  # 5-node deployment
โ””โ”€โ”€ scripts/            # Simulation utilities

๐Ÿ”ฎ Roadmap

v1.0.0 โœ…

  • Bio-Engine with PID-tuned evaporation
  • Hybrid mDNS/DHT discovery
  • Persistent identity and graph state
  • Security hardening (auth, DoS protection)
  • Docker deployment

v1.1.0 โœ…

  • ๐ŸŒ WAN Connectivity โ€” NAT traversal via Circuit Relay v2 + DCUtR hole punching
  • ๐Ÿ” AutoNAT โ€” Automatic NAT status detection

v1.1.2 (Current) โœ…

  • ๐Ÿ›ก๏ธ Stability Hardening โ€” Deadlock prevention, graph pruning, Monitor Pattern
  • ๐Ÿ”„ Fail-Fast Actors โ€” JoinHandle tracking triggers shutdown on panic

v2.0.0 (Planned)

  • ๐Ÿ Multi-Colony Competition โ€” Red vs Blue foraging strategies
  • ๐Ÿ”Œ WASM Plugins โ€” Hot-swap foraging logic at runtime
  • ๐Ÿ“Š Prometheus Metrics โ€” Production observability

๐Ÿ“„ License

MIT License โ€” see LICENSE for details.


Built with ๐Ÿฆ€ Rust and inspired by ๐Ÿœ Nature