forked from wownero/wownero
commit
5c0bc0050c
@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include "string_tools.h"
|
||||
#include "net/http_client.h"
|
||||
|
||||
namespace tools {
|
||||
|
||||
class t_http_connection {
|
||||
private:
|
||||
epee::net_utils::http::http_simple_client * mp_http_client;
|
||||
bool m_ok;
|
||||
public:
|
||||
static unsigned int const TIMEOUT = 200000;
|
||||
|
||||
t_http_connection(
|
||||
epee::net_utils::http::http_simple_client * p_http_client
|
||||
, uint32_t ip
|
||||
, uint16_t port
|
||||
)
|
||||
: mp_http_client(p_http_client)
|
||||
{
|
||||
// TODO fix http client so that it accepts properly typed arguments
|
||||
std::string ip_str = epee::string_tools::get_ip_string_from_int32(ip);
|
||||
std::string port_str = boost::lexical_cast<std::string>(port);
|
||||
m_ok = mp_http_client->connect(ip_str, port_str, TIMEOUT);
|
||||
}
|
||||
|
||||
~t_http_connection()
|
||||
{
|
||||
if (m_ok)
|
||||
{
|
||||
mp_http_client->disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
bool is_open()
|
||||
{
|
||||
return m_ok;
|
||||
}
|
||||
}; // class t_http_connection
|
||||
|
||||
} // namespace tools
|
@ -0,0 +1,132 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/http_connection.h"
|
||||
#include "common/scoped_message_writer.h"
|
||||
#include "rpc/core_rpc_server_commands_defs.h"
|
||||
#include "storages/http_abstract_invoke.h"
|
||||
#include "net/http_client.h"
|
||||
#include "string_tools.h"
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
namespace tools
|
||||
{
|
||||
class t_rpc_client final
|
||||
{
|
||||
private:
|
||||
epee::net_utils::http::http_simple_client m_http_client;
|
||||
uint32_t m_ip;
|
||||
uint16_t m_port;
|
||||
public:
|
||||
t_rpc_client(
|
||||
uint32_t ip
|
||||
, uint16_t port
|
||||
)
|
||||
: m_http_client{}
|
||||
, m_ip{ip}
|
||||
, m_port{port}
|
||||
{}
|
||||
|
||||
std::string build_url(std::string const & relative_url)
|
||||
{
|
||||
std::string result =
|
||||
"http://"
|
||||
+ epee::string_tools::get_ip_string_from_int32(m_ip)
|
||||
+ ":"
|
||||
+ boost::lexical_cast<std::string>(m_port)
|
||||
+ relative_url;
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T_req, typename T_res>
|
||||
bool basic_json_rpc_request(
|
||||
T_req & req
|
||||
, T_res & res
|
||||
, std::string const & method_name
|
||||
)
|
||||
{
|
||||
std::string rpc_url = build_url("/json_rpc");
|
||||
t_http_connection connection(&m_http_client, m_ip, m_port);
|
||||
|
||||
bool ok = connection.is_open();
|
||||
if (!ok)
|
||||
{
|
||||
fail_msg_writer() << "Couldn't connect to daemon";
|
||||
return false;
|
||||
}
|
||||
ok = ok && epee::net_utils::invoke_http_json_rpc(rpc_url, method_name, req, res, m_http_client);
|
||||
if (!ok)
|
||||
{
|
||||
fail_msg_writer() << "Daemon request failed";
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T_req, typename T_res>
|
||||
bool json_rpc_request(
|
||||
T_req & req
|
||||
, T_res & res
|
||||
, std::string const & method_name
|
||||
, std::string const & fail_msg
|
||||
)
|
||||
{
|
||||
std::string rpc_url = build_url("/json_rpc");
|
||||
t_http_connection connection(&m_http_client, m_ip, m_port);
|
||||
|
||||
bool ok = connection.is_open();
|
||||
ok = ok && epee::net_utils::invoke_http_json_rpc(rpc_url, method_name, req, res, m_http_client);
|
||||
if (!ok)
|
||||
{
|
||||
fail_msg_writer() << "Couldn't connect to daemon";
|
||||
return false;
|
||||
}
|
||||
else if (res.status != CORE_RPC_STATUS_OK) // TODO - handle CORE_RPC_STATUS_BUSY ?
|
||||
{
|
||||
fail_msg_writer() << fail_msg << " -- " << res.status;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T_req, typename T_res>
|
||||
bool rpc_request(
|
||||
T_req & req
|
||||
, T_res & res
|
||||
, std::string const & relative_url
|
||||
, std::string const & fail_msg
|
||||
)
|
||||
{
|
||||
std::string rpc_url = build_url(relative_url);
|
||||
t_http_connection connection(&m_http_client, m_ip, m_port);
|
||||
|
||||
bool ok = connection.is_open();
|
||||
ok = ok && epee::net_utils::invoke_http_json_remote_command2(rpc_url, req, res, m_http_client);
|
||||
if (!ok)
|
||||
{
|
||||
fail_msg_writer() << "Couldn't connect to daemon";
|
||||
return false;
|
||||
}
|
||||
else if (res.status != CORE_RPC_STATUS_OK) // TODO - handle CORE_RPC_STATUS_BUSY ?
|
||||
{
|
||||
fail_msg_writer() << fail_msg << " -- " << res.status;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool check_connection()
|
||||
{
|
||||
t_http_connection connection(&m_http_client, m_ip, m_port);
|
||||
return connection.is_open();
|
||||
}
|
||||
};
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
#pragma once
|
||||
|
||||
#include "misc_log_ex.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace tools
|
||||
{
|
||||
|
||||
class scoped_message_writer
|
||||
{
|
||||
private:
|
||||
bool m_flush;
|
||||
std::stringstream m_oss;
|
||||
epee::log_space::console_colors m_color;
|
||||
bool m_bright;
|
||||
int m_log_level;
|
||||
public:
|
||||
scoped_message_writer(
|
||||
epee::log_space::console_colors color = epee::log_space::console_color_default
|
||||
, bool bright = false
|
||||
, std::string&& prefix = std::string()
|
||||
, int log_level = LOG_LEVEL_2
|
||||
)
|
||||
: m_flush(true)
|
||||
, m_color(color)
|
||||
, m_bright(bright)
|
||||
, m_log_level(log_level)
|
||||
{
|
||||
m_oss << prefix;
|
||||
}
|
||||
|
||||
scoped_message_writer(scoped_message_writer&& rhs)
|
||||
: m_flush(std::move(rhs.m_flush))
|
||||
#if defined(_MSC_VER)
|
||||
, m_oss(std::move(rhs.m_oss))
|
||||
#else
|
||||
// GCC bug: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54316
|
||||
, m_oss(rhs.m_oss.str(), std::ios_base::out | std::ios_base::ate)
|
||||
#endif
|
||||
, m_color(std::move(rhs.m_color))
|
||||
, m_log_level(std::move(rhs.m_log_level))
|
||||
{
|
||||
rhs.m_flush = false;
|
||||
}
|
||||
|
||||
scoped_message_writer(scoped_message_writer& rhs) = delete;
|
||||
scoped_message_writer& operator=(scoped_message_writer& rhs) = delete;
|
||||
scoped_message_writer& operator=(scoped_message_writer&& rhs) = delete;
|
||||
|
||||
template<typename T>
|
||||
std::ostream& operator<<(const T& val)
|
||||
{
|
||||
m_oss << val;
|
||||
return m_oss;
|
||||
}
|
||||
|
||||
~scoped_message_writer()
|
||||
{
|
||||
if (m_flush)
|
||||
{
|
||||
m_flush = false;
|
||||
|
||||
LOG_PRINT(m_oss.str(), m_log_level)
|
||||
|
||||
if (epee::log_space::console_color_default == m_color)
|
||||
{
|
||||
std::cout << m_oss.str();
|
||||
}
|
||||
else
|
||||
{
|
||||
epee::log_space::set_console_color(m_color, m_bright);
|
||||
std::cout << m_oss.str();
|
||||
epee::log_space::reset_console_color();
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
inline scoped_message_writer success_msg_writer()
|
||||
{
|
||||
return scoped_message_writer(epee::log_space::console_color_green, false, std::string(), LOG_LEVEL_2);
|
||||
}
|
||||
|
||||
inline scoped_message_writer msg_writer(epee::log_space::console_colors color = epee::log_space::console_color_default)
|
||||
{
|
||||
return scoped_message_writer(color, false, std::string(), LOG_LEVEL_2);
|
||||
}
|
||||
|
||||
inline scoped_message_writer fail_msg_writer()
|
||||
{
|
||||
return scoped_message_writer(epee::log_space::console_color_red, true, "Error: ", LOG_LEVEL_0);
|
||||
}
|
||||
|
||||
} // namespace tools
|
@ -0,0 +1,76 @@
|
||||
// Copyright (c) 2014, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef DAEMON_COMMAND_LINE_ARGS_H
|
||||
#define DAEMON_COMMAND_LINE_ARGS_H
|
||||
|
||||
#include "common/command_line.h"
|
||||
#include "cryptonote_config.h"
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
namespace daemon_args
|
||||
{
|
||||
std::string const WINDOWS_SERVICE_NAME = "Monero Daemon";
|
||||
|
||||
const command_line::arg_descriptor<std::string> arg_config_file = {
|
||||
"config-file"
|
||||
, "Specify configuration file"
|
||||
, std::string(CRYPTONOTE_NAME ".conf")
|
||||
};
|
||||
const command_line::arg_descriptor<std::string> arg_log_file = {
|
||||
"log-file"
|
||||
, "Specify log file"
|
||||
, ""
|
||||
};
|
||||
const command_line::arg_descriptor<int> arg_log_level = {
|
||||
"log-level"
|
||||
, ""
|
||||
, LOG_LEVEL_0
|
||||
};
|
||||
const command_line::arg_descriptor<std::vector<std::string>> arg_command = {
|
||||
"daemon_command"
|
||||
, "Hidden"
|
||||
};
|
||||
const command_line::arg_descriptor<bool> arg_os_version = {
|
||||
"os-version"
|
||||
, "OS for which this executable was compiled"
|
||||
};
|
||||
const command_line::arg_descriptor<bool> arg_testnet_on = {
|
||||
"testnet"
|
||||
, "Run on testnet. The wallet must be launched with --testnet flag."
|
||||
, false
|
||||
};
|
||||
const command_line::arg_descriptor<bool> arg_dns_checkpoints = {
|
||||
"enforce-dns-checkpointing"
|
||||
, "checkpoints from DNS server will be enforced"
|
||||
, false
|
||||
};
|
||||
|
||||
} // namespace daemon_args
|
||||
|
||||
#endif // DAEMON_COMMAND_LINE_ARGS_H
|
@ -0,0 +1,297 @@
|
||||
// Copyright (c) 2014, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "cryptonote_core/cryptonote_basic_impl.h"
|
||||
#include "daemon/command_parser_executor.h"
|
||||
|
||||
namespace daemonize {
|
||||
|
||||
t_command_parser_executor::t_command_parser_executor(
|
||||
uint32_t ip
|
||||
, uint16_t port
|
||||
)
|
||||
: m_executor(ip, port)
|
||||
{}
|
||||
|
||||
bool t_command_parser_executor::print_peer_list(const std::vector<std::string>& args)
|
||||
{
|
||||
if (!args.empty()) return false;
|
||||
|
||||
return m_executor.print_peer_list();
|
||||
}
|
||||
|
||||
bool t_command_parser_executor::save_blockchain(const std::vector<std::string>& args)
|
||||
{
|
||||
if (!args.empty()) return false;
|
||||
|
||||
return m_executor.save_blockchain();
|
||||
}
|
||||
|
||||
bool t_command_parser_executor::show_hash_rate(const std::vector<std::string>& args)
|
||||
{
|
||||
if (!args.empty()) return false;
|
||||
|
||||
return m_executor.show_hash_rate();
|
||||
}
|
||||
|
||||
bool t_command_parser_executor::hide_hash_rate(const std::vector<std::string>& args)
|
||||
{
|
||||
if (!args.empty()) return false;
|
||||
|
||||
return m_executor.hide_hash_rate();
|
||||
}
|
||||
|
||||
bool t_command_parser_executor::show_difficulty(const std::vector<std::string>& args)
|
||||
{
|
||||
if (!args.empty()) return false;
|
||||
|
||||
return m_executor.show_difficulty();
|
||||
}
|
||||
|
||||
bool t_command_parser_executor::print_connections(const std::vector<std::string>& args)
|
||||
{
|
||||
if (!args.empty()) return false;
|
||||
|
||||
return m_executor.print_connections();
|
||||
}
|
||||
|
||||
bool t_command_parser_executor::print_blockchain_info(const std::vector<std::string>& args)
|
||||
{
|
||||
if(!args.size())
|
||||
{
|
||||
std::cout << "need block index parameter" << std::endl;
|
||||
return false;
|
||||
}
|
||||
uint64_t start_index = 0;
|
||||
uint64_t end_index = 0;
|
||||
if(!epee::string_tools::get_xtype_from_string(start_index, args[0]))
|
||||
{
|
||||
std::cout << "wrong starter block index parameter" << std::endl;
|
||||
return false;
|
||||
}
|
||||
if(args.size() >1 && !epee::string_tools::get_xtype_from_string(end_index, args[1]))
|
||||
{
|
||||
std::cout << "wrong end block index parameter" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return m_executor.print_blockchain_info(start_index, end_index);
|
||||
}
|
||||
|
||||
bool t_command_parser_executor::set_log_level(const std::vector<std::string>& args)
|
||||
{
|
||||
if(args.size() != 1)
|
||||
{
|
||||
std::cout << "use: set_log <log_level_number_0-4>" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
uint16_t l = 0;
|
||||
if(!epee::string_tools::get_xtype_from_string(l, args[0]))
|
||||
{
|
||||
std::cout << "wrong number format, use: set_log <log_level_number_0-4>" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
if(LOG_LEVEL_4 < l)
|
||||
{
|
||||
std::cout << "wrong number range, use: set_log <log_level_number_0-4>" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
return m_executor.set_log_level(l);
|
||||
}
|
||||
|
||||
bool t_command_parser_executor::print_height(const std::vector<std::string>& args)
|
||||
{
|
||||
if (!args.empty()) return false;
|
||||
|
||||
return m_executor.print_height();
|
||||
}
|
||||
|
||||
bool t_command_parser_executor::print_block(const std::vector<std::string>& args)
|
||||
{
|
||||
if (args.empty())
|
||||
{
|
||||
std::cout << "expected: print_block (<block_hash> | <block_height>)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string& arg = args.front();
|
||||
try
|
||||
{
|
||||
uint64_t height = boost::lexical_cast<uint64_t>(arg);
|
||||
return m_executor.print_block_by_height(height);
|
||||
}
|
||||
catch (boost::bad_lexical_cast&)
|
||||
{
|
||||
crypto::hash block_hash;
|
||||
if (parse_hash256(arg, block_hash))
|
||||
{
|
||||
return m_executor.print_block_by_hash(block_hash);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool t_command_parser_executor::print_transaction(const std::vector<std::string>& args)
|
||||
{
|
||||
if (args.empty())
|
||||
{
|
||||
std::cout << "expected: print_tx <transaction hash>" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::string& str_hash = args.front();
|
||||
crypto::hash tx_hash;
|
||||
if (parse_hash256(str_hash, tx_hash))
|
||||
{
|
||||
m_executor.print_transaction(tx_hash);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_command_parser_executor::print_transaction_pool_long(const std::vector<std::string>& args)
|
||||
{
|
||||
if (!args.empty()) return false;
|
||||
|
||||
return m_executor.print_transaction_pool_long();
|
||||
}
|
||||
|
||||
bool t_command_parser_executor::print_transaction_pool_short(const std::vector<std::string>& args)
|
||||
{
|
||||
if (!args.empty()) return false;
|
||||
|
||||
return m_executor.print_transaction_pool_short();
|
||||
}
|
||||
|
||||
bool t_command_parser_executor::start_mining(const std::vector<std::string>& args)
|
||||
{
|
||||
if(!args.size())
|
||||
{
|
||||
std::cout << "Please specify a wallet address to mine for: start_mining <addr> [threads=1]" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
cryptonote::account_public_address adr;
|
||||
if(!cryptonote::get_account_address_from_str(adr, false, args.front()))
|
||||
{
|
||||
if(!cryptonote::get_account_address_from_str(adr, true, args.front()))
|
||||
{
|
||||
std::cout << "target account address has wrong format" << std::endl;
|
||||
return true;
|
||||
}
|
||||
std::cout << "Mining to a testnet address, make sure this is intentional!" << std::endl;
|
||||
}
|
||||
uint64_t threads_count = 1;
|
||||
if(args.size() > 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if(args.size() == 2)
|
||||
{
|
||||
bool ok = epee::string_tools::get_xtype_from_string(threads_count, args[1]);
|
||||
threads_count = (ok && 0 < threads_count) ? threads_count : 1;
|
||||
}
|
||||
|
||||
m_executor.start_mining(adr, threads_count);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_command_parser_executor::stop_mining(const std::vector<std::string>& args)
|
||||
{
|
||||
if (!args.empty()) return false;
|
||||
|
||||
return m_executor.stop_mining();
|
||||
}
|
||||
|
||||
bool t_command_parser_executor::stop_daemon(const std::vector<std::string>& args)
|
||||
{
|
||||
if (!args.empty()) return false;
|
||||
|
||||
return m_executor.stop_daemon();
|
||||
}
|
||||
|
||||
bool t_command_parser_executor::print_status(const std::vector<std::string>& args)
|
||||
{
|
||||
if (!args.empty()) return false;
|
||||
|
||||
return m_executor.print_status();
|
||||
}
|
||||
|
||||
bool t_command_parser_executor::set_limit(const std::vector<std::string>& args)
|
||||
{
|
||||
if(args.size()!=1) return false;
|
||||
int limit;
|
||||
try {
|
||||
limit = std::stoi(args[0]);
|
||||
}
|
||||
catch(std::invalid_argument& ex) {
|
||||
return false;
|
||||
}
|
||||
if (limit==-1) limit=128;
|
||||
limit *= 1024;
|
||||
|
||||
return m_executor.set_limit(limit);
|
||||
}
|
||||
|
||||
bool t_command_parser_executor::set_limit_up(const std::vector<std::string>& args)
|
||||
{
|
||||
if(args.size()!=1) return false;
|
||||
int limit;
|
||||
try {
|
||||
limit = std::stoi(args[0]);
|
||||
}
|
||||
catch(std::invalid_argument& ex) {
|
||||
return false;
|
||||
}
|
||||
if (limit==-1) limit=128;
|
||||
limit *= 1024;
|
||||
|
||||
return m_executor.set_limit_up(limit);
|
||||
}
|
||||
|
||||
bool t_command_parser_executor::set_limit_down(const std::vector<std::string>& args)
|
||||
{
|
||||
if(args.size()!=1) return false;
|
||||
int limit;
|
||||
try {
|
||||
limit = std::stoi(args[0]);
|
||||
}
|
||||
catch(std::invalid_argument& ex) {
|
||||
return false;
|
||||
}
|
||||
if (limit==-1) limit=128;
|
||||
limit *= 1024;
|
||||
|
||||
return m_executor.set_limit_down(limit);
|
||||
}
|
||||
} // namespace daemonize
|
@ -0,0 +1,95 @@
|
||||
/**
|
||||
@file
|
||||
@details
|
||||
|
||||
@image html images/other/runtime-commands.png
|
||||
|
||||
*/
|
||||
|
||||
// Copyright (c) 2014, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "daemon/rpc_command_executor.h"
|
||||
|
||||
namespace daemonize {
|
||||
|
||||
class t_command_parser_executor final
|
||||
{
|
||||
private:
|
||||
t_rpc_command_executor m_executor;
|
||||
public:
|
||||
t_command_parser_executor(
|
||||
uint32_t ip
|
||||
, uint16_t port
|
||||
);
|
||||
|
||||
bool print_peer_list(const std::vector<std::string>& args);
|
||||
|
||||
bool save_blockchain(const std::vector<std::string>& args);
|
||||
|
||||
bool show_hash_rate(const std::vector<std::string>& args);
|
||||
|
||||
bool hide_hash_rate(const std::vector<std::string>& args);
|
||||
|
||||
bool show_difficulty(const std::vector<std::string>& args);
|
||||
|
||||
bool print_connections(const std::vector<std::string>& args);
|
||||
|
||||
bool print_blockchain_info(const std::vector<std::string>& args);
|
||||
|
||||
bool set_log_level(const std::vector<std::string>& args);
|
||||
|
||||
bool print_height(const std::vector<std::string>& args);
|
||||
|
||||
bool print_block(const std::vector<std::string>& args);
|
||||
|
||||
bool print_transaction(const std::vector<std::string>& args);
|
||||
|
||||
bool print_transaction_pool_long(const std::vector<std::string>& args);
|
||||
|
||||
bool print_transaction_pool_short(const std::vector<std::string>& args);
|
||||
|
||||
bool start_mining(const std::vector<std::string>& args);
|
||||
|
||||
bool stop_mining(const std::vector<std::string>& args);
|
||||
|
||||
bool stop_daemon(const std::vector<std::string>& args);
|
||||
|
||||
bool print_status(const std::vector<std::string>& args);
|
||||
|
||||
bool set_limit(const std::vector<std::string>& args);
|
||||
|
||||
bool set_limit_up(const std::vector<std::string>& args);
|
||||
|
||||
bool set_limit_down(const std::vector<std::string>& args);
|
||||
|
||||
};
|
||||
|
||||
} // namespace daemonize
|
@ -0,0 +1,184 @@
|
||||
// Copyright (c) 2014, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "cryptonote_config.h"
|
||||
#include "version.h"
|
||||
#include "daemon/command_server.h"
|
||||
|
||||
namespace daemonize {
|
||||
|
||||
namespace p = std::placeholders;
|
||||
|
||||
t_command_server::t_command_server(
|
||||
uint32_t ip
|
||||
, uint16_t port
|
||||
)
|
||||
: m_parser(ip, port)
|
||||
, m_command_lookup()
|
||||
{
|
||||
m_command_lookup.set_handler(
|
||||
"help"
|
||||
, std::bind(&t_command_server::help, this, p::_1)
|
||||
, "Show this help"
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
"print_height"
|
||||
, std::bind(&t_command_parser_executor::print_height, &m_parser, p::_1)
|
||||
, "Print local blockchain height"
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
"print_pl"
|
||||
, std::bind(&t_command_parser_executor::print_peer_list, &m_parser, p::_1)
|
||||
, "Print peer list"
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
"print_cn"
|
||||
, std::bind(&t_command_parser_executor::print_connections, &m_parser, p::_1)
|
||||
, "Print connections"
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
"print_bc"
|
||||
, std::bind(&t_command_parser_executor::print_blockchain_info, &m_parser, p::_1)
|
||||
, "Print blockchain info in a given blocks range, print_bc <begin_height> [<end_height>]"
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
"print_block"
|
||||
, std::bind(&t_command_parser_executor::print_block, &m_parser, p::_1)
|
||||
, "Print block, print_block <block_hash> | <block_height>"
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
"print_tx"
|
||||
, std::bind(&t_command_parser_executor::print_transaction, &m_parser, p::_1)
|
||||
, "Print transaction, print_tx <transaction_hash>"
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
"start_mining"
|
||||
, std::bind(&t_command_parser_executor::start_mining, &m_parser, p::_1)
|
||||
, "Start mining for specified address, start_mining <addr> [threads=1]"
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
"stop_mining"
|
||||
, std::bind(&t_command_parser_executor::stop_mining, &m_parser, p::_1)
|
||||
, "Stop mining"
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
"print_pool"
|
||||
, std::bind(&t_command_parser_executor::print_transaction_pool_long, &m_parser, p::_1)
|
||||
, "Print transaction pool (long format)"
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
"print_pool_sh"
|
||||
, std::bind(&t_command_parser_executor::print_transaction_pool_short, &m_parser, p::_1)
|
||||
, "Print transaction pool (short format)"
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
"show_hr"
|
||||
, std::bind(&t_command_parser_executor::show_hash_rate, &m_parser, p::_1)
|
||||
, "Start showing hash rate"
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
"hide_hr"
|
||||
, std::bind(&t_command_parser_executor::hide_hash_rate, &m_parser, p::_1)
|
||||
, "Stop showing hash rate"
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
"save"
|
||||
, std::bind(&t_command_parser_executor::save_blockchain, &m_parser, p::_1)
|
||||
, "Save blockchain"
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
"set_log"
|
||||
, std::bind(&t_command_parser_executor::set_log_level, &m_parser, p::_1)
|
||||
, "set_log <level> - Change current log detalization level, <level> is a number 0-4"
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
"diff"
|
||||
, std::bind(&t_command_parser_executor::show_difficulty, &m_parser, p::_1)
|
||||
, "Show difficulty"
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
"stop_daemon"
|
||||
, std::bind(&t_command_parser_executor::stop_daemon, &m_parser, p::_1)
|
||||
, "Stop the daemon"
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
"print_status"
|
||||
, std::bind(&t_command_parser_executor::print_status, &m_parser, p::_1)
|
||||
, "Prints daemon status"
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
"limit"
|
||||
, std::bind(&t_command_parser_executor::set_limit, &m_parser, p::_1)
|
||||
, "limit <kB/s> - Set download and upload limit"
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
"limit-up"
|
||||
, std::bind(&t_command_parser_executor::set_limit_up, &m_parser, p::_1)
|
||||
, "limit <kB/s> - Set upload limit"
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
"limit-down"
|
||||
, std::bind(&t_command_parser_executor::set_limit_down, &m_parser, p::_1)
|
||||
, "limit <kB/s> - Set download limit"
|
||||
);
|
||||
}
|
||||
|
||||
bool t_command_server::process_command_str(const std::string& cmd)
|
||||
{
|
||||
return m_command_lookup.process_command_str(cmd);
|
||||
}
|
||||
|
||||
bool t_command_server::process_command_vec(const std::vector<std::string>& cmd)
|
||||
{
|
||||
bool result = m_command_lookup.process_command_vec(cmd);
|
||||
if (!result)
|
||||
{
|
||||
help(std::vector<std::string>());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool t_command_server::help(const std::vector<std::string>& args)
|
||||
{
|
||||
std::cout << get_commands_str() << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string t_command_server::get_commands_str()
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << CRYPTONOTE_NAME << " v" << MONERO_VERSION_FULL << std::endl;
|
||||
ss << "Commands: " << std::endl;
|
||||
std::string usage = m_command_lookup.get_usage();
|
||||
boost::replace_all(usage, "\n", "\n ");
|
||||
usage.insert(0, " ");
|
||||
ss << usage << std::endl;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
} // namespace daemonize
|
@ -0,0 +1,67 @@
|
||||
/**
|
||||
@file
|
||||
@details
|
||||
|
||||
|
||||
Passing RPC commands:
|
||||
|
||||
@image html images/other/runtime-commands.png
|
||||
|
||||
*/
|
||||
|
||||
// Copyright (c) 2014, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "console_handler.h"
|
||||
#include "daemon/command_parser_executor.h"
|
||||
|
||||
namespace daemonize {
|
||||
|
||||
class t_command_server {
|
||||
private:
|
||||
t_command_parser_executor m_parser;
|
||||
epee::command_handler m_command_lookup;
|
||||
public:
|
||||
t_command_server(
|
||||
uint32_t ip
|
||||
, uint16_t port
|
||||
);
|
||||
|
||||
bool process_command_str(const std::string& cmd);
|
||||
|
||||
bool process_command_vec(const std::vector<std::string>& cmd);
|
||||
|
||||
private:
|
||||
bool help(const std::vector<std::string>& args);
|
||||
|
||||
std::string get_commands_str();
|
||||
};
|
||||
|
||||
} // namespace daemonize
|
@ -0,0 +1,99 @@
|
||||
// Copyright (c) 2014, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cryptonote_core/checkpoints_create.h"
|
||||
#include "cryptonote_core/cryptonote_core.h"
|
||||
#include "cryptonote_protocol/cryptonote_protocol_handler.h"
|
||||
#include "misc_log_ex.h"
|
||||
#include <stdexcept>
|
||||
#include <boost/program_options.hpp>
|
||||
#include "daemon/command_line_args.h"
|
||||
|
||||
namespace daemonize
|
||||
{
|
||||
|
||||
class t_core final
|
||||
{
|
||||
public:
|
||||
static void init_options(boost::program_options::options_description & option_spec)
|
||||
{
|
||||
cryptonote::core::init_options(option_spec);
|
||||
cryptonote::miner::init_options(option_spec);
|
||||
}
|
||||
private:
|
||||
typedef cryptonote::t_cryptonote_protocol_handler<cryptonote::core> t_protocol_raw;
|
||||
cryptonote::core m_core;
|
||||
// TEMPORARY HACK - Yes, this creates a copy, but otherwise the original
|
||||
// variable map could go out of scope before the run method is called
|
||||
boost::program_options::variables_map const m_vm_HACK;
|
||||
public:
|
||||
t_core(
|
||||
boost::program_options::variables_map const & vm
|
||||
)
|
||||
: m_core{nullptr}
|
||||
, m_vm_HACK{vm}
|
||||
{
|
||||
}
|
||||
|
||||
// TODO - get rid of circular dependencies in internals
|
||||
void set_protocol(t_protocol_raw & protocol)
|
||||
{
|
||||
m_core.set_cryptonote_protocol(&protocol);
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
//initialize core here
|
||||
LOG_PRINT_L0("Initializing core...");
|
||||
if (!m_core.init(m_vm_HACK))
|
||||
{
|
||||
throw std::runtime_error("Failed to initialize core");
|
||||
}
|
||||
LOG_PRINT_L0("Core initialized OK");
|
||||
}
|
||||
|
||||
cryptonote::core & get()
|
||||
{
|
||||
return m_core;
|
||||
}
|
||||
|
||||
~t_core()
|
||||
{
|
||||
LOG_PRINT_L0("Deinitializing core...");
|
||||
try {
|
||||
m_core.deinit();
|
||||
m_core.set_cryptonote_protocol(nullptr);
|
||||
} catch (...) {
|
||||
LOG_PRINT_L0("Failed to deinitialize core...");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
// Copyright (c) 2014, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
namespace daemonize {
|
||||
|
||||
class t_internals;
|
||||
|
||||
class t_daemon final {
|
||||
public:
|
||||
static void init_options(boost::program_options::options_description & option_spec);
|
||||
private:
|
||||
std::unique_ptr<t_internals> mp_internals;
|
||||
public:
|
||||
t_daemon(
|
||||
boost::program_options::variables_map const & vm
|
||||
);
|
||||
t_daemon(t_daemon && other);
|
||||
t_daemon & operator=(t_daemon && other);
|
||||
~t_daemon();
|
||||
|
||||
bool run();
|
||||
void stop();
|
||||
};
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
// Copyright (c) 2014, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "daemon/executor.h"
|
||||
|
||||
#include "misc_log_ex.h"
|
||||
|
||||
#include "common/command_line.h"
|
||||
#include "cryptonote_config.h"
|
||||
#include "version.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace daemonize
|
||||
{
|
||||
std::string const t_executor::NAME = "Monero Daemon";
|
||||
|
||||
void t_executor::init_options(
|
||||
boost::program_options::options_description & configurable_options
|
||||
)
|
||||
{
|
||||
t_daemon::init_options(configurable_options);
|
||||
}
|
||||
|
||||
std::string const & t_executor::name()
|
||||
{
|
||||
return NAME;
|
||||
}
|
||||
|
||||
t_daemon t_executor::create_daemon(
|
||||
boost::program_options::variables_map const & vm
|
||||
)
|
||||
{
|
||||
LOG_PRINT_L0(CRYPTONOTE_NAME << " v" << MONERO_VERSION_FULL);
|
||||
return t_daemon{vm};
|
||||
}
|
||||
|
||||
bool t_executor::run_interactive(
|
||||
boost::program_options::variables_map const & vm
|
||||
)
|
||||
{
|
||||
epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL);
|
||||
return t_daemon{vm}.run();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,60 @@
|
||||
// Copyright (c) 2014, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "daemon/daemon.h"
|
||||
#include <boost/program_options/options_description.hpp>
|
||||
#include <boost/program_options/variables_map.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace daemonize
|
||||
{
|
||||
class t_executor final
|
||||
{
|
||||
public:
|
||||
typedef ::daemonize::t_daemon t_daemon;
|
||||
|
||||
static std::string const NAME;
|
||||
|
||||
static void init_options(
|
||||
boost::program_options::options_description & configurable_options
|
||||
);
|
||||
|
||||
std::string const & name();
|
||||
|
||||
t_daemon create_daemon(
|
||||
boost::program_options::variables_map const & vm
|
||||
);
|
||||
|
||||
bool run_interactive(
|
||||
boost::program_options::variables_map const & vm
|
||||
);
|
||||
};
|
||||
}
|
@ -0,0 +1,238 @@
|
||||
// Copyright (c) 2014, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
||||
|
||||
#include "common/command_line.h"
|
||||
#include "common/scoped_message_writer.h"
|
||||
#include "common/util.h"
|
||||
#include "cryptonote_core/cryptonote_core.h"
|
||||
#include "cryptonote_core/miner.h"
|
||||
#include "daemon/command_server.h"
|
||||
#include "daemon/daemon.h"
|
||||
#include "daemon/executor.h"
|
||||
#include "daemonizer/daemonizer.h"
|
||||
#include "misc_log_ex.h"
|
||||
#include "p2p/net_node.h"
|
||||
#include "rpc/core_rpc_server.h"
|
||||
#include <boost/program_options.hpp>
|
||||
#include "daemon/command_line_args.h"
|
||||
|
||||
namespace po = boost::program_options;
|
||||
namespace bf = boost::filesystem;
|
||||
|
||||
int main(int argc, char const * argv[])
|
||||
{
|
||||
try {
|
||||
|
||||
epee::string_tools::set_module_name_and_folder(argv[0]);
|
||||
|
||||
// Build argument description
|
||||
po::options_description all_options("All");
|
||||
po::options_description hidden_options("Hidden");
|
||||
po::options_description visible_options("Options");
|
||||
po::options_description core_settings("Settings");
|
||||
po::positional_options_description positional_options;
|
||||
{
|
||||
bf::path default_data_dir = daemonizer::get_default_data_dir();
|
||||
bf::path default_testnet_data_dir = {default_data_dir / "testnet"};
|
||||
|
||||
// Misc Options
|
||||
|
||||
command_line::add_arg(visible_options, command_line::arg_help);
|
||||
command_line::add_arg(visible_options, command_line::arg_version);
|
||||
command_line::add_arg(visible_options, daemon_args::arg_os_version);
|
||||
command_line::add_arg(visible_options, command_line::arg_data_dir, default_data_dir.string());
|
||||
command_line::add_arg(visible_options, command_line::arg_testnet_data_dir, default_testnet_data_dir.string());
|
||||
bf::path default_conf = default_data_dir / std::string(CRYPTONOTE_NAME ".conf");
|
||||
command_line::add_arg(visible_options, daemon_args::arg_config_file, default_conf.string());
|
||||
|
||||
// Settings
|
||||
bf::path default_log = default_data_dir / std::string(CRYPTONOTE_NAME ".log");
|
||||
command_line::add_arg(core_settings, daemon_args::arg_log_file, default_log.string());
|
||||
command_line::add_arg(core_settings, daemon_args::arg_log_level);
|
||||
command_line::add_arg(core_settings, daemon_args::arg_testnet_on);
|
||||
command_line::add_arg(core_settings, daemon_args::arg_dns_checkpoints);
|
||||
daemonizer::init_options(hidden_options, visible_options);
|
||||
daemonize::t_executor::init_options(core_settings);
|
||||
|
||||
// Hidden options
|
||||
command_line::add_arg(hidden_options, daemon_args::arg_command);
|
||||
|
||||
visible_options.add(core_settings);
|
||||
all_options.add(visible_options);
|
||||
all_options.add(hidden_options);
|
||||
|
||||
// Positional
|
||||
positional_options.add(daemon_args::arg_command.name, -1); // -1 for unlimited arguments
|
||||
}
|
||||
|
||||
// Do command line parsing
|
||||
po::variables_map vm;
|
||||
bool ok = command_line::handle_error_helper(visible_options, [&]()
|
||||
{
|
||||
boost::program_options::store(
|
||||
boost::program_options::command_line_parser(argc, argv)
|
||||
.options(all_options).positional(positional_options).run()
|
||||
, vm
|
||||
);
|
||||
|
||||
return true;
|
||||
});
|
||||
if (!ok) return 1;
|
||||
|
||||
if (command_line::get_arg(vm, command_line::arg_help))
|
||||
{
|
||||
std::cout << CRYPTONOTE_NAME << " v" << MONERO_VERSION_FULL << ENDL << ENDL;
|
||||
std::cout << "Usage: " + std::string{argv[0]} + " [options|settings] [daemon_command...]" << std::endl << std::endl;
|
||||
std::cout << visible_options << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Monero Version
|
||||
if (command_line::get_arg(vm, command_line::arg_version))
|
||||
{
|
||||
std::cout << CRYPTONOTE_NAME << " v" << MONERO_VERSION_FULL << ENDL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// OS
|
||||
if (command_line::get_arg(vm, daemon_args::arg_os_version))
|
||||
{
|
||||
std::cout << "OS: " << tools::get_os_version_string() << ENDL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool testnet_mode = command_line::get_arg(vm, daemon_args::arg_testnet_on);
|
||||
|
||||
auto data_dir_arg = testnet_mode ? command_line::arg_testnet_data_dir : command_line::arg_data_dir;
|
||||
|
||||
// Create data dir if it doesn't exist
|
||||
boost::filesystem::path data_dir = boost::filesystem::absolute(
|
||||
command_line::get_arg(vm, data_dir_arg));
|
||||
tools::create_directories_if_necessary(data_dir.string());
|
||||
|
||||
// FIXME: not sure on windows implementation default, needs further review
|
||||
//bf::path relative_path_base = daemonizer::get_relative_path_base(vm);
|
||||
bf::path relative_path_base = data_dir;
|
||||
|
||||
std::string config = command_line::get_arg(vm, daemon_args::arg_config_file);
|
||||
|
||||
boost::filesystem::path data_dir_path(data_dir);
|
||||
boost::filesystem::path config_path(config);
|
||||
if (!config_path.has_parent_path())
|
||||
{
|
||||
config_path = data_dir / config_path;
|
||||
}
|
||||
|
||||
boost::system::error_code ec;
|
||||
if (bf::exists(config_path, ec))
|
||||
{
|
||||
po::store(po::parse_config_file<char>(config_path.string<std::string>().c_str(), core_settings), vm);
|
||||
}
|
||||
po::notify(vm);
|
||||
|
||||
// If there are positional options, we're running a daemon command
|
||||
{
|
||||
auto command = command_line::get_arg(vm, daemon_args::arg_command);
|
||||
|
||||
if (command.size())
|
||||
{
|
||||
auto rpc_ip_str = command_line::get_arg(vm, cryptonote::core_rpc_server::arg_rpc_bind_ip);
|
||||
auto rpc_port_str = command_line::get_arg(vm, cryptonote::core_rpc_server::arg_rpc_bind_port);
|
||||
if (testnet_mode)
|
||||
{
|
||||
rpc_port_str = command_line::get_arg(vm, cryptonote::core_rpc_server::arg_testnet_rpc_bind_port);
|
||||
}
|
||||
|
||||
uint32_t rpc_ip;
|
||||
uint16_t rpc_port;
|
||||
if (!epee::string_tools::get_ip_int32_from_string(rpc_ip, rpc_ip_str))
|
||||
{
|
||||
std::cerr << "Invalid IP: " << rpc_ip_str << std::endl;
|
||||
return 1;
|
||||
}
|
||||
if (!epee::string_tools::get_xtype_from_string(rpc_port, rpc_port_str))
|
||||
{
|
||||
std::cerr << "Invalid port: " << rpc_port_str << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
daemonize::t_command_server rpc_commands{rpc_ip, rpc_port};
|
||||
if (rpc_commands.process_command_vec(command))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Unknown command" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Start with log level 0
|
||||
epee::log_space::get_set_log_detalisation_level(true, LOG_LEVEL_0);
|
||||
|
||||
// Set log level
|
||||
{
|
||||
int new_log_level = command_line::get_arg(vm, daemon_args::arg_log_level);
|
||||
if(new_log_level < LOG_LEVEL_MIN || new_log_level > LOG_LEVEL_MAX)
|
||||
{
|
||||
LOG_PRINT_L0("Wrong log level value: " << new_log_level);
|
||||
}
|
||||
else if (epee::log_space::get_set_log_detalisation_level(false) != new_log_level)
|
||||
{
|
||||
epee::log_space::get_set_log_detalisation_level(true, new_log_level);
|
||||
LOG_PRINT_L0("LOG_LEVEL set to " << new_log_level);
|
||||
}
|
||||
}
|
||||
|
||||
// Set log file
|
||||
{
|
||||
bf::path log_file_path{bf::absolute(command_line::get_arg(vm, daemon_args::arg_log_file), relative_path_base)};
|
||||
|
||||
epee::log_space::log_singletone::add_logger(
|
||||
LOGGER_FILE
|
||||
, log_file_path.filename().string().c_str()
|
||||
, log_file_path.parent_path().string().c_str()
|
||||
);
|
||||
}
|
||||
|
||||
return daemonizer::daemonize(argc, argv, daemonize::t_executor{}, vm);
|
||||
}
|
||||
catch (std::exception const & ex)
|
||||
{
|
||||
LOG_ERROR("Exception in main! " << ex.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
LOG_ERROR("Exception in main!");
|
||||
}
|
||||
return 1;
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
// Copyright (c) 2014, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cryptonote_protocol/cryptonote_protocol_handler.h"
|
||||
#include "daemon/protocol.h"
|
||||
#include "misc_log_ex.h"
|
||||
#include "p2p/net_node.h"
|
||||
#include <stdexcept>
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
namespace daemonize
|
||||
{
|
||||
|
||||
class t_p2p final
|
||||
{
|
||||
private:
|
||||
typedef cryptonote::t_cryptonote_protocol_handler<cryptonote::core> t_protocol_raw;
|
||||
typedef nodetool::node_server<t_protocol_raw> t_node_server;
|
||||
public:
|
||||
static void init_options(boost::program_options::options_description & option_spec)
|
||||
{
|
||||
t_node_server::init_options(option_spec);
|
||||
}
|
||||
private:
|
||||
t_node_server m_server;
|
||||
public:
|
||||
t_p2p(
|
||||
boost::program_options::variables_map const & vm
|
||||
, t_protocol & protocol
|
||||
)
|
||||
: m_server{protocol.get()}
|
||||
{
|
||||
//initialize objects
|
||||
LOG_PRINT_L0("Initializing p2p server...");
|
||||
if (!m_server.init(vm))
|
||||
{
|
||||
throw std::runtime_error("Failed to initialize p2p server.");
|
||||
}
|
||||
LOG_PRINT_L0("P2p server initialized OK");
|
||||
}
|
||||
|
||||
t_node_server & get()
|
||||
{
|
||||
return m_server;
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
LOG_PRINT_L0("Starting p2p net loop...");
|
||||
m_server.run();
|
||||
LOG_PRINT_L0("p2p net loop stopped");
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
m_server.send_stop_signal();
|
||||
}
|
||||
|
||||
~t_p2p()
|
||||
{
|
||||
LOG_PRINT_L0("Deinitializing p2p...");
|
||||
try {
|
||||
m_server.deinit();
|
||||
} catch (...) {
|
||||
LOG_PRINT_L0("Failed to deinitialize p2p...");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
// Copyright (c) 2014, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cryptonote_protocol/cryptonote_protocol_handler.h"
|
||||
#include "misc_log_ex.h"
|
||||
#include "p2p/net_node.h"
|
||||
#include <stdexcept>
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
namespace daemonize
|
||||
{
|
||||
|
||||
class t_protocol final
|
||||
{
|
||||
private:
|
||||
typedef cryptonote::t_cryptonote_protocol_handler<cryptonote::core> t_protocol_raw;
|
||||
typedef nodetool::node_server<t_protocol_raw> t_node_server;
|
||||
|
||||
t_protocol_raw m_protocol;
|
||||
public:
|
||||
t_protocol(
|
||||
boost::program_options::variables_map const & vm
|
||||
, t_core & core
|
||||
)
|
||||
: m_protocol{core.get(), nullptr}
|
||||
{
|
||||
LOG_PRINT_L0("Initializing cryptonote protocol...");
|
||||
if (!m_protocol.init(vm))
|
||||
{
|
||||
throw std::runtime_error("Failed to initialize cryptonote protocol.");
|
||||
}
|
||||
LOG_PRINT_L0("Cryptonote protocol initialized OK");
|
||||
}
|
||||
|
||||
t_protocol_raw & get()
|
||||
{
|
||||
return m_protocol;
|
||||
}
|
||||
|
||||
void set_p2p_endpoint(
|
||||
t_node_server & server
|
||||
)
|
||||
{
|
||||
m_protocol.set_p2p_endpoint(&server);
|
||||
}
|
||||
|
||||
~t_protocol()
|
||||
{
|
||||
LOG_PRINT_L0("Deinitializing cryptonote_protocol...");
|
||||
try {
|
||||
m_protocol.deinit();
|
||||
m_protocol.set_p2p_endpoint(nullptr);
|
||||
} catch (...) {
|
||||
LOG_PRINT_L0("Failed to deinitialize protocol...");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
// Copyright (c) 2014, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "daemon/core.h"
|
||||
#include "daemon/p2p.h"
|
||||
#include "misc_log_ex.h"
|
||||
#include "rpc/core_rpc_server.h"
|
||||
#include <boost/program_options.hpp>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace daemonize
|
||||
{
|
||||
|
||||
class t_rpc final
|
||||
{
|
||||
public:
|
||||
static void init_options(boost::program_options::options_description & option_spec)
|
||||
{
|
||||
cryptonote::core_rpc_server::init_options(option_spec);
|
||||
}
|
||||
private:
|
||||
cryptonote::core_rpc_server m_server;
|
||||
public:
|
||||
t_rpc(
|
||||
boost::program_options::variables_map const & vm
|
||||
, t_core & core
|
||||
, t_p2p & p2p
|
||||
)
|
||||
: m_server{core.get(), p2p.get()}
|
||||
{
|
||||
LOG_PRINT_L0("Initializing core rpc server...");
|
||||
if (!m_server.init(vm))
|
||||
{
|
||||
throw std::runtime_error("Failed to initialize core rpc server.");
|
||||
}
|
||||
LOG_PRINT_GREEN("Core rpc server initialized OK on port: " << m_server.get_binded_port(), LOG_LEVEL_0);
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
LOG_PRINT_L0("Starting core rpc server...");
|
||||
if (!m_server.run(2, false))
|
||||
{
|
||||
throw std::runtime_error("Failed to start core rpc server.");
|
||||
}
|
||||
LOG_PRINT_L0("Core rpc server started ok");
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
LOG_PRINT_L0("Stopping core rpc server...");
|
||||
m_server.send_stop_signal();
|
||||
m_server.timed_wait_server_stop(5000);
|
||||
}
|
||||
|
||||
~t_rpc()
|
||||
{
|
||||
LOG_PRINT_L0("Deinitializing rpc server...");
|
||||
try {
|
||||
m_server.deinit();
|
||||
} catch (...) {
|
||||
LOG_PRINT_L0("Failed to deinitialize rpc server...");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
@ -0,0 +1,416 @@
|
||||
// Copyright (c) 2014, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
||||
|
||||
#include "string_tools.h"
|
||||
#include "common/scoped_message_writer.h"
|
||||
#include "daemon/rpc_command_executor.h"
|
||||
#include "rpc/core_rpc_server_commands_defs.h"
|
||||
#include <boost/format.hpp>
|
||||
#include <ctime>
|
||||
|
||||
namespace daemonize {
|
||||
|
||||
namespace {
|
||||
void print_peer(std::string const & prefix, cryptonote::peer const & peer)
|
||||
{
|
||||
time_t now;
|
||||
time(&now);
|
||||
time_t last_seen = static_cast<time_t>(peer.last_seen);
|
||||
|
||||
std::string id_str;
|
||||
std::string port_str;
|
||||
std::string elapsed = epee::misc_utils::get_time_interval_string(now - last_seen);
|
||||
std::string ip_str = epee::string_tools::get_ip_string_from_int32(peer.ip);
|
||||
epee::string_tools::xtype_to_string(peer.id, id_str);
|
||||
epee::string_tools::xtype_to_string(peer.port, port_str);
|
||||
std::string addr_str = ip_str + ":" + port_str;
|
||||
tools::msg_writer() << boost::format("%-10s %-25s %-25s %s") % prefix % id_str % addr_str % elapsed;
|
||||
}
|
||||
|
||||
void print_block_header(cryptonote::block_header_responce const & header)
|
||||
{
|
||||
tools::success_msg_writer()
|
||||
<< "timestamp: " << boost::lexical_cast<std::string>(header.timestamp) << std::endl
|
||||
<< "previous hash: " << header.prev_hash << std::endl
|
||||
<< "nonce: " << boost::lexical_cast<std::string>(header.nonce) << std::endl
|
||||
<< "is orphan: " << header.orphan_status << std::endl
|
||||
<< "height: " << boost::lexical_cast<std::string>(header.height) << std::endl
|
||||
<< "depth: " << boost::lexical_cast<std::string>(header.depth) << std::endl
|
||||
<< "hash: " << header.hash
|
||||
<< "difficulty: " << boost::lexical_cast<std::string>(header.difficulty) << std::endl
|
||||
<< "reward: " << boost::lexical_cast<std::string>(header.reward);
|
||||
}
|
||||
}
|
||||
|
||||
t_rpc_command_executor::t_rpc_command_executor(
|
||||
uint32_t ip
|
||||
, uint16_t port
|
||||
)
|
||||
: m_rpc_client{ip, port}
|
||||
{}
|
||||
|
||||
bool t_rpc_command_executor::print_peer_list() {
|
||||
cryptonote::COMMAND_RPC_GET_PEER_LIST::request req;
|
||||
cryptonote::COMMAND_RPC_GET_PEER_LIST::response res;
|
||||
|
||||
bool ok = m_rpc_client.rpc_request(req, res, "/get_peer_list", "Couldn't retrieve peer list");
|
||||
|
||||
if (!ok) return false;
|
||||
|
||||
for (auto & peer : res.white_list)
|
||||
{
|
||||
print_peer("white", peer);
|
||||
}
|
||||
|
||||
for (auto & peer : res.gray_list)
|
||||
{
|
||||
print_peer("gray", peer);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_rpc_command_executor::save_blockchain() {
|
||||
cryptonote::COMMAND_RPC_SAVE_BC::request req;
|
||||
cryptonote::COMMAND_RPC_SAVE_BC::response res;
|
||||
|
||||
if (m_rpc_client.rpc_request(req, res, "/save_bc", "Couldn't save blockchain"))
|
||||
{
|
||||
tools::success_msg_writer() << "Blockchain saved";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_rpc_command_executor::show_hash_rate() {
|
||||
cryptonote::COMMAND_RPC_SET_LOG_HASH_RATE::request req;
|
||||
cryptonote::COMMAND_RPC_SET_LOG_HASH_RATE::response res;
|
||||
req.visible = true;
|
||||
|
||||
if (m_rpc_client.rpc_request(req, res, "/set_log_hash_rate", "Unsuccessful"))
|
||||
{
|
||||
tools::success_msg_writer() << "Hash rate logging is on";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_rpc_command_executor::hide_hash_rate() {
|
||||
cryptonote::COMMAND_RPC_SET_LOG_HASH_RATE::request req;
|
||||
cryptonote::COMMAND_RPC_SET_LOG_HASH_RATE::response res;
|
||||
req.visible = false;
|
||||
|
||||
if (m_rpc_client.rpc_request(req, res, "/set_log_hash_rate", "Unsuccessful"))
|
||||
{
|
||||
tools::success_msg_writer() << "Hash rate logging is off";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_rpc_command_executor::show_difficulty() {
|
||||
cryptonote::COMMAND_RPC_GET_INFO::request req;
|
||||
cryptonote::COMMAND_RPC_GET_INFO::response res;
|
||||
|
||||
if (m_rpc_client.rpc_request(req, res, "/getinfo", "Problem fetching info"))
|
||||
{
|
||||
tools::success_msg_writer() << "BH: " << res.height
|
||||
<< ", DIFF: " << res.difficulty
|
||||
<< ", HR: " << (int) res.difficulty / 60L << " H/s";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_rpc_command_executor::print_connections() {
|
||||
cryptonote::COMMAND_RPC_GET_CONNECTIONS::request req;
|
||||
cryptonote::COMMAND_RPC_GET_CONNECTIONS::response res;
|
||||
|
||||
if (m_rpc_client.rpc_request(req, res, "/get_connections", "Unsuccessful"))
|
||||
{
|
||||
for (auto & info : res.connections)
|
||||
{
|
||||
std::string address = info.ip + ":" + info.port;
|
||||
std::string in_out = info.incoming ? "INC" : "OUT";
|
||||
tools::msg_writer() << boost::format("%-25s peer_id: %-25s %s") % address % info.peer_id % in_out;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_rpc_command_executor::print_blockchain_info(uint64_t start_block_index, uint64_t end_block_index) {
|
||||
cryptonote::COMMAND_RPC_GET_BLOCK_HEADERS_RANGE::request req;
|
||||
cryptonote::COMMAND_RPC_GET_BLOCK_HEADERS_RANGE::response res;
|
||||
|
||||
req.start_height = start_block_index;
|
||||
req.end_height = end_block_index;
|
||||
|
||||
if (m_rpc_client.json_rpc_request(req, res, "getblockheadersrange", "Unsuccessful"))
|
||||
{
|
||||
for (auto & header : res.headers)
|
||||
{
|
||||
std::cout
|
||||
<< "major version: " << header.major_version << std::endl
|
||||
<< "minor version: " << header.minor_version << std::endl
|
||||
<< "height: " << header.height << ", timestamp: " << header.timestamp << ", difficulty: " << header.difficulty << std::endl
|
||||
<< "block id: " << header.hash << std::endl
|
||||
<< "previous block id: " << header.prev_hash << std::endl
|
||||
<< "difficulty: " << header.difficulty << ", nonce " << header.nonce << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_rpc_command_executor::set_log_level(int8_t level) {
|
||||
cryptonote::COMMAND_RPC_SET_LOG_LEVEL::request req;
|
||||
cryptonote::COMMAND_RPC_SET_LOG_LEVEL::response res;
|
||||
req.level = level;
|
||||
|
||||
if (m_rpc_client.rpc_request(req, res, "/set_log_level", "Unsuccessful"))
|
||||
{
|
||||
tools::success_msg_writer() << "Log level is now " << boost::lexical_cast<std::string>(level);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_rpc_command_executor::print_height() {
|
||||
cryptonote::COMMAND_RPC_GET_HEIGHT::request req;
|
||||
cryptonote::COMMAND_RPC_GET_HEIGHT::response res;
|
||||
|
||||
if (m_rpc_client.rpc_request(req, res, "/getheight", "Unsuccessful"))
|
||||
{
|
||||
tools::success_msg_writer() << boost::lexical_cast<std::string>(res.height);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_rpc_command_executor::print_block_by_hash(crypto::hash block_hash) {
|
||||
cryptonote::COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH::request req;
|
||||
cryptonote::COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH::response res;
|
||||
|
||||
req.hash = epee::string_tools::pod_to_hex(block_hash);
|
||||
|
||||
if (m_rpc_client.json_rpc_request(req, res, "getblockheaderbyhash", "Unsuccessful"))
|
||||
{
|
||||
print_block_header(res.block_header);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_rpc_command_executor::print_block_by_height(uint64_t height) {
|
||||
cryptonote::COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT::request req;
|
||||
cryptonote::COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT::response res;
|
||||
|
||||
req.height = height;
|
||||
|
||||
if (m_rpc_client.json_rpc_request(req, res, "getblockheaderbyheight", "Unsuccessful"))
|
||||
{
|
||||
print_block_header(res.block_header);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_rpc_command_executor::print_transaction(crypto::hash transaction_hash) {
|
||||
cryptonote::COMMAND_RPC_GET_TRANSACTIONS::request req;
|
||||
cryptonote::COMMAND_RPC_GET_TRANSACTIONS::response res;
|
||||
|
||||
if (m_rpc_client.rpc_request(req, res, "/gettransactions", "Problem fetching transaction"))
|
||||
{
|
||||
if (1 == res.txs_as_hex.size())
|
||||
{
|
||||
tools::success_msg_writer() << res.txs_as_hex.front();
|
||||
}
|
||||
else
|
||||
{
|
||||
tools::fail_msg_writer() << "transaction wasn't found: <" << transaction_hash << '>' << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_rpc_command_executor::print_transaction_pool_long() {
|
||||
cryptonote::COMMAND_RPC_GET_TRANSACTION_POOL::request req;
|
||||
cryptonote::COMMAND_RPC_GET_TRANSACTION_POOL::response res;
|
||||
|
||||
if (m_rpc_client.rpc_request(req, res, "/get_transaction_pool", "Problem fetching transaction pool"))
|
||||
{
|
||||
if (res.transactions.empty())
|
||||
{
|
||||
tools::msg_writer() << "Pool is empty" << std::endl;
|
||||
}
|
||||
for (auto & tx_info : res.transactions)
|
||||
{
|
||||
tools::msg_writer() << "id: " << tx_info.id_hash << std::endl
|
||||
<< "blob_size: " << tx_info.blob_size << std::endl
|
||||
<< "fee: " << tx_info.fee << std::endl
|
||||
<< "kept_by_block: " << tx_info.kept_by_block << std::endl
|
||||
<< "max_used_block_height: " << tx_info.max_used_block_height << std::endl
|
||||
<< "max_used_block_id: " << tx_info.max_used_block_id_hash << std::endl
|
||||
<< "last_failed_height: " << tx_info.last_failed_height << std::endl
|
||||
<< "last_failed_id: " << tx_info.last_failed_id_hash << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_rpc_command_executor::print_transaction_pool_short() {
|
||||
cryptonote::COMMAND_RPC_GET_TRANSACTION_POOL::request req;
|
||||
cryptonote::COMMAND_RPC_GET_TRANSACTION_POOL::response res;
|
||||
|
||||
if (m_rpc_client.rpc_request(req, res, "/get_transaction_pool", "Problem fetching transaction pool"))
|
||||
{
|
||||
for (auto & tx_info : res.transactions)
|
||||
{
|
||||
if (res.transactions.empty())
|
||||
{
|
||||
tools::msg_writer() << "Pool is empty" << std::endl;
|
||||
}
|
||||
tools::msg_writer() << "id: " << tx_info.id_hash << std::endl
|
||||
<< tx_info.tx_json << std::endl
|
||||
<< "blob_size: " << tx_info.blob_size << std::endl
|
||||
<< "fee: " << tx_info.fee << std::endl
|
||||
<< "kept_by_block: " << tx_info.kept_by_block << std::endl
|
||||
<< "max_used_block_height: " << tx_info.max_used_block_height << std::endl
|
||||
<< "max_used_block_id: " << tx_info.max_used_block_id_hash << std::endl
|
||||
<< "last_failed_height: " << tx_info.last_failed_height << std::endl
|
||||
<< "last_failed_id: " << tx_info.last_failed_id_hash << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: update this for testnet
|
||||
bool t_rpc_command_executor::start_mining(cryptonote::account_public_address address, uint64_t num_threads) {
|
||||
cryptonote::COMMAND_RPC_START_MINING::request req;
|
||||
cryptonote::COMMAND_RPC_START_MINING::response res;
|
||||
req.miner_address = cryptonote::get_account_address_as_str(false, address);
|
||||
req.threads_count = num_threads;
|
||||
|
||||
if (m_rpc_client.rpc_request(req, res, "/start_mining", "Mining did not start"))
|
||||
{
|
||||
tools::success_msg_writer() << "Mining started";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_rpc_command_executor::stop_mining() {
|
||||
cryptonote::COMMAND_RPC_STOP_MINING::request req;
|
||||
cryptonote::COMMAND_RPC_STOP_MINING::response res;
|
||||
|
||||
if (m_rpc_client.rpc_request(req, res, "/stop_mining", "Mining did not stop"))
|
||||
{
|
||||
tools::success_msg_writer() << "Mining stopped";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_rpc_command_executor::stop_daemon()
|
||||
{
|
||||
cryptonote::COMMAND_RPC_STOP_DAEMON::request req;
|
||||
cryptonote::COMMAND_RPC_STOP_DAEMON::response res;
|
||||
|
||||
//# ifdef WIN32
|
||||
// // Stop via service API
|
||||
// // TODO - this is only temporary! Get rid of hard-coded constants!
|
||||
// bool ok = windows::stop_service("BitMonero Daemon");
|
||||
// ok = windows::uninstall_service("BitMonero Daemon");
|
||||
// //bool ok = windows::stop_service(SERVICE_NAME);
|
||||
// //ok = windows::uninstall_service(SERVICE_NAME);
|
||||
// if (ok)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
//# endif
|
||||
|
||||
// Stop via RPC
|
||||
if(m_rpc_client.rpc_request(req, res, "/stop_daemon", "Daemon did not stop"))
|
||||
{
|
||||
tools::success_msg_writer() << "Stop signal sent";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_rpc_command_executor::print_status()
|
||||
{
|
||||
bool daemon_is_alive = m_rpc_client.check_connection();
|
||||
|
||||
if(daemon_is_alive) {
|
||||
tools::success_msg_writer() << "bitmonerod is running";
|
||||
}
|
||||
else {
|
||||
tools::fail_msg_writer() << "bitmonerod is NOT running";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_rpc_command_executor::set_limit(int limit)
|
||||
{
|
||||
/*
|
||||
epee::net_utils::connection_basic::set_rate_down_limit( limit );
|
||||
epee::net_utils::connection_basic::set_rate_up_limit( limit );
|
||||
std::cout << "Set limit-down to " << limit/1024 << " kB/s" << std::endl;
|
||||
std::cout << "Set limit-up to " << limit/1024 << " kB/s" << std::endl;
|
||||
*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_rpc_command_executor::set_limit_up(int limit)
|
||||
{
|
||||
/*
|
||||
epee::net_utils::connection_basic::set_rate_up_limit( limit );
|
||||
std::cout << "Set limit-up to " << limit/1024 << " kB/s" << std::endl;
|
||||
*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_rpc_command_executor::set_limit_down(int limit)
|
||||
{
|
||||
/*
|
||||
epee::net_utils::connection_basic::set_rate_down_limit( limit );
|
||||
std::cout << "Set limit-down to " << limit/1024 << " kB/s" << std::endl;
|
||||
*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}// namespace daemonize
|
@ -0,0 +1,103 @@
|
||||
/**
|
||||
@file
|
||||
@details
|
||||
|
||||
@image html images/other/runtime-commands.png
|
||||
|
||||
*/
|
||||
|
||||
// Copyright (c) 2014, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/rpc_client.h"
|
||||
#include "misc_log_ex.h"
|
||||
#include "cryptonote_core/cryptonote_core.h"
|
||||
#include "cryptonote_protocol/cryptonote_protocol_handler.h"
|
||||
#include "p2p/net_node.h"
|
||||
|
||||
namespace daemonize {
|
||||
|
||||
class t_rpc_command_executor final {
|
||||
private:
|
||||
tools::t_rpc_client m_rpc_client;
|
||||
public:
|
||||
t_rpc_command_executor(
|
||||
uint32_t ip
|
||||
, uint16_t port
|
||||
);
|
||||
|
||||
bool print_peer_list();
|
||||
|
||||
bool save_blockchain();
|
||||
|
||||
bool show_hash_rate();
|
||||
|
||||
bool hide_hash_rate();
|
||||
|
||||
bool show_difficulty();
|
||||
|
||||
bool print_connections();
|
||||
|
||||
bool print_blockchain_info(uint64_t start_block_index, uint64_t end_block_index);
|
||||
|
||||
bool set_log_level(int8_t level);
|
||||
|
||||
bool print_height();
|
||||
|
||||
bool print_block_by_hash(crypto::hash block_hash);
|
||||
|
||||
bool print_block_by_height(uint64_t height);
|
||||
|
||||
bool print_transaction(crypto::hash transaction_hash);
|
||||
|
||||
bool print_transaction_pool_long();
|
||||
|
||||
bool print_transaction_pool_short();
|
||||
|
||||
bool start_mining(cryptonote::account_public_address address, uint64_t num_threads);
|
||||
|
||||
bool stop_mining();
|
||||
|
||||
bool stop_daemon();
|
||||
|
||||
bool print_status();
|
||||
|
||||
bool set_limit(int limit);
|
||||
|
||||
bool set_limit_up(int limit);
|
||||
|
||||
bool set_limit_down(int limit);
|
||||
|
||||
|
||||
};
|
||||
|
||||
} // namespace daemonize
|
@ -0,0 +1,74 @@
|
||||
# Copyright (c) 2014-2015, The Monero Project
|
||||
#
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification, are
|
||||
# permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other
|
||||
# materials provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software without specific
|
||||
# prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
if(MSVC OR MINGW)
|
||||
set(daemonizer_sources
|
||||
windows_service.cpp
|
||||
windows_daemonizer.inl
|
||||
)
|
||||
else()
|
||||
set(daemonizer_sources
|
||||
posix_fork.cpp
|
||||
posix_daemonizer.inl
|
||||
)
|
||||
endif()
|
||||
|
||||
set(daemonizer_headers
|
||||
)
|
||||
|
||||
if(MSVC OR MINGW)
|
||||
set(daemonizer_private_headers
|
||||
daemonizer.h
|
||||
windows_service.h
|
||||
windows_service_runner.h
|
||||
)
|
||||
else()
|
||||
set(daemonizer_private_headers
|
||||
daemonizer.h
|
||||
posix_fork.h
|
||||
)
|
||||
endif()
|
||||
|
||||
bitmonero_private_headers(daemonizer
|
||||
${daemonizer_private_headers})
|
||||
bitmonero_add_library(daemonizer
|
||||
${daemonizer_sources}
|
||||
${daemonizer_headers}
|
||||
${daemonizer_private_headers})
|
||||
target_link_libraries(daemonizer
|
||||
LINK_PRIVATE
|
||||
common
|
||||
${Boost_CHRONO_LIBRARY}
|
||||
${Boost_FILESYSTEM_LIBRARY}
|
||||
${Boost_PROGRAM_OPTIONS_LIBRARY}
|
||||
${Boost_REGEX_LIBRARY}
|
||||
${Boost_SYSTEM_LIBRARY}
|
||||
${Boost_THREAD_LIBRARY}
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
${UPNP_LIBRARIES}
|
||||
${EXTRA_LIBRARIES})
|
@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/program_options/options_description.hpp>
|
||||
#include <boost/program_options/variables_map.hpp>
|
||||
|
||||
namespace daemonizer
|
||||
{
|
||||
void init_options(
|
||||
boost::program_options::options_description & hidden_options
|
||||
, boost::program_options::options_description & normal_options
|
||||
);
|
||||
|
||||
boost::filesystem::path get_default_data_dir();
|
||||
|
||||
boost::filesystem::path get_relative_path_base(
|
||||
boost::program_options::variables_map const & vm
|
||||
);
|
||||
|
||||
/**
|
||||
* @arg create_before_detach - this indicates that the daemon should be
|
||||
* created before the fork, giving it a chance to report initialization
|
||||
* errors. At the time of this writing, this is not possible in the primary
|
||||
* daemon (likely due to the size of the blockchain in memory).
|
||||
*/
|
||||
template <typename T_executor>
|
||||
bool daemonize(
|
||||
int argc, char const * argv[]
|
||||
, T_executor && executor // universal ref
|
||||
, boost::program_options::variables_map const & vm
|
||||
);
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
# include "daemonizer/windows_daemonizer.inl"
|
||||
#else
|
||||
# include "daemonizer/posix_daemonizer.inl"
|
||||
#endif
|
@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/scoped_message_writer.h"
|
||||
#include "common/util.h"
|
||||
#include "daemonizer/posix_fork.h"
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
namespace daemonizer
|
||||
{
|
||||
namespace
|
||||
{
|
||||
const command_line::arg_descriptor<bool> arg_detach = {
|
||||
"detach"
|
||||
, "Run as daemon"
|
||||
};
|
||||
}
|
||||
|
||||
inline void init_options(
|
||||
boost::program_options::options_description & hidden_options
|
||||
, boost::program_options::options_description & normal_options
|
||||
)
|
||||
{
|
||||
command_line::add_arg(normal_options, arg_detach);
|
||||
}
|
||||
|
||||
inline boost::filesystem::path get_default_data_dir()
|
||||
{
|
||||
return boost::filesystem::absolute(tools::get_default_data_dir());
|
||||
}
|
||||
|
||||
inline boost::filesystem::path get_relative_path_base(
|
||||
boost::program_options::variables_map const & vm
|
||||
)
|
||||
{
|
||||
return boost::filesystem::current_path();
|
||||
}
|
||||
|
||||
template <typename T_executor>
|
||||
inline bool daemonize(
|
||||
int argc, char const * argv[]
|
||||
, T_executor && executor // universal ref
|
||||
, boost::program_options::variables_map const & vm
|
||||
)
|
||||
{
|
||||
if (command_line::has_arg(vm, arg_detach))
|
||||
{
|
||||
auto daemon = executor.create_daemon(vm);
|
||||
tools::success_msg_writer() << "Forking to background...";
|
||||
posix::fork();
|
||||
return daemon.run();
|
||||
}
|
||||
else
|
||||
{
|
||||
//LOG_PRINT_L0(CRYPTONOTE_NAME << " v" << MONERO_VERSION_FULL);
|
||||
return executor.run_interactive(vm);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
// Copyright (c) 2003-2011 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include "daemonizer/posix_fork.h"
|
||||
#include "misc_log_ex.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
|
||||
namespace posix {
|
||||
|
||||
namespace {
|
||||
void quit(std::string const & message)
|
||||
{
|
||||
LOG_ERROR(message);
|
||||
throw std::runtime_error(message);
|
||||
}
|
||||
}
|
||||
|
||||
void fork()
|
||||
{
|
||||
// Fork the process and have the parent exit. If the process was started
|
||||
// from a shell, this returns control to the user. Forking a new process is
|
||||
// also a prerequisite for the subsequent call to setsid().
|
||||
if (pid_t pid = ::fork())
|
||||
{
|
||||
if (pid > 0)
|
||||
{
|
||||
// We're in the parent process and need to exit.
|
||||
//
|
||||
// When the exit() function is used, the program terminates without
|
||||
// invoking local variables' destructors. Only global variables are
|
||||
// destroyed.
|
||||
exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
quit("First fork failed");
|
||||
}
|
||||
}
|
||||
|
||||
// Make the process a new session leader. This detaches it from the
|
||||
// terminal.
|
||||
setsid();
|
||||
|
||||
// A process inherits its working directory from its parent. This could be
|
||||
// on a mounted filesystem, which means that the running daemon would
|
||||
// prevent this filesystem from being unmounted. Changing to the root
|
||||
// directory avoids this problem.
|
||||
if (chdir("/") < 0)
|
||||
{
|
||||
quit("Unable to change working directory to root");
|
||||
}
|
||||
|
||||
// The file mode creation mask is also inherited from the parent process.
|
||||
// We don't want to restrict the permissions on files created by the
|
||||
// daemon, so the mask is cleared.
|
||||
umask(0);
|
||||
|
||||
// A second fork ensures the process cannot acquire a controlling terminal.
|
||||
if (pid_t pid = ::fork())
|
||||
{
|
||||
if (pid > 0)
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
quit("Second fork failed");
|
||||
}
|
||||
}
|
||||
|
||||
// Close the standard streams. This decouples the daemon from the terminal
|
||||
// that started it.
|
||||
close(0);
|
||||
close(1);
|
||||
close(2);
|
||||
|
||||
// We don't want the daemon to have any standard input.
|
||||
if (open("/dev/null", O_RDONLY) < 0)
|
||||
{
|
||||
quit("Unable to open /dev/null");
|
||||
}
|
||||
|
||||
// Send standard output to a log file.
|
||||
const char* output = "/tmp/bitmonero.daemon.stdout.stderr";
|
||||
const int flags = O_WRONLY | O_CREAT | O_APPEND;
|
||||
const mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
|
||||
if (open(output, flags, mode) < 0)
|
||||
{
|
||||
quit("Unable to open output file: " + std::string(output));
|
||||
}
|
||||
|
||||
// Also send standard error to the same log file.
|
||||
if (dup(1) < 0)
|
||||
{
|
||||
quit("Unable to dup output descriptor");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace posix
|
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef WIN32
|
||||
|
||||
namespace posix {
|
||||
|
||||
void fork();
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,156 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/util.h"
|
||||
#include "daemonizer/windows_service.h"
|
||||
#include "daemonizer/windows_service_runner.h"
|
||||
|
||||
#include <shlobj.h>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
namespace daemonizer
|
||||
{
|
||||
namespace
|
||||
{
|
||||
const command_line::arg_descriptor<bool> arg_install_service = {
|
||||
"install-service"
|
||||
, "Install Windows service"
|
||||
};
|
||||
const command_line::arg_descriptor<bool> arg_uninstall_service = {
|
||||
"uninstall-service"
|
||||
, "Uninstall Windows service"
|
||||
};
|
||||
const command_line::arg_descriptor<bool> arg_start_service = {
|
||||
"start-service"
|
||||
, "Start Windows service"
|
||||
};
|
||||
const command_line::arg_descriptor<bool> arg_stop_service = {
|
||||
"stop-service"
|
||||
, "Stop Windows service"
|
||||
};
|
||||
const command_line::arg_descriptor<bool> arg_is_service = {
|
||||
"run-as-service"
|
||||
, "Hidden -- true if running as windows service"
|
||||
};
|
||||
|
||||
std::string get_argument_string(int argc, char const * argv[])
|
||||
{
|
||||
std::string result = "";
|
||||
for (int i = 1; i < argc; ++i)
|
||||
{
|
||||
result += " " + std::string{argv[i]};
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
inline void init_options(
|
||||
boost::program_options::options_description & hidden_options
|
||||
, boost::program_options::options_description & normal_options
|
||||
)
|
||||
{
|
||||
command_line::add_arg(normal_options, arg_install_service);
|
||||
command_line::add_arg(normal_options, arg_uninstall_service);
|
||||
command_line::add_arg(normal_options, arg_start_service);
|
||||
command_line::add_arg(normal_options, arg_stop_service);
|
||||
command_line::add_arg(hidden_options, arg_is_service);
|
||||
}
|
||||
|
||||
inline boost::filesystem::path get_default_data_dir()
|
||||
{
|
||||
bool admin;
|
||||
if (!windows::check_admin(admin))
|
||||
{
|
||||
admin = false;
|
||||
}
|
||||
if (admin)
|
||||
{
|
||||
return boost::filesystem::absolute(
|
||||
tools::get_special_folder_path(CSIDL_COMMON_APPDATA, true) + "\\" + CRYPTONOTE_NAME
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
return boost::filesystem::absolute(
|
||||
tools::get_special_folder_path(CSIDL_APPDATA, true) + "\\" + CRYPTONOTE_NAME
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
inline boost::filesystem::path get_relative_path_base(
|
||||
boost::program_options::variables_map const & vm
|
||||
)
|
||||
{
|
||||
if (command_line::has_arg(vm, arg_is_service))
|
||||
{
|
||||
if (command_line::has_arg(vm, command_line::arg_data_dir))
|
||||
{
|
||||
return command_line::get_arg(vm, command_line::arg_data_dir);
|
||||
}
|
||||
else
|
||||
{
|
||||
return tools::get_default_data_dir();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return boost::filesystem::current_path();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T_executor>
|
||||
inline bool daemonize(
|
||||
int argc, char const * argv[]
|
||||
, T_executor && executor // universal ref
|
||||
, boost::program_options::variables_map const & vm
|
||||
)
|
||||
{
|
||||
std::string arguments = get_argument_string(argc, argv);
|
||||
|
||||
if (command_line::has_arg(vm, arg_is_service))
|
||||
{
|
||||
// TODO - Set the service status here for return codes
|
||||
windows::t_service_runner<typename T_executor::t_daemon>::run(
|
||||
executor.name()
|
||||
, executor.create_daemon(vm)
|
||||
);
|
||||
return true;
|
||||
}
|
||||
else if (command_line::has_arg(vm, arg_install_service))
|
||||
{
|
||||
if (windows::ensure_admin(arguments))
|
||||
{
|
||||
arguments += " --run-as-service";
|
||||
return windows::install_service(executor.name(), arguments);
|
||||
}
|
||||
}
|
||||
else if (command_line::has_arg(vm, arg_uninstall_service))
|
||||
{
|
||||
if (windows::ensure_admin(arguments))
|
||||
{
|
||||
return windows::uninstall_service(executor.name());
|
||||
}
|
||||
}
|
||||
else if (command_line::has_arg(vm, arg_start_service))
|
||||
{
|
||||
if (windows::ensure_admin(arguments))
|
||||
{
|
||||
return windows::start_service(executor.name());
|
||||
}
|
||||
}
|
||||
else if (command_line::has_arg(vm, arg_stop_service))
|
||||
{
|
||||
if (windows::ensure_admin(arguments))
|
||||
{
|
||||
return windows::stop_service(executor.name());
|
||||
}
|
||||
}
|
||||
else // interactive
|
||||
{
|
||||
//LOG_PRINT_L0(CRYPTONOTE_NAME << " v" << MONERO_VERSION_FULL);
|
||||
return executor.run_interactive(vm);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,341 @@
|
||||
#undef UNICODE
|
||||
#undef _UNICODE
|
||||
|
||||
#include "common/scoped_message_writer.h"
|
||||
#include "daemonizer/windows_service.h"
|
||||
#include "string_tools.h"
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <utility>
|
||||
#include <memory>
|
||||
#include <shellapi.h>
|
||||
#include <thread>
|
||||
#include <windows.h>
|
||||
|
||||
namespace windows {
|
||||
|
||||
namespace {
|
||||
typedef std::unique_ptr<std::remove_pointer<SC_HANDLE>::type, decltype(&::CloseServiceHandle)> service_handle;
|
||||
|
||||
std::string get_last_error()
|
||||
{
|
||||
LPSTR p_error_text = nullptr;
|
||||
|
||||
FormatMessage(
|
||||
FORMAT_MESSAGE_FROM_SYSTEM
|
||||
| FORMAT_MESSAGE_ALLOCATE_BUFFER
|
||||
| FORMAT_MESSAGE_IGNORE_INSERTS
|
||||
, nullptr
|
||||
, GetLastError()
|
||||
, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT)
|
||||
, reinterpret_cast<LPSTR>(&p_error_text)
|
||||
, 0
|
||||
, nullptr
|
||||
);
|
||||
|
||||
if (nullptr == p_error_text)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
else
|
||||
{
|
||||
return std::string{p_error_text};
|
||||
LocalFree(p_error_text);
|
||||
}
|
||||
}
|
||||
|
||||
bool relaunch_as_admin(
|
||||
std::string const & command
|
||||
, std::string const & arguments
|
||||
)
|
||||
{
|
||||
SHELLEXECUTEINFO info{};
|
||||
info.cbSize = sizeof(info);
|
||||
info.lpVerb = "runas";
|
||||
info.lpFile = command.c_str();
|
||||
info.lpParameters = arguments.c_str();
|
||||
info.hwnd = nullptr;
|
||||
info.nShow = SW_SHOWNORMAL;
|
||||
if (!ShellExecuteEx(&info))
|
||||
{
|
||||
tools::fail_msg_writer() << "Admin relaunch failed: " << get_last_error();
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// When we relaunch as admin, Windows opens a new window. This just pauses
|
||||
// to allow the user to read any output.
|
||||
void pause_to_display_admin_window_messages()
|
||||
{
|
||||
std::chrono::milliseconds how_long{1500};
|
||||
std::this_thread::sleep_for(how_long);
|
||||
}
|
||||
}
|
||||
|
||||
bool check_admin(bool & result)
|
||||
{
|
||||
BOOL is_admin = FALSE;
|
||||
PSID p_administrators_group = nullptr;
|
||||
|
||||
SID_IDENTIFIER_AUTHORITY nt_authority = SECURITY_NT_AUTHORITY;
|
||||
|
||||
if (!AllocateAndInitializeSid(
|
||||
&nt_authority
|
||||
, 2
|
||||
, SECURITY_BUILTIN_DOMAIN_RID
|
||||
, DOMAIN_ALIAS_RID_ADMINS
|
||||
, 0, 0, 0, 0, 0, 0
|
||||
, &p_administrators_group
|
||||
))
|
||||
{
|
||||
tools::fail_msg_writer() << "Security Identifier creation failed: " << get_last_error();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CheckTokenMembership(
|
||||
nullptr
|
||||
, p_administrators_group
|
||||
, &is_admin
|
||||
))
|
||||
{
|
||||
tools::fail_msg_writer() << "Permissions check failed: " << get_last_error();
|
||||
return false;
|
||||
}
|
||||
|
||||
result = is_admin ? true : false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ensure_admin(
|
||||
std::string const & arguments
|
||||
)
|
||||
{
|
||||
bool admin;
|
||||
|
||||
if (!check_admin(admin))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (admin)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string command = epee::string_tools::get_current_module_path();
|
||||
relaunch_as_admin(command, arguments);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool install_service(
|
||||
std::string const & service_name
|
||||
, std::string const & arguments
|
||||
)
|
||||
{
|
||||
std::string command = epee::string_tools::get_current_module_path();
|
||||
std::string full_command = command + arguments;
|
||||
|
||||
service_handle p_manager{
|
||||
OpenSCManager(
|
||||
nullptr
|
||||
, nullptr
|
||||
, SC_MANAGER_CONNECT | SC_MANAGER_CREATE_SERVICE
|
||||
)
|
||||
, &::CloseServiceHandle
|
||||
};
|
||||
if (p_manager == nullptr)
|
||||
{
|
||||
tools::fail_msg_writer() << "Couldn't connect to service manager: " << get_last_error();
|
||||
return false;
|
||||
}
|
||||
|
||||
service_handle p_service{
|
||||
CreateService(
|
||||
p_manager.get()
|
||||
, service_name.c_str()
|
||||
, service_name.c_str()
|
||||
, 0
|
||||
//, GENERIC_EXECUTE | GENERIC_READ
|
||||
, SERVICE_WIN32_OWN_PROCESS
|
||||
, SERVICE_DEMAND_START
|
||||
, SERVICE_ERROR_NORMAL
|
||||
, full_command.c_str()
|
||||
, nullptr
|
||||
, nullptr
|
||||
, ""
|
||||
//, "NT AUTHORITY\\LocalService"
|
||||
, nullptr // Implies LocalSystem account
|
||||
, nullptr
|
||||
)
|
||||
, &::CloseServiceHandle
|
||||
};
|
||||
if (p_service == nullptr)
|
||||
{
|
||||
tools::fail_msg_writer() << "Couldn't create service: " << get_last_error();
|
||||
return false;
|
||||
}
|
||||
|
||||
tools::success_msg_writer() << "Service installed";
|
||||
|
||||
pause_to_display_admin_window_messages();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool start_service(
|
||||
std::string const & service_name
|
||||
)
|
||||
{
|
||||
tools::msg_writer() << "Starting service";
|
||||
|
||||
SERVICE_STATUS_PROCESS service_status = {};
|
||||
DWORD unused = 0;
|
||||
|
||||
service_handle p_manager{
|
||||
OpenSCManager(
|
||||
nullptr
|
||||
, nullptr
|
||||
, SC_MANAGER_CONNECT
|
||||
)
|
||||
, &::CloseServiceHandle
|
||||
};
|
||||
if (p_manager == nullptr)
|
||||
{
|
||||
tools::fail_msg_writer() << "Couldn't connect to service manager: " << get_last_error();
|
||||
return false;
|
||||
}
|
||||
|
||||
service_handle p_service{
|
||||
OpenService(
|
||||
p_manager.get()
|
||||
, service_name.c_str()
|
||||
//, SERVICE_START | SERVICE_QUERY_STATUS
|
||||
, SERVICE_START
|
||||
)
|
||||
, &::CloseServiceHandle
|
||||
};
|
||||
if (p_service == nullptr)
|
||||
{
|
||||
tools::fail_msg_writer() << "Couldn't find service: " << get_last_error();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!StartService(
|
||||
p_service.get()
|
||||
, 0
|
||||
, nullptr
|
||||
))
|
||||
{
|
||||
tools::fail_msg_writer() << "Service start request failed: " << get_last_error();
|
||||
return false;
|
||||
}
|
||||
|
||||
tools::success_msg_writer() << "Service started";
|
||||
|
||||
pause_to_display_admin_window_messages();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool stop_service(
|
||||
std::string const & service_name
|
||||
)
|
||||
{
|
||||
tools::msg_writer() << "Stopping service";
|
||||
|
||||
service_handle p_manager{
|
||||
OpenSCManager(
|
||||
nullptr
|
||||
, nullptr
|
||||
, SC_MANAGER_CONNECT
|
||||
)
|
||||
, &::CloseServiceHandle
|
||||
};
|
||||
if (p_manager == nullptr)
|
||||
{
|
||||
tools::fail_msg_writer() << "Couldn't connect to service manager: " << get_last_error();
|
||||
return false;
|
||||
}
|
||||
|
||||
service_handle p_service{
|
||||
OpenService(
|
||||
p_manager.get()
|
||||
, service_name.c_str()
|
||||
, SERVICE_STOP | SERVICE_QUERY_STATUS
|
||||
)
|
||||
, &::CloseServiceHandle
|
||||
};
|
||||
if (p_service == nullptr)
|
||||
{
|
||||
tools::fail_msg_writer() << "Couldn't find service: " << get_last_error();
|
||||
return false;
|
||||
}
|
||||
|
||||
SERVICE_STATUS status = {};
|
||||
if (!ControlService(p_service.get(), SERVICE_CONTROL_STOP, &status))
|
||||
{
|
||||
tools::fail_msg_writer() << "Couldn't request service stop: " << get_last_error();
|
||||
return false;
|
||||
}
|
||||
|
||||
tools::success_msg_writer() << "Service stopped";
|
||||
|
||||
pause_to_display_admin_window_messages();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool uninstall_service(
|
||||
std::string const & service_name
|
||||
)
|
||||
{
|
||||
service_handle p_manager{
|
||||
OpenSCManager(
|
||||
nullptr
|
||||
, nullptr
|
||||
, SC_MANAGER_CONNECT
|
||||
)
|
||||
, &::CloseServiceHandle
|
||||
};
|
||||
if (p_manager == nullptr)
|
||||
{
|
||||
tools::fail_msg_writer() << "Couldn't connect to service manager: " << get_last_error();
|
||||
return false;
|
||||
}
|
||||
|
||||
service_handle p_service{
|
||||
OpenService(
|
||||
p_manager.get()
|
||||
, service_name.c_str()
|
||||
, SERVICE_QUERY_STATUS | DELETE
|
||||
)
|
||||
, &::CloseServiceHandle
|
||||
};
|
||||
if (p_service == nullptr)
|
||||
{
|
||||
tools::fail_msg_writer() << "Couldn't find service: " << get_last_error();
|
||||
return false;
|
||||
}
|
||||
|
||||
SERVICE_STATUS status = {};
|
||||
if (!DeleteService(p_service.get()))
|
||||
{
|
||||
tools::fail_msg_writer() << "Couldn't uninstall service: " << get_last_error();
|
||||
return false;
|
||||
}
|
||||
|
||||
tools::success_msg_writer() << "Service uninstalled";
|
||||
|
||||
pause_to_display_admin_window_messages();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace windows
|
@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#undef UNICODE
|
||||
#undef _UNICODE
|
||||
|
||||
#include <string>
|
||||
#include <windows.h>
|
||||
|
||||
namespace windows
|
||||
{
|
||||
bool check_admin(bool & result);
|
||||
|
||||
bool ensure_admin(
|
||||
std::string const & arguments
|
||||
);
|
||||
|
||||
bool install_service(
|
||||
std::string const & service_name
|
||||
, std::string const & arguments
|
||||
);
|
||||
|
||||
bool uninstall_service(
|
||||
std::string const & service_name
|
||||
);
|
||||
|
||||
bool start_service(
|
||||
std::string const & service_name
|
||||
);
|
||||
|
||||
bool stop_service(
|
||||
std::string const & service_name
|
||||
);
|
||||
}
|
||||
#endif
|
@ -0,0 +1,157 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#undef UNICODE
|
||||
#undef _UNICODE
|
||||
|
||||
#include "daemonizer/windows_service.h"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <windows.h>
|
||||
|
||||
namespace windows {
|
||||
namespace
|
||||
{
|
||||
std::vector<char> vecstring(std::string const & str)
|
||||
{
|
||||
std::vector<char> result{str.begin(), str.end()};
|
||||
result.push_back('\0');
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T_handler>
|
||||
class t_service_runner final
|
||||
{
|
||||
private:
|
||||
SERVICE_STATUS_HANDLE m_status_handle{nullptr};
|
||||
SERVICE_STATUS m_status{};
|
||||
std::mutex m_lock{};
|
||||
std::string m_name;
|
||||
T_handler m_handler;
|
||||
|
||||
static std::unique_ptr<t_service_runner<T_handler>> sp_instance;
|
||||
public:
|
||||
t_service_runner(
|
||||
std::string name
|
||||
, T_handler handler
|
||||
)
|
||||
: m_name{std::move(name)}
|
||||
, m_handler{std::move(handler)}
|
||||
{
|
||||
m_status.dwServiceType = SERVICE_WIN32;
|
||||
m_status.dwCurrentState = SERVICE_STOPPED;
|
||||
m_status.dwControlsAccepted = 0;
|
||||
m_status.dwWin32ExitCode = NO_ERROR;
|
||||
m_status.dwServiceSpecificExitCode = NO_ERROR;
|
||||
m_status.dwCheckPoint = 0;
|
||||
m_status.dwWaitHint = 0;
|
||||
}
|
||||
|
||||
t_service_runner & operator=(t_service_runner && other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
m_status_handle = std::move(other.m_status_handle);
|
||||
m_status = std::move(other.m_status);
|
||||
m_name = std::move(other.m_name);
|
||||
m_handler = std::move(other.m_handler);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
static void run(
|
||||
std::string name
|
||||
, T_handler handler
|
||||
)
|
||||
{
|
||||
sp_instance.reset(new t_service_runner<T_handler>{
|
||||
std::move(name)
|
||||
, std::move(handler)
|
||||
});
|
||||
|
||||
sp_instance->run_();
|
||||
}
|
||||
|
||||
private:
|
||||
void run_()
|
||||
{
|
||||
SERVICE_TABLE_ENTRY table[] =
|
||||
{
|
||||
{ vecstring(m_name).data(), &service_main }
|
||||
, { 0, 0 }
|
||||
};
|
||||
|
||||
StartServiceCtrlDispatcher(table);
|
||||
}
|
||||
|
||||
void report_status(DWORD status)
|
||||
{
|
||||
m_status.dwCurrentState = status;
|
||||
if (status == SERVICE_RUNNING)
|
||||
{
|
||||
m_status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
|
||||
}
|
||||
else if(status == SERVICE_STOP_PENDING)
|
||||
{
|
||||
m_status.dwControlsAccepted = 0;
|
||||
}
|
||||
SetServiceStatus(m_status_handle, &m_status);
|
||||
}
|
||||
|
||||
static void WINAPI service_main(DWORD argc, LPSTR * argv)
|
||||
{
|
||||
sp_instance->service_main_(argc, argv);
|
||||
}
|
||||
|
||||
void service_main_(DWORD argc, LPSTR * argv)
|
||||
{
|
||||
m_status_handle = RegisterServiceCtrlHandler(m_name.c_str(), &on_state_change_request);
|
||||
if (m_status_handle == nullptr) return;
|
||||
|
||||
report_status(SERVICE_START_PENDING);
|
||||
|
||||
report_status(SERVICE_RUNNING);
|
||||
|
||||
m_handler.run();
|
||||
|
||||
on_state_change_request_(SERVICE_CONTROL_STOP);
|
||||
|
||||
// Ensure that the service is uninstalled
|
||||
uninstall_service(m_name);
|
||||
}
|
||||
|
||||
static void WINAPI on_state_change_request(DWORD control_code)
|
||||
{
|
||||
sp_instance->on_state_change_request_(control_code);
|
||||
}
|
||||
|
||||
void on_state_change_request_(DWORD control_code)
|
||||
{
|
||||
switch (control_code)
|
||||
{
|
||||
case SERVICE_CONTROL_INTERROGATE:
|
||||
break;
|
||||
case SERVICE_CONTROL_SHUTDOWN:
|
||||
case SERVICE_CONTROL_STOP:
|
||||
report_status(SERVICE_STOP_PENDING);
|
||||
m_handler.stop();
|
||||
report_status(SERVICE_STOPPED);
|
||||
break;
|
||||
case SERVICE_CONTROL_PAUSE:
|
||||
break;
|
||||
case SERVICE_CONTROL_CONTINUE:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T_handler>
|
||||
std::unique_ptr<t_service_runner<T_handler>> t_service_runner<T_handler>::sp_instance;
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,157 @@
|
||||
Changes for 1.7.0:
|
||||
|
||||
* New feature: death tests are supported on OpenBSD and in iOS
|
||||
simulator now.
|
||||
* New feature: Google Test now implements a protocol to allow
|
||||
a test runner to detect that a test program has exited
|
||||
prematurely and report it as a failure (before it would be
|
||||
falsely reported as a success if the exit code is 0).
|
||||
* New feature: Test::RecordProperty() can now be used outside of the
|
||||
lifespan of a test method, in which case it will be attributed to
|
||||
the current test case or the test program in the XML report.
|
||||
* New feature (potentially breaking): --gtest_list_tests now prints
|
||||
the type parameters and value parameters for each test.
|
||||
* Improvement: char pointers and char arrays are now escaped properly
|
||||
in failure messages.
|
||||
* Improvement: failure summary in XML reports now includes file and
|
||||
line information.
|
||||
* Improvement: the <testsuites> XML element now has a timestamp attribute.
|
||||
* Improvement: When --gtest_filter is specified, XML report now doesn't
|
||||
contain information about tests that are filtered out.
|
||||
* Fixed the bug where long --gtest_filter flag values are truncated in
|
||||
death tests.
|
||||
* Potentially breaking change: RUN_ALL_TESTS() is now implemented as a
|
||||
function instead of a macro in order to work better with Clang.
|
||||
* Compatibility fixes with C++ 11 and various platforms.
|
||||
* Bug/warning fixes.
|
||||
|
||||
Changes for 1.6.0:
|
||||
|
||||
* New feature: ADD_FAILURE_AT() for reporting a test failure at the
|
||||
given source location -- useful for writing testing utilities.
|
||||
* New feature: the universal value printer is moved from Google Mock
|
||||
to Google Test.
|
||||
* New feature: type parameters and value parameters are reported in
|
||||
the XML report now.
|
||||
* A gtest_disable_pthreads CMake option.
|
||||
* Colored output works in GNU Screen sessions now.
|
||||
* Parameters of value-parameterized tests are now printed in the
|
||||
textual output.
|
||||
* Failures from ad hoc test assertions run before RUN_ALL_TESTS() are
|
||||
now correctly reported.
|
||||
* Arguments of ASSERT_XY and EXPECT_XY no longer need to support << to
|
||||
ostream.
|
||||
* More complete handling of exceptions.
|
||||
* GTEST_ASSERT_XY can be used instead of ASSERT_XY in case the latter
|
||||
name is already used by another library.
|
||||
* --gtest_catch_exceptions is now true by default, allowing a test
|
||||
program to continue after an exception is thrown.
|
||||
* Value-parameterized test fixtures can now derive from Test and
|
||||
WithParamInterface<T> separately, easing conversion of legacy tests.
|
||||
* Death test messages are clearly marked to make them more
|
||||
distinguishable from other messages.
|
||||
* Compatibility fixes for Android, Google Native Client, MinGW, HP UX,
|
||||
PowerPC, Lucid autotools, libCStd, Sun C++, Borland C++ Builder (Code Gear),
|
||||
IBM XL C++ (Visual Age C++), and C++0x.
|
||||
* Bug fixes and implementation clean-ups.
|
||||
* Potentially incompatible changes: disables the harmful 'make install'
|
||||
command in autotools.
|
||||
|
||||
Changes for 1.5.0:
|
||||
|
||||
* New feature: assertions can be safely called in multiple threads
|
||||
where the pthreads library is available.
|
||||
* New feature: predicates used inside EXPECT_TRUE() and friends
|
||||
can now generate custom failure messages.
|
||||
* New feature: Google Test can now be compiled as a DLL.
|
||||
* New feature: fused source files are included.
|
||||
* New feature: prints help when encountering unrecognized Google Test flags.
|
||||
* Experimental feature: CMake build script (requires CMake 2.6.4+).
|
||||
* Experimental feature: the Pump script for meta programming.
|
||||
* double values streamed to an assertion are printed with enough precision
|
||||
to differentiate any two different values.
|
||||
* Google Test now works on Solaris and AIX.
|
||||
* Build and test script improvements.
|
||||
* Bug fixes and implementation clean-ups.
|
||||
|
||||
Potentially breaking changes:
|
||||
|
||||
* Stopped supporting VC++ 7.1 with exceptions disabled.
|
||||
* Dropped support for 'make install'.
|
||||
|
||||
Changes for 1.4.0:
|
||||
|
||||
* New feature: the event listener API
|
||||
* New feature: test shuffling
|
||||
* New feature: the XML report format is closer to junitreport and can
|
||||
be parsed by Hudson now.
|
||||
* New feature: when a test runs under Visual Studio, its failures are
|
||||
integrated in the IDE.
|
||||
* New feature: /MD(d) versions of VC++ projects.
|
||||
* New feature: elapsed time for the tests is printed by default.
|
||||
* New feature: comes with a TR1 tuple implementation such that Boost
|
||||
is no longer needed for Combine().
|
||||
* New feature: EXPECT_DEATH_IF_SUPPORTED macro and friends.
|
||||
* New feature: the Xcode project can now produce static gtest
|
||||
libraries in addition to a framework.
|
||||
* Compatibility fixes for Solaris, Cygwin, minGW, Windows Mobile,
|
||||
Symbian, gcc, and C++Builder.
|
||||
* Bug fixes and implementation clean-ups.
|
||||
|
||||
Changes for 1.3.0:
|
||||
|
||||
* New feature: death tests on Windows, Cygwin, and Mac.
|
||||
* New feature: ability to use Google Test assertions in other testing
|
||||
frameworks.
|
||||
* New feature: ability to run disabled test via
|
||||
--gtest_also_run_disabled_tests.
|
||||
* New feature: the --help flag for printing the usage.
|
||||
* New feature: access to Google Test flag values in user code.
|
||||
* New feature: a script that packs Google Test into one .h and one
|
||||
.cc file for easy deployment.
|
||||
* New feature: support for distributing test functions to multiple
|
||||
machines (requires support from the test runner).
|
||||
* Bug fixes and implementation clean-ups.
|
||||
|
||||
Changes for 1.2.1:
|
||||
|
||||
* Compatibility fixes for Linux IA-64 and IBM z/OS.
|
||||
* Added support for using Boost and other TR1 implementations.
|
||||
* Changes to the build scripts to support upcoming release of Google C++
|
||||
Mocking Framework.
|
||||
* Added Makefile to the distribution package.
|
||||
* Improved build instructions in README.
|
||||
|
||||
Changes for 1.2.0:
|
||||
|
||||
* New feature: value-parameterized tests.
|
||||
* New feature: the ASSERT/EXPECT_(NON)FATAL_FAILURE(_ON_ALL_THREADS)
|
||||
macros.
|
||||
* Changed the XML report format to match JUnit/Ant's.
|
||||
* Added tests to the Xcode project.
|
||||
* Added scons/SConscript for building with SCons.
|
||||
* Added src/gtest-all.cc for building Google Test from a single file.
|
||||
* Fixed compatibility with Solaris and z/OS.
|
||||
* Enabled running Python tests on systems with python 2.3 installed,
|
||||
e.g. Mac OS X 10.4.
|
||||
* Bug fixes.
|
||||
|
||||
Changes for 1.1.0:
|
||||
|
||||
* New feature: type-parameterized tests.
|
||||
* New feature: exception assertions.
|
||||
* New feature: printing elapsed time of tests.
|
||||
* Improved the robustness of death tests.
|
||||
* Added an Xcode project and samples.
|
||||
* Adjusted the output format on Windows to be understandable by Visual Studio.
|
||||
* Minor bug fixes.
|
||||
|
||||
Changes for 1.0.1:
|
||||
|
||||
* Added project files for Visual Studio 7.1.
|
||||
* Fixed issues with compiling on Mac OS X.
|
||||
* Fixed issues with compiling on Cygwin.
|
||||
|
||||
Changes for 1.0.0:
|
||||
|
||||
* Initial Open Source release of Google Test
|
@ -0,0 +1,37 @@
|
||||
# This file contains a list of people who've made non-trivial
|
||||
# contribution to the Google C++ Testing Framework project. People
|
||||
# who commit code to the project are encouraged to add their names
|
||||
# here. Please keep the list sorted by first names.
|
||||
|
||||
Ajay Joshi <jaj@google.com>
|
||||
Balázs Dán <balazs.dan@gmail.com>
|
||||
Bharat Mediratta <bharat@menalto.com>
|
||||
Chandler Carruth <chandlerc@google.com>
|
||||
Chris Prince <cprince@google.com>
|
||||
Chris Taylor <taylorc@google.com>
|
||||
Dan Egnor <egnor@google.com>
|
||||
Eric Roman <eroman@chromium.org>
|
||||
Hady Zalek <hady.zalek@gmail.com>
|
||||
Jeffrey Yasskin <jyasskin@google.com>
|
||||
Jói Sigurðsson <joi@google.com>
|
||||
Keir Mierle <mierle@gmail.com>
|
||||
Keith Ray <keith.ray@gmail.com>
|
||||
Kenton Varda <kenton@google.com>
|
||||
Manuel Klimek <klimek@google.com>
|
||||
Markus Heule <markus.heule@gmail.com>
|
||||
Mika Raento <mikie@iki.fi>
|
||||
Miklós Fazekas <mfazekas@szemafor.com>
|
||||
Pasi Valminen <pasi.valminen@gmail.com>
|
||||
Patrick Hanna <phanna@google.com>
|
||||
Patrick Riley <pfr@google.com>
|
||||
Peter Kaminski <piotrk@google.com>
|
||||
Preston Jackson <preston.a.jackson@gmail.com>
|
||||
Rainer Klaffenboeck <rainer.klaffenboeck@dynatrace.com>
|
||||
Russ Cox <rsc@google.com>
|
||||
Russ Rufer <russ@pentad.com>
|
||||
Sean Mcafee <eefacm@gmail.com>
|
||||
Sigurður Ásgeirsson <siggi@google.com>
|
||||
Tracy Bialik <tracy@pentad.com>
|
||||
Vadim Berman <vadimb@google.com>
|
||||
Vlad Losev <vladl@google.com>
|
||||
Zhanyong Wan <wan@google.com>
|
@ -0,0 +1,28 @@
|
||||
Copyright 2008, Google Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@ -0,0 +1,435 @@
|
||||
Google C++ Testing Framework
|
||||
============================
|
||||
|
||||
http://code.google.com/p/googletest/
|
||||
|
||||
Overview
|
||||
--------
|
||||
|
||||
Google's framework for writing C++ tests on a variety of platforms
|
||||
(Linux, Mac OS X, Windows, Windows CE, Symbian, etc). Based on the
|
||||
xUnit architecture. Supports automatic test discovery, a rich set of
|
||||
assertions, user-defined assertions, death tests, fatal and non-fatal
|
||||
failures, various options for running the tests, and XML test report
|
||||
generation.
|
||||
|
||||
Please see the project page above for more information as well as the
|
||||
mailing list for questions, discussions, and development. There is
|
||||
also an IRC channel on OFTC (irc.oftc.net) #gtest available. Please
|
||||
join us!
|
||||
|
||||
Requirements for End Users
|
||||
--------------------------
|
||||
|
||||
Google Test is designed to have fairly minimal requirements to build
|
||||
and use with your projects, but there are some. Currently, we support
|
||||
Linux, Windows, Mac OS X, and Cygwin. We will also make our best
|
||||
effort to support other platforms (e.g. Solaris, AIX, and z/OS).
|
||||
However, since core members of the Google Test project have no access
|
||||
to these platforms, Google Test may have outstanding issues there. If
|
||||
you notice any problems on your platform, please notify
|
||||
googletestframework@googlegroups.com. Patches for fixing them are
|
||||
even more welcome!
|
||||
|
||||
### Linux Requirements ###
|
||||
|
||||
These are the base requirements to build and use Google Test from a source
|
||||
package (as described below):
|
||||
* GNU-compatible Make or gmake
|
||||
* POSIX-standard shell
|
||||
* POSIX(-2) Regular Expressions (regex.h)
|
||||
* A C++98-standard-compliant compiler
|
||||
|
||||
### Windows Requirements ###
|
||||
|
||||
* Microsoft Visual C++ 7.1 or newer
|
||||
|
||||
### Cygwin Requirements ###
|
||||
|
||||
* Cygwin 1.5.25-14 or newer
|
||||
|
||||
### Mac OS X Requirements ###
|
||||
|
||||
* Mac OS X 10.4 Tiger or newer
|
||||
* Developer Tools Installed
|
||||
|
||||
Also, you'll need CMake 2.6.4 or higher if you want to build the
|
||||
samples using the provided CMake script, regardless of the platform.
|
||||
|
||||
Requirements for Contributors
|
||||
-----------------------------
|
||||
|
||||
We welcome patches. If you plan to contribute a patch, you need to
|
||||
build Google Test and its own tests from an SVN checkout (described
|
||||
below), which has further requirements:
|
||||
|
||||
* Python version 2.3 or newer (for running some of the tests and
|
||||
re-generating certain source files from templates)
|
||||
* CMake 2.6.4 or newer
|
||||
|
||||
Getting the Source
|
||||
------------------
|
||||
|
||||
There are two primary ways of getting Google Test's source code: you
|
||||
can download a stable source release in your preferred archive format,
|
||||
or directly check out the source from our Subversion (SVN) repository.
|
||||
The SVN checkout requires a few extra steps and some extra software
|
||||
packages on your system, but lets you track the latest development and
|
||||
make patches much more easily, so we highly encourage it.
|
||||
|
||||
### Source Package ###
|
||||
|
||||
Google Test is released in versioned source packages which can be
|
||||
downloaded from the download page [1]. Several different archive
|
||||
formats are provided, but the only difference is the tools used to
|
||||
manipulate them, and the size of the resulting file. Download
|
||||
whichever you are most comfortable with.
|
||||
|
||||
[1] http://code.google.com/p/googletest/downloads/list
|
||||
|
||||
Once the package is downloaded, expand it using whichever tools you
|
||||
prefer for that type. This will result in a new directory with the
|
||||
name "gtest-X.Y.Z" which contains all of the source code. Here are
|
||||
some examples on Linux:
|
||||
|
||||
tar -xvzf gtest-X.Y.Z.tar.gz
|
||||
tar -xvjf gtest-X.Y.Z.tar.bz2
|
||||
unzip gtest-X.Y.Z.zip
|
||||
|
||||
### SVN Checkout ###
|
||||
|
||||
To check out the main branch (also known as the "trunk") of Google
|
||||
Test, run the following Subversion command:
|
||||
|
||||
svn checkout http://googletest.googlecode.com/svn/trunk/ gtest-svn
|
||||
|
||||
Setting up the Build
|
||||
--------------------
|
||||
|
||||
To build Google Test and your tests that use it, you need to tell your
|
||||
build system where to find its headers and source files. The exact
|
||||
way to do it depends on which build system you use, and is usually
|
||||
straightforward.
|
||||
|
||||
### Generic Build Instructions ###
|
||||
|
||||
Suppose you put Google Test in directory ${GTEST_DIR}. To build it,
|
||||
create a library build target (or a project as called by Visual Studio
|
||||
and Xcode) to compile
|
||||
|
||||
${GTEST_DIR}/src/gtest-all.cc
|
||||
|
||||
with ${GTEST_DIR}/include in the system header search path and ${GTEST_DIR}
|
||||
in the normal header search path. Assuming a Linux-like system and gcc,
|
||||
something like the following will do:
|
||||
|
||||
g++ -isystem ${GTEST_DIR}/include -I${GTEST_DIR} \
|
||||
-pthread -c ${GTEST_DIR}/src/gtest-all.cc
|
||||
ar -rv libgtest.a gtest-all.o
|
||||
|
||||
(We need -pthread as Google Test uses threads.)
|
||||
|
||||
Next, you should compile your test source file with
|
||||
${GTEST_DIR}/include in the system header search path, and link it
|
||||
with gtest and any other necessary libraries:
|
||||
|
||||
g++ -isystem ${GTEST_DIR}/include -pthread path/to/your_test.cc libgtest.a \
|
||||
-o your_test
|
||||
|
||||
As an example, the make/ directory contains a Makefile that you can
|
||||
use to build Google Test on systems where GNU make is available
|
||||
(e.g. Linux, Mac OS X, and Cygwin). It doesn't try to build Google
|
||||
Test's own tests. Instead, it just builds the Google Test library and
|
||||
a sample test. You can use it as a starting point for your own build
|
||||
script.
|
||||
|
||||
If the default settings are correct for your environment, the
|
||||
following commands should succeed:
|
||||
|
||||
cd ${GTEST_DIR}/make
|
||||
make
|
||||
./sample1_unittest
|
||||
|
||||
If you see errors, try to tweak the contents of make/Makefile to make
|
||||
them go away. There are instructions in make/Makefile on how to do
|
||||
it.
|
||||
|
||||
### Using CMake ###
|
||||
|
||||
Google Test comes with a CMake build script (CMakeLists.txt) that can
|
||||
be used on a wide range of platforms ("C" stands for cross-platform.).
|
||||
If you don't have CMake installed already, you can download it for
|
||||
free from http://www.cmake.org/.
|
||||
|
||||
CMake works by generating native makefiles or build projects that can
|
||||
be used in the compiler environment of your choice. The typical
|
||||
workflow starts with:
|
||||
|
||||
mkdir mybuild # Create a directory to hold the build output.
|
||||
cd mybuild
|
||||
cmake ${GTEST_DIR} # Generate native build scripts.
|
||||
|
||||
If you want to build Google Test's samples, you should replace the
|
||||
last command with
|
||||
|
||||
cmake -Dgtest_build_samples=ON ${GTEST_DIR}
|
||||
|
||||
If you are on a *nix system, you should now see a Makefile in the
|
||||
current directory. Just type 'make' to build gtest.
|
||||
|
||||
If you use Windows and have Visual Studio installed, a gtest.sln file
|
||||
and several .vcproj files will be created. You can then build them
|
||||
using Visual Studio.
|
||||
|
||||
On Mac OS X with Xcode installed, a .xcodeproj file will be generated.
|
||||
|
||||
### Legacy Build Scripts ###
|
||||
|
||||
Before settling on CMake, we have been providing hand-maintained build
|
||||
projects/scripts for Visual Studio, Xcode, and Autotools. While we
|
||||
continue to provide them for convenience, they are not actively
|
||||
maintained any more. We highly recommend that you follow the
|
||||
instructions in the previous two sections to integrate Google Test
|
||||
with your existing build system.
|
||||
|
||||
If you still need to use the legacy build scripts, here's how:
|
||||
|
||||
The msvc\ folder contains two solutions with Visual C++ projects.
|
||||
Open the gtest.sln or gtest-md.sln file using Visual Studio, and you
|
||||
are ready to build Google Test the same way you build any Visual
|
||||
Studio project. Files that have names ending with -md use DLL
|
||||
versions of Microsoft runtime libraries (the /MD or the /MDd compiler
|
||||
option). Files without that suffix use static versions of the runtime
|
||||
libraries (the /MT or the /MTd option). Please note that one must use
|
||||
the same option to compile both gtest and the test code. If you use
|
||||
Visual Studio 2005 or above, we recommend the -md version as /MD is
|
||||
the default for new projects in these versions of Visual Studio.
|
||||
|
||||
On Mac OS X, open the gtest.xcodeproj in the xcode/ folder using
|
||||
Xcode. Build the "gtest" target. The universal binary framework will
|
||||
end up in your selected build directory (selected in the Xcode
|
||||
"Preferences..." -> "Building" pane and defaults to xcode/build).
|
||||
Alternatively, at the command line, enter:
|
||||
|
||||
xcodebuild
|
||||
|
||||
This will build the "Release" configuration of gtest.framework in your
|
||||
default build location. See the "xcodebuild" man page for more
|
||||
information about building different configurations and building in
|
||||
different locations.
|
||||
|
||||
If you wish to use the Google Test Xcode project with Xcode 4.x and
|
||||
above, you need to either:
|
||||
* update the SDK configuration options in xcode/Config/General.xconfig.
|
||||
Comment options SDKROOT, MACOS_DEPLOYMENT_TARGET, and GCC_VERSION. If
|
||||
you choose this route you lose the ability to target earlier versions
|
||||
of MacOS X.
|
||||
* Install an SDK for an earlier version. This doesn't appear to be
|
||||
supported by Apple, but has been reported to work
|
||||
(http://stackoverflow.com/questions/5378518).
|
||||
|
||||
Tweaking Google Test
|
||||
--------------------
|
||||
|
||||
Google Test can be used in diverse environments. The default
|
||||
configuration may not work (or may not work well) out of the box in
|
||||
some environments. However, you can easily tweak Google Test by
|
||||
defining control macros on the compiler command line. Generally,
|
||||
these macros are named like GTEST_XYZ and you define them to either 1
|
||||
or 0 to enable or disable a certain feature.
|
||||
|
||||
We list the most frequently used macros below. For a complete list,
|
||||
see file include/gtest/internal/gtest-port.h.
|
||||
|
||||
### Choosing a TR1 Tuple Library ###
|
||||
|
||||
Some Google Test features require the C++ Technical Report 1 (TR1)
|
||||
tuple library, which is not yet available with all compilers. The
|
||||
good news is that Google Test implements a subset of TR1 tuple that's
|
||||
enough for its own need, and will automatically use this when the
|
||||
compiler doesn't provide TR1 tuple.
|
||||
|
||||
Usually you don't need to care about which tuple library Google Test
|
||||
uses. However, if your project already uses TR1 tuple, you need to
|
||||
tell Google Test to use the same TR1 tuple library the rest of your
|
||||
project uses, or the two tuple implementations will clash. To do
|
||||
that, add
|
||||
|
||||
-DGTEST_USE_OWN_TR1_TUPLE=0
|
||||
|
||||
to the compiler flags while compiling Google Test and your tests. If
|
||||
you want to force Google Test to use its own tuple library, just add
|
||||
|
||||
-DGTEST_USE_OWN_TR1_TUPLE=1
|
||||
|
||||
to the compiler flags instead.
|
||||
|
||||
If you don't want Google Test to use tuple at all, add
|
||||
|
||||
-DGTEST_HAS_TR1_TUPLE=0
|
||||
|
||||
and all features using tuple will be disabled.
|
||||
|
||||
### Multi-threaded Tests ###
|
||||
|
||||
Google Test is thread-safe where the pthread library is available.
|
||||
After #include "gtest/gtest.h", you can check the GTEST_IS_THREADSAFE
|
||||
macro to see whether this is the case (yes if the macro is #defined to
|
||||
1, no if it's undefined.).
|
||||
|
||||
If Google Test doesn't correctly detect whether pthread is available
|
||||
in your environment, you can force it with
|
||||
|
||||
-DGTEST_HAS_PTHREAD=1
|
||||
|
||||
or
|
||||
|
||||
-DGTEST_HAS_PTHREAD=0
|
||||
|
||||
When Google Test uses pthread, you may need to add flags to your
|
||||
compiler and/or linker to select the pthread library, or you'll get
|
||||
link errors. If you use the CMake script or the deprecated Autotools
|
||||
script, this is taken care of for you. If you use your own build
|
||||
script, you'll need to read your compiler and linker's manual to
|
||||
figure out what flags to add.
|
||||
|
||||
### As a Shared Library (DLL) ###
|
||||
|
||||
Google Test is compact, so most users can build and link it as a
|
||||
static library for the simplicity. You can choose to use Google Test
|
||||
as a shared library (known as a DLL on Windows) if you prefer.
|
||||
|
||||
To compile *gtest* as a shared library, add
|
||||
|
||||
-DGTEST_CREATE_SHARED_LIBRARY=1
|
||||
|
||||
to the compiler flags. You'll also need to tell the linker to produce
|
||||
a shared library instead - consult your linker's manual for how to do
|
||||
it.
|
||||
|
||||
To compile your *tests* that use the gtest shared library, add
|
||||
|
||||
-DGTEST_LINKED_AS_SHARED_LIBRARY=1
|
||||
|
||||
to the compiler flags.
|
||||
|
||||
Note: while the above steps aren't technically necessary today when
|
||||
using some compilers (e.g. GCC), they may become necessary in the
|
||||
future, if we decide to improve the speed of loading the library (see
|
||||
http://gcc.gnu.org/wiki/Visibility for details). Therefore you are
|
||||
recommended to always add the above flags when using Google Test as a
|
||||
shared library. Otherwise a future release of Google Test may break
|
||||
your build script.
|
||||
|
||||
### Avoiding Macro Name Clashes ###
|
||||
|
||||
In C++, macros don't obey namespaces. Therefore two libraries that
|
||||
both define a macro of the same name will clash if you #include both
|
||||
definitions. In case a Google Test macro clashes with another
|
||||
library, you can force Google Test to rename its macro to avoid the
|
||||
conflict.
|
||||
|
||||
Specifically, if both Google Test and some other code define macro
|
||||
FOO, you can add
|
||||
|
||||
-DGTEST_DONT_DEFINE_FOO=1
|
||||
|
||||
to the compiler flags to tell Google Test to change the macro's name
|
||||
from FOO to GTEST_FOO. Currently FOO can be FAIL, SUCCEED, or TEST.
|
||||
For example, with -DGTEST_DONT_DEFINE_TEST=1, you'll need to write
|
||||
|
||||
GTEST_TEST(SomeTest, DoesThis) { ... }
|
||||
|
||||
instead of
|
||||
|
||||
TEST(SomeTest, DoesThis) { ... }
|
||||
|
||||
in order to define a test.
|
||||
|
||||
Upgrating from an Earlier Version
|
||||
---------------------------------
|
||||
|
||||
We strive to keep Google Test releases backward compatible.
|
||||
Sometimes, though, we have to make some breaking changes for the
|
||||
users' long-term benefits. This section describes what you'll need to
|
||||
do if you are upgrading from an earlier version of Google Test.
|
||||
|
||||
### Upgrading from 1.3.0 or Earlier ###
|
||||
|
||||
You may need to explicitly enable or disable Google Test's own TR1
|
||||
tuple library. See the instructions in section "Choosing a TR1 Tuple
|
||||
Library".
|
||||
|
||||
### Upgrading from 1.4.0 or Earlier ###
|
||||
|
||||
The Autotools build script (configure + make) is no longer officially
|
||||
supportted. You are encouraged to migrate to your own build system or
|
||||
use CMake. If you still need to use Autotools, you can find
|
||||
instructions in the README file from Google Test 1.4.0.
|
||||
|
||||
On platforms where the pthread library is available, Google Test uses
|
||||
it in order to be thread-safe. See the "Multi-threaded Tests" section
|
||||
for what this means to your build script.
|
||||
|
||||
If you use Microsoft Visual C++ 7.1 with exceptions disabled, Google
|
||||
Test will no longer compile. This should affect very few people, as a
|
||||
large portion of STL (including <string>) doesn't compile in this mode
|
||||
anyway. We decided to stop supporting it in order to greatly simplify
|
||||
Google Test's implementation.
|
||||
|
||||
Developing Google Test
|
||||
----------------------
|
||||
|
||||
This section discusses how to make your own changes to Google Test.
|
||||
|
||||
### Testing Google Test Itself ###
|
||||
|
||||
To make sure your changes work as intended and don't break existing
|
||||
functionality, you'll want to compile and run Google Test's own tests.
|
||||
For that you can use CMake:
|
||||
|
||||
mkdir mybuild
|
||||
cd mybuild
|
||||
cmake -Dgtest_build_tests=ON ${GTEST_DIR}
|
||||
|
||||
Make sure you have Python installed, as some of Google Test's tests
|
||||
are written in Python. If the cmake command complains about not being
|
||||
able to find Python ("Could NOT find PythonInterp (missing:
|
||||
PYTHON_EXECUTABLE)"), try telling it explicitly where your Python
|
||||
executable can be found:
|
||||
|
||||
cmake -DPYTHON_EXECUTABLE=path/to/python -Dgtest_build_tests=ON ${GTEST_DIR}
|
||||
|
||||
Next, you can build Google Test and all of its own tests. On *nix,
|
||||
this is usually done by 'make'. To run the tests, do
|
||||
|
||||
make test
|
||||
|
||||
All tests should pass.
|
||||
|
||||
### Regenerating Source Files ###
|
||||
|
||||
Some of Google Test's source files are generated from templates (not
|
||||
in the C++ sense) using a script. A template file is named FOO.pump,
|
||||
where FOO is the name of the file it will generate. For example, the
|
||||
file include/gtest/internal/gtest-type-util.h.pump is used to generate
|
||||
gtest-type-util.h in the same directory.
|
||||
|
||||
Normally you don't need to worry about regenerating the source files,
|
||||
unless you need to modify them. In that case, you should modify the
|
||||
corresponding .pump files instead and run the pump.py Python script to
|
||||
regenerate them. You can find pump.py in the scripts/ directory.
|
||||
Read the Pump manual [2] for how to use it.
|
||||
|
||||
[2] http://code.google.com/p/googletest/wiki/PumpManual
|
||||
|
||||
### Contributing a Patch ###
|
||||
|
||||
We welcome patches. Please read the Google Test developer's guide [3]
|
||||
for how you can contribute. In particular, make sure you have signed
|
||||
the Contributor License Agreement, or we won't be able to accept the
|
||||
patch.
|
||||
|
||||
[3] http://code.google.com/p/googletest/wiki/GoogleTestDevGuide
|
||||
|
||||
Happy testing!
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue