2828namespace libbitcoin {
2929namespace node {
3030
31- class session_outbound ;
31+ class full_node ;
3232
3333// / Session base class template for protocol attachment.
3434// / node::session does not derive from network::session (siblings).
@@ -40,21 +40,7 @@ class attach
4040{
4141public:
4242 attach (full_node& node, uint64_t identifier) NOEXCEPT
43- : Session(node, identifier),
44- session (node),
45- relay_(node.config().network.enable_relay),
46- delay_(node.config().node.delay_inbound),
47- headers_(node.config().node.headers_first),
48- node_network_(to_bool(system::bit_and<uint64_t >
49- (
50- node.config().network.services_maximum,
51- network::messages::peer::service::node_network
52- ))),
53- node_client_filters_(to_bool(system::bit_and<uint64_t >
54- (
55- node.config().network.services_maximum,
56- network::messages::peer::service::node_client_filters
57- )))
43+ : Session(node, identifier), session(node)
5844 {
5945 }
6046
@@ -72,7 +58,22 @@ class attach
7258
7359 void attach_protocols (const network::channel::ptr& channel) NOEXCEPT override
7460 {
61+ using namespace system ;
7562 using namespace network ::messages::peer;
63+ const auto relay = config ().network .enable_relay ;
64+ const auto delay = config ().node .delay_inbound ;
65+ const auto headers = config ().node .headers_first ;
66+ const auto node_network = to_bool (bit_and<uint64_t >
67+ (
68+ config ().network .services_maximum ,
69+ network::messages::peer::service::node_network
70+ ));
71+ const auto node_client_filters = to_bool (bit_and<uint64_t >
72+ (
73+ config ().network .services_maximum ,
74+ network::messages::peer::service::node_client_filters
75+ ));
76+
7677 const auto self = session::shared_from_sibling<attach<Session>,
7778 network::session>();
7879
@@ -83,7 +84,7 @@ class attach
8384 channel->attach <protocol_observer>(self)->start ();
8485
8586 // Ready to relay blocks or block filters.
86- const auto blocks_out = !delay_ || is_recent ();
87+ const auto blocks_out = !delay || is_recent ();
8788
8889 // /////////////////////////////////////////////////////////////////////
8990 // bip152: "Upon receipt of a `sendcmpct` message with the first and
@@ -96,28 +97,28 @@ class attach
9697 channel);
9798
9899 // Node must advertise node_client_filters or no out filters.
99- if (node_client_filters_ && blocks_out &&
100+ if (node_client_filters && blocks_out &&
100101 peer->is_negotiated (level::bip157))
101102 channel->attach <protocol_filter_out_70015>(self)->start ();
102103
103104 // Node must advertise node_network or no in|out blocks|txs.
104- if (!node_network_ )
105+ if (!node_network )
105106 return ;
106107
107108 // Ready to relay transactions.
108- const auto txs_in_out = relay_ && peer->is_negotiated (level::bip37) &&
109- (!delay_ || is_current (true ));
109+ const auto txs_in_out = relay && peer->is_negotiated (level::bip37) &&
110+ (!delay || is_current (true ));
110111
111112 // Peer advertises chain (blocks in).
112113 if (peer->is_peer_service (service::node_network))
113114 {
114- if (headers_ && peer->is_negotiated (level::bip130))
115+ if (headers && peer->is_negotiated (level::bip130))
115116 {
116117 channel->attach <protocol_header_in_70012>(self)->start ();
117118 channel->attach <protocol_block_in_31800>(self)->start ();
118119
119120 }
120- else if (headers_ && peer->is_negotiated (level::headers_protocol))
121+ else if (headers && peer->is_negotiated (level::headers_protocol))
121122 {
122123 channel->attach <protocol_header_in_31800>(self)->start ();
123124 channel->attach <protocol_block_in_31800>(self)->start ();
@@ -133,12 +134,12 @@ class attach
133134 // Blocks are ready (blocks out).
134135 if (blocks_out)
135136 {
136- if (headers_ && peer->is_negotiated (level::bip130))
137+ if (headers && peer->is_negotiated (level::bip130))
137138 {
138139 channel->attach <protocol_header_out_70012>(self)->start ();
139140 channel->attach <protocol_block_out_70012>(self)->start ();
140141 }
141- else if (headers_ && peer->is_negotiated (level::headers_protocol))
142+ else if (headers && peer->is_negotiated (level::headers_protocol))
142143 {
143144 channel->attach <protocol_header_out_31800>(self)->start ();
144145 channel->attach <protocol_block_out_106>(self)->start ();
@@ -164,14 +165,6 @@ class attach
164165 network::session::log, socket, node::session::config (),
165166 network::session::create_key ()));
166167 }
167-
168- private:
169- // These are thread safe.
170- const bool relay_;
171- const bool delay_;
172- const bool headers_;
173- const bool node_network_;
174- const bool node_client_filters_;
175168};
176169
177170} // namespace node
0 commit comments