2222#include < memory>
2323#include < utility>
2424#include < bitcoin/node/define.hpp>
25- #include < bitcoin/node/sessions/session_tcp .hpp>
25+ #include < bitcoin/node/sessions/session .hpp>
2626
2727namespace libbitcoin {
2828namespace node {
2929
30- class full_node ;
31-
32- // make_shared<>
3330BC_PUSH_WARNING (NO_THROW_IN_NOEXCEPT)
3431
32+ class full_node ;
33+
3534// / Declare a concrete instance of this type for client-server protocols built
36- // / on tcp/ip. session_tcp processing performs all connection management and
35+ // / on tcp/ip. session_base processing performs all connection management and
3736// / session tracking. This includes start/stop/disable/enable/black/whitelist.
3837// / Protocol must declare options_t and channel_t. This protocol is constructed
3938// / and attached to a constructed instance of channel_t. The protocol construct
4039// / and attachment can be overridden and/or augmented with other protocols.
4140template <typename Protocol>
4241class session_server
43- : public session_tcp,
42+ : public network::session_server,
43+ public node::session,
4444 protected network::tracker<session_server<Protocol>>
4545{
4646public:
@@ -51,23 +51,31 @@ class session_server
5151 using channel_t = typename Protocol::channel_t ;
5252
5353 // / Construct an instance (network should be started).
54- template < typename ... Args>
55- session_server (full_node& node, uint64_t identifier, const options_t & options,
56- Args&&... args) NOEXCEPT
57- : session_tcp(node, identifier, options, std::forward<Args>(args)... ),
58- options_ (options ),
59- network::tracker<session_server<Protocol>>(node )
54+ inline session_server (full_node& node, uint64_t identifier,
55+ const options_t & options) NOEXCEPT
56+ : network::session_server((network::net&)node, identifier, options),
57+ node::session(node ),
58+ network::tracker<session_server<Protocol>>(node ),
59+ options_(options )
6060 {
6161 }
6262
6363protected:
6464 using socket_ptr = network::socket::ptr;
6565 using channel_ptr = network::channel::ptr;
6666
67+ // / Inbound connection attempts are dropped unless confirmed is current.
68+ // / Used instead of suspension because that has independent start/stop.
69+ inline bool enabled () const NOEXCEPT override
70+ {
71+ return !config ().node .delay_inbound || is_recent ();
72+ }
73+
6774 // / Override to construct channel. This allows the implementation to pass
6875 // / other values to protocol construction and/or select the desired channel
6976 // / based on available factors (e.g. a distinct protocol version).
70- channel_ptr create_channel (const socket_ptr& socket) NOEXCEPT override
77+ inline channel_ptr create_channel (
78+ const socket_ptr& socket) NOEXCEPT override
7179 {
7280 BC_ASSERT (stranded ());
7381
@@ -82,25 +90,25 @@ class session_server
8290 // / is used to implement TLS and WebSocket upgrade from http (for example).
8391 // / Handshake protocol(s) must invoke handler one time at completion.
8492 // / Use std::dynamic_pointer_cast<channel_t>(channel) to obtain channel_t.
85- void attach_handshake (const channel_ptr& channel,
93+ inline void attach_handshake (const channel_ptr& channel,
8694 network::result_handler&& handler) NOEXCEPT override
8795 {
8896 BC_ASSERT (channel->stranded ());
8997 BC_ASSERT (channel->paused ());
9098
91- session_tcp ::attach_handshake (channel, std::move (handler));
99+ network::session_server ::attach_handshake (channel, std::move (handler));
92100 }
93101
94102 // / Overridden to set channel protocols. This allows the implementation to
95103 // / pass other values to protocol construction and/or select the desired
96104 // / protocol based on available factors (e.g. a distinct protocol version).
97105 // / Use std::dynamic_pointer_cast<channel_t>(channel) to obtain channel_t.
98- void attach_protocols (const channel_ptr& channel) NOEXCEPT override
106+ inline void attach_protocols (const channel_ptr& channel) NOEXCEPT override
99107 {
100108 BC_ASSERT (channel->stranded ());
101109 BC_ASSERT (channel->paused ());
102110
103- const auto self = shared_from_base<session_tcp >();
111+ const auto self = shared_from_base<session_server<Protocol> >();
104112 channel->attach <Protocol>(self, options_)->start ();
105113 }
106114
0 commit comments