discv4::discv4_client¶
Discovery v4 protocol client. More...
#include <discv4_client.hpp>
Public Functions¶
| Name | |
|---|---|
| discv4_client(asio::io_context & io_context, const discv4Config & config) | |
| ~discv4_client() | |
| rlpx::VoidResult | start() |
| void | stop() |
| discv4::Result< discv4_pong > | ping(const std::string & ip, uint16_t port, const NodeId & node_id, boost::asio::yield_context yield) Send PING to a specific node. |
| rlpx::VoidResult | find_node(const std::string & ip, uint16_t port, const NodeId & target_id, boost::asio::yield_context yield) Send FIND_NODE to discover peers near a target. |
| discv4::Result< discv4_enr_response > | request_enr(const std::string & ip, uint16_t port, boost::asio::yield_context yield) Send ENRRequest to a bonded peer and return the raw ENR record bytes. |
| std::vector< DiscoveredPeer > | get_peers() const |
| void | set_peer_discovered_callback(PeerDiscoveredCallback callback) |
| void | set_error_callback(ErrorCallback callback) |
| const NodeId & | local_node_id() const |
| uint16_t | bound_port() const Return the local UDP port the socket is bound to. Useful in tests where bind_port=0 (OS-assigned ephemeral port). |
Detailed Description¶
Discovery v4 protocol client.
Implements the Ethereum Discovery v4 protocol for peer discovery. Uses UDP for communication with bootstrap nodes and discovered peers.
Protocol flow:
- Send PING to bootstrap nodes
- Receive PONG responses
- Send FIND_NODE to discover more peers
- Receive NEIGHBOURS responses with peer lists
- Maintain K-bucket routing table
Public Functions Documentation¶
function discv4_client¶
function ~discv4_client¶
function start¶
function stop¶
function ping¶
discv4::Result< discv4_pong > ping(
const std::string & ip,
uint16_t port,
const NodeId & node_id,
boost::asio::yield_context yield
)
Send PING to a specific node.
Parameters:
- ip Target node IP address.
- port Target node UDP port.
- node_id Target node identifier.
- yield Boost.Asio stackful coroutine context.
function find_node¶
rlpx::VoidResult find_node(
const std::string & ip,
uint16_t port,
const NodeId & target_id,
boost::asio::yield_context yield
)
Send FIND_NODE to discover peers near a target.
Parameters:
- ip Target node IP address.
- port Target node UDP port.
- target_id Target node identifier to search near.
- yield Boost.Asio stackful coroutine context.
function request_enr¶
discv4::Result< discv4_enr_response > request_enr(
const std::string & ip,
uint16_t port,
boost::asio::yield_context yield
)
Send ENRRequest to a bonded peer and return the raw ENR record bytes.
Parameters:
- ip Target node IP address.
- port Target node UDP port.
- yield Boost.Asio stackful coroutine context.
Return: Parsed ENRResponse on success, error on timeout or parse failure.
The peer must already be bonded (ping/pong complete) before calling this. Mirrors go-ethereum UDPv4::RequestENR().
function get_peers¶
function set_peer_discovered_callback¶
function set_error_callback¶
function local_node_id¶
function bound_port¶
Return the local UDP port the socket is bound to. Useful in tests where bind_port=0 (OS-assigned ephemeral port).
Updated on 2026-04-13 at 23:22:46 -0700