Peer-to-peer engine for Vix.cpp.
The P2P module provides the networking and replication foundation used to build offline-first, local-first, and distributed C++ systems with peer discovery, secure handshakes, message framing, transport abstraction, routing, WAL replication, and safe sync.
Full documentation will be available here:
https://docs.vixcpp.com/modules/p2p/
API reference:
https://docs.vixcpp.com/modules/p2p/api-reference
- Peer discovery
- LAN discovery
- Registry-based bootstrap
- Secure handshake
- Message framing
- Protocol envelopes
- Message dispatch
- Transport abstraction
- Peer routing
- WAL replication
- Outbox synchronization
- Offline-first sync
- Failure-tolerant replication model
#include <vix/p2p.hpp>Or include specific headers when needed:
#include <vix/p2p/discovery.hpp>
#include <vix/p2p/framing.hpp>
#include <vix/p2p/envelope.hpp>
#include <vix/p2p/dispatch.hpp>
#include <vix/p2p/router.hpp>
#include <vix/p2p/sync.hpp>local write
-> WAL
-> envelope
-> framing
-> transport
-> peer
-> apply
-> ack
-> retry until convergence
The network is not required for local correctness. Nodes can continue working offline and synchronize when connectivity returns.
Discovery
-> finds peers
Transport
-> sends bytes
Framing
-> splits byte streams into messages
Envelope
-> wraps protocol messages
Dispatch
-> routes message types
EdgeSync
-> WAL replication and outbox sync
Router
-> optional peer routing
encode(message)
-> envelope
-> framing
-> transport
-> network
-> decode
-> dispatch
-> handler
A -> Hello
B -> HelloAck
A -> HelloFinish
After the handshake, the peer session can become connected and start exchanging protocol messages.
local operation
-> append to WAL
-> push WAL batch
-> peer applies operation
-> peer sends acknowledgement
-> retry pending operations until convergence
vix run examples/p2p/01_envelope_and_framing_basic.cppvix run examples/p2p/02_hello_handshake_messages.cppvix run examples/p2p/03_discovery_announce_json.cppvix run examples/p2p/04_router_memory_basic.cppvix run examples/p2p/05_pack_secure_envelope.cppvix run examples/p2p/06_dispatch_decode_basic.cppvix run examples/p2p/07_wal_push_and_ack.cppTerminal 1:
vix run examples/p2p/08_runtime_manual_connect.cpp --run serverTerminal 2:
vix run examples/p2p/08_runtime_manual_connect.cpp --run client 127.0.0.1 9101Terminal 1:
vix run examples/p2p/09_udp_discovery_basic.cpp --run node-a 9201Terminal 2:
vix run examples/p2p/09_udp_discovery_basic.cpp --run node-b 9202vix run examples/p2p/10_bootstrap_http_basic.cpp --run http://127.0.0.1:8080/peersYou can also run a P2P node directly from the Vix CLI:
vix p2p --id A --listen 9001Connect another node:
vix p2p --id B --listen 9002 --connect 127.0.0.1:9001When using vix run, keep this rule:
-- = compiler or linker flags
--run = runtime arguments passed to the program
Example:
vix run examples/p2p/08_runtime_manual_connect.cpp --run client 127.0.0.1 9101Contributors should use the Vix CLI to build this module.
Vix wraps the C++ build workflow with project detection, presets, Ninja builds, clean logs, caching, and focused diagnostics. This keeps the contributor workflow consistent and helps avoid hidden C++ build issues.
git clone https://github.com/vixcpp/vix.git
cd vix
vix buildUse this before running the full test suite, install workflows, or release checks:
vix build --build-target allUse this when the local CMake cache or build directory may be stale:
vix build --cleanvix build --preset releaseBuild all targets first, then run tests:
vix build --build-target all
vix testsBefore opening a pull request, use:
vix fmt --check
vix build --build-target all
vix tests- P2P documentation: https://docs.vixcpp.com/modules/p2p/
- P2P API reference: https://docs.vixcpp.com/modules/p2p/api-reference
- P2P CLI command: https://docs.vixcpp.com/cli/p2p
- Build command: https://docs.vixcpp.com/cli/build
- Tests command: https://docs.vixcpp.com/cli/tests
- Documentation: https://docs.vixcpp.com/
- Engineering notes: https://blog.vixcpp.com/
- Registry: https://registry.vixcpp.com/
- GitHub: https://github.com/vixcpp/vix
MIT License.
See LICENSE for details.