Skip to content

Commit 3207745

Browse files
committed
Refactor node to allow full_node to include sessions.
1 parent d0e1e2b commit 3207745

File tree

5 files changed

+44
-47
lines changed

5 files changed

+44
-47
lines changed

include/bitcoin/node/define.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,9 @@ using type_id = network::messages::peer::inventory_item::type_id;
120120
// settings : define
121121
// configuration : define settings
122122
// parser : define configuration
123-
// /chasers : define configuration [forward: full_node]
123+
// /chasers : define configuration [forward: full_node]
124124
// full_node : define /chasers
125-
// session : define full_node
126-
// /protocols : define session
127-
128-
// Session is only included by full_node.cpp (avoids cycle).
129-
// /sessions : define full_node /protocols
125+
// attach : define session [forward: full_node]
126+
// session : define [forward: full_node]
127+
// /sessions : define attach /protocols [forward: full_node]
128+
// /protocols : define session

include/bitcoin/node/full_node.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include <bitcoin/node/chasers/chasers.hpp>
2626
#include <bitcoin/node/configuration.hpp>
2727
#include <bitcoin/node/define.hpp>
28+
////#include <bitcoin/node/protocols/protocols.hpp>
29+
////#include <bitcoin/node/sessions/sessions.hpp>
2830

2931
namespace libbitcoin {
3032
namespace node {
@@ -40,9 +42,9 @@ class BCN_API full_node
4042
: public network::net
4143
{
4244
public:
43-
using memory_controller = block_memory;
4445
using store = node::store;
4546
using query = node::query;
47+
using memory_controller = block_memory;
4648
typedef std::shared_ptr<full_node> ptr;
4749

4850
/// Constructors.

include/bitcoin/node/sessions/attach.hpp

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
namespace libbitcoin {
2929
namespace 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
{
4141
public:
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

include/bitcoin/node/sessions/session.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121

2222
#include <bitcoin/database.hpp>
2323
#include <bitcoin/network.hpp>
24+
#include <bitcoin/node/configuration.hpp>
2425
#include <bitcoin/node/define.hpp>
25-
#include <bitcoin/node/full_node.hpp>
2626

2727
namespace libbitcoin {
2828
namespace node {
29-
29+
30+
class full_node;
31+
3032
/// Common session context, presumes will be joined with network::session.
3133
/// This could be templatized on the sibling, but there only one implemented.
3234
class BCN_API session
@@ -93,7 +95,7 @@ class BCN_API session
9395
/// -----------------------------------------------------------------------
9496

9597
/// Thread safe synchronous archival interface.
96-
full_node::query& archive() const NOEXCEPT;
98+
node::query& archive() const NOEXCEPT;
9799

98100
/// Configuration settings for all libraries.
99101
const configuration& config() const NOEXCEPT;

src/full_node.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
#include <bitcoin/network.hpp>
2424
#include <bitcoin/node/chasers/chasers.hpp>
2525
#include <bitcoin/node/define.hpp>
26-
#include <bitcoin/node/sessions/sessions.hpp>
26+
////#include <bitcoin/node/protocols/protocols.hpp>
27+
////#include <bitcoin/node/sessions/sessions.hpp>
2728

2829
namespace libbitcoin {
2930
namespace node {
@@ -419,17 +420,17 @@ network::memory& full_node::get_memory() NOEXCEPT
419420

420421
network::session_manual::ptr full_node::attach_manual_session() NOEXCEPT
421422
{
422-
return net::attach<node::session_manual>(*this);
423+
return attach<node::session_manual>(*this);
423424
}
424425

425426
network::session_inbound::ptr full_node::attach_inbound_session() NOEXCEPT
426427
{
427-
return net::attach<node::session_inbound>(*this);
428+
return attach<node::session_inbound>(*this);
428429
}
429430

430431
network::session_outbound::ptr full_node::attach_outbound_session() NOEXCEPT
431432
{
432-
return net::attach<node::session_outbound>(*this);
433+
return attach<node::session_outbound>(*this);
433434
}
434435

435436
BC_POP_WARNING()

0 commit comments

Comments
 (0)