Skip to content
/ p2p Public

Vix.cpp P2P is a secure, offline-first peer-to-peer networking layer for high-performance C++ systems.

License

Notifications You must be signed in to change notification settings

vixcpp/p2p

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

55 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

⚑ Vix.cpp β€” P2P Module

High-performance peer-to-peer & edge networking module for Vix.cpp.
Designed for offline-first systems, unstable networks, and secure distributed runtimes.

This module powers Vix’s sync engine (WAL / outbox) and forms the transport backbone of the ecosystem.


✨ What this module provides

βœ… TCP peer connections
βœ… Secure handshake lifecycle
βœ… Per-peer session state
βœ… Peer discovery (UDP broadcast / multicast)
βœ… HTTP bootstrap (registry pull / announce)
βœ… Runtime peer & handshake statistics
βœ… Clean shutdown & signal handling
βœ… Modular, production-shaped architecture

This is not a toy P2P example.


πŸ“‚ Repository layout

modules/p2p/
β”œβ”€β”€ include/            # Public P2P API (Node, Peer, Protocol, Crypto, …)
β”œβ”€β”€ src/                # Implementation
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ manual/         # Manual integration tests
β”‚   β”‚   β”œβ”€β”€ main.cpp    # p2p_demo (real runtime demo)
β”‚   β”‚   └── registry.py # HTTP bootstrap registry (test server)
β”‚   └── CMakeLists.txt
β”œβ”€β”€ build/              # Build output
β”‚   └── tests/
β”‚       └── p2p_demo    # Compiled demo binary
β”œβ”€β”€ CMakeLists.txt
β”œβ”€β”€ README.md
β”œβ”€β”€ CHANGELOG.md
└── LICENSE

πŸ§ͺ Demo: p2p_demo

The real executable demo lives here after build:

cmake -S . -B build -DVIX_P2P_BUILD_TESTS=ON
cmake --build build -j
build/tests/p2p_demo

It spins up a full P2P node with:

  • listening socket
  • optional outbound connections
  • discovery
  • bootstrap
  • live stats

πŸš€ Run the demo

Terminal A

./build/tests/p2p_demo --id A --listen 9001

Terminal B

./build/tests/p2p_demo --id B --listen 9002 --connect 127.0.0.1:9001

Delayed connect (handshake timeout test)

./build/tests/p2p_demo \
  --id B \
  --listen 9002 \
  --connect 127.0.0.1:9001 \
  --connect-delay 8000

Auto stop after 20 seconds

./build/tests/p2p_demo --id A --listen 9001 --run 20

πŸ“Š Runtime statistics

Printed periodically while running:

peers_total=2
peers_connected=1
handshakes_started=1
handshakes_completed=1

Final stats are always printed on exit.


🌐 Discovery & Bootstrap (optional)

UDP discovery

--discovery on
--disc-mode broadcast | multicast
--disc-port 37020

HTTP bootstrap registry

--bootstrap on
--registry http://127.0.0.1:8080/p2p/v1
--announce on

A minimal test registry is provided in:

tests/manual/registry.py

πŸ” Security model (high-level)

  • Explicit handshake state machine
  • Per-peer session lifecycle
  • Control messages remain plaintext (safe bootstrapping)
  • Designed for AEAD encrypted payloads
  • Ready for secure WAL / sync traffic

🎯 Who this is for

  • C++ backend engineers
  • Distributed systems developers
  • Offline-first / local-first builders
  • Edge & P2P networking enthusiasts
  • Anyone who wants real P2P, not fake examples

⭐ Why star this module?

  • Clean production-oriented P2P design
  • Minimal but realistic
  • Built for unstable networks
  • Reusable as a base for:
    • sync engines
    • mesh networks
    • decentralized runtimes
  • Actively used inside Vix.cpp

🧭 Status

βœ”οΈ Actively developed
βœ”οΈ Manually tested
βœ”οΈ Used internally
🚧 Continuously evolving


If this module helped you understand how real P2P in C++ should look,
leave a ⭐ it genuinely helps the project grow.

About

Vix.cpp P2P is a secure, offline-first peer-to-peer networking layer for high-performance C++ systems.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published