1616 * You should have received a copy of the GNU Affero General Public License
1717 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1818 */
19- #ifndef LIBBITCOIN_NODE_SESSIONS_ATTACH_HPP
20- #define LIBBITCOIN_NODE_SESSIONS_ATTACH_HPP
19+ #ifndef LIBBITCOIN_NODE_SESSIONS_SESSION_PEER_HPP
20+ #define LIBBITCOIN_NODE_SESSIONS_SESSION_PEER_HPP
2121
2222#include < memory>
2323#include < utility>
@@ -31,17 +31,16 @@ namespace node {
3131
3232class full_node ;
3333
34- // / Session base class template for network session attachment .
34+ // / CRTP base class template for network session multiple derivation .
3535// / node::session does not derive from network::session (siblings).
3636// / This avoids the diamond inheritance problem between network/node.
37- // / Protocol contructors are templatized on Session, obtaining session.
3837template <class Session >
39- class attach
38+ class session_peer
4039 : public Session, public node::session
4140{
4241public:
4342 template <typename ... Args>
44- attach (full_node& node, uint64_t identifier, Args&&... args) NOEXCEPT
43+ session_peer (full_node& node, uint64_t identifier, Args&&... args) NOEXCEPT
4544 : Session(node, identifier, std::forward<Args>(args)...),
4645 node::session (node)
4746 {
@@ -52,8 +51,9 @@ class attach
5251 network::result_handler&& handler) NOEXCEPT override
5352 {
5453 // Set the current top for version protocol, before handshake.
55- std::dynamic_pointer_cast<network::channel_peer>(channel)->
56- set_start_height (archive ().get_top_confirmed ());
54+ const auto top = archive ().get_top_confirmed ();
55+ const auto peer = std::dynamic_pointer_cast<channel_peer>(channel);
56+ peer->set_start_height (top);
5757
5858 // Attach and execute appropriate version protocol.
5959 Session::attach_handshake (channel, std::move (handler));
@@ -63,24 +63,26 @@ class attach
6363 const network::channel::ptr& channel) NOEXCEPT override
6464 {
6565 using namespace system ;
66- using namespace network ::messages::peer;
66+ using namespace network ;
67+ using namespace messages ::peer;
68+ using base = session_peer<Session>;
69+
70+ // this-> is required for dependent base access in CRTP.
71+ const auto self = this ->template shared_from_base <base>();
6772 const auto relay = this ->config ().network .enable_relay ;
6873 const auto delay = this ->config ().node .delay_inbound ;
6974 const auto headers = this ->config ().node .headers_first ;
7075 const auto node_network = to_bool (bit_and<uint64_t >
7176 (
7277 this ->config ().network .services_maximum ,
73- network::messages::peer:: service::node_network
78+ service::node_network
7479 ));
7580 const auto node_client_filters = to_bool (bit_and<uint64_t >
7681 (
7782 this ->config ().network .services_maximum ,
78- network::messages::peer:: service::node_client_filters
83+ service::node_client_filters
7984 ));
8085
81- const auto self = session::shared_from_sibling<attach<Session>,
82- network::session>();
83-
8486 // Attach appropriate alert, reject, ping, and/or address protocols.
8587 Session::attach_protocols (channel);
8688
@@ -97,8 +99,7 @@ class attach
9799 // This allows the node to support bip157 without supporting bip152.
98100 // /////////////////////////////////////////////////////////////////////
99101
100- const auto peer = std::dynamic_pointer_cast<network::channel_peer>(
101- channel);
102+ const auto peer = std::dynamic_pointer_cast<channel_peer>(channel);
102103
103104 // Node must advertise node_client_filters or no out filters.
104105 if (node_client_filters && blocks_out &&
@@ -165,9 +166,12 @@ class attach
165166 network::channel::ptr create_channel (
166167 const network::socket::ptr& socket) NOEXCEPT override
167168 {
168- return std::static_pointer_cast<network::channel>(
169- std::make_shared<node::channel_peer>(this ->get_memory (), this ->log ,
170- socket, this ->config (), this ->create_key ()));
169+ // this-> is required for dependent base access in CRTP.
170+ const auto channel = std::make_shared<node::channel_peer>(
171+ this ->get_memory (), this ->log , socket, this ->config (),
172+ this ->create_key ());
173+
174+ return std::static_pointer_cast<network::channel>(channel);
171175 }
172176};
173177
0 commit comments