vix p2p
vix p2p runs a peer-to-peer node from the CLI.
Use it when you want to start a local P2P node, connect it to another peer, test peer discovery, use a bootstrap registry, or inspect peer connection behavior.
vix p2p --id <node_id> --listen <port> [options]Overview
vix p2p starts a TCP-based P2P node.
It can:
listen for incoming peer connections
connect to another peer manually
discover peers on the local network
bootstrap peers from an HTTP registry
announce itself to a registry
run for a fixed duration
stream live runtime statistics
dedupe repeated connection attempts
apply backoff after failed connections
handle SIGINT cleanly2
3
4
5
6
7
8
9
10
The command is useful for local testing, demos, debugging, and validating the P2P layer before integrating it into a larger application.
Usage
vix p2p --id <node_id> --listen <port> [options]Required options
| Option | Description |
|---|---|
--id <node_id> | Unique node identifier. |
--listen <port> | TCP port used by this node. |
Example:
vix p2p --id A --listen 9001If either --id or --listen is missing, Vix stops and prints a clear error.
Basic usage
Start node A:
vix p2p --id A --listen 9001Start node B in another terminal and connect it to node A:
vix p2p --id B --listen 9002 --connect 127.0.0.1:9001You can also use a TCP URL-style endpoint:
vix p2p --id B --listen 9002 --connect tcp://127.0.0.1:9001What happens
When you run:
vix p2p --id A --listen 9001Vix:
creates a P2P node
opens a TCP listener
starts discovery when enabled
starts bootstrap when enabled
starts the heartbeat loop
prints runtime statistics
waits until stopped2
3
4
5
6
7
The node can accept incoming peers and can also connect to peers explicitly with --connect.
Run two local nodes
Terminal 1:
vix p2p --id A --listen 9001Terminal 2:
vix p2p --id B --listen 9002 --connect 127.0.0.1:9001This is the simplest local test.
Node A listens.
Node B listens and connects to node A.
Manual connection
Use --connect to connect to a peer when the node starts.
vix p2p --id B --listen 9002 --connect 127.0.0.1:9001With a delay:
vix p2p --id B \
--listen 9002 \
--connect 127.0.0.1:9001 \
--connect-delay 10002
3
4
Use --connect-delay when the peer may need a moment to start.
Disable auto connection
vix p2p --id B --listen 9002 --connect 127.0.0.1:9001 --no-connect--no-connect disables automatic connection behavior.
This is useful when you want the node to listen, discover, or bootstrap without immediately dialing a peer.
Auto-stop
Use --run <seconds> to stop automatically after a fixed duration.
vix p2p --id A --listen 9001 --run 10This is useful for demos, scripts, tests, and CI-style checks.
Example:
vix p2p --id A --listen 9001 --run 10 --quietStats output
By default, vix p2p prints runtime stats.
The stats include:
peers_total
peers_connected
handshakes_started
handshakes_completed
connect_attempts
connect_deduped
connect_failures
backoff_skips
tracked_endpoints2
3
4
5
6
7
8
9
Example shape:
[vix p2p] peers_total=1 peers_connected=1 handshakes_started=1 handshakes_completed=1 connect_attempts=1 connect_deduped=0 connect_failures=0 backoff_skips=0 tracked_endpoints=1Stats interval
Use --stats-every <ms> to control how often stats are printed.
vix p2p --id A --listen 9001 --stats-every 500Default:
1000 msTUI mode
vix p2p can print live stats in a single updating terminal line when stdout is a TTY.
Force TUI on:
vix p2p --id A --listen 9001 --tui onForce TUI off:
vix p2p --id A --listen 9001 --tui offUse --tui off when you want clean line-by-line logs.
Quiet mode
Use --quiet to reduce output.
vix p2p --id A --listen 9001 --run 10 --quietThis is useful for scripts where you only want minimal output.
Discovery
Discovery lets nodes find each other on the local network.
Discovery is enabled by default.
vix p2p --id A --listen 9001 --discovery onDisable discovery:
vix p2p --id A --listen 9001 --discovery offSet discovery port:
vix p2p --id A --listen 9001 --disc-port 37020Set discovery mode:
vix p2p --id A --listen 9001 --disc-mode broadcast
vix p2p --id A --listen 9001 --disc-mode multicast2
Set discovery interval:
vix p2p --id A --listen 9001 --disc-interval 2000Local discovery demo
Terminal 1:
vix p2p --id A \
--listen 9001 \
--discovery on \
--disc-port 370202
3
4
Terminal 2:
vix p2p --id B \
--listen 9002 \
--discovery on \
--disc-port 370202
3
4
Both nodes must use the same discovery port.
Bootstrap registry
Bootstrap lets a node pull peers from an HTTP registry.
vix p2p --id A \
--listen 9001 \
--bootstrap on \
--registry http://127.0.0.1:80802
3
4
By default, bootstrap is off.
Enable it with:
--bootstrap onProvide a registry endpoint with:
--registry <url>Example:
vix p2p --id A \
--listen 9001 \
--bootstrap on \
--registry http://127.0.0.1:8080 \
--boot-interval 152
3
4
5
Bootstrap announce mode
The node can announce itself to the registry.
vix p2p --id A \
--listen 9001 \
--bootstrap on \
--registry http://127.0.0.1:8080 \
--announce on2
3
4
5
Disable announce:
vix p2p --id A \
--listen 9001 \
--bootstrap on \
--registry http://127.0.0.1:8080 \
--announce off2
3
4
5
When announce is enabled, the node can publish its node id and TCP port to the registry.
Expected bootstrap registry shape
The bootstrap registry should expose a peer list.
Expected response shape:
{
"peers": [
{
"node_id": "A",
"host": "127.0.0.1",
"tcp_port": 9001
}
]
}2
3
4
5
6
7
8
9
The bootstrap client reads peers from this response and attempts to connect to them.
Bootstrap endpoints
The HTTP bootstrap implementation expects two logical endpoints:
GET /peers?limit=<n>
POST /announce2
GET /peers returns peer candidates.
POST /announce lets a node announce itself when announce mode is enabled.
Logging
Use --log-level to control logs.
vix p2p --id A --listen 9001 --log-level debugSupported values:
trace
debug
info
warn
warning
error
err
critical
fatal
off
none2
3
4
5
6
7
8
9
10
11
Examples:
vix p2p --id A --listen 9001 --log-level trace
vix p2p --id A --listen 9001 --log-level info
vix p2p --id A --listen 9001 --log-level off2
3
Connection guard
vix p2p protects the node from repeated connection attempts.
It tracks endpoints and applies:
deduplication
failure counting
backoff
tracked endpoint statistics2
3
4
This matters for discovery and bootstrap because the same peer can be found repeatedly.
Instead of blindly dialing the same endpoint again and again, Vix can skip duplicate attempts or wait until backoff expires.
Manual vs automatic attempts
Manual attempts come from:
--connectAutomatic attempts can come from:
discovery
bootstrap2
Automatic attempts are deduped more aggressively to avoid repeated network noise.
Manual attempts still get backoff after failures.
Runtime stats
The P2P runtime exposes node stats and connection guard stats.
Node stats include:
peers_total
peers_connected
handshakes_started
handshakes_completed2
3
4
Connection stats include:
connect_attempts
connect_deduped
connect_failures
backoff_skips
tracked_endpoints2
3
4
5
These counters help you see whether the node is connecting, deduping, failing, or backing off.
Peer lifecycle
A peer can move through several states:
Disconnected
Connecting
Handshaking
Connected
Stale
Closed2
3
4
5
6
The CLI is not only opening a socket.
It starts a real peer lifecycle with handshakes, connection state, heartbeat, and peer tracking.
Handshake behavior
When peers connect, Vix performs a handshake.
The handshake uses messages such as:
Hello
HelloAck
HelloFinish2
3
After a successful handshake, the peer becomes connected.
The node tracks:
handshakes_started
handshakes_completed2
These counters are visible in CLI stats.
Heartbeat behavior
The node sends heartbeat messages to connected peers.
The heartbeat uses:
Ping
Pong2
If a peer becomes stale, the node can close the connection.
This helps detect inactive or dead peers.
Security behavior
The P2P layer has cryptographic hooks.
The node can attach a crypto provider and stores peer metadata such as:
public key
secure flag
session key
send nonce counter
receive nonce tracking
anti-replay window2
3
4
5
6
This means the P2P model is designed for secure sessions, replay protection, and encrypted message support.
Core options
| Option | Description | |
|---|---|---|
--id <node_id> | Unique node identifier. | |
--listen <port> | TCP listen port. | |
--connect <host:port> | Connect to a peer on startup. | |
--connect tcp://<host:port> | Connect using TCP endpoint notation. | |
--connect-delay <ms> | Wait before connecting. | |
--run <seconds> | Auto-stop after N seconds. | |
--stats-every <ms> | Stats interval. Default is 1000. | |
| `--tui <on | off>` | Enable or disable live stats display. |
--quiet | Reduce output. | |
--no-connect | Disable automatic connect behavior. | |
-h, --help | Show command help. |
Discovery options
| Option | Description | |
|---|---|---|
| `--discovery <on | off>` | Enable or disable discovery. Default is on. |
--disc-port <port> | Discovery port. Default is 37020. | |
--disc-mode <mode> | Discovery mode: broadcast or multicast. | |
--disc-interval <ms> | Discovery interval. Default is 2000. |
Bootstrap options
| Option | Description | |
|---|---|---|
| `--bootstrap <on | off>` | Enable or disable registry bootstrap. Default is off. |
--registry <url> | Bootstrap registry endpoint. | |
--boot-interval <sec> | Registry refresh interval. Default is 15. | |
| `--announce <on | off>` | Announce node to registry. Default is on. |
Logging options
| Option | Description |
|---|---|
--log-level <level> | Set runtime log level. |
Supported levels:
trace
debug
info
warn
error
critical
off2
3
4
5
6
7
Aliases:
warning -> warn
err -> error
fatal -> critical
none -> off2
3
4
Common workflows
Run one node
vix p2p --id A --listen 9001Run two local nodes
Terminal 1:
vix p2p --id A --listen 9001Terminal 2:
vix p2p --id B --listen 9002 --connect 127.0.0.1:9001Run a short demo
vix p2p --id A --listen 9001 --run 10Run quietly in a script
vix p2p --id A --listen 9001 --run 10 --quietUse explicit stats interval
vix p2p --id A --listen 9001 --stats-every 500Disable TUI output
vix p2p --id A --listen 9001 --tui offUse discovery
Terminal 1:
vix p2p --id A \
--listen 9001 \
--discovery on \
--disc-port 370202
3
4
Terminal 2:
vix p2p --id B \
--listen 9002 \
--discovery on \
--disc-port 370202
3
4
Use bootstrap registry
vix p2p --id A \
--listen 9001 \
--bootstrap on \
--registry http://127.0.0.1:8080 \
--boot-interval 15 \
--announce on2
3
4
5
6
Debug connection behavior
vix p2p --id B \
--listen 9002 \
--connect 127.0.0.1:9001 \
--log-level debug \
--tui off2
3
4
5
Example output
Output shape:
[vix p2p] peers_total=1 peers_connected=1 handshakes_started=1 handshakes_completed=1 connect_attempts=1 connect_deduped=0 connect_failures=0 backoff_skips=0 tracked_endpoints=1This tells you:
how many peers are known
how many peers are connected
whether handshakes are happening
whether connection attempts are being deduped
whether backoff is active2
3
4
5
Common mistakes
Missing required options
Wrong:
vix p2pCorrect:
vix p2p --id A --listen 9001Reusing the same port
Wrong:
vix p2p --id A --listen 9001
vix p2p --id B --listen 90012
Correct:
vix p2p --id A --listen 9001
vix p2p --id B --listen 90022
Each local node needs its own TCP listen port.
Reusing the same node id
Wrong:
vix p2p --id A --listen 9001
vix p2p --id A --listen 90022
Correct:
vix p2p --id A --listen 9001
vix p2p --id B --listen 90022
Use one unique id per node.
Connecting before the peer is ready
Start the listening peer first.
Or use:
vix p2p --id B \
--listen 9002 \
--connect 127.0.0.1:9001 \
--connect-delay 10002
3
4
Using different discovery ports
Wrong:
vix p2p --id A --listen 9001 --discovery on --disc-port 37020
vix p2p --id B --listen 9002 --discovery on --disc-port 370212
Correct:
vix p2p --id A --listen 9001 --discovery on --disc-port 37020
vix p2p --id B --listen 9002 --discovery on --disc-port 370202
Discovery peers must use the same discovery port.
Enabling bootstrap without a registry URL
Wrong:
vix p2p --id A --listen 9001 --bootstrap onCorrect:
vix p2p --id A \
--listen 9001 \
--bootstrap on \
--registry http://127.0.0.1:80802
3
4
Expecting discovery to work across every network
Local discovery depends on network behavior.
Firewalls, containers, VPNs, Wi-Fi isolation, and cloud networks can block broadcast or multicast traffic.
For non-local networks, use bootstrap.
Expecting --quiet to help debugging
--quiet reduces output.
For debugging, prefer:
vix p2p --id A --listen 9001 --log-level debug --tui offTroubleshooting
Port already in use
Use another port:
vix p2p --id A --listen 9003Or find the process using the port:
sudo lsof -i :9001Node does not connect
Check that the target node is already running:
vix p2p --id A --listen 9001Then connect:
vix p2p --id B --listen 9002 --connect 127.0.0.1:9001If startup timing is the issue:
vix p2p --id B \
--listen 9002 \
--connect 127.0.0.1:9001 \
--connect-delay 10002
3
4
Discovery does not find peers
Check:
both nodes use --discovery on
both nodes use the same --disc-port
firewall allows local discovery traffic
nodes are on the same network
broadcast or multicast is supported2
3
4
5
Try explicit connection first:
vix p2p --id B --listen 9002 --connect 127.0.0.1:9001Bootstrap does not return peers
Check the registry URL:
curl http://127.0.0.1:8080/peers?limit=20Expected shape:
{
"peers": []
}2
3
If announce is enabled, check that the registry supports:
POST /announceToo many connection attempts
Look at:
connect_deduped
backoff_skips
tracked_endpoints2
3
If connect_deduped increases, Vix is protecting the node from repeated automatic attempts.
If backoff_skips increases, endpoints are failing and Vix is waiting before retrying.
Handshakes start but do not complete
Look at:
handshakes_started
handshakes_completed2
If started increases but completed does not, the peer may be disconnecting, handshake validation may be failing, or the remote node may not be compatible.
Use:
vix p2p --id A --listen 9001 --log-level debug --tui offBest practices
Use unique node ids.
Use unique listen ports for local nodes.
Start the first node before connecting the second node.
Use --connect-delay in scripts.
Use --run for demos and automated checks.
Use --tui off when saving logs.
Use --log-level debug when diagnosing peer behavior.
Use discovery for local network demos.
Use bootstrap for non-local or structured peer discovery.
Use the stats counters to understand what the node is doing.
Related commands
| Command | Purpose |
|---|---|
vix run | Run a C++ file, project, script, or app. |
vix dev | Run a project in development mode. |
vix check | Validate project health. |
vix info | Inspect Vix paths and local state. |
vix doctor | Check the local environment. |
vix logs | Inspect production logs when used with deployed services. |
vix health | Check local, public, or WebSocket service health. |
Next step
Continue with environment information.