Skip to content

Commit 1486d56

Browse files
authored
Merge pull request #868 from evoskuil/master
Add websockets channel.
2 parents daa95ce + 8db8c93 commit 1486d56

File tree

8 files changed

+66
-2
lines changed

8 files changed

+66
-2
lines changed

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ include_bitcoin_node_channels_HEADERS = \
163163
include/bitcoin/node/channels/channel_http.hpp \
164164
include/bitcoin/node/channels/channel_peer.hpp \
165165
include/bitcoin/node/channels/channel_tcp.hpp \
166+
include/bitcoin/node/channels/channel_websocket.hpp \
166167
include/bitcoin/node/channels/channels.hpp
167168

168169
include_bitcoin_node_chasersdir = ${includedir}/bitcoin/node/chasers

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@
170170
<ClInclude Include="..\..\..\..\include\bitcoin\node\channels\channel_http.hpp" />
171171
<ClInclude Include="..\..\..\..\include\bitcoin\node\channels\channel_peer.hpp" />
172172
<ClInclude Include="..\..\..\..\include\bitcoin\node\channels\channel_tcp.hpp" />
173+
<ClInclude Include="..\..\..\..\include\bitcoin\node\channels\channel_websocket.hpp" />
173174
<ClInclude Include="..\..\..\..\include\bitcoin\node\channels\channels.hpp" />
174175
<ClInclude Include="..\..\..\..\include\bitcoin\node\chase.hpp" />
175176
<ClInclude Include="..\..\..\..\include\bitcoin\node\chasers\chaser.hpp" />

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@
197197
<ClInclude Include="..\..\..\..\include\bitcoin\node\channels\channel_tcp.hpp">
198198
<Filter>include\bitcoin\node\channels</Filter>
199199
</ClInclude>
200+
<ClInclude Include="..\..\..\..\include\bitcoin\node\channels\channel_websocket.hpp">
201+
<Filter>include\bitcoin\node\channels</Filter>
202+
</ClInclude>
200203
<ClInclude Include="..\..\..\..\include\bitcoin\node\channels\channels.hpp">
201204
<Filter>include\bitcoin\node\channels</Filter>
202205
</ClInclude>

include/bitcoin/node.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <bitcoin/node/channels/channel_http.hpp>
3232
#include <bitcoin/node/channels/channel_peer.hpp>
3333
#include <bitcoin/node/channels/channel_tcp.hpp>
34+
#include <bitcoin/node/channels/channel_websocket.hpp>
3435
#include <bitcoin/node/channels/channels.hpp>
3536
#include <bitcoin/node/chasers/chaser.hpp>
3637
#include <bitcoin/node/chasers/chaser_block.hpp>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS)
3+
*
4+
* This file is part of libbitcoin.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
#ifndef LIBBITCOIN_NODE_CHANNELS_CHANNEL_WEBSOCKET_HPP
20+
#define LIBBITCOIN_NODE_CHANNELS_CHANNEL_WEBSOCKET_HPP
21+
22+
#include <memory>
23+
#include <bitcoin/node/channels/channel.hpp>
24+
#include <bitcoin/node/configuration.hpp>
25+
#include <bitcoin/node/define.hpp>
26+
27+
namespace libbitcoin {
28+
namespace node {
29+
30+
/// Abstract base websocket channel state for the node.
31+
class BCN_API channel_websocket
32+
: public network::channel_websocket,
33+
public node::channel
34+
{
35+
public:
36+
typedef std::shared_ptr<node::channel_websocket> ptr;
37+
using options_t = network::channel_websocket::options_t;
38+
39+
channel_websocket(const network::logger& log,
40+
const network::socket::ptr& socket,
41+
const node::configuration& config, uint64_t identifier=zero,
42+
const options_t& options={}) NOEXCEPT
43+
: network::channel_websocket(log, socket, config.network, identifier,
44+
options),
45+
node::channel(log, socket, config, identifier)
46+
{
47+
}
48+
};
49+
50+
} // namespace node
51+
} // namespace libbitcoin
52+
53+
#endif

include/bitcoin/node/channels/channels.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <bitcoin/node/channels/channel_peer.hpp>
2424
#include <bitcoin/node/channels/channel_tcp.hpp>
2525
#include <bitcoin/node/channels/channel_http.hpp>
26-
// add channel_websocket to network and derive here
26+
#include <bitcoin/node/channels/channel_websocket.hpp>
2727

2828
#endif
2929

include/bitcoin/node/protocols/protocol_websocket.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,18 @@
2626
namespace libbitcoin {
2727
namespace node {
2828

29+
// TODO: maybe make this an intermediate base class for websockets.
30+
// TODO: and then create a distinct concrete class for deployment.
2931
class BCN_API protocol_websocket
3032
: public node::protocol_http,
3133
protected network::tracker<protocol_websocket>
3234
{
3335
public:
3436
typedef std::shared_ptr<protocol_websocket> ptr;
3537

38+
// Replace base class channel_t (node::channel_http).
39+
using channel_t = node::channel_websocket;
40+
3641
protocol_websocket(const auto& session,
3742
const network::channel::ptr& channel,
3843
const options_t& options) NOEXCEPT

include/bitcoin/node/settings.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class BCN_API settings
136136
server::settings::html_server explore{ "explore" };
137137

138138
/// native websocket query interface (http/s->tcp/s, json, handshake)
139-
network::settings::webs_server websocket{ "websocket" };
139+
network::settings::websocket_server websocket{ "websocket" };
140140

141141
/// bitcoind compat interface (http/s, stateless json-rpc-v2)
142142
network::settings::http_server bitcoind{ "bitcoind" };

0 commit comments

Comments
 (0)