forked from libbitcoin/libbitcoin-node
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathprotocol_peer.hpp
More file actions
116 lines (92 loc) · 3.92 KB
/
protocol_peer.hpp
File metadata and controls
116 lines (92 loc) · 3.92 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_PEER_HPP
#define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_PEER_HPP
#include <memory>
#include <bitcoin/node/channels/channels.hpp>
#include <bitcoin/node/define.hpp>
#include <bitcoin/node/protocols/protocol.hpp>
// Only session.hpp.
#include <bitcoin/node/sessions/session.hpp>
namespace libbitcoin {
namespace node {
/// Abstract base for node peer protocols, thread safe.
class BCN_API protocol_peer
: public node::protocol,
public network::protocol_peer
{
public:
// Replace base class channel_t (network::channel_peer).
using channel_t = node::channel_peer;
protected:
/// Constructors.
/// -----------------------------------------------------------------------
/// static_pointer_cast relies on create_channel().
inline protocol_peer(const auto& session,
const network::channel::ptr& channel) NOEXCEPT
: node::protocol(session, channel),
network::protocol_peer(session, channel),
channel_(std::static_pointer_cast<node::channel_peer>(channel)),
session_(session)
{
}
/// Organizers.
/// -----------------------------------------------------------------------
/// Organize a validated header.
virtual void organize(const system::chain::header::cptr& header,
organize_handler&& handler) NOEXCEPT;
/// Organize a checked block.
virtual void organize(const system::chain::block::cptr& block,
organize_handler&& handler) NOEXCEPT;
/// Get block hashes for blocks to download.
virtual void get_hashes(map_handler&& handler) NOEXCEPT;
/// Submit block hashes for blocks not downloaded.
virtual void put_hashes(const map_ptr& map,
network::result_handler&& handler) NOEXCEPT;
/// Methods.
/// -----------------------------------------------------------------------
/// Report performance, handler may direct self-terminate.
virtual void performance(uint64_t speed,
network::result_handler&& handler) const NOEXCEPT;
/// Suspend all existing and future network connections.
/// A race condition could result in an unsuspended connection.
virtual code fault(const code& ec) NOEXCEPT;
/// Announcements.
/// -----------------------------------------------------------------------
/// Set an incoming block or tx hash that peer announced.
virtual void set_announced(const system::hash_digest&) NOEXCEPT;
/// Determine if outgoing block or tx was previously announced by peer.
virtual bool was_announced(const system::hash_digest&) const NOEXCEPT;
/// Events notification.
/// -----------------------------------------------------------------------
/// Set a chaser event.
virtual void notify(const code& ec, chase event_,
event_value value) const NOEXCEPT;
/// Set a chaser event.
virtual void notify_one(object_key key, const code& ec, chase event_,
event_value value) const NOEXCEPT;
private:
// This derived channel requires stranded calls, base is thread safe.
const node::channel_peer::ptr channel_;
// This is thread safe.
const node::session::ptr session_;
};
} // namespace node
} // namespace libbitcoin
#endif