-
Notifications
You must be signed in to change notification settings - Fork 659
Expand file tree
/
Copy pathgood_node.cpp
More file actions
69 lines (64 loc) · 2.09 KB
/
good_node.cpp
File metadata and controls
69 lines (64 loc) · 2.09 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
#include "../common/application_helper.hpp"
#include <fc/log/logger.hpp>
#include <fc/log/logger_config.hpp>
#include <thread>
#include <memory>
#include <csignal>
namespace fc {
extern std::unordered_map<std::string,logger>& get_logger_map();
extern std::unordered_map<std::string,appender::ptr>& get_appender_map();
}
int main(int argc, char** argv)
{
fc::temp_directory td;
std::shared_ptr<fc::path> temp_dir = nullptr;
std::string remote_node_ip;
std::string my_port = "0";
int timeout = -1;
for (int i = 1; i < argc; i++)
{
if (std::string(argv[i]) == "-d")
temp_dir = std::make_shared<fc::path>( fc::path(argv[i+1]));
if (std::string(argv[i]) == "-s")
remote_node_ip = argv[i+1];
if (std::string(argv[i]) == "-p")
my_port = argv[i+1];
if (std::string(argv[i]) == "-t")
timeout = std::stoi(argv[i+1]);
}
// we were not passed a temp directory, create one
if (!temp_dir)
temp_dir = std::make_shared<fc::path>( td.path() );
// start node
graphene::test::application_runner app(temp_dir, std::stoi(my_port));
app.start();
std::string p2p_address = "127.0.0.1:" + std::to_string( app.p2p_port_number );
// adjust logging
auto log_map = fc::get_logger_map();
auto appenders = fc::get_appender_map();
auto p2p_logger = log_map["p2p"];
p2p_logger.add_appender( appenders["stdout"] );
p2p_logger.set_log_level(fc::log_level::debug);
auto default_logger = log_map["default"];
default_logger.set_log_level(fc::log_level::debug);
std::cout << "Running on " << p2p_address << std::endl;
// add node if passed in
if (!remote_node_ip.empty())
{
std::this_thread::sleep_for(std::chrono::seconds(5));
std::cout << "attempting to add node " << remote_node_ip << "\n";
app.add_node(remote_node_ip);
}
if (timeout == -1)
{
std::cout << "Press e [enter] to exit" << std::endl;
char c = 0;
while( c != 'e' )
std::cin >> c;
}
else
{
std::this_thread::sleep_for(std::chrono::seconds(timeout));
::raise(SIGINT);
}
}