Skip to content

Commit 653563c

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

File tree

5 files changed

+38
-42
lines changed

5 files changed

+38
-42
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: 20 additions & 28 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,6 +58,20 @@ class attach
7258

7359
void attach_protocols(const network::channel::ptr& channel) NOEXCEPT override
7460
{
61+
const auto relay = config().network.enable_relay;
62+
const auto delay = node.config().node.delay_inbound;
63+
const auto headers = node.config().node.headers_first;
64+
const auto node_network = to_bool(system::bit_and<uint64_t>
65+
(
66+
node.config().network.services_maximum,
67+
network::messages::peer::service::node_network
68+
));
69+
const auto node_client_filters = to_bool(system::bit_and<uint64_t>
70+
(
71+
node.config().network.services_maximum,
72+
network::messages::peer::service::node_client_filters
73+
));
74+
7575
using namespace network::messages::peer;
7676
const auto self = session::shared_from_sibling<attach<Session>,
7777
network::session>();
@@ -83,7 +83,7 @@ class attach
8383
channel->attach<protocol_observer>(self)->start();
8484

8585
// Ready to relay blocks or block filters.
86-
const auto blocks_out = !delay_ || is_recent();
86+
const auto blocks_out = !delay || is_recent();
8787

8888
///////////////////////////////////////////////////////////////////////
8989
// bip152: "Upon receipt of a `sendcmpct` message with the first and
@@ -101,12 +101,12 @@ class attach
101101
channel->attach<protocol_filter_out_70015>(self)->start();
102102

103103
// Node must advertise node_network or no in|out blocks|txs.
104-
if (!node_network_)
104+
if (!node_network)
105105
return;
106106

107107
// Ready to relay transactions.
108-
const auto txs_in_out = relay_ && peer->is_negotiated(level::bip37) &&
109-
(!delay_ || is_current(true));
108+
const auto txs_in_out = relay && peer->is_negotiated(level::bip37) &&
109+
(!delay || is_current(true));
110110

111111
// Peer advertises chain (blocks in).
112112
if (peer->is_peer_service(service::node_network))
@@ -164,14 +164,6 @@ class attach
164164
network::session::log, socket, node::session::config(),
165165
network::session::create_key()));
166166
}
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_;
175167
};
176168

177169
} // 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)