This repository has been archived by the owner on Mar 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
node_base.hpp
110 lines (93 loc) · 4.96 KB
/
node_base.hpp
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
// Copyright (C) 2018 Bluzelle
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License, version 3,
// as published by the Free Software Foundation.
//
// 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/>.
#pragma once
#include <boost/asio.hpp>
#include <node/session_base.hpp>
#include <json/json.h>
#include <proto/bluzelle.pb.h>
namespace bzn
{
class pbft_base;
class node_base
{
public:
virtual ~node_base() = default;
/**
* Register for a callback to be execute when a certain message type arrives
* @param msg_type message type (crud, pbft etc.)
* @param msg_handler callback
* @return true if registration succeeded
*/
virtual bool register_for_message(const bzn_envelope::PayloadCase type, bzn::protobuf_handler msg_handler) = 0;
/**
* Register for a callback to be executed when a connection error occurs
* @param ep endpoint we tried to connect to
* @param ec error that occurred
* @param error_callback callback to invoke
*/
virtual void register_error_handler(std::function<void(const boost::asio::ip::tcp::endpoint& ep, const boost::system::error_code&)> error_callback) = 0;
/**
* Start server's listener etc.
*/
virtual void start(std::shared_ptr<bzn::pbft_base> pbft) = 0;
/**
* Send a raw string message
* @param ep host to send the message to
* @param msg message to send
*/
virtual void send_message_str(const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr<bzn::encoded_message> msg) = 0;
/**
* Send a message to a node identified by endpoint. If the sender field is empty or contains our uuid, the message will be
* signed before sending. If the sender field contains something else, an existing signature will be kept intact.
* @param ep host to send the message to
* @param msg message to send
*/
virtual void send_signed_message(const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr<bzn_envelope> msg) = 0;
/**
* As send_signed_message, but send the same message to multiple recipients. The signature is computed only once
* and the whole operation is async.
* @param eps hosts to send the message to
* @param msg message to send
*/
virtual void multicast_signed_message(std::shared_ptr<std::vector<boost::asio::ip::tcp::endpoint>> eps, std::shared_ptr<bzn_envelope> msg) = 0;
/**
* Send a message to a node identified by uuid. If the sender field is empty or contains our uuid, the message will be
* signed before sending. If the sender field contains something else, an existing signature will be kept intact.
* @param uuid host to send the message to
* @param msg message to send
*/
virtual void send_signed_message(const bzn::uuid_t& uuid, std::shared_ptr<bzn_envelope> msg) = 0;
/**
* Send a message to a node identified by endpoint. If the sender field is empty or contains our uuid, the message will be
* signed before sending. If the sender field contains something else, an existing signature will be kept intact.
* @param ep host to send the message to
* @param msg message to send
*/
virtual void send_maybe_signed_message(const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr<bzn_envelope> msg) = 0;
/**
* As send_signed_message, but send the same message to multiple recipients. The signature is computed only once
* and the whole operation is async.
* @param eps hosts to send the message to
* @param msg message to send
*/
virtual void multicast_maybe_signed_message(std::shared_ptr<std::vector<boost::asio::ip::tcp::endpoint>> eps, std::shared_ptr<bzn_envelope> msg) = 0;
/**
* Send a message to a node identified by uuid. If the sender field is empty or contains our uuid, the message will be
* signed before sending. If the sender field contains something else, an existing signature will be kept intact.
* @param uuid host to send the message to
* @param msg message to send
*/
virtual void send_maybe_signed_message(const bzn::uuid_t& uuid, std::shared_ptr<bzn_envelope> msg) = 0;
};
} // bzn