This repository has been archived by the owner on Feb 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 174
/
client.hpp
169 lines (135 loc) · 5.68 KB
/
client.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#pragma once
#include <bts/blockchain/chain_database.hpp>
#include <bts/wallet/wallet.hpp>
#include <bts/net/node.hpp>
#include <bts/rpc/rpc_client_api.hpp>
#include <bts/api/common_api.hpp>
#include <bts/rpc_stubs/common_api_client.hpp>
#include <fc/thread/thread.hpp>
#include <fc/log/logger_config.hpp>
#include <memory>
#include <boost/program_options.hpp>
namespace bts { namespace rpc {
class rpc_server;
typedef std::shared_ptr<rpc_server> rpc_server_ptr;
} }
namespace bts { namespace cli {
class cli;
}};
namespace bts { namespace client {
using namespace bts::blockchain;
using namespace bts::wallet;
boost::program_options::variables_map parse_option_variables(int argc, char** argv);
fc::path get_data_dir(const boost::program_options::variables_map& option_variables);
namespace detail { class client_impl; }
using namespace bts::rpc;
struct rpc_server_config
{
rpc_server_config()
: enable(false),
rpc_endpoint(fc::ip::endpoint::from_string("127.0.0.1:0")),
httpd_endpoint(fc::ip::endpoint::from_string("127.0.0.1:0")),
htdocs("./htdocs")
{}
bool enable;
std::string rpc_user;
std::string rpc_password;
fc::ip::endpoint rpc_endpoint;
fc::ip::endpoint httpd_endpoint;
fc::path htdocs;
bool is_valid() const; /* Currently just checks if rpc port is set */
};
struct config
{
config( ) :
default_peers(vector<string>{"178.62.50.61:", "178.62.50.61:", "178.62.50.61:", "80.240.133.79:", "80.240.133.79:"}),
ignore_console(false),
use_upnp(true),
maximum_number_of_connections(BTS_NET_DEFAULT_MAX_CONNECTIONS) ,
delegate_server( fc::ip::endpoint::from_string("0.0.0.0:0") ),
default_delegate_peers( vector<string>({"178.62.50.61:9988"}) )
{
default_peers[0]+=fc::to_string( BTS_NETWORK_DEFAULT_P2P_PORT );
default_peers[1]+=fc::to_string( BTS_NETWORK_DEFAULT_P2P_PORT+1 );
default_peers[2]+=fc::to_string( BTS_NETWORK_DEFAULT_P2P_PORT+2 );
default_peers[3]+=fc::to_string( BTS_NETWORK_DEFAULT_P2P_PORT );
default_peers[4]+=fc::to_string( BTS_NETWORK_DEFAULT_P2P_PORT+1 );
logging = fc::logging_config::default_config();
}
rpc_server_config rpc;
vector<string> default_peers;
bool ignore_console;
bool use_upnp;
optional<fc::path> genesis_config;
uint16_t maximum_number_of_connections;
fc::logging_config logging;
fc::ip::endpoint delegate_server;
vector<string> default_delegate_peers;
};
/**
* @class client
* @brief integrates the network, wallet, and blockchain
*
*/
class client : public bts::rpc_stubs::common_api_client,
public std::enable_shared_from_this<client>
{
public:
client();
client(bts::net::simulated_network_ptr network_to_connect_to);
void simulate_disconnect( bool state );
virtual ~client();
void configure_from_command_line(int argc, char** argv);
fc::future<void> start();
void open( const path& data_dir,
optional<fc::path> genesis_file_path = optional<fc::path>());
void init_cli();
void set_daemon_mode(bool daemon_mode);
void add_node( const string& ep );
void start_delegate_loop();
chain_database_ptr get_chain()const;
wallet_ptr get_wallet()const;
bts::rpc::rpc_server_ptr get_rpc_server()const;
bts::net::node_ptr get_node()const;
fc::path get_data_dir()const;
// returns true if the client is connected to the network
bool is_connected() const;
bts::net::node_id_t get_node_id() const;
void configure( const fc::path& configuration_directory );
// functions for taking command-line parameters and passing them on to the p2p node
void listen_on_port( uint16_t port_to_listen, bool wait_if_not_available);
void listen_to_p2p_network();
void connect_to_peer( const string& remote_endpoint );
void connect_to_p2p_network();
fc::ip::endpoint get_p2p_listening_endpoint() const;
#ifndef NDEBUG
bool handle_message(const bts::net::message&, bool sync_mode);
#endif
protected:
virtual bts::api::common_api* get_impl() const override;
private:
unique_ptr<detail::client_impl> my;
};
typedef shared_ptr<client> client_ptr;
/* Message broadcast on the network to notify all clients of some important information
(security vulnerability, new version, that sort of thing) */
class client_notification
{
public:
fc::time_point_sec timestamp;
string message;
fc::ecc::compact_signature signature;
//client_notification();
fc::sha256 digest() const;
void sign(const fc::ecc::private_key& key);
fc::ecc::public_key signee() const;
};
typedef shared_ptr<client_notification> client_notification_ptr;
} } // bts::client
extern const std::string BTS_MESSAGE_MAGIC;
FC_REFLECT(bts::client::client_notification, (timestamp)(message)(signature) )
FC_REFLECT( bts::client::rpc_server_config, (enable)(rpc_user)(rpc_password)(rpc_endpoint)(httpd_endpoint)(htdocs) )
FC_REFLECT( bts::client::config,
(rpc)(default_peers)(ignore_console)(logging)
(delegate_server)
(default_delegate_peers) )