Skip to content

eth/eth_peer_session.hpp

Namespaces

Name
eth

Classes

Name
struct eth::EthStatusHandshakeStart
Parameters for starting the ETH Status handshake on a negotiated session.
struct eth::EthStatusHandshakeResult
Result of the ETH Status startup handshake owned by the ETH layer.

Types

Name
using std::function< void(const StatusMessage &)> EthStatusAcceptedHandler
Callback invoked when the remote ETH Status message is accepted.
using std::function< void(rlpx::DisconnectReason)> EthStatusRemoteDisconnectHandler
Callback invoked when the remote sends an RLPx Disconnect during ETH Status.

Functions

Name
StatusMessage BuildLocalStatusMessage(uint8_t negotiated_protocol_version, uint64_t network_id, const Hash256 & genesis_hash, const ForkId & fork_id)
Build the local ETH Status message for the negotiated ETH protocol version.
protocol::ValidationResult ValidateRemoteStatusMessage(const StatusMessage & remote_status, uint8_t negotiated_protocol_version, uint64_t expected_network_id, const Hash256 & expected_genesis_hash)
Validate a remote ETH Status message against negotiated version and chain.
bool StartEthStatusHandshake(const EthStatusHandshakeStart & start)
Install post-handshake ETH inbound handling on a negotiated session.

Types Documentation

using EthStatusAcceptedHandler

using eth::EthStatusAcceptedHandler = std::function<void(const StatusMessage&)>;

Callback invoked when the remote ETH Status message is accepted.

using EthStatusRemoteDisconnectHandler

using eth::EthStatusRemoteDisconnectHandler = std::function<void(rlpx::DisconnectReason)>;

Callback invoked when the remote sends an RLPx Disconnect during ETH Status.

Functions Documentation

function BuildLocalStatusMessage

StatusMessage BuildLocalStatusMessage(
    uint8_t negotiated_protocol_version,
    uint64_t network_id,
    const Hash256 & genesis_hash,
    const ForkId & fork_id
)

Build the local ETH Status message for the negotiated ETH protocol version.

Parameters:

  • negotiated_protocol_version The negotiated ETH subprotocol version.
  • network_id Local chain network id.
  • genesis_hash Local chain genesis hash.
  • fork_id Local chain fork id.

Return: ETH/68 or ETH/69 Status message matching the negotiated version.

function ValidateRemoteStatusMessage

protocol::ValidationResult ValidateRemoteStatusMessage(
    const StatusMessage & remote_status,
    uint8_t negotiated_protocol_version,
    uint64_t expected_network_id,
    const Hash256 & expected_genesis_hash
)

Validate a remote ETH Status message against negotiated version and chain.

Parameters:

  • remote_status Decoded remote Status message.
  • negotiated_protocol_version Negotiated ETH subprotocol version.
  • expected_network_id Expected chain network id.
  • expected_genesis_hash Expected chain genesis hash.

Return: Success when the status matches the negotiated version and chain.

function StartEthStatusHandshake

bool StartEthStatusHandshake(
    const EthStatusHandshakeStart & start
)

Install post-handshake ETH inbound handling on a negotiated session.

Parameters:

  • start Handshake start parameters bound to the negotiated session/channel.

Return: True when the post-handshake handler was installed successfully.

Source code

// Copyright 2026 Genius Ventures, Inc.
// SPDX-License-Identifier: MIT

#ifndef EVMRELAY_INCLUDE_ETH_ETH_PEER_SESSION_HPP
#define EVMRELAY_INCLUDE_ETH_ETH_PEER_SESSION_HPP

#include <eth/messages.hpp>
#include <eth/eth_session_channel.hpp>
#include <boost/asio/spawn.hpp>

namespace eth {

using EthStatusAcceptedHandler = std::function<void(const StatusMessage&)>;

using EthStatusRemoteDisconnectHandler = std::function<void(rlpx::DisconnectReason)>;

struct EthStatusHandshakeStart
{
    std::shared_ptr<IEthSessionChannel> channel;
    uint64_t                           network_id = 0;
    Hash256                            genesis_hash{};
    ForkId                             fork_id{};
    std::vector<EthMessageSchema>      eth_message_schemas;
    EthStatusAcceptedHandler           accepted_status_handler;
    EthStatusRemoteDisconnectHandler   remote_disconnect_handler;
    rlpx::EthMessageHandler            inbound_message_handler;
};

struct EthStatusHandshakeResult
{
    StatusMessage remote_status{};
};

[[nodiscard]] StatusMessage BuildLocalStatusMessage(
    uint8_t             negotiated_protocol_version,
    uint64_t            network_id,
    const Hash256&      genesis_hash,
    const ForkId&       fork_id) noexcept;

[[nodiscard]] protocol::ValidationResult ValidateRemoteStatusMessage(
    const StatusMessage& remote_status,
    uint8_t              negotiated_protocol_version,
    uint64_t             expected_network_id,
    const Hash256&       expected_genesis_hash) noexcept;

[[nodiscard]] bool StartEthStatusHandshake(
    const EthStatusHandshakeStart& start) noexcept;

} // namespace eth


#endif // EVMRELAY_INCLUDE_ETH_ETH_PEER_SESSION_HPP

Updated on 2026-06-05 at 17:22:19 -0700