From 1b14b0b36ecca2e8bd5a764b9b852d464d6b634c Mon Sep 17 00:00:00 2001 From: evoskuil Date: Fri, 17 Oct 2025 03:23:50 -0400 Subject: [PATCH] Add protocol_websocket_handshake. --- Makefile.am | 1 + .../libbitcoin-node/libbitcoin-node.vcxproj | 1 + .../libbitcoin-node.vcxproj.filters | 3 + include/bitcoin/node.hpp | 1 + .../node/protocols/protocol_websocket.hpp | 14 ++-- .../protocol_websocket_handshake.hpp | 65 +++++++++++++++++++ include/bitcoin/node/protocols/protocols.hpp | 2 + 7 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 include/bitcoin/node/protocols/protocol_websocket_handshake.hpp diff --git a/Makefile.am b/Makefile.am index 602264cc1..dca45e965 100644 --- a/Makefile.am +++ b/Makefile.am @@ -212,6 +212,7 @@ include_bitcoin_node_protocols_HEADERS = \ include/bitcoin/node/protocols/protocol_transaction_out_106.hpp \ include/bitcoin/node/protocols/protocol_web.hpp \ include/bitcoin/node/protocols/protocol_websocket.hpp \ + include/bitcoin/node/protocols/protocol_websocket_handshake.hpp \ include/bitcoin/node/protocols/protocols.hpp include_bitcoin_node_sessionsdir = ${includedir}/bitcoin/node/sessions diff --git a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj index 6b3f15912..01e85c7fd 100644 --- a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj +++ b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj @@ -216,6 +216,7 @@ + diff --git a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters index 6306a2c66..57f3e2f58 100644 --- a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters +++ b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters @@ -335,6 +335,9 @@ include\bitcoin\node\protocols + + include\bitcoin\node\protocols + include\bitcoin\node\protocols diff --git a/include/bitcoin/node.hpp b/include/bitcoin/node.hpp index 3c0c4bec9..1e9b1f4a6 100644 --- a/include/bitcoin/node.hpp +++ b/include/bitcoin/node.hpp @@ -70,6 +70,7 @@ #include #include #include +#include #include #include #include diff --git a/include/bitcoin/node/protocols/protocol_websocket.hpp b/include/bitcoin/node/protocols/protocol_websocket.hpp index 90b5e4e7a..6eb3dfa1e 100644 --- a/include/bitcoin/node/protocols/protocol_websocket.hpp +++ b/include/bitcoin/node/protocols/protocol_websocket.hpp @@ -21,27 +21,29 @@ #include #include -#include +#include namespace libbitcoin { namespace node { -// TODO: maybe make this an intermediate base class for websockets. +// TODO: make this an intermediate base class for websocket. // TODO: and then create a distinct concrete class for deployment. class BCN_API protocol_websocket - : public node::protocol_http, + : public network::protocol_websocket, + public node::protocol, protected network::tracker { public: typedef std::shared_ptr ptr; - // Replace base class channel_t (node::channel_http). + // Replace base class channel_t (network::channel_websocket). using channel_t = node::channel_websocket; protocol_websocket(const auto& session, const network::channel::ptr& channel, const options_t& options) NOEXCEPT - : node::protocol_http(session, channel, options), + : network::protocol_websocket(session, channel, options), + node::protocol(session, channel), network::tracker(session->log) { } @@ -49,7 +51,7 @@ class BCN_API protocol_websocket /// Public start is required. void start() NOEXCEPT override { - node::protocol_http::start(); + network::protocol_websocket::start(); } private: diff --git a/include/bitcoin/node/protocols/protocol_websocket_handshake.hpp b/include/bitcoin/node/protocols/protocol_websocket_handshake.hpp new file mode 100644 index 000000000..f5034854b --- /dev/null +++ b/include/bitcoin/node/protocols/protocol_websocket_handshake.hpp @@ -0,0 +1,65 @@ +/** + * 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_NODE_PROTOCOLS_PROTOCOL_WEBSOCKET_HANDSHAKE_HPP +#define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_WEBSOCKET_HANDSHAKE_HPP + +#include +#include +#include + +namespace libbitcoin { +namespace node { + +// TODO: make this an intermediate base class for websocket_handshake. +// TODO: and then create a distinct concrete class for deployment. +class BCN_API protocol_websocket_handshake + : public network::protocol_websocket_handshake, + public node::protocol, + protected network::tracker +{ +public: + typedef std::shared_ptr ptr; + + // Replace base class channel_t (network::channel_http). + using channel_t = node::channel_http; + + protocol_websocket_handshake(const auto& session, + const network::channel::ptr& channel, + const options_t& options) NOEXCEPT + : network::protocol_websocket_handshake(session, channel, options), + node::protocol(session, channel), + network::tracker(session->log) + { + } + + /// Public start is required. + void start() NOEXCEPT override + { + network::protocol_websocket_handshake::start(); + } + +private: + // This is thread safe. + ////const options_t& options_; +}; + +} // namespace node +} // namespace libbitcoin + +#endif diff --git a/include/bitcoin/node/protocols/protocols.hpp b/include/bitcoin/node/protocols/protocols.hpp index a78a5b9af..78bb663f8 100644 --- a/include/bitcoin/node/protocols/protocols.hpp +++ b/include/bitcoin/node/protocols/protocols.hpp @@ -49,5 +49,7 @@ #include #include #include +#include +#include #endif