From ff1f146efb1d9705f89fbf151559f1705fb45528 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Wed, 15 Oct 2025 15:48:57 -0400 Subject: [PATCH 1/3] Rename attach<> to session_peer, style, comments on RCTP. --- Makefile.am | 2 +- .../libbitcoin-node/libbitcoin-node.vcxproj | 2 +- .../libbitcoin-node.vcxproj.filters | 6 +-- include/bitcoin/node.hpp | 2 +- .../bitcoin/node/sessions/session_inbound.hpp | 6 +-- .../bitcoin/node/sessions/session_manual.hpp | 6 +-- .../node/sessions/session_outbound.hpp | 6 +-- .../sessions/{attach.hpp => session_peer.hpp} | 40 +++++++++++-------- include/bitcoin/node/sessions/sessions.hpp | 2 +- 9 files changed, 39 insertions(+), 33 deletions(-) rename include/bitcoin/node/sessions/{attach.hpp => session_peer.hpp} (83%) diff --git a/Makefile.am b/Makefile.am index 6dc738bdc..8494a00aa 100644 --- a/Makefile.am +++ b/Makefile.am @@ -196,11 +196,11 @@ include_bitcoin_node_protocols_HEADERS = \ include_bitcoin_node_sessionsdir = ${includedir}/bitcoin/node/sessions include_bitcoin_node_sessions_HEADERS = \ - include/bitcoin/node/sessions/attach.hpp \ include/bitcoin/node/sessions/session.hpp \ include/bitcoin/node/sessions/session_inbound.hpp \ include/bitcoin/node/sessions/session_manual.hpp \ include/bitcoin/node/sessions/session_outbound.hpp \ + include/bitcoin/node/sessions/session_peer.hpp \ include/bitcoin/node/sessions/session_tcp.hpp \ include/bitcoin/node/sessions/sessions.hpp diff --git a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj index b0d09e10c..34767481c 100644 --- a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj +++ b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj @@ -200,11 +200,11 @@ - + diff --git a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters index 2f73303a8..50b94fc58 100644 --- a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters +++ b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters @@ -281,9 +281,6 @@ include\bitcoin\node\protocols - - include\bitcoin\node\sessions - include\bitcoin\node\sessions @@ -296,6 +293,9 @@ include\bitcoin\node\sessions + + include\bitcoin\node\sessions + include\bitcoin\node\sessions diff --git a/include/bitcoin/node.hpp b/include/bitcoin/node.hpp index c95f9dc9a..848c44558 100644 --- a/include/bitcoin/node.hpp +++ b/include/bitcoin/node.hpp @@ -56,11 +56,11 @@ #include #include #include -#include #include #include #include #include +#include #include #include diff --git a/include/bitcoin/node/sessions/session_inbound.hpp b/include/bitcoin/node/sessions/session_inbound.hpp index 470aef738..ffd53cdf9 100644 --- a/include/bitcoin/node/sessions/session_inbound.hpp +++ b/include/bitcoin/node/sessions/session_inbound.hpp @@ -21,17 +21,17 @@ #include #include -#include +#include namespace libbitcoin { namespace node { class session_inbound - : public attach + : public session_peer { public: typedef std::shared_ptr ptr; - using base = attach; + using base = session_peer; using base::base; protected: diff --git a/include/bitcoin/node/sessions/session_manual.hpp b/include/bitcoin/node/sessions/session_manual.hpp index 0d6d25b24..28649d3d6 100644 --- a/include/bitcoin/node/sessions/session_manual.hpp +++ b/include/bitcoin/node/sessions/session_manual.hpp @@ -21,17 +21,17 @@ #include #include -#include +#include namespace libbitcoin { namespace node { class session_manual - : public attach + : public session_peer { public: typedef std::shared_ptr ptr; - using base = attach; + using base = session_peer; using base::base; }; diff --git a/include/bitcoin/node/sessions/session_outbound.hpp b/include/bitcoin/node/sessions/session_outbound.hpp index 09e27cf4e..3f4c331df 100644 --- a/include/bitcoin/node/sessions/session_outbound.hpp +++ b/include/bitcoin/node/sessions/session_outbound.hpp @@ -21,17 +21,17 @@ #include #include -#include +#include namespace libbitcoin { namespace node { class session_outbound - : public attach + : public session_peer { public: typedef std::shared_ptr ptr; - using base = attach; + using base = session_peer; using base::base; }; diff --git a/include/bitcoin/node/sessions/attach.hpp b/include/bitcoin/node/sessions/session_peer.hpp similarity index 83% rename from include/bitcoin/node/sessions/attach.hpp rename to include/bitcoin/node/sessions/session_peer.hpp index da23f4bff..5f98ae3d3 100644 --- a/include/bitcoin/node/sessions/attach.hpp +++ b/include/bitcoin/node/sessions/session_peer.hpp @@ -16,8 +16,8 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#ifndef LIBBITCOIN_NODE_SESSIONS_ATTACH_HPP -#define LIBBITCOIN_NODE_SESSIONS_ATTACH_HPP +#ifndef LIBBITCOIN_NODE_SESSIONS_SESSION_PEER_HPP +#define LIBBITCOIN_NODE_SESSIONS_SESSION_PEER_HPP #include #include @@ -31,17 +31,16 @@ namespace node { class full_node; -/// Session base class template for network session attachment. +/// CRTP base class template for network session multiple derivation. /// node::session does not derive from network::session (siblings). /// This avoids the diamond inheritance problem between network/node. -/// Protocol contructors are templatized on Session, obtaining session. template -class attach +class session_peer : public Session, public node::session { public: template - attach(full_node& node, uint64_t identifier, Args&&... args) NOEXCEPT + session_peer(full_node& node, uint64_t identifier, Args&&... args) NOEXCEPT : Session(node, identifier, std::forward(args)...), node::session(node) { @@ -51,9 +50,11 @@ class attach void attach_handshake(const network::channel::ptr& channel, network::result_handler&& handler) NOEXCEPT override { + using namespace network; + // Set the current top for version protocol, before handshake. - std::dynamic_pointer_cast(channel)-> - set_start_height(archive().get_top_confirmed()); + const auto top = archive().get_top_confirmed(); + std::dynamic_pointer_cast(channel)->set_start_height(top); // Attach and execute appropriate version protocol. Session::attach_handshake(channel, std::move(handler)); @@ -63,22 +64,25 @@ class attach const network::channel::ptr& channel) NOEXCEPT override { using namespace system; - using namespace network::messages::peer; + using namespace network; + using namespace messages::peer; + + // this-> is required for dependent base access in CRTP. const auto relay = this->config().network.enable_relay; const auto delay = this->config().node.delay_inbound; const auto headers = this->config().node.headers_first; const auto node_network = to_bool(bit_and ( this->config().network.services_maximum, - network::messages::peer::service::node_network + service::node_network )); const auto node_client_filters = to_bool(bit_and ( this->config().network.services_maximum, - network::messages::peer::service::node_client_filters + service::node_client_filters )); - const auto self = session::shared_from_sibling, + const auto self = session::shared_from_sibling, network::session>(); // Attach appropriate alert, reject, ping, and/or address protocols. @@ -97,8 +101,7 @@ class attach // This allows the node to support bip157 without supporting bip152. /////////////////////////////////////////////////////////////////////// - const auto peer = std::dynamic_pointer_cast( - channel); + const auto peer = std::dynamic_pointer_cast(channel); // Node must advertise node_client_filters or no out filters. if (node_client_filters && blocks_out && @@ -165,9 +168,12 @@ class attach network::channel::ptr create_channel( const network::socket::ptr& socket) NOEXCEPT override { - return std::static_pointer_cast( - std::make_shared(this->get_memory(), this->log, - socket, this->config(), this->create_key())); + // this-> is required for dependent base access in CRTP. + const auto channel = std::make_shared( + this->get_memory(), this->log, socket, this->config(), + this->create_key()); + + return std::static_pointer_cast(channel); } }; diff --git a/include/bitcoin/node/sessions/sessions.hpp b/include/bitcoin/node/sessions/sessions.hpp index dec55b118..22aa8e5d3 100644 --- a/include/bitcoin/node/sessions/sessions.hpp +++ b/include/bitcoin/node/sessions/sessions.hpp @@ -19,11 +19,11 @@ #ifndef LIBBITCOIN_NODE_SESSIONS_SESSIONS_HPP #define LIBBITCOIN_NODE_SESSIONS_SESSIONS_HPP -#include #include #include #include #include +#include #include #endif From 902b85fa66245e7ac25256887c97a5dfe74238d7 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Wed, 15 Oct 2025 20:34:48 -0400 Subject: [PATCH 2/3] Use shared_from_base<> in multiple inherit, style. --- include/bitcoin/node/sessions/session.hpp | 8 -------- include/bitcoin/node/sessions/session_peer.hpp | 9 +++------ 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/include/bitcoin/node/sessions/session.hpp b/include/bitcoin/node/sessions/session.hpp index 4c8aa1e38..f449617c1 100644 --- a/include/bitcoin/node/sessions/session.hpp +++ b/include/bitcoin/node/sessions/session.hpp @@ -107,14 +107,6 @@ class BCN_API session virtual bool is_recent() const NOEXCEPT; protected: - template - std::shared_ptr shared_from_sibling() NOEXCEPT - { - BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) - return std::dynamic_pointer_cast( - dynamic_cast(this)->shared_from_this()); - BC_POP_WARNING() - } /// Constructors. /// ----------------------------------------------------------------------- diff --git a/include/bitcoin/node/sessions/session_peer.hpp b/include/bitcoin/node/sessions/session_peer.hpp index 5f98ae3d3..fb284f17b 100644 --- a/include/bitcoin/node/sessions/session_peer.hpp +++ b/include/bitcoin/node/sessions/session_peer.hpp @@ -50,11 +50,10 @@ class session_peer void attach_handshake(const network::channel::ptr& channel, network::result_handler&& handler) NOEXCEPT override { - using namespace network; - // Set the current top for version protocol, before handshake. const auto top = archive().get_top_confirmed(); - std::dynamic_pointer_cast(channel)->set_start_height(top); + const auto peer = std::dynamic_pointer_cast(channel); + peer->set_start_height(top); // Attach and execute appropriate version protocol. Session::attach_handshake(channel, std::move(handler)); @@ -68,6 +67,7 @@ class session_peer using namespace messages::peer; // this-> is required for dependent base access in CRTP. + const auto self = this->shared_from_base>(); const auto relay = this->config().network.enable_relay; const auto delay = this->config().node.delay_inbound; const auto headers = this->config().node.headers_first; @@ -82,9 +82,6 @@ class session_peer service::node_client_filters )); - const auto self = session::shared_from_sibling, - network::session>(); - // Attach appropriate alert, reject, ping, and/or address protocols. Session::attach_protocols(channel); From 64969b901845ef50330e5bb63f384822b65781ae Mon Sep 17 00:00:00 2001 From: evoskuil Date: Wed, 15 Oct 2025 20:58:16 -0400 Subject: [PATCH 3/3] Add missing template qualifier. --- include/bitcoin/node/sessions/session_peer.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/bitcoin/node/sessions/session_peer.hpp b/include/bitcoin/node/sessions/session_peer.hpp index fb284f17b..f74037729 100644 --- a/include/bitcoin/node/sessions/session_peer.hpp +++ b/include/bitcoin/node/sessions/session_peer.hpp @@ -65,9 +65,10 @@ class session_peer using namespace system; using namespace network; using namespace messages::peer; + using base = session_peer; // this-> is required for dependent base access in CRTP. - const auto self = this->shared_from_base>(); + const auto self = this->template shared_from_base(); const auto relay = this->config().network.enable_relay; const auto delay = this->config().node.delay_inbound; const auto headers = this->config().node.headers_first;