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.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_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..f74037729 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)
{
@@ -52,8 +51,9 @@ class attach
network::result_handler&& handler) NOEXCEPT override
{
// 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();
+ 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));
@@ -63,24 +63,26 @@ class attach
const network::channel::ptr& channel) NOEXCEPT override
{
using namespace system;
- using namespace network::messages::peer;
+ using namespace network;
+ using namespace messages::peer;
+ using base = session_peer;
+
+ // this-> is required for dependent base access in CRTP.
+ 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;
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,
- network::session>();
-
// Attach appropriate alert, reject, ping, and/or address protocols.
Session::attach_protocols(channel);
@@ -97,8 +99,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 +166,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