Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
main.cpp File Reference
#include <string>
#include <vector>
#include <math.h>
#include <sstream>
#include <regex>
#include <boost/algorithm/string.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/ip/host_name.hpp>
#include <boost/program_options.hpp>
#include <boost/process/child.hpp>
#include <boost/process/env.hpp>
#include <boost/process/system.hpp>
#include <boost/process/io.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/fstream.hpp>
#include <fc/crypto/private_key.hpp>
#include <fc/crypto/public_key.hpp>
#include <fc/io/json.hpp>
#include <fc/network/ip.hpp>
#include <fc/reflect/variant.hpp>
#include <fc/log/logger_config.hpp>
#include <ifaddrs.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <net/if.h>
#include <sysio/chain/genesis_state.hpp>
#include "config.hpp"
Include dependency graph for main.cpp:

Go to the source code of this file.

Classes

struct  local_identity
 
class  host_def
 
class  eosd_def
 
class  tn_node_def
 
struct  remote_deploy
 
struct  testnet_def
 
struct  prodkey_def
 
struct  producer_set_def
 
struct  server_name_def
 
struct  server_identities
 
struct  node_rt_info
 
struct  last_run_def
 
class  producer_names
 
struct  launcher_def
 

Enumerations

enum  launch_modes {
  LM_NONE , LM_LOCAL , LM_REMOTE , LM_NAMED ,
  LM_ALL , LM_VERIFY
}
 
enum  allowed_connection : char { PC_NONE = 0 , PC_PRODUCERS = 1 << 0 , PC_SPECIFIED = 1 << 1 , PC_ANY = 1 << 2 }
 

Functions

template<class enum_type , class = typename std::enable_if<std::is_enum<enum_type>::value>::type>
enum_type & operator|= (enum_type &lhs, const enum_type &rhs)
 
template<typename T >
void retrieve_paired_array_parameters (const variables_map &vmap, const std::string &num_selector, const std::string &paired_selector, std::map< uint, T > &selector_map)
 
void write_default_config (const bfs::path &cfg_file, const options_description &cfg)
 
int main (int argc, char *argv[])
 
 FC_REFLECT (remote_deploy,(ssh_cmd)(scp_cmd)(ssh_identity)(ssh_args)) FC_REFLECT(prodkey_def
 
 producer_name (block_signing_key)) FC_REFLECT(producer_set_def
 
schedule FC_REFLECT (host_def,(genesis)(ssh_identity)(ssh_args)(sysio_home)(host_name)(public_name)(base_p2p_port)(base_http_port)(def_file_size)(instances)) FC_REFLECT(eosd_def
 
schedule config_dir_name data_dir_name p2p_port http_port file_size name host (p2p_endpoint)) FC_REFLECT(tn_node_def
 
schedule config_dir_name data_dir_name p2p_port http_port file_size name name keys peers producers (dont_start)) FC_REFLECT(testnet_def
 
schedule config_dir_name data_dir_name p2p_port http_port file_size name name keys peers name ssh_helper (nodes)) FC_REFLECT(server_name_def
 
schedule config_dir_name data_dir_name p2p_port http_port file_size name name keys peers name ipaddr name has_bios sysio_home (instances)) FC_REFLECT(server_identities
 
schedule config_dir_name data_dir_name p2p_port http_port file_size name name keys peers name ipaddr name has_bios producer nonprod db default_sysio_home (ssh)) FC_REFLECT(node_rt_info
 

Variables

const string block_dir = "blocks"
 
const string shared_mem_dir = "state"
 
struct local_identity local_id
 

Enumeration Type Documentation

◆ allowed_connection

enum allowed_connection : char
Enumerator
PC_NONE 
PC_PRODUCERS 
PC_SPECIFIED 
PC_ANY 

Definition at line 333 of file main.cpp.

333 : char {
334 PC_NONE = 0,
335 PC_PRODUCERS = 1 << 0,
336 PC_SPECIFIED = 1 << 1,
337 PC_ANY = 1 << 2
338};
@ PC_NONE
Definition main.cpp:334
@ PC_PRODUCERS
Definition main.cpp:335
@ PC_ANY
Definition main.cpp:337
@ PC_SPECIFIED
Definition main.cpp:336

◆ launch_modes

Enumerator
LM_NONE 
LM_LOCAL 
LM_REMOTE 
LM_NAMED 
LM_ALL 
LM_VERIFY 

Definition at line 324 of file main.cpp.

324 {
325 LM_NONE,
326 LM_LOCAL,
327 LM_REMOTE,
328 LM_NAMED,
329 LM_ALL,
331};
@ LM_NONE
Definition main.cpp:325
@ LM_ALL
Definition main.cpp:329
@ LM_NAMED
Definition main.cpp:328
@ LM_VERIFY
Definition main.cpp:330
@ LM_LOCAL
Definition main.cpp:326
@ LM_REMOTE
Definition main.cpp:327

Function Documentation

◆ default_sysio_home()

schedule config_dir_name data_dir_name p2p_port http_port file_size name name keys peers name ipaddr name has_bios producer nonprod db default_sysio_home ( ssh )

◆ FC_REFLECT() [1/2]

schedule FC_REFLECT ( host_def ,
(genesis)(ssh_identity)(ssh_args)(sysio_home)(host_name)(public_name)(base_p2p_port)(base_http_port)(def_file_size)(instances)  )

◆ FC_REFLECT() [2/2]

FC_REFLECT ( remote_deploy ,
(ssh_cmd)(scp_cmd)(ssh_identity)(ssh_args)  )

◆ host()

schedule config_dir_name data_dir_name p2p_port http_port file_size name host ( p2p_endpoint )
Here is the caller graph for this function:

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 1983 of file main.cpp.

1983 {
1984
1985 variables_map vmap;
1986 options_description cfg ("Testnet launcher config options");
1987 options_description cli ("launcher command line options");
1988 launcher_def top;
1989 string gts;
1990 launch_modes mode;
1991 string kill_arg;
1992 string bounce_nodes;
1993 string down_nodes;
1994 string roll_nodes;
1995 bfs::path config_dir;
1996 bfs::path config_file;
1997
1998 local_id.initialize();
1999 top.set_options(cfg);
2000
2001 cli.add_options()
2002 ("timestamp,i",bpo::value<string>(&gts),"set the timestamp for the first block. Use \"now\" to indicate the current time")
2003 ("launch,l",bpo::value<string>(), "select a subset of nodes to launch. Currently may be \"all\", \"none\", or \"local\". If not set, the default is to launch all unless an output file is named, in which case it starts none.")
2004 ("output,o",bpo::value<bfs::path>(&top.output),"save a copy of the generated topology in this file")
2005 ("kill,k", bpo::value<string>(&kill_arg),"The launcher retrieves the previously started process ids and issues a kill to each.")
2006 ("down", bpo::value<string>(&down_nodes),"comma-separated list of node numbers that will be taken down using the sysio-tn_down.sh script")
2007 ("bounce", bpo::value<string>(&bounce_nodes),"comma-separated list of node numbers that will be restarted using the sysio-tn_bounce.sh script")
2008 ("roll", bpo::value<string>(&roll_nodes),"comma-separated list of host names where the nodes should be rolled to a new version using the sysio-tn_roll.sh script")
2009 ("version,v", "print version information")
2010 ("help,h","print this list")
2011 ("config-dir", bpo::value<bfs::path>(), "Directory containing configuration files such as config.ini")
2012 ("config,c", bpo::value<bfs::path>()->default_value( "config.ini" ), "Configuration file name relative to config-dir");
2013
2014 cli.add(cfg);
2015
2016 try {
2017 bpo::store(bpo::parse_command_line(argc, argv, cli), vmap);
2018 bpo::notify(vmap);
2019
2020 top.initialize(vmap);
2021
2022 if (vmap.count("help") > 0) {
2023 cli.print(cerr);
2024 return 0;
2025 }
2026 if (vmap.count("version") > 0) {
2027 cout << sysio::launcher::config::version_str << endl;
2028 return 0;
2029 }
2030
2031 if( vmap.count( "config-dir" ) ) {
2032 config_dir = vmap["config-dir"].as<bfs::path>();
2033 if( config_dir.is_relative() )
2034 config_dir = bfs::current_path() / config_dir;
2035 }
2036
2037 bfs::path config_file_name = config_dir / "config.ini";
2038 if( vmap.count( "config" ) ) {
2039 config_file_name = vmap["config"].as<bfs::path>();
2040 if( config_file_name.is_relative() )
2041 config_file_name = config_dir / config_file_name;
2042 }
2043
2044 if(!bfs::exists(config_file_name)) {
2045 if(config_file_name.compare(config_dir / "config.ini") != 0)
2046 {
2047 cout << "Config file " << config_file_name << " missing." << std::endl;
2048 return -1;
2049 }
2050 write_default_config(config_file_name, cfg);
2051 }
2052
2053
2054 bpo::store(bpo::parse_config_file<char>(config_file_name.make_preferred().string().c_str(),
2055 cfg, true), vmap);
2056
2057
2058
2059 if (vmap.count("launch")) {
2060 string l = vmap["launch"].as<string>();
2061 if (boost::iequals(l,"all"))
2062 mode = LM_ALL;
2063 else if (boost::iequals(l,"local"))
2064 mode = LM_LOCAL;
2065 else if (boost::iequals(l,"remote"))
2066 mode = LM_REMOTE;
2067 else if (boost::iequals(l,"none"))
2068 mode = LM_NONE;
2069 else if (boost::iequals(l,"verify"))
2070 mode = LM_VERIFY;
2071 else {
2072 mode = LM_NAMED;
2073 top.launch_name = l;
2074 }
2075 }
2076 else {
2077 mode = !kill_arg.empty() || top.output.empty() ? LM_ALL : LM_NONE;
2078 }
2079
2080 if (!kill_arg.empty()) {
2081 cout << "killing" << std::endl;
2082 if (kill_arg[0] != '-') {
2083 kill_arg = "-" + kill_arg;
2084 }
2085 top.kill (mode, kill_arg);
2086 }
2087 else if (!bounce_nodes.empty()) {
2088 top.bounce(bounce_nodes);
2089 }
2090 else if (!down_nodes.empty()) {
2091 top.down(down_nodes);
2092 }
2093 else if (!roll_nodes.empty()) {
2094 top.roll(roll_nodes);
2095 }
2096 else {
2097 top.generate();
2098 top.start_all(gts, mode);
2099 top.ignite();
2100 }
2101 } catch (bpo::unknown_option &ex) {
2102 cerr << ex.what() << endl;
2103 cli.print (cerr);
2104 }
2105 return 0;
2106}
char ** argv
std::ostream & cerr()
struct local_identity local_id
launch_modes
Definition main.cpp:324
void write_default_config(const bfs::path &cfg_file, const options_description &cfg)
Definition main.cpp:1941
void down(const string &node_numbers)
Definition main.cpp:1835
void set_options(bpo::options_description &cli)
Definition main.cpp:477
void roll(const string &host_names)
Definition main.cpp:1850
void bounce(const string &node_numbers)
Definition main.cpp:1815
string launch_name
Definition main.cpp:419
void ignite()
Definition main.cpp:1862
void start_all(string &gts, launch_modes mode)
Definition main.cpp:1885
bool generate()
Definition main.cpp:717
bfs::path output
Definition main.cpp:396
void kill(launch_modes mode, string sig_opt)
Definition main.cpp:1684
void initialize(const variables_map &vmap)
Definition main.cpp:540
void cli()
int l
Here is the call graph for this function:

◆ operator|=()

template<class enum_type , class = typename std::enable_if<std::is_enum<enum_type>::value>::type>
enum_type & operator|= ( enum_type & lhs,
const enum_type & rhs )
inline

Definition at line 511 of file main.cpp.

512{
513 using T = std::underlying_type_t <enum_type>;
514 return lhs = static_cast<enum_type>(static_cast<T>(lhs) | static_cast<T>(rhs));
515}
#define T(meth, val, expected)

◆ producer_name()

producer_name ( block_signing_key )
Here is the caller graph for this function:

◆ producers()

schedule config_dir_name data_dir_name p2p_port http_port file_size name name keys peers producers ( dont_start )
Here is the caller graph for this function:

◆ retrieve_paired_array_parameters()

template<typename T >
void retrieve_paired_array_parameters ( const variables_map & vmap,
const std::string & num_selector,
const std::string & paired_selector,
std::map< uint, T > & selector_map )

Definition at line 518 of file main.cpp.

518 {
519 if (vmap.count(num_selector)) {
520 const auto specific_nums = vmap[num_selector].as<vector<uint>>();
521 const auto specific_args = vmap[paired_selector].as<vector<string>>();
522 if (specific_nums.size() != specific_args.size()) {
523 cerr << "ERROR: every " << num_selector << " argument must be paired with a " << paired_selector << " argument" << endl;
524 exit (-1);
525 }
526 const auto total_nodes = vmap["nodes"].as<size_t>();
527 for(uint i = 0; i < specific_nums.size(); ++i)
528 {
529 const auto& num = specific_nums[i];
530 if (num >= total_nodes) {
531 cerr << "\"--" << num_selector << "\" provided value= " << num << " is higher than \"--nodes\" provided value=" << total_nodes << endl;
532 exit (-1);
533 }
534 selector_map[num] = specific_args[i];
535 }
536 }
537}
Here is the caller graph for this function:

◆ ssh_helper()

schedule config_dir_name data_dir_name p2p_port http_port file_size name name keys peers name ssh_helper ( nodes )

◆ sysio_home()

schedule config_dir_name data_dir_name p2p_port http_port file_size name name keys peers name ipaddr name has_bios sysio_home ( instances )

◆ write_default_config()

void write_default_config ( const bfs::path & cfg_file,
const options_description & cfg )

Definition at line 1941 of file main.cpp.

1941 {
1942 bfs::path parent = cfg_file.parent_path();
1943 if (parent.empty()) {
1944 parent = ".";
1945 }
1946 if(!bfs::exists(parent)) {
1947 try {
1948 bfs::create_directories(parent);
1949 } catch (bfs::filesystem_error &ex) {
1950 cerr << "could not create new directory: " << cfg_file.parent_path()
1951 << " caught " << ex.what() << endl;
1952 exit (-1);
1953 }
1954 }
1955
1956 std::ofstream out_cfg( bfs::path(cfg_file).make_preferred().string());
1957 for(const boost::shared_ptr<bpo::option_description>& od : cfg.options())
1958 {
1959 if(!od->description().empty()) {
1960 out_cfg << "# " << od->description() << std::endl;
1961 }
1962 boost::any store;
1963 if(!od->semantic()->apply_default(store))
1964 out_cfg << "# " << od->long_name() << " = " << std::endl;
1965 else {
1966 auto example = od->format_parameter();
1967 if(example.empty())
1968 // This is a boolean switch
1969 out_cfg << od->long_name() << " = " << "false" << std::endl;
1970 else {
1971 // The string is formatted "arg (=<interesting part>)"
1972 example.erase(0, 6);
1973 example.erase(example.length()-1);
1974 out_cfg << od->long_name() << " = " << example << std::endl;
1975 }
1976 }
1977 out_cfg << std::endl;
1978 }
1979 out_cfg.close();
1980}
Here is the caller graph for this function:

Variable Documentation

◆ block_dir

const string block_dir = "blocks"

Definition at line 48 of file main.cpp.

◆ local_id

struct local_identity local_id

◆ shared_mem_dir

const string shared_mem_dir = "state"

Definition at line 49 of file main.cpp.