Testing RPC Communication
This guide explains how to test the JSON-RPC communication between icnd (daemon) and icnctl (CLI).
Prerequisites
Build both binaries:
cargo build --bin icnd cargo build --bin icnctlCreate an identity (required for daemon to spawn network actors and RPC server):
./target/debug/icnctl id initFollow the prompts to set a passphrase. This will create
~/.icn/identity.age.
Testing Procedure
1. Start the Daemon
In terminal 1:
./target/debug/icnd
You should see output like:
INFO icnd: ICNd starting
INFO icnd: Data directory: "/home/user/.local/share/icn"
INFO icn_core::supervisor: Supervisor starting
INFO icn_core::supervisor: Network actor spawned on 0.0.0.0:7777
INFO icn_core::supervisor: RPC server spawned on 127.0.0.1:5050
The daemon will prompt for your passphrase to unlock the keystore.
2. Test Network Commands
In terminal 2, run these commands:
Check Network Status
./target/debug/icnctl network status
Expected output:
Network Actor Status:
Running: true
Listener address: 0.0.0.0:7777
View Network Statistics
./target/debug/icnctl network stats
Expected output:
Network Statistics:
Peers discovered: 0
Active connections: 0
Total connections: 0
List Discovered Peers
./target/debug/icnctl network peers
Expected output (when no peers are available):
No peers discovered yet.
Tip: Ensure other ICN nodes are running on the network.
Dial a Peer (Example)
./target/debug/icnctl network dial did:icn:z6MkpTHR8VNs... --addr 192.168.1.100:7777
Note: This requires a valid peer DID and address.
Testing Without an Identity
If you run icnd without creating an identity first, you'll see:
WARN icnd: No identity keystore found
WARN icnd: Run 'icnctl id init' to create an identity
WARN icnd: Daemon will run without Identity and Network actors
In this case, the RPC server won't be spawned and icnctl network commands will fail with:
Error: Failed to get status from daemon. Is icnd running?
RPC Protocol Details
- Protocol: JSON-RPC 2.0 over HTTP/1.1
- Server Address: 127.0.0.1:5050
- Transport: HTTP POST requests with JSON payload
Available RPC Methods
network.peers- List discovered peersnetwork.dial- Connect to a peernetwork.stats- Get network statisticsnetwork.status- Get network actor status
Example Raw RPC Request
You can test the RPC server directly with curl:
curl -X POST http://127.0.0.1:5050 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "network.status",
"params": {},
"id": 1
}'
Expected response:
{
"jsonrpc": "2.0",
"result": {
"running": true,
"listen_addr": "0.0.0.0:7777"
},
"id": 1
}
Troubleshooting
"Failed to get status from daemon. Is icnd running?"
- Check if
icndis running:ps aux | grep icnd - Verify the RPC server is listening:
lsof -i :5050 - Ensure you created an identity:
ls ~/.icn/identity.age
"Connection refused"
The daemon's RPC server only spawns when an identity exists. Run icnctl id init first.
"No peers discovered yet"
mDNS discovery requires:
- Other ICN nodes running on the same local network
- Multicast DNS support in your network
- Firewall rules allowing mDNS traffic (UDP port 5353)
Next Steps
To test peer discovery and connections, you'll need to:
- Run multiple
icndinstances on the same network (different machines or VMs) - Each instance needs its own data directory:
icnd --data-dir ~/.icn-node2 - Peers should automatically discover each other via mDNS
- Use
icnctl network peersto verify discovery - Use
icnctl network dial <did>to establish connections