From d2fc33bf47cd3968467704060447ad3a685640e7 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Mon, 9 Feb 2026 19:32:07 -0500 Subject: [PATCH 1/6] Add intermediate channel base class. --- Makefile.am | 1 + .../libbitcoin-server.vcxproj | 1 + .../libbitcoin-server.vcxproj.filters | 3 ++ include/bitcoin/server.hpp | 1 + include/bitcoin/server/channels/channel.hpp | 42 +++++++++++++++++++ .../server/channels/channel_electrum.hpp | 5 ++- .../bitcoin/server/channels/channel_http.hpp | 5 ++- .../server/channels/channel_stratum_v1.hpp | 5 ++- .../server/channels/channel_stratum_v2.hpp | 5 ++- .../bitcoin/server/channels/channel_ws.hpp | 5 ++- include/bitcoin/server/channels/channels.hpp | 1 + 11 files changed, 64 insertions(+), 10 deletions(-) create mode 100644 include/bitcoin/server/channels/channel.hpp diff --git a/Makefile.am b/Makefile.am index e412f114..70d48382 100644 --- a/Makefile.am +++ b/Makefile.am @@ -135,6 +135,7 @@ include_bitcoin_server_HEADERS = \ include_bitcoin_server_channelsdir = ${includedir}/bitcoin/server/channels include_bitcoin_server_channels_HEADERS = \ + include/bitcoin/server/channels/channel.hpp \ include/bitcoin/server/channels/channel_electrum.hpp \ include/bitcoin/server/channels/channel_http.hpp \ include/bitcoin/server/channels/channel_stratum_v1.hpp \ diff --git a/builds/msvc/vs2022/libbitcoin-server/libbitcoin-server.vcxproj b/builds/msvc/vs2022/libbitcoin-server/libbitcoin-server.vcxproj index 9279656b..b910afbb 100644 --- a/builds/msvc/vs2022/libbitcoin-server/libbitcoin-server.vcxproj +++ b/builds/msvc/vs2022/libbitcoin-server/libbitcoin-server.vcxproj @@ -141,6 +141,7 @@ + diff --git a/builds/msvc/vs2022/libbitcoin-server/libbitcoin-server.vcxproj.filters b/builds/msvc/vs2022/libbitcoin-server/libbitcoin-server.vcxproj.filters index 203c552a..16e6bcd3 100644 --- a/builds/msvc/vs2022/libbitcoin-server/libbitcoin-server.vcxproj.filters +++ b/builds/msvc/vs2022/libbitcoin-server/libbitcoin-server.vcxproj.filters @@ -107,6 +107,9 @@ include\bitcoin + + include\bitcoin\server\channels + include\bitcoin\server\channels diff --git a/include/bitcoin/server.hpp b/include/bitcoin/server.hpp index 8ebcfa81..daa9c4ae 100644 --- a/include/bitcoin/server.hpp +++ b/include/bitcoin/server.hpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include diff --git a/include/bitcoin/server/channels/channel.hpp b/include/bitcoin/server/channels/channel.hpp new file mode 100644 index 00000000..2b32b7fa --- /dev/null +++ b/include/bitcoin/server/channels/channel.hpp @@ -0,0 +1,42 @@ +/** + * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) + * + * This file is part of libbitcoin. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +#ifndef LIBBITCOIN_SERVER_CHANNELS_CHANNEL_HPP +#define LIBBITCOIN_SERVER_CHANNELS_CHANNEL_HPP + +#include +#include + +namespace libbitcoin { +namespace server { + +/// Intermediate base class for future server injection. +class BCS_API channel + : public node::channel +{ +public: + typedef std::shared_ptr ptr; + using base = node::channel; + + using base::channel; +}; + +} // namespace server +} // namespace libbitcoin + +#endif diff --git a/include/bitcoin/server/channels/channel_electrum.hpp b/include/bitcoin/server/channels/channel_electrum.hpp index e31c73bf..82340a19 100644 --- a/include/bitcoin/server/channels/channel_electrum.hpp +++ b/include/bitcoin/server/channels/channel_electrum.hpp @@ -20,6 +20,7 @@ #define LIBBITCOIN_SERVER_CHANNELS_CHANNEL_ELECTRUM_HPP #include +#include #include #include #include @@ -31,7 +32,7 @@ namespace server { // TODO: strip extraneous args before electrum version dispatch. /// Channel for electrum channels (non-http json-rpc). class BCS_API channel_electrum - : public node::channel, + : public server::channel, public network::channel_rpc, protected network::tracker { @@ -43,7 +44,7 @@ class BCS_API channel_electrum inline channel_electrum(const network::logger& log, const network::socket::ptr& socket, uint64_t identifier, const node::configuration& config, const options_t& options) NOEXCEPT - : node::channel(log, socket, identifier, config), + : server::channel(log, socket, identifier, config), network::channel_rpc(log, socket, identifier, config.network, options), network::tracker(log) diff --git a/include/bitcoin/server/channels/channel_http.hpp b/include/bitcoin/server/channels/channel_http.hpp index 41a38dd3..f737dfad 100644 --- a/include/bitcoin/server/channels/channel_http.hpp +++ b/include/bitcoin/server/channels/channel_http.hpp @@ -20,6 +20,7 @@ #define LIBBITCOIN_SERVER_CHANNELS_CHANNEL_HTTP_HPP #include +#include #include #include @@ -27,7 +28,7 @@ namespace libbitcoin { namespace server { class BCS_API channel_http - : public node::channel, + : public server::channel, public network::channel_http, protected network::tracker { @@ -37,7 +38,7 @@ class BCS_API channel_http inline channel_http(const network::logger& log, const network::socket::ptr& socket, uint64_t identifier, const node::configuration& config, const options_t& options) NOEXCEPT - : node::channel(log, socket, identifier, config), + : server::channel(log, socket, identifier, config), network::channel_http(log, socket, identifier, config.network, options), network::tracker(log) { diff --git a/include/bitcoin/server/channels/channel_stratum_v1.hpp b/include/bitcoin/server/channels/channel_stratum_v1.hpp index 7fb252cf..7ee7cf86 100644 --- a/include/bitcoin/server/channels/channel_stratum_v1.hpp +++ b/include/bitcoin/server/channels/channel_stratum_v1.hpp @@ -20,6 +20,7 @@ #define LIBBITCOIN_SERVER_CHANNELS_CHANNEL_STRATUM_V1_HPP #include +#include #include #include #include @@ -29,7 +30,7 @@ namespace server { /// Channel for stratum v1 channels (non-http json-rpc). class BCS_API channel_stratum_v1 - : public node::channel, + : public server::channel, public network::channel_rpc, protected network::tracker { @@ -41,7 +42,7 @@ class BCS_API channel_stratum_v1 inline channel_stratum_v1(const network::logger& log, const network::socket::ptr& socket, uint64_t identifier, const node::configuration& config, const options_t& options) NOEXCEPT - : node::channel(log, socket, identifier, config), + : server::channel(log, socket, identifier, config), network::channel_rpc(log, socket, identifier, config.network, options), network::tracker(log) diff --git a/include/bitcoin/server/channels/channel_stratum_v2.hpp b/include/bitcoin/server/channels/channel_stratum_v2.hpp index 321900fb..0f028e93 100644 --- a/include/bitcoin/server/channels/channel_stratum_v2.hpp +++ b/include/bitcoin/server/channels/channel_stratum_v2.hpp @@ -20,6 +20,7 @@ #define LIBBITCOIN_SERVER_CHANNELS_CHANNEL_STRATUM_V2_HPP #include +#include #include #include @@ -28,7 +29,7 @@ namespace server { /// Channel for stratum v2 (custom protocol, not implemented). class BCS_API channel_stratum_v2 - : public node::channel, + : public server::channel, public network::channel, protected network::tracker { @@ -38,7 +39,7 @@ class BCS_API channel_stratum_v2 inline channel_stratum_v2(const network::logger& log, const network::socket::ptr& socket, uint64_t identifier, const node::configuration& config, const options_t& options) NOEXCEPT - : node::channel(log, socket, identifier, config), + : server::channel(log, socket, identifier, config), network::channel(log, socket, identifier, config.network, options), network::tracker(log) { diff --git a/include/bitcoin/server/channels/channel_ws.hpp b/include/bitcoin/server/channels/channel_ws.hpp index 72e57750..eec2e8f8 100644 --- a/include/bitcoin/server/channels/channel_ws.hpp +++ b/include/bitcoin/server/channels/channel_ws.hpp @@ -20,6 +20,7 @@ #define LIBBITCOIN_SERVER_CHANNELS_CHANNEL_WS_HPP #include +#include #include #include @@ -27,7 +28,7 @@ namespace libbitcoin { namespace server { class BCS_API channel_ws - : public node::channel, + : public server::channel, public network::channel_ws, protected network::tracker { @@ -72,7 +73,7 @@ class BCS_API channel_ws inline channel_ws(const network::logger& log, const network::socket::ptr& socket, uint64_t identifier, const node::configuration& config, const options_t& options) NOEXCEPT - : node::channel(log, socket, identifier, config), + : server::channel(log, socket, identifier, config), network::channel_ws(log, socket, identifier, config.network, options), network::tracker(log) { diff --git a/include/bitcoin/server/channels/channels.hpp b/include/bitcoin/server/channels/channels.hpp index ec6a95db..3eb40025 100644 --- a/include/bitcoin/server/channels/channels.hpp +++ b/include/bitcoin/server/channels/channels.hpp @@ -19,6 +19,7 @@ #ifndef LIBBITCOIN_SERVER_CHANNELS_CHANNELS_HPP #define LIBBITCOIN_SERVER_CHANNELS_CHANNELS_HPP +#include #include #include #include From 2e6d6a0fb306e7f745103159412344091bca54a3 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Mon, 9 Feb 2026 19:32:48 -0500 Subject: [PATCH 2/6] Suppress bogus vc++ DIAMOND_INHERITANCE warning. --- include/bitcoin/server/define.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/bitcoin/server/define.hpp b/include/bitcoin/server/define.hpp index 0b2c5e9c..0b8d0ce0 100644 --- a/include/bitcoin/server/define.hpp +++ b/include/bitcoin/server/define.hpp @@ -37,6 +37,9 @@ #define BCS_INTERNAL BC_HELPER_DLL_LOCAL #endif +/// Prevent bogus vc++ warnings on protocol. +BC_DISABLE_WARNING(DIAMOND_INHERITANCE) + /// Augment limited xcode placeholder defines (10 vs. common 20). /// --------------------------------------------------------------------------- #if defined (HAVE_XCODE) From 3b0439b3faa1f0cbc763dfd6733c9bcec7a186ca Mon Sep 17 00:00:00 2001 From: evoskuil Date: Mon, 9 Feb 2026 21:16:19 -0500 Subject: [PATCH 3/6] Add intermediate session base class. --- Makefile.am | 1 + .../libbitcoin-server.vcxproj | 1 + .../libbitcoin-server.vcxproj.filters | 3 + include/bitcoin/server.hpp | 1 + include/bitcoin/server/sessions/session.hpp | 67 +++++++++++++++++++ .../server/sessions/session_server.hpp | 22 ++---- include/bitcoin/server/sessions/sessions.hpp | 1 + 7 files changed, 79 insertions(+), 17 deletions(-) create mode 100644 include/bitcoin/server/sessions/session.hpp diff --git a/Makefile.am b/Makefile.am index 70d48382..921d52ea 100644 --- a/Makefile.am +++ b/Makefile.am @@ -185,6 +185,7 @@ include_bitcoin_server_protocols_HEADERS = \ include_bitcoin_server_sessionsdir = ${includedir}/bitcoin/server/sessions include_bitcoin_server_sessions_HEADERS = \ + include/bitcoin/server/sessions/session.hpp \ include/bitcoin/server/sessions/session_handshake.hpp \ include/bitcoin/server/sessions/session_server.hpp \ include/bitcoin/server/sessions/sessions.hpp diff --git a/builds/msvc/vs2022/libbitcoin-server/libbitcoin-server.vcxproj b/builds/msvc/vs2022/libbitcoin-server/libbitcoin-server.vcxproj index b910afbb..d83044cf 100644 --- a/builds/msvc/vs2022/libbitcoin-server/libbitcoin-server.vcxproj +++ b/builds/msvc/vs2022/libbitcoin-server/libbitcoin-server.vcxproj @@ -180,6 +180,7 @@ + diff --git a/builds/msvc/vs2022/libbitcoin-server/libbitcoin-server.vcxproj.filters b/builds/msvc/vs2022/libbitcoin-server/libbitcoin-server.vcxproj.filters index 16e6bcd3..7989780a 100644 --- a/builds/msvc/vs2022/libbitcoin-server/libbitcoin-server.vcxproj.filters +++ b/builds/msvc/vs2022/libbitcoin-server/libbitcoin-server.vcxproj.filters @@ -224,6 +224,9 @@ include\bitcoin\server + + include\bitcoin\server\sessions + include\bitcoin\server\sessions diff --git a/include/bitcoin/server.hpp b/include/bitcoin/server.hpp index daa9c4ae..9772848e 100644 --- a/include/bitcoin/server.hpp +++ b/include/bitcoin/server.hpp @@ -56,6 +56,7 @@ #include #include #include +#include #include #include #include diff --git a/include/bitcoin/server/sessions/session.hpp b/include/bitcoin/server/sessions/session.hpp new file mode 100644 index 00000000..52ed58d9 --- /dev/null +++ b/include/bitcoin/server/sessions/session.hpp @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) + * + * This file is part of libbitcoin. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +#ifndef LIBBITCOIN_SERVER_SESSIONS_SESSION_HPP +#define LIBBITCOIN_SERVER_SESSIONS_SESSION_HPP + +#include +#include +#include +#include + +namespace libbitcoin { +namespace server { + +class server_node; + +/// Intermediate base class for future server injection. +class session + : public node::session, + protected network::tracker +{ +public: + typedef std::shared_ptr ptr; + + /// Construct an instance (network should be started). + inline session(server_node& node, const configuration& config) NOEXCEPT + : node::session((node::full_node&)node), config_(config), + network::tracker((network::net&)node) + { + } + + /// Configuration settings for all server libraries. + inline const configuration& server_config() const NOEXCEPT + { + return config_; + } + + /// Server config settings. + inline const settings& server_settings() const NOEXCEPT + { + return server_config().server; + } + +private: + // This is thread safe. + const configuration& config_; +}; + +} // namespace server +} // namespace libbitcoin + +#endif diff --git a/include/bitcoin/server/sessions/session_server.hpp b/include/bitcoin/server/sessions/session_server.hpp index 479e5dfd..c89e11d3 100644 --- a/include/bitcoin/server/sessions/session_server.hpp +++ b/include/bitcoin/server/sessions/session_server.hpp @@ -23,6 +23,7 @@ #include #include #include +#include namespace libbitcoin { namespace server { @@ -40,7 +41,7 @@ class server_node; /// other protocols. template class session_server - : public node::session, + : public server::session, public network::session_server, protected network::tracker> { @@ -59,25 +60,13 @@ class session_server /// Construct an instance (network should be started). inline session_server(server_node& node, uint64_t identifier, const configuration& config, const options_t& options) NOEXCEPT - : node::session((node::full_node&)node), + : server::session(node, config), network::session_server((network::net&)node, identifier, options), - config_(config), options_(options), + options_(options), network::tracker>(node) { } - /// Configuration settings for all server libraries. - inline const configuration& server_config() const NOEXCEPT - { - return config_; - } - - /// Server config settings. - inline const settings& server_settings() const NOEXCEPT - { - return server_config().server; - } - protected: using socket_ptr = network::socket::ptr; using channel_ptr = network::channel::ptr; @@ -124,8 +113,7 @@ class session_server } protected: - // These are thread safe. - const configuration& config_; + // This is thread safe. const options_t& options_; }; diff --git a/include/bitcoin/server/sessions/sessions.hpp b/include/bitcoin/server/sessions/sessions.hpp index 809bad66..9447199e 100644 --- a/include/bitcoin/server/sessions/sessions.hpp +++ b/include/bitcoin/server/sessions/sessions.hpp @@ -19,6 +19,7 @@ #ifndef LIBBITCOIN_SERVER_SESSIONS_SESSIONS_HPP #define LIBBITCOIN_SERVER_SESSIONS_SESSIONS_HPP +#include #include #include From f3bfaa7ce1e81eea9826617ca29f0782455ac8e6 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Mon, 9 Feb 2026 21:16:26 -0500 Subject: [PATCH 4/6] Whitespace. --- include/bitcoin/server/channels/channel.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/include/bitcoin/server/channels/channel.hpp b/include/bitcoin/server/channels/channel.hpp index 2b32b7fa..16cb9af2 100644 --- a/include/bitcoin/server/channels/channel.hpp +++ b/include/bitcoin/server/channels/channel.hpp @@ -32,7 +32,6 @@ class BCS_API channel public: typedef std::shared_ptr ptr; using base = node::channel; - using base::channel; }; From da5ba6a63165e134be4da4d55439f78f0b765936 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Mon, 9 Feb 2026 21:19:16 -0500 Subject: [PATCH 5/6] Object hierarchy documentation. --- include/bitcoin/server/channels/channels.hpp | 29 +++++++++ .../bitcoin/server/protocols/protocols.hpp | 64 +++++++++++++++++++ include/bitcoin/server/sessions/sessions.hpp | 40 ++++++++++++ 3 files changed, 133 insertions(+) diff --git a/include/bitcoin/server/channels/channels.hpp b/include/bitcoin/server/channels/channels.hpp index 3eb40025..e0a1f3cd 100644 --- a/include/bitcoin/server/channels/channels.hpp +++ b/include/bitcoin/server/channels/channels.hpp @@ -28,3 +28,32 @@ #endif +/* + +Network provides the base for all channels as rpc, http, peer. Websocket and +html are not fully independent subclasses (operate within http). + +network::channel +├── [server::channel_stratum_v2] +├── channel_rpc +│ └── [server::channel_stratum_v1] +│ └── [server::channel_electrum] +├── channel_http +│ ├── [server::channel_http] +│ └── channel_ws +│ └── [server::channel_ws] +└── channel_peer + └── [node::channel_peer] + +node::channel +├── [server::channel] +└── channel_peer → network::channel_peer + +server::channel → node::channel +├── channel_stratum_v2 → network::channel +├── channel_stratum_v1 → network::channel_rpc +├── channel_electrum → network::channel_rpc +├── channel_http → network::channel_http +└── channel_ws → network::channel_ws + +*/ diff --git a/include/bitcoin/server/protocols/protocols.hpp b/include/bitcoin/server/protocols/protocols.hpp index 55cee377..711082e1 100644 --- a/include/bitcoin/server/protocols/protocols.hpp +++ b/include/bitcoin/server/protocols/protocols.hpp @@ -33,3 +33,67 @@ #include #endif + +/* + +Network provides the base for all protocols as rpc, http, peer. However node +and server do not inherit directly from network. Server extends node, but +neither inherit from network until a subclass is defined (rpc, http, peer). +Since stratum_v2 is just a stub it doesn't yet have its own subclass. Websocket +and html are not independent subclasses (operate within http). + +network::protocol +├── [server:protocol_stratum_v2] +├── protocol_rpc +│ └── [server::protocol_rpc] +│ └── [server::protocol_rpc] +├── protocol_http +│ ├── [server::protocol_bitcoind_rpc] +│ └── protocol_ws +│ └── [server::protocol_html] +└── protocol_peer + ├── [node::protocol_peer] + ├── protocol_alert_311 + ├── protocol_reject_70002 + ├── protocol_seed_209 + ├── protocol_address_in_209 + ├── protocol_address_out_209 + ├── protocol_ping_106 + │ └── protocol_ping_60001 + └── protocol_version_106 + └── protocol_version_70001 + └── protocol_version_70002 + └── protocol_version_70016 + +node::protocol +├── [server::protocol] +└── protocol_peer → network::protocol_peer + ├── protocol_observer + ├── protocol_filter_out_70015 + ├── protocol_block_in_106 + ├── protocol_performer + │ └── protocol_block_in_31800 + ├── protocol_block_out_106 + │ └── protocol_block_out_70012 + ├── protocol_header_in_31800 + │ └── protocol_header_in_70012 + ├── protocol_header_out_31800 + │ └── protocol_header_out_70012 + ├── protocol_transaction_in_106 + └── protocol_transaction_out_106 + +server::protocol → node::protocol +├── protocol_stratum_v2 → network::protocol +├── protocol_rpc → network::protocol_rpc +│ └── protocol_stratum_v1 +├── protocol_rpc → network::protocol_rpc +│ ├── protocol_electrum +│ └── protocol_electrum_version +└── protocol_http + ├── protocol_html → network::protocol_ws + │ ├── protocol_admin + │ └── protocol_native + └── protocol_bitcoind_rpc → network::protocol_http + └── protocol_bitcoind_rest + +*/ diff --git a/include/bitcoin/server/sessions/sessions.hpp b/include/bitcoin/server/sessions/sessions.hpp index 9447199e..e7fec967 100644 --- a/include/bitcoin/server/sessions/sessions.hpp +++ b/include/bitcoin/server/sessions/sessions.hpp @@ -41,3 +41,43 @@ using session_electrum = session_handshake] +└── session_peer + ├── session_seed + ├── session_inbound + │ └── [node::session_peer] + ├── session_outbound + │ └── [node::session_peer] + └── session_manual + └── [node::session_peer] + +node::session +├── [server::session] +└── session_peer → NetworkSession + ╞══ session_peer + │ └── session_inbound + ╞══ session_peer + │ └── session_outbound + ╘══ session_peer + └── session_manual + +server::session → node::session +└── server::session_server<...Protocols> → network::session_server + ╞══ session_admin = server::session_server + ╞══ session_native = server::session_server + ╞══ session_bitcoind = server::session_server + ╞══ session_stratum_v1 = server::session_server + ╞══ session_stratum_v2 = server::session_server + └── server::session_handshake<...Protocols> + ╘══ session_electrum = server::session_handshake< + protocol_electrum_version, protocol_electrum> + +*/ From af6f9a5abfadbd0dc962b0b89016d4ed43507950 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Tue, 10 Feb 2026 00:47:07 -0500 Subject: [PATCH 6/6] Fix channel scope resolution from server to network. --- console/executor_runner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/console/executor_runner.cpp b/console/executor_runner.cpp index 39f976b5..2f25b2c6 100644 --- a/console/executor_runner.cpp +++ b/console/executor_runner.cpp @@ -46,7 +46,7 @@ void executor::subscribe_connect() { node_->subscribe_connect ( - [&](const code&, const channel::ptr&) + [&](const code&, const network::channel::ptr&) { log_.write(levels::verbose) << "{in:" << node_->inbound_channel_count() << "}"