Skip to content

Commit 76f3653

Browse files
committed
Consolidate session_tcp and session_server<>.
1 parent a721ef7 commit 76f3653

File tree

12 files changed

+44
-137
lines changed

12 files changed

+44
-137
lines changed

Makefile.am

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ src_libbitcoin_node_la_SOURCES = \
7575
src/sessions/session.cpp \
7676
src/sessions/session_inbound.cpp \
7777
src/sessions/session_manual.cpp \
78-
src/sessions/session_outbound.cpp \
79-
src/sessions/session_tcp.cpp
78+
src/sessions/session_outbound.cpp
8079

8180
# local: test/libbitcoin-node-test
8281
#------------------------------------------------------------------------------
@@ -243,7 +242,6 @@ include_bitcoin_node_sessions_HEADERS = \
243242
include/bitcoin/node/sessions/session_outbound.hpp \
244243
include/bitcoin/node/sessions/session_peer.hpp \
245244
include/bitcoin/node/sessions/session_server.hpp \
246-
include/bitcoin/node/sessions/session_tcp.hpp \
247245
include/bitcoin/node/sessions/sessions.hpp
248246

249247
# files => ${bash_completiondir}

builds/cmake/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,7 @@ add_library( ${CANONICAL_LIB_NAME}
287287
"../../src/sessions/session.cpp"
288288
"../../src/sessions/session_inbound.cpp"
289289
"../../src/sessions/session_manual.cpp"
290-
"../../src/sessions/session_outbound.cpp"
291-
"../../src/sessions/session_tcp.cpp" )
290+
"../../src/sessions/session_outbound.cpp" )
292291

293292
# ${CANONICAL_LIB_NAME} project specific include directory normalization for build.
294293
#------------------------------------------------------------------------------

builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@
161161
<ClCompile Include="..\..\..\..\src\sessions\session_inbound.cpp" />
162162
<ClCompile Include="..\..\..\..\src\sessions\session_manual.cpp" />
163163
<ClCompile Include="..\..\..\..\src\sessions\session_outbound.cpp" />
164-
<ClCompile Include="..\..\..\..\src\sessions\session_tcp.cpp" />
165164
<ClCompile Include="..\..\..\..\src\settings.cpp" />
166165
</ItemGroup>
167166
<ItemGroup>
@@ -228,7 +227,6 @@
228227
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\session_outbound.hpp" />
229228
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\session_peer.hpp" />
230229
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\session_server.hpp" />
231-
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\session_tcp.hpp" />
232230
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\sessions.hpp" />
233231
<ClInclude Include="..\..\..\..\include\bitcoin\node\settings.hpp" />
234232
<ClInclude Include="..\..\..\..\include\bitcoin\node\version.hpp" />

builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,6 @@
180180
<ClCompile Include="..\..\..\..\src\sessions\session_outbound.cpp">
181181
<Filter>src\sessions</Filter>
182182
</ClCompile>
183-
<ClCompile Include="..\..\..\..\src\sessions\session_tcp.cpp">
184-
<Filter>src\sessions</Filter>
185-
</ClCompile>
186183
<ClCompile Include="..\..\..\..\src\settings.cpp">
187184
<Filter>src</Filter>
188185
</ClCompile>
@@ -377,9 +374,6 @@
377374
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\session_server.hpp">
378375
<Filter>include\bitcoin\node\sessions</Filter>
379376
</ClInclude>
380-
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\session_tcp.hpp">
381-
<Filter>include\bitcoin\node\sessions</Filter>
382-
</ClInclude>
383377
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\sessions.hpp">
384378
<Filter>include\bitcoin\node\sessions</Filter>
385379
</ClInclude>

include/bitcoin/node.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
#include <bitcoin/node/sessions/session_outbound.hpp>
8181
#include <bitcoin/node/sessions/session_peer.hpp>
8282
#include <bitcoin/node/sessions/session_server.hpp>
83-
#include <bitcoin/node/sessions/session_tcp.hpp>
8483
#include <bitcoin/node/sessions/sessions.hpp>
8584

8685
#endif

include/bitcoin/node/protocols/protocol_ws.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ namespace node {
2929
// TODO: make this an intermediate base class for websocket.
3030
// TODO: and then create a distinct concrete class for deployment.
3131
class BCN_API protocol_ws
32-
: public network::protocol_ws,
33-
public node::protocol,
32+
: public node::protocol,
33+
public network::protocol_ws,
3434
protected network::tracker<protocol_ws>
3535
{
3636
public:
@@ -42,8 +42,8 @@ class BCN_API protocol_ws
4242
protocol_ws(const auto& session,
4343
const network::channel::ptr& channel,
4444
const options_t& options) NOEXCEPT
45-
: network::protocol_ws(session, channel, options),
46-
node::protocol(session, channel),
45+
: node::protocol(session, channel),
46+
network::protocol_ws(session, channel, options),
4747
network::tracker<protocol_ws>(session->log)
4848
{
4949
}

include/bitcoin/node/sessions/session.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ namespace node {
2828
class full_node;
2929

3030
/// Common session context, presumes will be joined with network::session.
31-
/// This could be templatized on the sibling, but there only one implemented.
3231
class BCN_API session
3332
{
3433
public:

include/bitcoin/node/sessions/session_peer.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,21 @@ namespace node {
3232
/// Template for network::session derivation with node::session.
3333
/// node::session does not derive from network::session (siblings).
3434
/// This avoids the diamond inheritance problem between network/node.
35-
template <class Session>
35+
template <class NetworkSession>
3636
class session_peer
37-
: public Session,
38-
public node::session
37+
: public node::session,
38+
public NetworkSession
3939
{
4040
public:
41-
typedef std::shared_ptr<session_peer<Session>> ptr;
42-
using options_t = typename Session::options_t;
41+
typedef std::shared_ptr<session_peer<NetworkSession>> ptr;
42+
using options_t = typename NetworkSession::options_t;
4343
using channel_t = node::channel_peer;
4444

4545
/// Construct an instance.
4646
template <typename Node, typename... Args>
4747
session_peer(Node& node, Args&&... args) NOEXCEPT
48-
: Session(node, std::forward<Args>(args)...),
49-
node::session(node)
48+
: node::session(node),
49+
NetworkSession(node, std::forward<Args>(args)...)
5050
{
5151
}
5252

@@ -79,7 +79,7 @@ class session_peer
7979
peer->set_start_height(top);
8080

8181
// Attach and execute appropriate version protocol.
82-
Session::attach_handshake(channel, std::move(handler));
82+
NetworkSession::attach_handshake(channel, std::move(handler));
8383
}
8484

8585
void attach_protocols(const channel_ptr& channel) NOEXCEPT override
@@ -90,7 +90,7 @@ class session_peer
9090
using namespace system;
9191
using namespace network;
9292
using namespace messages::peer;
93-
using base = session_peer<Session>;
93+
using base = session_peer<NetworkSession>;
9494

9595
const auto self = this->template shared_from_base<base>();
9696
const auto relay = this->config().network.enable_relay;
@@ -108,7 +108,7 @@ class session_peer
108108
));
109109

110110
// Attach appropriate alert, reject, ping, and/or address protocols.
111-
Session::attach_protocols(channel);
111+
NetworkSession::attach_protocols(channel);
112112

113113
// Channel suspensions.
114114
channel->attach<protocol_observer>(self)->start();

include/bitcoin/node/sessions/session_server.hpp

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,25 @@
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

2727
namespace libbitcoin {
2828
namespace node {
2929

30-
class full_node;
31-
32-
// make_shared<>
3330
BC_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.
4140
template <typename Protocol>
4241
class session_server
43-
: public session_tcp,
42+
: public network::session_server,
43+
public node::session,
4444
protected network::tracker<session_server<Protocol>>
4545
{
4646
public:
@@ -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

6363
protected:
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

include/bitcoin/node/sessions/session_tcp.hpp

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)