Skip to content

Commit e17f595

Browse files
authored
Merge pull request #869 from evoskuil/master
Add protocol_websocket_handshake.
2 parents 1486d56 + 1b14b0b commit e17f595

File tree

7 files changed

+81
-6
lines changed

7 files changed

+81
-6
lines changed

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ include_bitcoin_node_protocols_HEADERS = \
212212
include/bitcoin/node/protocols/protocol_transaction_out_106.hpp \
213213
include/bitcoin/node/protocols/protocol_web.hpp \
214214
include/bitcoin/node/protocols/protocol_websocket.hpp \
215+
include/bitcoin/node/protocols/protocol_websocket_handshake.hpp \
215216
include/bitcoin/node/protocols/protocols.hpp
216217

217218
include_bitcoin_node_sessionsdir = ${includedir}/bitcoin/node/sessions

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@
216216
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_transaction_out_106.hpp" />
217217
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_web.hpp" />
218218
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_websocket.hpp" />
219+
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_websocket_handshake.hpp" />
219220
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocols.hpp" />
220221
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\session.hpp" />
221222
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\session_inbound.hpp" />

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,9 @@
335335
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_websocket.hpp">
336336
<Filter>include\bitcoin\node\protocols</Filter>
337337
</ClInclude>
338+
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_websocket_handshake.hpp">
339+
<Filter>include\bitcoin\node\protocols</Filter>
340+
</ClInclude>
338341
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocols.hpp">
339342
<Filter>include\bitcoin\node\protocols</Filter>
340343
</ClInclude>

include/bitcoin/node.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
#include <bitcoin/node/protocols/protocol_transaction_out_106.hpp>
7171
#include <bitcoin/node/protocols/protocol_web.hpp>
7272
#include <bitcoin/node/protocols/protocol_websocket.hpp>
73+
#include <bitcoin/node/protocols/protocol_websocket_handshake.hpp>
7374
#include <bitcoin/node/protocols/protocols.hpp>
7475
#include <bitcoin/node/sessions/session.hpp>
7576
#include <bitcoin/node/sessions/session_inbound.hpp>

include/bitcoin/node/protocols/protocol_websocket.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,37 @@
2121

2222
#include <memory>
2323
#include <bitcoin/node/define.hpp>
24-
#include <bitcoin/node/protocols/protocol_http.hpp>
24+
#include <bitcoin/node/protocols/protocol.hpp>
2525

2626
namespace libbitcoin {
2727
namespace node {
2828

29-
// TODO: maybe make this an intermediate base class for websockets.
29+
// 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_websocket
32-
: public node::protocol_http,
32+
: public network::protocol_websocket,
33+
public node::protocol,
3334
protected network::tracker<protocol_websocket>
3435
{
3536
public:
3637
typedef std::shared_ptr<protocol_websocket> ptr;
3738

38-
// Replace base class channel_t (node::channel_http).
39+
// Replace base class channel_t (network::channel_websocket).
3940
using channel_t = node::channel_websocket;
4041

4142
protocol_websocket(const auto& session,
4243
const network::channel::ptr& channel,
4344
const options_t& options) NOEXCEPT
44-
: node::protocol_http(session, channel, options),
45+
: network::protocol_websocket(session, channel, options),
46+
node::protocol(session, channel),
4547
network::tracker<protocol_websocket>(session->log)
4648
{
4749
}
4850

4951
/// Public start is required.
5052
void start() NOEXCEPT override
5153
{
52-
node::protocol_http::start();
54+
network::protocol_websocket::start();
5355
}
5456

5557
private:
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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_PROTOCOLS_PROTOCOL_WEBSOCKET_HANDSHAKE_HPP
20+
#define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_WEBSOCKET_HANDSHAKE_HPP
21+
22+
#include <memory>
23+
#include <bitcoin/node/define.hpp>
24+
#include <bitcoin/node/protocols/protocol.hpp>
25+
26+
namespace libbitcoin {
27+
namespace node {
28+
29+
// TODO: make this an intermediate base class for websocket_handshake.
30+
// TODO: and then create a distinct concrete class for deployment.
31+
class BCN_API protocol_websocket_handshake
32+
: public network::protocol_websocket_handshake,
33+
public node::protocol,
34+
protected network::tracker<protocol_websocket_handshake>
35+
{
36+
public:
37+
typedef std::shared_ptr<protocol_websocket_handshake> ptr;
38+
39+
// Replace base class channel_t (network::channel_http).
40+
using channel_t = node::channel_http;
41+
42+
protocol_websocket_handshake(const auto& session,
43+
const network::channel::ptr& channel,
44+
const options_t& options) NOEXCEPT
45+
: network::protocol_websocket_handshake(session, channel, options),
46+
node::protocol(session, channel),
47+
network::tracker<protocol_websocket_handshake>(session->log)
48+
{
49+
}
50+
51+
/// Public start is required.
52+
void start() NOEXCEPT override
53+
{
54+
network::protocol_websocket_handshake::start();
55+
}
56+
57+
private:
58+
// This is thread safe.
59+
////const options_t& options_;
60+
};
61+
62+
} // namespace node
63+
} // namespace libbitcoin
64+
65+
#endif

include/bitcoin/node/protocols/protocols.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,7 @@
4949
#include <bitcoin/node/protocols/protocol_electrum.hpp>
5050
#include <bitcoin/node/protocols/protocol_stratum_v1.hpp>
5151
#include <bitcoin/node/protocols/protocol_stratum_v2.hpp>
52+
#include <bitcoin/node/protocols/protocol_websocket.hpp>
53+
#include <bitcoin/node/protocols/protocol_websocket_handshake.hpp>
5254

5355
#endif

0 commit comments

Comments
 (0)