forked from libbitcoin/libbitcoin-server
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprotocol_electrum_version.hpp
More file actions
93 lines (77 loc) · 3.25 KB
/
protocol_electrum_version.hpp
File metadata and controls
93 lines (77 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* Copyright (c) 2011-2026 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 <http://www.gnu.org/licenses/>.
*/
#ifndef LIBBITCOIN_SERVER_PROTOCOLS_PROTOCOL_ELECTRUM_VERSION_HPP
#define LIBBITCOIN_SERVER_PROTOCOLS_PROTOCOL_ELECTRUM_VERSION_HPP
#include <memory>
#include <bitcoin/server/channels/channels.hpp>
#include <bitcoin/server/define.hpp>
#include <bitcoin/server/interfaces/interfaces.hpp>
#include <bitcoin/server/parsers/parsers.hpp>
#include <bitcoin/server/protocols/protocol_rpc.hpp>
namespace libbitcoin {
namespace server {
class BCS_API protocol_electrum_version
: public protocol_rpc<channel_electrum>,
protected network::tracker<protocol_electrum_version>
{
public:
typedef std::shared_ptr<protocol_electrum_version> ptr;
using rpc_interface = interface::electrum;
static constexpr electrum::version minimum = electrum::version::v1_0;
static constexpr electrum::version maximum = electrum::version::v1_6;
inline protocol_electrum_version(const auto& session,
const network::channel::ptr& channel,
const options_t& options) NOEXCEPT
: protocol_rpc<channel_electrum>(session, channel, options),
options_(options),
channel_(std::dynamic_pointer_cast<channel_t>(channel)),
network::tracker<protocol_electrum_version>(session->log)
{
}
virtual void shake(network::result_handler&& handler) NOEXCEPT;
virtual void finished(const code& ec, const code& shake) NOEXCEPT;
protected:
static constexpr size_t max_client_name_length = 1024;
void handle_server_version(const code& ec,
rpc_interface::server_version, const std::string& client_name,
const interface::value_t& protocol_version) NOEXCEPT;
electrum::version version() const NOEXCEPT;
std::string_view negotiated_version() const NOEXCEPT;
bool set_version(const interface::value_t& version) NOEXCEPT;
bool get_versions(electrum::version& min, electrum::version& max,
const interface::value_t& version) NOEXCEPT;
std::string_view server_name() const NOEXCEPT;
std::string_view client_name() const NOEXCEPT;
std::string escape_client(const std::string& in) NOEXCEPT;
bool set_client(const std::string& name) NOEXCEPT;
inline const options_t& options() const NOEXCEPT
{
return options_;
}
private:
// This is thread safe.
const options_t& options_;
// This is mostly thread safe, and used in a thread safe manner.
const channel_t::ptr channel_;
// This is protected by strand.
std::shared_ptr<network::result_handler> handler_{};
};
} // namespace server
} // namespace libbitcoin
#endif