Skip to content

feat(api): add peer management to admin RPC - #86

Open
317787106 wants to merge 8 commits into
feature/admin_rpcfrom
feature/peer_management
Open

feat(api): add peer management to admin RPC#86
317787106 wants to merge 8 commits into
feature/admin_rpcfrom
feature/peer_management

Conversation

@317787106

@317787106 317787106 commented Aug 20, 2026

Copy link
Copy Markdown
Owner

What does this PR do?

This PR adds runtime peer management to the Admin JSON-RPC API over both HTTP and IPC. It introduces admin_addPeer, admin_removePeer, admin_disconnectPeer, admin_listActivePeers, admin_blockIp, admin_unblockIp, and admin_listBlockedIps.

Active nodes can be added or removed without restarting the node, while an exact peer connection can be disconnected independently. Manually blocked IPs are persisted in CommonStore under blocked-ips, loaded before libp2p starts, applied to TCP connections, and exposed through the Admin API. Invalid persisted data is deleted on a best-effort basis and does not prevent network startup.

The active-peer response reuses the immutable statistics used by PeerConnection.log(), including connection, latency, and synchronization state. Peer and blocked-IP mutations share one structured PeerOperationResult response.

Why are these changes required?

Operators need a way to react immediately after identifying a malicious peer: disconnecting or blocking it cuts the attack path, while adding a trusted endpoint restores useful connectivity without restarting the node. This helps preserve synchronization, block production, and message propagation during Sybil or isolation attacks.

Behavior notes

  • admin_addPeer adds an active node but does not add it to trustNodes.
  • When node.dynamicConfig.enable is enabled, add/remove active-node operations return a structured failure directing operators to update node.active instead.
  • Adding an endpoint whose IP is manually blocked is rejected.
  • Blocking an IP persists the new snapshot before applying it to libp2p and disconnecting matching TCP connections.
  • The first phase does not filter UDP discovery traffic from Kademlia or DNS discovery.
  • No new peer-management configuration switch is introduced; existing Admin HTTP/IPC controls remain authoritative.

Testing

  • Added unit coverage for startup loading, corrupt-data recovery, persistence ordering, idempotency, concurrent block updates, active-node operations, blocked-IP conflicts, dynamic-config behavior, and active-peer statistics.
  • Added HTTP and IPC dispatch/error-code coverage for the new methods.
  • Added lifecycle and effective-connection compatibility tests.
  • checkstyleMain, checkstyleTest, and the related framework test suites pass.

Follow-up

Use the released libp2p version after the dependent PR is merged; UDP discovery filtering can be considered in a later phase.

Extra details

Depends on libp2p PR #6. No protobuf, P2P wire-message, consensus, or chain-data format changes are introduced.

@317787106 317787106 changed the title support peer management based on ipc feat(net): support runtime peer management Aug 20, 2026
@317787106 317787106 changed the title feat(net): support runtime peer management feat(api): add peer management to admin RPC Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant