p2p_http is a lightweight HTTP module for Vix.cpp that exposes a control API
to observe, manage, and interact with the P2P runtime.
It is designed as a control plane, not a data plane:
- HTTP is used for introspection and orchestration
- P2P transports (TCP, QUIC, …) are used for actual peer-to-peer traffic
- Provide a simple HTTP API to control the P2P node
- Enable web UIs, CLIs, and dashboards to interact with P2P
- Stay stateless, safe, and non-blocking
- Integrate cleanly with Vix middleware and runtime
- Exposes HTTP endpoints on top of a running
vix::p2p::Node - Allows external clients (web UI, curl, CLI) to:
- Inspect node status
- List peers
- Connect to new peers
- Acts as a bridge between HTTP and the P2P runtime
- ❌ It does not implement P2P protocols
- ❌ It does not handle encryption or transport logic
- ❌ It does not store peer data persistently
All networking, crypto, handshakes, and state live in vix::p2p.
Returns global node status and statistics.
{
"ok": true,
"running": true,
"peers_total": 3,
"peers_connected": 2,
"handshakes_started": 4,
"handshakes_completed": 2
}Returns a snapshot of known peers.
{
"ok": true,
"peers": [
{
"id": "a3f1…",
"state": "Connected",
"endpoint": "tcp://127.0.0.1:9002",
"secure": true,
"last_seen_ms": 1234
}
]
}Connects to a peer endpoint.
Request body:
{
"host": "127.0.0.1",
"port": 9002,
"scheme": "tcp"
}Response:
{
"ok": true,
"started": true,
"endpoint": "tcp://127.0.0.1:9002"
}Validation rules:
hostmust be non-emptyportmust be in range 1–65535schemedefaults totcp
This example starts two P2P nodes and connects one to the other over TCP.
#include <vix.hpp>
#include <vix/console.hpp>
#include <vix/p2p/Node.hpp>
#include <vix/p2p/P2P.hpp>
using namespace vix;
int main()
{
vix::p2p::NodeConfig cfg;
cfg.node_id = "node-A";
cfg.listen_port = 9001;
cfg.on_log = [](std::string_view s) {
console.info(std::string(s));
};
auto node = vix::p2p::make_tcp_node(cfg);
vix::p2p::P2PRuntime runtime(node);
runtime.start();
console.info("Node A running on port 9001");
runtime.wait(); // blocks
return 0;
}#include <vix.hpp>
#include <vix/console.hpp>
#include <vix/p2p/Node.hpp>
#include <vix/p2p/P2P.hpp>
using namespace vix;
int main()
{
vix::p2p::NodeConfig cfg;
cfg.node_id = "node-B";
cfg.on_log = [](std::string_view s) {
console.info(std::string(s));
};
auto node = vix::p2p::make_tcp_node(cfg);
vix::p2p::P2PRuntime runtime(node);
runtime.start();
vix::p2p::PeerEndpoint ep;
ep.host = "127.0.0.1";
ep.port = 9001;
ep.scheme = "tcp";
node->connect(ep);
console.info("Node B connecting to node A...");
runtime.wait(); // blocks
return 0;
}✅ Pure P2P (no HTTP, no UI) ✅ Asynchronous TCP transport ✅ Secure handshake (Hello / Ack / Finish) ✅ Heartbeats + peer lifecycle ✅ Logs via cfg.on_log
# terminal 1
vix run node_a.cpp
# terminal 2
vix run node_b.cpp[p2p] connect() requested: tcp://127.0.0.1:9001
[p2p] connect() ready: peer_id=...
[p2p] handshake completed- Shows the smallest useful P2P setup
- No framework noise
- Easy mental model
Perfect starting point for:
- messaging
- replication
- offline-first sync
- custom protocols
When compiled with middleware support, routes can be marked as heavy or protected. This allows safe exposure in production environments.
- All P2P operations are dispatched into the P2P runtime
- HTTP handlers never block on network operations
- JSON parsing is validated and defensive
- No raw pointers are stored across requests
- Control plane only
- No hidden background threads
- Explicit and observable behavior
- Crash-safe input handling
MIT — same as Vix.cpp https://github.com/vixcpp/vix