Replaced Boost log with Plog. (#124)

This commit is contained in:
priyadharsun
2020-09-23 06:06:42 +05:30
committed by GitHub
parent 37629471c5
commit 91122474a1
27 changed files with 286 additions and 331 deletions

View File

@@ -58,8 +58,6 @@ target_link_libraries(hpcore
libblake3.so
libboost_system.a
libboost_thread.a
libboost_log.a
libboost_log_setup.a
libboost_filesystem.a
libboost_stacktrace_backtrace.a
backtrace

View File

@@ -91,6 +91,11 @@ Example: When you make a change to `p2pmsg_content_.fbc` defnition file, you nee
1. Download [concurrentqueue 1.0.2](https://github.com/cameron314/concurrentqueue/archive/1.0.2.zip) and extract.
2. Run `sudo cp concurrentqueue.h /usr/local/include/`
#### Install plog
1. Download and extract [plog1.1.5](https://github.com/SergiusTheBest/plog/archive/1.1.5.zip)
2. Navigate into the extracted directory in a terminal.
3. Run `sudo cp -r include/plog /usr/local/include/`
#### Run ldconfig
`sudo ldconfig`

View File

@@ -28,7 +28,7 @@ void report_violation(const std::string host)
{
if (whitelist.find(host) != whitelist.end()) // Is in whitelist
{
LOG_DBG << host << " is whitelisted. Ignoring the violation.";
LOG_DEBUG << host << " is whitelisted. Ignoring the violation.";
return;
}
@@ -55,7 +55,7 @@ void report_violation(const std::string host)
stat.counter = 0;
graylist.emplace(host, VIOLATION_REFRESH_INTERVAL);
LOG_WARN << host << " placed on graylist.";
LOG_WARNING << host << " placed on graylist.";
}
else if (elapsed_time > VIOLATION_REFRESH_INTERVAL)
{

View File

@@ -28,7 +28,7 @@ namespace comm
// setup pipe I/O
if (pipe(read_pipe) < 0 || pipe(write_pipe) < 0)
{
LOG_ERR << errno << ": websocat pipe creation failed.";
LOG_ERROR << errno << ": websocat pipe creation failed.";
return -1;
}
@@ -85,12 +85,12 @@ namespace comm
NULL};
const int ret = execv(execv_args[0], execv_args);
LOG_ERR << errno << ": websocat process execv failed.";
LOG_ERROR << errno << ": websocat process execv failed.";
exit(1);
}
else
{
LOG_ERR << errno << ": fork() failed when starting websocat process.";
LOG_ERROR << errno << ": fork() failed when starting websocat process.";
return -1;
}

View File

@@ -34,7 +34,7 @@ namespace comm
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd == -1)
{
LOG_ERR << errno << ": Domain socket open error";
LOG_ERROR << errno << ": Domain socket open error";
return -1;
}
@@ -47,13 +47,13 @@ namespace comm
if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) == -1)
{
LOG_ERR << errno << ": Domain socket bind error";
LOG_ERROR << errno << ": Domain socket bind error";
return -1;
}
if (listen(fd, 5) == -1)
{
LOG_ERR << errno << ": Domain socket listen error";
LOG_ERROR << errno << ": Domain socket listen error";
return -1;
}
@@ -137,7 +137,7 @@ namespace comm
int client_fd = accept(accept_fd, NULL, NULL);
if (client_fd == -1 && errno != EAGAIN)
{
LOG_ERR << errno << ": Domain socket accept error";
LOG_ERROR << errno << ": Domain socket accept error";
}
else if (client_fd > 0)
{
@@ -147,7 +147,7 @@ namespace comm
{
if (corebill::is_banned(ip))
{
LOG_DBG << "Dropping connection for banned host " << ip;
LOG_DEBUG << "Dropping connection for banned host " << ip;
close(client_fd);
}
else
@@ -168,7 +168,7 @@ namespace comm
else
{
close(client_fd);
LOG_ERR << "Closed bad client socket: " << client_fd;
LOG_ERROR << "Closed bad client socket: " << client_fd;
}
}
}
@@ -197,12 +197,12 @@ namespace comm
std::string_view host = ipport.first;
const uint16_t port = ipport.second;
LOG_DBG << "Trying to connect " << host << ":" << std::to_string(port);
LOG_DEBUG << "Trying to connect " << host << ":" << std::to_string(port);
comm::comm_client client;
if (client.start(host, port, metric_thresholds, conf::cfg.peermaxsize) == -1)
{
LOG_ERR << "Outbound connection attempt failed: " << host << ":" << std::to_string(port);
LOG_ERROR << "Outbound connection attempt failed: " << host << ":" << std::to_string(port);
}
else
{
@@ -266,7 +266,7 @@ namespace comm
if (pipe(firewall_pipe))
{
LOG_ERR << errno << ": pipe() call failed for firewall";
LOG_ERROR << errno << ": pipe() call failed for firewall";
}
else
{
@@ -335,12 +335,12 @@ namespace comm
execv_args[idx] = NULL;
const int ret = execv(execv_args[0], execv_args);
LOG_ERR << errno << ": websocketd process execv failed.";
LOG_ERROR << errno << ": websocketd process execv failed.";
exit(1);
}
else
{
LOG_ERR << errno << ": fork() failed when starting websocketd process.";
LOG_ERROR << errno << ": fork() failed when starting websocketd process.";
return -1;
}
@@ -372,7 +372,7 @@ namespace comm
// Ask the operating system for information about the other process
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &uc, &length) == -1)
{
LOG_ERR << errno << ": Could not retrieve PID from unix domain socket";
LOG_ERROR << errno << ": Could not retrieve PID from unix domain socket";
return "";
}
@@ -384,7 +384,7 @@ namespace comm
const int envfd = open(fn.c_str(), O_RDONLY | O_CLOEXEC);
if (!envfd)
{
LOG_ERR << errno << ": Could not open environ block for process on other end of unix domain socket PID=" << uc.pid;
LOG_ERROR << errno << ": Could not open environ block for process on other end of unix domain socket PID=" << uc.pid;
return "";
}
@@ -404,7 +404,7 @@ namespace comm
}
}
LOG_ERR << "Could not find REMOTE_ADDR variable in /proc/" << uc.pid << "/environ";
LOG_ERROR << "Could not find REMOTE_ADDR variable in /proc/" << uc.pid << "/environ";
return "";
}

View File

@@ -57,7 +57,7 @@ namespace comm
if (poll(pollfds, 1, 20) == -1)
{
LOG_ERR << errno << ": Session reader poll failed.";
LOG_ERROR << errno << ": Session reader poll failed.";
break;
}
@@ -231,7 +231,7 @@ namespace comm
if (writev(write_fd, memsegs, 2) == -1)
{
LOG_ERR << errno << ": Session " << uniqueid.substr(0, 10) << " send writev failed.";
LOG_ERROR << errno << ": Session " << uniqueid.substr(0, 10) << " send writev failed.";
return -1;
}
return 0;
@@ -301,7 +301,7 @@ namespace comm
reader_thread.join();
writer_thread.join();
LOG_DBG << (session_type == SESSION_TYPE::PEER ? "Peer" : "User") << " session closed: "
LOG_DEBUG << (session_type == SESSION_TYPE::PEER ? "Peer" : "User") << " session closed: "
<< uniqueid.substr(0, 10) << (is_inbound ? "[in]" : "[out]") << (is_self ? "[self]" : "");
}

View File

@@ -2,7 +2,6 @@
#include "conf.hpp"
#include "crypto.hpp"
#include "util.hpp"
#include "hplog.hpp"
namespace conf
{
@@ -78,6 +77,7 @@ namespace conf
boost::filesystem::create_directories(ctx.config_dir);
boost::filesystem::create_directories(ctx.hist_dir);
boost::filesystem::create_directories(ctx.state_rw_dir);
boost::filesystem::create_directories(ctx.log_dir);
//Create config file with default settings.
@@ -92,12 +92,15 @@ namespace conf
cfg.pubport = 8080;
#ifndef NDEBUG
cfg.loglevel = "debug";
cfg.loglevel_type = conf::LOG_SEVERITY::DEBUG;
cfg.loglevel = "dbg";
#else
cfg.loglevel = "warn";
cfg.loglevel_type = conf::LOG_SEVERITY::WARN;
cfg.loglevel = "wrn";
#endif
cfg.loggers.emplace("console");
cfg.loggers.emplace("console");
cfg.loggers.emplace("file");
cfg.binary = "<your contract binary here>";
//Save the default settings into the config file.
@@ -282,6 +285,7 @@ namespace conf
cfg.peermaxcons = d["peermaxcons"].as<unsigned int>();
cfg.loglevel = d["loglevel"].as<std::string>();
cfg.loglevel_type = get_loglevel_type(cfg.loglevel);
cfg.loggers.clear();
for (auto &v : d["loggers"].array_range())
cfg.loggers.emplace(v.as<std::string>());
@@ -348,7 +352,7 @@ namespace conf
d.insert_or_assign("peermaxbadsigpm", cfg.peermaxbadsigpm);
d.insert_or_assign("peermaxcons", cfg.peermaxcons);
d.insert_or_assign("loglevel", cfg.loglevel.data());
d.insert_or_assign("loglevel", cfg.loglevel);
jsoncons::ojson loggers(jsoncons::json_array_arg);
for (std::string_view logger : cfg.loggers)
@@ -457,10 +461,10 @@ namespace conf
}
// Log settings
const std::unordered_set<std::string> valid_loglevels({"debug", "info", "warn", "error"});
const std::unordered_set<std::string> valid_loglevels({"dbg", "inf", "wrn", "err"});
if (valid_loglevels.count(cfg.loglevel) != 1)
{
std::cout << "Invalid loglevel configured. Valid values: debug|info|warn|error\n";
std::cout << "Invalid loglevel configured. Valid values: dbg|inf|wrn|err\n";
return -1;
}
@@ -537,4 +541,20 @@ namespace conf
LOG_INFO << "Switched back to PROPOSER mode.";
}
/**
* Convert string to Log Severity enum type.
* @param severity log severity code.
* @return log severity type.
*/
LOG_SEVERITY get_loglevel_type(std::string_view severity)
{
if (severity == "dbg")
return LOG_SEVERITY::DEBUG;
else if (severity == "wrn")
return LOG_SEVERITY::WARN;
else if (severity == "inf")
return LOG_SEVERITY::INFO;
else
return LOG_SEVERITY::ERROR;
}
} // namespace conf

View File

@@ -22,6 +22,15 @@ namespace conf
PROPOSER = 1 // Consensus participant mode.
};
// Log severity levels used in Hot Pocket.
enum LOG_SEVERITY
{
DEBUG,
INFO,
WARN,
ERROR
};
// Holds contextual information about the currently loaded contract.
struct contract_ctx
{
@@ -81,6 +90,7 @@ namespace conf
uint16_t peermaxcons = 0; // Max inbound peer connections
std::string loglevel; // Log severity level (debug, info, warn, error)
LOG_SEVERITY loglevel_type; // Log severity level enum (debug, info, warn, error)
std::unordered_set<std::string> loggers; // List of enabled loggers (console, file)
};
@@ -116,6 +126,7 @@ namespace conf
void change_operating_mode(const OPERATING_MODE mode);
LOG_SEVERITY get_loglevel_type(std::string_view severity);
} // namespace conf
#endif

View File

@@ -48,7 +48,7 @@ namespace cons
if (get_initial_state_hash(ctx.state) == -1)
{
LOG_ERR << "Failed to get initial state hash.";
LOG_ERROR << "Failed to get initial state hash.";
return -1;
}
@@ -107,7 +107,7 @@ namespace cons
{
if (consensus() == -1)
{
LOG_ERR << "Consensus thread exited due to an error.";
LOG_ERROR << "Consensus thread exited due to an error.";
break;
}
}
@@ -171,7 +171,7 @@ namespace cons
ctx.candidate_npl_messages.erase(itr++);
}
LOG_DBG << "Started stage " << std::to_string(ctx.stage);
LOG_DEBUG << "Started stage " << std::to_string(ctx.stage);
if (ctx.stage == 0) // Stage 0 means begining of a consensus round.
{
@@ -253,7 +253,7 @@ namespace cons
}
else
{
LOG_ERR << "Error occured in Stage 3 consensus execution.";
LOG_ERROR << "Error occured in Stage 3 consensus execution.";
}
}
}
@@ -279,7 +279,7 @@ namespace cons
// only consider recent proposals and proposals from previous stage and current stage.
const bool keep_candidate = (time_diff < (conf::cfg.roundtime * 4)) && (stage_diff == -3 || stage_diff <= 1);
LOG_DBG << (keep_candidate ? "Prop--->" : "Erased")
LOG_DEBUG << (keep_candidate ? "Prop--->" : "Erased")
<< " [s" << std::to_string(cp.stage)
<< "] u/i/o:" << cp.users.size()
<< "/" << cp.hash_inputs.size()
@@ -318,7 +318,7 @@ namespace cons
stage_start = current_round_start + conf::cfg.roundtime;
const int64_t to_wait = stage_start - now;
LOG_DBG << "Waiting " << std::to_string(to_wait) << "ms for next round stage 0";
LOG_DEBUG << "Waiting " << std::to_string(to_wait) << "ms for next round stage 0";
util::sleep(to_wait);
return true;
}
@@ -334,13 +334,13 @@ namespace cons
// it will continue particapating in this round, otherwise will join in next round.
if (to_wait < ctx.stage_reset_wait_threshold) //todo: self claculating/adjusting network delay
{
LOG_DBG << "Missed stage " << std::to_string(ctx.stage) << " window. Resetting to stage 0";
LOG_DEBUG << "Missed stage " << std::to_string(ctx.stage) << " window. Resetting to stage 0";
ctx.stage = 0;
return false;
}
else
{
LOG_DBG << "Waiting " << std::to_string(to_wait) << "ms for stage " << std::to_string(ctx.stage);
LOG_DEBUG << "Waiting " << std::to_string(to_wait) << "ms for stage " << std::to_string(ctx.stage);
util::sleep(to_wait);
return true;
}
@@ -376,7 +376,7 @@ namespace cons
p2pmsg::create_msg_from_nonunl_proposal(fbuf, nup);
p2p::broadcast_message(fbuf, true);
LOG_DBG << "NUP sent."
LOG_DEBUG << "NUP sent."
<< " users:" << nup.user_inputs.size();
}
@@ -454,19 +454,19 @@ namespace cons
}
else
{
LOG_DBG << "User message bad max ledger seq expired.";
LOG_DEBUG << "User message bad max ledger seq expired.";
reject_reason = msg::usrmsg::REASON_MAX_LEDGER_EXPIRED;
}
}
else
{
LOG_DBG << "User message bad signature.";
LOG_DEBUG << "User message bad signature.";
reject_reason = msg::usrmsg::REASON_BAD_SIG;
}
}
else
{
LOG_DBG << "Duplicate user message.";
LOG_DEBUG << "Duplicate user message.";
reject_reason = msg::usrmsg::REASON_DUPLICATE_MSG;
}
@@ -524,7 +524,7 @@ namespace cons
// before execution chdir into a valid the latest state data directory that contains an appbill.table
chdir(conf::ctx.state_rw_dir.c_str());
int ret = execv(execv_args[0], execv_args);
LOG_ERR << "Appbill process execv failed: " << ret;
LOG_ERROR << "Appbill process execv failed: " << ret;
return false;
}
else
@@ -542,7 +542,7 @@ namespace cons
else
{
// user's key did not pass, do not add to user input candidates
LOG_DBG << "Appbill validation failed " << hexpubkey << " return code was " << status;
LOG_DEBUG << "Appbill validation failed " << hexpubkey << " return code was " << status;
return false;
}
}
@@ -666,7 +666,7 @@ namespace cons
else
p2p::broadcast_message(fbuf, true);
LOG_DBG << "Proposed u/i/o:" << p.users.size()
LOG_DEBUG << "Proposed u/i/o:" << p.users.size()
<< "/" << p.hash_inputs.size()
<< "/" << p.hash_outputs.size()
<< " ts:" << std::to_string(p.time)
@@ -692,7 +692,7 @@ namespace cons
if (total_lcl_votes < (MAJORITY_THRESHOLD * conf::cfg.unl.size()))
{
LOG_DBG << "Not enough peers proposing to perform consensus. votes:" << total_lcl_votes << " needed:" << ceil(MAJORITY_THRESHOLD * conf::cfg.unl.size());
LOG_DEBUG << "Not enough peers proposing to perform consensus. votes:" << total_lcl_votes << " needed:" << ceil(MAJORITY_THRESHOLD * conf::cfg.unl.size());
is_desync = true;
return;
}
@@ -712,7 +712,7 @@ namespace cons
//Should request history from a peer.
if (ctx.lcl != majority_lcl)
{
LOG_DBG << "We are not on the consensus ledger, requesting history from a random peer";
LOG_DEBUG << "We are not on the consensus ledger, requesting history from a random peer";
is_desync = true;
//Node is not in sync with current lcl ->switch to observer mode.
@@ -725,7 +725,7 @@ namespace cons
if (winning_votes < MAJORITY_THRESHOLD * ctx.candidate_proposals.size())
{
// potential fork condition.
LOG_DBG << "No consensus on lcl. Possible fork condition. won:" << winning_votes << " total:" << ctx.candidate_proposals.size();
LOG_DEBUG << "No consensus on lcl. Possible fork condition. won:" << winning_votes << " total:" << ctx.candidate_proposals.size();
is_desync = true;
return;
}
@@ -816,7 +816,7 @@ namespace cons
if (sc::execute_contract(ctx.contract_ctx) == -1)
{
LOG_ERR << "Contract execution failed.";
LOG_ERROR << "Contract execution failed.";
return -1;
}
@@ -843,7 +843,7 @@ namespace cons
const bool hashfound = (cu_itr != ctx.candidate_user_outputs.end());
if (!hashfound)
{
LOG_ERR << "Output required but wasn't in our candidate outputs map, this will potentially cause desync.";
LOG_ERROR << "Output required but wasn't in our candidate outputs map, this will potentially cause desync.";
// todo: consider fatal
}
else
@@ -897,7 +897,7 @@ namespace cons
const bool hashfound = (itr != ctx.candidate_user_inputs.end());
if (!hashfound)
{
LOG_ERR << "input required but wasn't in our candidate inputs map, this will potentially cause desync.";
LOG_ERROR << "input required but wasn't in our candidate inputs map, this will potentially cause desync.";
// TODO: consider fatal
}
else
@@ -913,7 +913,7 @@ namespace cons
bufpair.inputs.push_back(std::move(inputtofeed));
// Remove the input from the candidate set because we no longer need it.
//LOG_DBG << "candidate input deleted.";
//LOG_DEBUG << "candidate input deleted.";
ctx.candidate_user_inputs.erase(itr);
}
}

View File

@@ -32,7 +32,7 @@ const std::tuple<const uint64_t, std::string> save_ledger(const p2p::proposal &p
else
{
//lcl records should follow [ledger sequnce numer]-lcl[lcl hex] format.
LOG_ERR << "Invalid lcl name: " << proposal.lcl << " when saving ledger.";
LOG_ERROR << "Invalid lcl name: " << proposal.lcl << " when saving ledger.";
}
//Serialize lcl using flatbuffer ledger schema.
@@ -162,11 +162,11 @@ const ledger_history load_ledger()
if (boost::filesystem::is_directory(file_path))
{
LOG_ERR << "Found directory " << file_name << " in " << conf::ctx.hist_dir << ". There should be no folders in this directory";
LOG_ERROR << "Found directory " << file_name << " in " << conf::ctx.hist_dir << ". There should be no folders in this directory";
}
else if (file_path.extension() != ".lcl")
{
LOG_ERR << "Found invalid file extension: " << file_path.extension() << " for lcl file " << file_name << " in " << conf::ctx.hist_dir;
LOG_ERROR << "Found invalid file extension: " << file_path.extension() << " for lcl file " << file_name << " in " << conf::ctx.hist_dir;
}
else
{
@@ -196,7 +196,7 @@ const ledger_history load_ledger()
else
{
//lcl records should follow [ledger sequnce numer]-lcl[lcl hex] format.
LOG_ERR << "Invalid lcl file name: " << file_name << " in " << conf::ctx.hist_dir;
LOG_ERROR << "Invalid lcl file name: " << file_name << " in " << conf::ctx.hist_dir;
}
}
}
@@ -239,7 +239,7 @@ void send_ledger_history_request(const std::string &minimum_lcl, const std::stri
ctx.last_requested_lcl = required_lcl;
LOG_DBG << "Ledger history request sent. Required lcl:" << required_lcl.substr(0, 15);
LOG_DEBUG << "Ledger history request sent. Required lcl:" << required_lcl.substr(0, 15);
}
/**
@@ -263,14 +263,14 @@ bool check_required_lcl_availability(const p2p::history_request &hr)
const auto itr = cons::ctx.ledger_cache.find(req_seq_no);
if (itr == cons::ctx.ledger_cache.end())
{
LOG_DBG << "Required lcl peer asked for is not in our lcl cache.";
LOG_DEBUG << "Required lcl peer asked for is not in our lcl cache.";
//either this node is also not in consesnsus ledger or other node requesting a lcl that is older than node's current
// minimum lcl sequence becuase of maximum ledger history range.
return false;
}
else if (itr->second.lcl != hr.required_lcl)
{
LOG_DBG << "Required lcl peer asked for is not in our lcl cache.";
LOG_DEBUG << "Required lcl peer asked for is not in our lcl cache.";
//either this node or requesting node is in a fork condition.
return false;
}
@@ -307,24 +307,24 @@ const p2p::history_response retrieve_ledger_history(const p2p::history_request &
//eventhough sequence number are same, lcl hash can be changed if one of node is in a fork condition.
if (hr.minimum_lcl != itr->second.lcl)
{
LOG_DBG << "Invalid minimum ledger. Recieved min hash: " << hr.minimum_lcl << " Node hash: " << itr->second.lcl;
LOG_DEBUG << "Invalid minimum ledger. Recieved min hash: " << hr.minimum_lcl << " Node hash: " << itr->second.lcl;
history_response.error = p2p::LEDGER_RESPONSE_ERROR::INVALID_MIN_LEDGER;
return history_response;
}
}
else if (min_seq_no > cons::ctx.ledger_cache.rbegin()->first) //Recieved minimum lcl sequence is ahead of node's lcl sequence.
{
LOG_DBG << "Invalid minimum ledger. Recieved minimum sequence number is ahead of node current lcl sequence. Recvd hash: " << hr.minimum_lcl;
LOG_DEBUG << "Invalid minimum ledger. Recieved minimum sequence number is ahead of node current lcl sequence. Recvd hash: " << hr.minimum_lcl;
history_response.error = p2p::LEDGER_RESPONSE_ERROR::INVALID_MIN_LEDGER;
return history_response;
}
else
{
LOG_DBG << "Minimum lcl peer asked for is not in our lcl cache. Therefore sending from node minimum lcl";
LOG_DEBUG << "Minimum lcl peer asked for is not in our lcl cache. Therefore sending from node minimum lcl";
min_seq_no = cons::ctx.ledger_cache.begin()->first;
}
//LOG_DBG << "history request min seq: " << std::to_string(min_seq_no);
//LOG_DEBUG << "history request min seq: " << std::to_string(min_seq_no);
//copy current history cache.
std::map<uint64_t, ledger_cache_entry> led_cache = cons::ctx.ledger_cache;
@@ -375,7 +375,7 @@ void handle_ledger_history_response(const p2p::history_response &hr)
//check response object contains
if (ctx.last_requested_lcl.empty())
{
LOG_DBG << "Peer sent us a history response but we never asked for one!";
LOG_DEBUG << "Peer sent us a history response but we never asked for one!";
return;
}
@@ -385,7 +385,7 @@ void handle_ledger_history_response(const p2p::history_response &hr)
// Basically in the long run we'll rolback one by one untill we catch up to valid minimum ledger .
remove_ledger(ctx.lcl);
cons::ctx.ledger_cache.erase(ctx.ledger_cache.rbegin()->first);
LOG_DBG << "Invalid min ledger. Removed last ledger.";
LOG_DEBUG << "Invalid min ledger. Removed last ledger.";
}
else
{
@@ -402,7 +402,7 @@ void handle_ledger_history_response(const p2p::history_response &hr)
if (!have_requested_lcl)
{
LOG_DBG << "Peer sent us a history response but not containing the lcl we asked for! " << hr.hist_ledgers.size();
LOG_DEBUG << "Peer sent us a history response but not containing the lcl we asked for! " << hr.hist_ledgers.size();
return;
}
@@ -423,12 +423,12 @@ void handle_ledger_history_response(const p2p::history_response &hr)
reinterpret_cast<const unsigned char *>(lcl.data()),
lcl.size());
//LOG_DBG << "passed lcl: " << ledger.lcl << " gen lcl: " << lcl_hash;
//LOG_DEBUG << "passed lcl: " << ledger.lcl << " gen lcl: " << lcl_hash;
//recieved lcl hash and hash generated from recieved lcl content doesn't match -> abandon applying it
if (lcl_hash != rec_lcl_hash)
{
LOG_WARN << "peer sent us a history response we asked for but the ledger data does not match the ledger hashes";
LOG_WARNING << "peer sent us a history response we asked for but the ledger data does not match the ledger hashes";
//todo: we should penalize peer who send this?
return;
}

View File

@@ -16,7 +16,7 @@ namespace hpfs
int init()
{
active_hpfs_trace_arg = (conf::cfg.loglevel == "debug" ? HPFS_TRACE_ARG_DEBUG : HPFS_TRACE_ARG_ERROR);
active_hpfs_trace_arg = (conf::cfg.loglevel_type == conf::LOG_SEVERITY::DEBUG ? HPFS_TRACE_ARG_DEBUG : HPFS_TRACE_ARG_ERROR);
LOG_INFO << "Starting hpfs merge process...";
if (start_merge_process() == -1)
@@ -67,12 +67,12 @@ namespace hpfs
NULL};
const int ret = execv(execv_args[0], execv_args);
LOG_ERR << errno << ": hpfs merge process execv failed.";
LOG_ERROR << errno << ": hpfs merge process execv failed.";
exit(1);
}
else
{
LOG_ERR << errno << ": fork() failed when starting hpfs merge process.";
LOG_ERROR << errno << ": fork() failed when starting hpfs merge process.";
return -1;
}
@@ -87,7 +87,7 @@ namespace hpfs
if (pid > 0)
{
// HotPocket process.
LOG_DBG << "Starting hpfs " << mode << " session...";
LOG_DEBUG << "Starting hpfs " << mode << " session...";
// If the mount dir is not specified, assign a mount dir based on hpfs process id.
if (mount_dir.empty())
@@ -112,7 +112,7 @@ namespace hpfs
// Sending signal 0 to test whether process exist.
if (util::kill_process(pid, false, 0) == -1)
{
LOG_ERR << "hpfs process " << pid << " has stopped.";
LOG_ERROR << "hpfs process " << pid << " has stopped.";
break;
}
@@ -126,7 +126,7 @@ namespace hpfs
// When hpfs is fully initialized we should receive some file from check_path.
if (!hpfs_initialized && errno != ENOENT)
{
LOG_ERR << errno << ": Error in checking hpfs status.";
LOG_ERROR << errno << ": Error in checking hpfs status.";
break;
}
@@ -135,7 +135,7 @@ namespace hpfs
// Kill the process if hpfs couldn't be initialized after the wait period.
if (!hpfs_initialized)
{
LOG_ERR << "Couldn't initialize hpfs session.";
LOG_ERROR << "Couldn't initialize hpfs session.";
util::kill_process(pid, true);
return -1;
}
@@ -165,12 +165,12 @@ namespace hpfs
NULL};
const int ret = execv(execv_args[0], execv_args);
LOG_ERR << errno << ": hpfs session process execv failed.";
LOG_ERROR << errno << ": hpfs session process execv failed.";
exit(1);
}
else
{
LOG_ERR << errno << ": fork() failed when starting hpfs session process.";
LOG_ERROR << errno << ": fork() failed when starting hpfs session process.";
return -1;
}
@@ -187,12 +187,12 @@ namespace hpfs
const int fd = open(path.c_str(), O_RDONLY | O_CLOEXEC);
if (fd == -1 && errno == ENOENT)
{
LOG_DBG << "Cannot get hash. vpath not found. " << vpath;
LOG_DEBUG << "Cannot get hash. vpath not found. " << vpath;
return 0;
}
else if (fd == -1)
{
LOG_ERR << errno << ": Error opening hash file. " << vpath;
LOG_ERROR << errno << ": Error opening hash file. " << vpath;
return -1;
}
@@ -200,7 +200,7 @@ namespace hpfs
close(fd);
if (res == -1)
{
LOG_ERR << errno << ": Error reading hash file. " << vpath;
LOG_ERROR << errno << ": Error reading hash file. " << vpath;
return -1;
}
return 1;
@@ -216,12 +216,12 @@ namespace hpfs
const int fd = open(path.c_str(), O_RDONLY | O_CLOEXEC);
if (fd == -1 && errno == ENOENT)
{
LOG_DBG << "Cannot get file block hashes. vpath not found. " << vpath;
LOG_DEBUG << "Cannot get file block hashes. vpath not found. " << vpath;
return 0;
}
else if (fd == -1)
{
LOG_DBG << errno << ": Error opening hashmap children. " << vpath;
LOG_DEBUG << errno << ": Error opening hashmap children. " << vpath;
return -1;
}
@@ -229,7 +229,7 @@ namespace hpfs
if (fstat(fd, &st) == -1)
{
close(fd);
LOG_ERR << errno << ": Error reading block hashes length. " << vpath;
LOG_ERROR << errno << ": Error reading block hashes length. " << vpath;
return -1;
}
@@ -240,7 +240,7 @@ namespace hpfs
close(fd);
if (res == -1)
{
LOG_ERR << errno << ": Error reading block hashes. " << vpath;
LOG_ERROR << errno << ": Error reading block hashes. " << vpath;
return -1;
}
return 1;
@@ -256,12 +256,12 @@ namespace hpfs
const int fd = open(path.c_str(), O_RDONLY | O_CLOEXEC);
if (fd == -1 && errno == ENOENT)
{
LOG_DBG << "Cannot get dir children hashes. Dir vpath not found. " << dir_vpath;
LOG_DEBUG << "Cannot get dir children hashes. Dir vpath not found. " << dir_vpath;
return 0;
}
else if (fd == -1)
{
LOG_ERR << errno << ": Error opening dir hash children nodes. " << dir_vpath;
LOG_ERROR << errno << ": Error opening dir hash children nodes. " << dir_vpath;
return -1;
}
@@ -269,7 +269,7 @@ namespace hpfs
if (fstat(fd, &st) == -1)
{
close(fd);
LOG_ERR << errno << ": Error reading hash children nodes length. " << dir_vpath;
LOG_ERROR << errno << ": Error reading hash children nodes length. " << dir_vpath;
return -1;
}
@@ -280,7 +280,7 @@ namespace hpfs
close(fd);
if (res == -1)
{
LOG_ERR << errno << ": Error reading hash children nodes. " << dir_vpath;
LOG_ERROR << errno << ": Error reading hash children nodes. " << dir_vpath;
return -1;
}
return 1;

View File

@@ -2,89 +2,66 @@
#include "conf.hpp"
#include "hplog.hpp"
namespace logging = boost::log;
namespace sinks = boost::log::sinks;
namespace src = boost::log::sources;
namespace expr = boost::log::expressions;
namespace attrs = boost::log::attributes;
namespace keywords = boost::log::keywords;
namespace hplog
{
constexpr size_t MAX_TRACE_FILESIZE = 10 * 1024 * 1024; // Maximum file size (10MB)
constexpr size_t MAX_TRACE_FILECOUNT = 50; // Maximum files in a folder
/**
* Stream operator overload for converting integer severity value to text.
*/
std::ostream &operator<<(std::ostream &os, LOG_SEVERITY level)
class plog_formatter;
// Custom formatter adopted from:
// https://github.com/SergiusTheBest/plog/blob/master/include/plog/Formatters/TxtFormatter.h
class plog_formatter
{
static std::string_view loglevels[] = {"dbg", "inf", "wrn", "err"};
os << loglevels[level];
return os;
}
public:
static plog::util::nstring header()
{
return plog::util::nstring();
}
// Severity attribute value tag type
struct severity_tag;
static plog::util::nstring format(const plog::Record &record)
{
tm t;
plog::util::localtime_s(&t, &record.getTime().time); // local time
plog::util::nostringstream ss;
ss << t.tm_year + 1900 << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_mon + 1 << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_mday << PLOG_NSTR(" ");
ss << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_hour << PLOG_NSTR(":") << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_min << PLOG_NSTR(":") << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_sec << PLOG_NSTR(" ");
ss << PLOG_NSTR("[") << conf::cfg.loglevel << PLOG_NSTR("][hp] ");
ss << record.getMessage() << PLOG_NSTR("\n");
return ss.str();
}
};
void init()
{
// Set log severity level based on contract config.
LOG_SEVERITY severity = LOG_SEVERITY::WARN;
if (conf::cfg.loglevel == "debug")
severity = LOG_SEVERITY::DEBUG;
else if (conf::cfg.loglevel == "info")
severity = LOG_SEVERITY::INFO;
else if (conf::cfg.loglevel == "warn")
severity = LOG_SEVERITY::WARN;
else if (conf::cfg.loglevel == "error")
severity = LOG_SEVERITY::ERROR;
plog::Severity level;
// Log line format expression.
const auto format_expr = (expr::stream
<< expr::format_date_time<boost::posix_time::ptime>("TimeStamp", "%Y%m%d %H:%M:%S ")
// << ":" << expr::attr<boost::log::attributes::current_thread_id::value_type>("ThreadID")
// << "[" << expr::attr<std::string>("Channel") << "] "
<< "[" << expr::attr<LOG_SEVERITY, severity_tag>("Severity") << "][hp] "
<< expr::smessage);
if (conf::cfg.loglevel_type == conf::LOG_SEVERITY::DEBUG)
level = plog::Severity::debug;
else if (conf::cfg.loglevel_type == conf::LOG_SEVERITY::INFO)
level = plog::Severity::info;
else if (conf::cfg.loglevel_type == conf::LOG_SEVERITY::WARN)
level = plog::Severity::warning;
else
level = plog::Severity::error;
const std::string trace_file = conf::ctx.log_dir + "/hp.log";
static plog::RollingFileAppender<plog_formatter> fileAppender(trace_file.c_str(), MAX_TRACE_FILESIZE, MAX_TRACE_FILECOUNT);
static plog::ConsoleAppender<plog_formatter> consoleAppender;
plog::Logger<0> &logger = plog::init(level);
// Take decision to append logger for file / console or both.
if (conf::cfg.loggers.count("console") == 1)
{
logging::add_console_log(
std::clog,
keywords::filter = (a_severity >= severity),
keywords::format = format_expr);
logger.addAppender(&consoleAppender);
}
if (conf::cfg.loggers.count("file") == 1)
{
logging::add_file_log(
keywords::target = conf::ctx.log_dir, // Log file directory.
keywords::file_name = conf::ctx.log_dir + "/hp_%N.log", // File name pattern "hp_1.log".
keywords::rotation_size = 10 * 1024 * 1024, // Rotate files every 10 MB.
keywords::max_size = 500 * 1024 * 1024, // Do not exceed 500 MB total logs.
keywords::filter = (a_severity >= severity),
keywords::format = format_expr,
// This will make every new launch of Hot Pocket to start a new log file number.
// It will scan existing log files matching the pattern and find the next number.
keywords::scan_method = sinks::file::scan_matching
#ifndef NDEBUG
// We enable auto_flush to immediately get the logs onto the file. Otherwise it takes time
// for buffered logs to reach the file. This impacts performance. So enabled only in debug build.
,
keywords::auto_flush = true
#endif
);
logger.addAppender(&fileAppender);
}
// Add Boost Log built-in fields for log entries.
logging::add_common_attributes();
}
void deinit()
{
// This will make all buffered logs to be flushed to the sink.
logging::core::get()->remove_all_sinks();
}
} // namespace hplog

View File

@@ -1,54 +1,9 @@
#ifndef _HP_HPLOG_
#define _HP_HPLOG_
#include "pchheader.hpp"
#include "conf.hpp"
namespace src = boost::log::sources;
namespace keywords = boost::log::keywords;
namespace hplog
{
// Log severity levels used in Hot Pocket.
enum LOG_SEVERITY
{
DEBUG,
INFO,
WARN,
ERROR
};
BOOST_LOG_ATTRIBUTE_KEYWORD(a_severity, "Severity", hplog::LOG_SEVERITY);
void init();
void deinit();
void init();
} // namespace hplog
// Thread-safe global logger type using custom LOG_SEVERITY enum..
typedef src::severity_channel_logger_mt<hplog::LOG_SEVERITY, std::string> logger;
// hplogger is the log source for Hot Pocket generated logs.
BOOST_LOG_INLINE_GLOBAL_LOGGER_INIT(hplogger, logger)
{
return logger(keywords::channel = "hp");
}
// sclogger is the log source for logging captured stdour/stderr from smart contract.
BOOST_LOG_INLINE_GLOBAL_LOGGER_INIT(sclogger, logger)
{
return logger(keywords::channel = "sc");
}
// HP logging macros.
#define LOG_DBG BOOST_LOG_SEV(hplogger::get(), hplog::LOG_SEVERITY::DEBUG)
#define LOG_INFO BOOST_LOG_SEV(hplogger::get(), hplog::LOG_SEVERITY::INFO)
#define LOG_WARN BOOST_LOG_SEV(hplogger::get(), hplog::LOG_SEVERITY::WARN)
#define LOG_ERR BOOST_LOG_SEV(hplogger::get(), hplog::LOG_SEVERITY::ERROR)
// SC stdout/err logging macros.
#define LOG_INFO_SC BOOST_LOG_SEV(sclogger::get(), hplog::LOG_SEVERITY::INFO)
#define LOG_ERR_SC BOOST_LOG_SEV(sclogger::get(), hplog::LOG_SEVERITY::ERROR)
#endif

View File

@@ -74,12 +74,11 @@ void deinit()
usr::deinit();
p2p::deinit();
hpfs::deinit();
hplog::deinit();
}
void sigint_handler(int signum)
{
LOG_WARN << "Interrupt signal (" << signum << ") received.";
LOG_WARNING << "Interrupt signal (" << signum << ") received.";
deinit();
std::cout << "hpcore exiting\n";
exit(signum);
@@ -105,19 +104,19 @@ void std_terminate() noexcept
}
catch (std::exception &ex)
{
LOG_ERR << "std error: " << ex.what();
LOG_ERROR << "std error: " << ex.what();
}
catch (...)
{
LOG_ERR << "std error: Terminated due to unknown exception";
LOG_ERROR << "std error: Terminated due to unknown exception";
}
}
else
{
LOG_ERR << "std error: Terminated due to unknown reason";
LOG_ERROR << "std error: Terminated due to unknown reason";
}
LOG_ERR << boost::stacktrace::stacktrace();
LOG_ERROR << boost::stacktrace::stacktrace();
exit(1);
}

View File

@@ -130,13 +130,13 @@ namespace msg::usrmsg::bson
}
catch (const std::exception &e)
{
LOG_DBG << "User bson message parsing failed.";
LOG_DEBUG << "User bson message parsing failed.";
return -1;
}
if (!d.contains(FLD_TYPE) || !d[FLD_TYPE].is_string())
{
LOG_DBG << "User bson message 'type' missing or invalid.";
LOG_DEBUG << "User bson message 'type' missing or invalid.";
return -1;
}
@@ -168,7 +168,7 @@ namespace msg::usrmsg::bson
{
if (!d.contains(msg::usrmsg::FLD_CONTENT) || !d[msg::usrmsg::FLD_CONTENT].is_byte_string_view())
{
LOG_DBG << "Read request 'content' field missing or invalid.";
LOG_DEBUG << "Read request 'content' field missing or invalid.";
return -1;
}
@@ -197,7 +197,7 @@ namespace msg::usrmsg::bson
if (!d.contains(msg::usrmsg::FLD_INPUT_CONTAINER) || !d.contains(msg::usrmsg::FLD_SIG) ||
!d[msg::usrmsg::FLD_INPUT_CONTAINER].is_byte_string_view() || !d[msg::usrmsg::FLD_SIG].is_byte_string_view())
{
LOG_DBG << "User signed input required fields missing or invalid.";
LOG_DEBUG << "User signed input required fields missing or invalid.";
return -1;
}
@@ -232,14 +232,14 @@ namespace msg::usrmsg::bson
}
catch (const std::exception &e)
{
LOG_DBG << "User input container bson parsing failed.";
LOG_DEBUG << "User input container bson parsing failed.";
return -1;
}
if (!d.contains(msg::usrmsg::FLD_INPUT) || !d.contains(msg::usrmsg::FLD_NONCE) || !d.contains(msg::usrmsg::FLD_MAX_LCL_SEQ) ||
!d[msg::usrmsg::FLD_INPUT].is_byte_string_view() || !d[msg::usrmsg::FLD_NONCE].is_string() || !d[msg::usrmsg::FLD_MAX_LCL_SEQ].is_uint64())
{
LOG_DBG << "User input container required fields missing or invalid.";
LOG_DEBUG << "User input container required fields missing or invalid.";
return -1;
}

View File

@@ -57,7 +57,7 @@ namespace msg::fbuf::p2pmsg
//Verify container message using flatbuffer verifier
if (!VerifyContainerBuffer(container_verifier))
{
LOG_DBG << "Flatbuffer verify: Bad peer message container.";
LOG_DEBUG << "Flatbuffer verify: Bad peer message container.";
return -1;
}
@@ -68,7 +68,7 @@ namespace msg::fbuf::p2pmsg
const uint16_t version = container->version();
if (version < util::MIN_PEERMSG_VERSION)
{
LOG_DBG << "Peer message is from unsupported protocol version (" << version << ").";
LOG_DEBUG << "Peer message is from unsupported protocol version (" << version << ").";
return -1;
}
@@ -78,7 +78,7 @@ namespace msg::fbuf::p2pmsg
const int64_t time_now = util::get_epoch_milliseconds();
if (container->timestamp() < (time_now - conf::cfg.roundtime * 4))
{
LOG_DBG << "Peer message is too old.";
LOG_DEBUG << "Peer message is too old.";
return -1;
}
}
@@ -99,14 +99,14 @@ namespace msg::fbuf::p2pmsg
if (msg_pubkey.empty() || msg_sig.empty())
{
LOG_DBG << "Peer message key pair incomplete. Trust verification failed.";
LOG_DEBUG << "Peer message key pair incomplete. Trust verification failed.";
return -1;
}
//validate if the message is not from a node of current node's unl list.
if (!conf::cfg.unl.count(std::string(msg_pubkey)))
{
LOG_DBG << "Peer message pubkey verification failed. Not in UNL.";
LOG_DEBUG << "Peer message pubkey verification failed. Not in UNL.";
return -1;
}
@@ -116,7 +116,7 @@ namespace msg::fbuf::p2pmsg
if (crypto::verify(msg_content, msg_sig, msg_pubkey) != 0)
{
LOG_DBG << "Peer message signature verification failed.";
LOG_DEBUG << "Peer message signature verification failed.";
return -1;
}
@@ -141,7 +141,7 @@ namespace msg::fbuf::p2pmsg
//verify content message using flatbuffer verifier.
if (!VerifyContainerBuffer(content_verifier))
{
LOG_DBG << "Flatbuffer verify: Bad content.";
LOG_DEBUG << "Flatbuffer verify: Bad content.";
return -1;
}

View File

@@ -228,28 +228,28 @@ namespace msg::usrmsg::json
// Validate msg type.
if (d[msg::usrmsg::FLD_TYPE] != msg::usrmsg::MSGTYPE_HANDSHAKE_RESPONSE)
{
LOG_DBG << "User handshake response type invalid. 'handshake_response' expected.";
LOG_DEBUG << "User handshake response type invalid. 'handshake_response' expected.";
return -1;
}
// Compare the response handshake string with the original issued challenge.
if (!d.contains(msg::usrmsg::FLD_CHALLENGE) || d[msg::usrmsg::FLD_CHALLENGE] != original_challenge.data())
{
LOG_DBG << "User handshake response 'challenge' invalid.";
LOG_DEBUG << "User handshake response 'challenge' invalid.";
return -1;
}
// Check for the 'sig' field existence.
if (!d.contains(msg::usrmsg::FLD_SIG) || !d[msg::usrmsg::FLD_SIG].is<std::string>())
{
LOG_DBG << "User handshake response 'challenge signature' invalid.";
LOG_DEBUG << "User handshake response 'challenge signature' invalid.";
return -1;
}
// Check for the 'pubkey' field existence.
if (!d.contains(msg::usrmsg::FLD_PUBKEY) || !d[msg::usrmsg::FLD_PUBKEY].is<std::string>())
{
LOG_DBG << "User handshake response 'public key' invalid.";
LOG_DEBUG << "User handshake response 'public key' invalid.";
return -1;
}
@@ -257,14 +257,14 @@ namespace msg::usrmsg::json
if (!d.contains(msg::usrmsg::FLD_PROTOCOL) || !d[msg::usrmsg::FLD_PROTOCOL].is<std::string>())
{
LOG_DBG << "User handshake response 'protocol' invalid.";
LOG_DEBUG << "User handshake response 'protocol' invalid.";
return -1;
}
std::string_view protocolsv = d[msg::usrmsg::FLD_PROTOCOL].as<std::string_view>();
if (protocolsv != "json" && protocolsv != "bson")
{
LOG_DBG << "User handshake response 'protocol' type invalid.";
LOG_DEBUG << "User handshake response 'protocol' type invalid.";
return -1;
}
@@ -275,7 +275,7 @@ namespace msg::usrmsg::json
d[msg::usrmsg::FLD_SIG].as<std::string_view>(),
pubkeysv) != 0)
{
LOG_DBG << "User challenge response signature verification failed.";
LOG_DEBUG << "User challenge response signature verification failed.";
return -1;
}
@@ -304,14 +304,14 @@ namespace msg::usrmsg::json
}
catch(const std::exception& e)
{
LOG_DBG << "User json message parsing failed.";
LOG_DEBUG << "User json message parsing failed.";
return -1;
}
// Check existence of msg type field.
if (!d.contains(msg::usrmsg::FLD_TYPE) || !d[msg::usrmsg::FLD_TYPE].is<std::string>())
{
LOG_DBG << "User json message 'type' missing or invalid.";
LOG_DEBUG << "User json message 'type' missing or invalid.";
return -1;
}
@@ -343,13 +343,13 @@ namespace msg::usrmsg::json
{
if (!d.contains(msg::usrmsg::FLD_CONTENT))
{
LOG_DBG << "Read request required fields missing.";
LOG_DEBUG << "Read request required fields missing.";
return -1;
}
if (!d[msg::usrmsg::FLD_CONTENT].is<std::string>())
{
LOG_DBG << "Read request invalid field values.";
LOG_DEBUG << "Read request invalid field values.";
return -1;
}
@@ -362,7 +362,7 @@ namespace msg::usrmsg::json
content.length(),
contenthex) != 0)
{
LOG_DBG << "Read request format invalid.";
LOG_DEBUG << "Read request format invalid.";
return -1;
}
@@ -389,13 +389,13 @@ namespace msg::usrmsg::json
{
if (!d.contains(msg::usrmsg::FLD_INPUT_CONTAINER) || !d.contains(msg::usrmsg::FLD_SIG))
{
LOG_DBG << "User signed input required fields missing.";
LOG_DEBUG << "User signed input required fields missing.";
return -1;
}
if (!d[msg::usrmsg::FLD_INPUT_CONTAINER].is<std::string>() || !d[msg::usrmsg::FLD_SIG].is<std::string>())
{
LOG_DBG << "User signed input invalid field values.";
LOG_DEBUG << "User signed input invalid field values.";
return -1;
}
@@ -439,19 +439,19 @@ namespace msg::usrmsg::json
}
catch(const std::exception& e)
{
LOG_DBG << "User input container json parsing failed.";
LOG_DEBUG << "User input container json parsing failed.";
return -1;
}
if (!d.contains(msg::usrmsg::FLD_INPUT) || !d.contains(msg::usrmsg::FLD_NONCE) || !d.contains(msg::usrmsg::FLD_MAX_LCL_SEQ))
{
LOG_DBG << "User input container required fields missing.";
LOG_DEBUG << "User input container required fields missing.";
return -1;
}
if (!d[msg::usrmsg::FLD_INPUT].is<std::string>() || !d[msg::usrmsg::FLD_NONCE].is<std::string>() || !d[msg::usrmsg::FLD_MAX_LCL_SEQ].is<uint64_t>())
{
LOG_DBG << "User input container invalid field values.";
LOG_DEBUG << "User input container invalid field values.";
return -1;
}
@@ -464,7 +464,7 @@ namespace msg::usrmsg::json
input.length(),
inputhex) != 0)
{
LOG_DBG << "Contract input format invalid.";
LOG_DEBUG << "Contract input format invalid.";
return -1;
}

View File

@@ -61,7 +61,7 @@ namespace p2p
// Compare the response challenge string with the original issued challenge.
if (session.issued_challenge != challenge_resp.challenge)
{
LOG_DBG << "Peer challenge response, challenge invalid.";
LOG_DEBUG << "Peer challenge response, challenge invalid.";
return -1;
}
@@ -71,7 +71,7 @@ namespace p2p
challenge_resp.signature,
challenge_resp.pubkey) != 0)
{
LOG_DBG << "Peer challenge response signature verification failed.";
LOG_DEBUG << "Peer challenge response signature verification failed.";
return -1;
}
@@ -128,7 +128,7 @@ namespace p2p
p2p::ctx.peer_connections.erase(iter); // remove existing session.
p2p::ctx.peer_connections.try_emplace(session.uniqueid, &session); // add new session.
LOG_DBG << "Replacing existing connection [" << session.uniqueid.substr(0, 10) << "]";
LOG_DEBUG << "Replacing existing connection [" << session.uniqueid.substr(0, 10) << "]";
return 0;
}
else if (ex_session.known_ipport.first.empty() || !session.known_ipport.first.empty())
@@ -139,7 +139,7 @@ namespace p2p
}
// Reaching this point means we don't need the new session.
LOG_DBG << "Rejecting new peer connection because existing connection takes priority [" << pubkeyhex.substr(0, 10) << "]";
LOG_DEBUG << "Rejecting new peer connection because existing connection takes priority [" << pubkeyhex.substr(0, 10) << "]";
return -1;
}
}
@@ -153,7 +153,7 @@ namespace p2p
{
if (ctx.peer_connections.size() == 0)
{
LOG_DBG << "No peers to broadcast (not even self). Cannot broadcast.";
LOG_DEBUG << "No peers to broadcast (not even self). Cannot broadcast.";
return;
}
@@ -204,12 +204,12 @@ namespace p2p
const size_t connected_peers = ctx.peer_connections.size();
if (connected_peers == 0)
{
LOG_DBG << "No peers to random send.";
LOG_DEBUG << "No peers to random send.";
return;
}
else if (connected_peers == 1 && ctx.peer_connections.begin()->second->is_self)
{
LOG_DBG << "Only self is connected. Cannot random send.";
LOG_DEBUG << "Only self is connected. Cannot random send.";
return;
}

View File

@@ -33,7 +33,7 @@ namespace p2p
// Limit max number of inbound connections.
if (conf::cfg.peermaxcons > 0 && ctx.peer_connections.size() >= conf::cfg.peermaxcons)
{
LOG_DBG << "Max peer connections reached. Dropped connection " << session.uniqueid.substr(0, 10);
LOG_DEBUG << "Max peer connections reached. Dropped connection " << session.uniqueid.substr(0, 10);
return -1;
}
}
@@ -70,7 +70,7 @@ namespace p2p
if (!recent_peermsg_hashes.try_emplace(crypto::get_hash(message)))
{
session.increment_metric(comm::SESSION_THRESHOLDS::MAX_DUPMSGS_PER_MINUTE, 1);
LOG_DBG << "Duplicate peer message. " << session.uniqueid.substr(0, 10);
LOG_DEBUG << "Duplicate peer message. " << session.uniqueid.substr(0, 10);
return 0;
}
@@ -99,7 +99,7 @@ namespace p2p
if (session.challenge_status != comm::CHALLENGE_VERIFIED)
{
LOG_DBG << "Cannot accept messages. Peer challenge unresolved. " << session.uniqueid.substr(0, 10);
LOG_DEBUG << "Cannot accept messages. Peer challenge unresolved. " << session.uniqueid.substr(0, 10);
return 0;
}
@@ -109,7 +109,7 @@ namespace p2p
if (p2pmsg::validate_container_trust(container) != 0)
{
session.increment_metric(comm::SESSION_THRESHOLDS::MAX_BADSIGMSGS_PER_MINUTE, 1);
LOG_DBG << "Proposal rejected due to trust failure. " << session.uniqueid.substr(0, 10);
LOG_DEBUG << "Proposal rejected due to trust failure. " << session.uniqueid.substr(0, 10);
return 0;
}
@@ -129,7 +129,7 @@ namespace p2p
{
if (p2pmsg::validate_container_trust(container) != 0)
{
LOG_DBG << "NPL message rejected due to trust failure. " << session.uniqueid.substr(0, 10);
LOG_DEBUG << "NPL message rejected due to trust failure. " << session.uniqueid.substr(0, 10);
return 0;
}
@@ -146,7 +146,7 @@ namespace p2p
{
if (p2pmsg::validate_container_trust(container) != 0)
{
LOG_DBG << "State request message rejected due to trust failure. " << session.uniqueid.substr(0, 10);
LOG_DEBUG << "State request message rejected due to trust failure. " << session.uniqueid.substr(0, 10);
return 0;
}
@@ -159,7 +159,7 @@ namespace p2p
{
if (p2pmsg::validate_container_trust(container) != 0)
{
LOG_DBG << "State response message rejected due to trust failure. " << session.uniqueid.substr(0, 10);
LOG_DEBUG << "State response message rejected due to trust failure. " << session.uniqueid.substr(0, 10);
return 0;
}
@@ -175,7 +175,7 @@ namespace p2p
{
if (p2pmsg::validate_container_trust(container) != 0)
{
LOG_DBG << "History request message rejected due to trust failure. " << session.uniqueid.substr(0, 10);
LOG_DEBUG << "History request message rejected due to trust failure. " << session.uniqueid.substr(0, 10);
return 0;
}
@@ -196,7 +196,7 @@ namespace p2p
{
if (p2pmsg::validate_container_trust(container) != 0)
{
LOG_DBG << "History response message rejected due to trust failure. " << session.uniqueid.substr(0, 10);
LOG_DEBUG << "History response message rejected due to trust failure. " << session.uniqueid.substr(0, 10);
return 0;
}
@@ -206,7 +206,7 @@ namespace p2p
else
{
session.increment_metric(comm::SESSION_THRESHOLDS::MAX_BADMSGS_PER_MINUTE, 1);
LOG_DBG << "Received invalid peer message type. " << session.uniqueid.substr(0, 10);
LOG_DEBUG << "Received invalid peer message type. " << session.uniqueid.substr(0, 10);
}
return 0;
}

View File

@@ -6,18 +6,6 @@
#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>
#include <boost/log/core.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/expressions/keyword.hpp>
#include <boost/log/expressions/keyword_fwd.hpp>
#include <boost/log/sources/global_logger_storage.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/sources/severity_channel_logger.hpp>
#include <boost/log/support/date_time.hpp>
#include <boost/log/utility/manipulators/to_log.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/utility/setup/console.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/stacktrace.hpp>
#include <chrono>
#include <cstdio>
@@ -54,5 +42,7 @@
#include <vector>
#include <blake3.h>
#include <concurrentqueue.h>
#include <plog/Log.h>
#include <plog/Appenders/ColorConsoleAppender.h>
#endif

View File

@@ -50,14 +50,14 @@ namespace sc
const int presult = await_process_execution(ctx.contract_pid);
ctx.contract_pid = 0;
LOG_DBG << "Contract process ended." << (ctx.args.readonly ? " (rdonly)" : "");
LOG_DEBUG << "Contract process ended." << (ctx.args.readonly ? " (rdonly)" : "");
// Wait for the output collection thread to gracefully stop.
ctx.output_fetcher_thread.join();
if (presult != 0)
{
LOG_ERR << "Contract process exited with non-normal status code: " << presult;
LOG_ERROR << "Contract process exited with non-normal status code: " << presult;
goto failure;
}
}
@@ -74,7 +74,7 @@ namespace sc
// Write the contract input message from HotPocket to the stdin (0) of the contract process.
write_contract_args(ctx);
LOG_DBG << "Starting contract process..." << (ctx.args.readonly ? " (rdonly)" : "");
LOG_DEBUG << "Starting contract process..." << (ctx.args.readonly ? " (rdonly)" : "");
const bool using_appbill = !ctx.args.readonly && !conf::cfg.appbill.empty();
int len = conf::cfg.runtime_binexec_args.size() + 1;
@@ -97,12 +97,12 @@ namespace sc
chdir(ctx.args.state_dir.c_str());
int ret = execv(execv_args[0], execv_args);
LOG_ERR << errno << ": Contract process execv failed." << (ctx.args.readonly ? " (rdonly)" : "");
LOG_ERROR << errno << ": Contract process execv failed." << (ctx.args.readonly ? " (rdonly)" : "");
exit(1);
}
else
{
LOG_ERR << errno << ": fork() failed when starting contract process." << (ctx.args.readonly ? " (rdonly)" : "");
LOG_ERROR << errno << ": fork() failed when starting contract process." << (ctx.args.readonly ? " (rdonly)" : "");
goto failure;
}
@@ -146,7 +146,7 @@ namespace sc
if (hpfs::start_fs_session(ctx.hpfs_pid, ctx.args.state_dir, ctx.args.readonly ? "ro" : "rw", true) == -1)
return -1;
LOG_DBG << "hpfs session started. pid:" << ctx.hpfs_pid << (ctx.args.readonly ? " (rdonly)" : "");
LOG_DEBUG << "hpfs session started. pid:" << ctx.hpfs_pid << (ctx.args.readonly ? " (rdonly)" : "");
return 0;
}
@@ -159,8 +159,8 @@ namespace sc
if (!ctx.args.readonly && hpfs::get_hash(ctx.args.post_execution_state_hash, ctx.args.state_dir, "/") < 1)
return -1;
LOG_DBG << "Stopping hpfs session... pid:" << ctx.hpfs_pid << (ctx.args.readonly ? " (rdonly)" : "");
LOG_DEBUG << "Stopping hpfs session... pid:" << ctx.hpfs_pid << (ctx.args.readonly ? " (rdonly)" : "");
if (util::kill_process(ctx.hpfs_pid, true) == -1)
return -1;
@@ -232,7 +232,7 @@ namespace sc
int stdinpipe[2];
if (pipe(stdinpipe) == -1)
{
LOG_ERR << errno << ": Failed to create pipe to the contract process.";
LOG_ERROR << errno << ": Failed to create pipe to the contract process.";
return -1;
}
@@ -244,7 +244,7 @@ namespace sc
// Write the json message and close write fd.
if (write(stdinpipe[1], json.data(), json.size()) == -1)
{
LOG_ERR << errno << ": Failed to write to stdin of contract process.";
LOG_ERROR << errno << ": Failed to write to stdin of contract process.";
return -1;
}
close(stdinpipe[1]);
@@ -265,7 +265,7 @@ namespace sc
// Write any verified (consensus-reached) user inputs to user pipes.
if (write_contract_fdmap_inputs(ctx.userfds, ctx.args.userbufs) == -1)
{
LOG_ERR << "Failed to write user inputs to contract.";
LOG_ERROR << "Failed to write user inputs to contract.";
return -1;
}
@@ -288,7 +288,7 @@ namespace sc
const int user_res = read_contract_fdmap_outputs(ctx.userfds, ctx.args.userbufs);
if (user_res == -1)
{
LOG_ERR << "Error reading user outputs from the contract.";
LOG_ERROR << "Error reading user outputs from the contract.";
return -1;
}
@@ -299,7 +299,7 @@ namespace sc
util::sleep(20);
}
LOG_DBG << "Contract outputs collected.\n";
LOG_DEBUG << "Contract outputs collected.";
return 0;
}
@@ -310,7 +310,7 @@ namespace sc
{
if (write_iopipe(ctx.hpscfds, ctx.args.hpscbufs.inputs) == -1)
{
LOG_ERR << "Error writing HP inputs to SC";
LOG_ERROR << "Error writing HP inputs to SC";
return -1;
}
@@ -390,14 +390,14 @@ namespace sc
const int hpsc_res = read_iopipe(ctx.hpscfds, ctx.args.hpscbufs.output);
if (hpsc_res == -1)
{
LOG_ERR << "Error reading HP output from the contract.";
LOG_ERROR << "Error reading HP output from the contract.";
return -1;
}
const int npl_res = read_iopipe(ctx.nplfds, ctx.args.npl_output);
if (npl_res == -1)
{
LOG_ERR << "Error reading NPL output from the contract.";
LOG_ERROR << "Error reading NPL output from the contract.";
return -1;
}

View File

@@ -113,7 +113,7 @@ namespace state_serve
*/
int create_state_response(flatbuffers::FlatBufferBuilder &fbuf, const p2p::state_request &sr)
{
LOG_DBG << "Serving state req. path:" << sr.parent_path << " block_id:" << sr.block_id;
LOG_DEBUG << "Serving state req. path:" << sr.parent_path << " block_id:" << sr.block_id;
// If block_id > -1 this means this is a file block data request.
if (sr.block_id > -1)
@@ -125,7 +125,7 @@ namespace state_serve
if (result == -1)
{
LOG_ERR << "Error in getting file block: " << sr.parent_path;
LOG_ERROR << "Error in getting file block: " << sr.parent_path;
return -1;
}
else if (result == 1)
@@ -151,7 +151,7 @@ namespace state_serve
if (result == -1)
{
LOG_ERR << "Error in getting block hashes: " << sr.parent_path;
LOG_ERROR << "Error in getting block hashes: " << sr.parent_path;
return -1;
}
else if (result == 1)
@@ -171,7 +171,7 @@ namespace state_serve
if (result == -1)
{
LOG_ERR << "Error in getting fs entries: " << sr.parent_path;
LOG_ERROR << "Error in getting fs entries: " << sr.parent_path;
return -1;
}
else if (result == 1)
@@ -183,7 +183,7 @@ namespace state_serve
}
}
LOG_DBG << "No state response generated.";
LOG_DEBUG << "No state response generated.";
return 0;
}
@@ -206,12 +206,12 @@ namespace state_serve
{
if (block_id >= block_hashes.size())
{
LOG_DBG << "Requested block_id " << block_id << " does not exist.";
LOG_DEBUG << "Requested block_id " << block_id << " does not exist.";
result = 0;
}
else if (block_hashes[block_id] != expected_hash)
{
LOG_DBG << "Expected hash mismatch.";
LOG_DEBUG << "Expected hash mismatch.";
result = 0;
}
else // Get actual block data.
@@ -222,24 +222,24 @@ namespace state_serve
const int fd = open(file_path.c_str(), O_RDONLY | O_CLOEXEC);
if (fd == -1)
{
LOG_ERR << errno << ": Open failed. " << file_path;
LOG_ERROR << errno << ": Open failed. " << file_path;
result = -1;
}
else
{
if (fstat(fd, &st) == -1)
{
LOG_ERR << errno << ": Stat failed. " << file_path;
LOG_ERROR << errno << ": Stat failed. " << file_path;
result = -1;
}
else if (!S_ISREG(st.st_mode))
{
LOG_ERR << "Not a file. " << file_path;
LOG_ERROR << "Not a file. " << file_path;
result = -1;
}
else if (block_offset > st.st_size)
{
LOG_ERR << "Block offset " << block_offset << " larger than file " << st.st_size << " - " << file_path;
LOG_ERROR << "Block offset " << block_offset << " larger than file " << st.st_size << " - " << file_path;
result = -1;
}
else
@@ -251,7 +251,7 @@ namespace state_serve
const int res = read(fd, block.data(), read_len);
if (res < read_len)
{
LOG_ERR << errno << ": Read failed (result:" << res
LOG_ERROR << errno << ": Read failed (result:" << res
<< " off:" << block_offset << " len:" << read_len << "). " << file_path;
result = -1;
}
@@ -290,7 +290,7 @@ namespace state_serve
{
if (file_hash != expected_hash)
{
LOG_DBG << "Expected hash mismatch.";
LOG_DEBUG << "Expected hash mismatch.";
result = 0;
}
// Get the block hashes.
@@ -305,7 +305,7 @@ namespace state_serve
struct stat st;
if (stat(file_path.c_str(), &st) == -1)
{
LOG_ERR << errno << ": Stat failed when getting file length. " << file_path;
LOG_ERROR << errno << ": Stat failed when getting file length. " << file_path;
result = -1;
}
file_length = st.st_size;
@@ -337,7 +337,7 @@ namespace state_serve
{
if (dir_hash != expected_hash)
{
LOG_DBG << "Expected hash mismatch.";
LOG_DEBUG << "Expected hash mismatch.";
result = 0;
}
// Get the children hash nodes.

View File

@@ -121,12 +121,12 @@ namespace state_sync
}
// Stop hpfs rw session.
LOG_DBG << "State sync: Stopping hpfs session... pid:" << hpfs_pid;
LOG_DEBUG << "State sync: Stopping hpfs session... pid:" << hpfs_pid;
util::kill_process(hpfs_pid, true);
}
else
{
LOG_ERR << "State sync: Failed to start hpfs rw session";
LOG_ERROR << "State sync: Failed to start hpfs rw session";
}
ctx.target_state = hpfs::h32_empty;
@@ -169,7 +169,7 @@ namespace state_sync
const auto pending_resp_itr = ctx.submitted_requests.find(key);
if (pending_resp_itr == ctx.submitted_requests.end())
{
LOG_DBG << "Skipping state response due to hash mismatch.";
LOG_DEBUG << "Skipping state response due to hash mismatch.";
continue;
}
@@ -189,11 +189,11 @@ namespace state_sync
// After handling each response, check whether we have reached target state.
if (hpfs::get_hash(updated_state, ctx.hpfs_mount_dir, "/") < 1)
{
LOG_ERR << "State sync: exiting due to hash check error.";
LOG_ERROR << "State sync: exiting due to hash check error.";
return;
}
LOG_DBG << "State sync: current:" << updated_state << " | target:" << current_target;
LOG_DEBUG << "State sync: current:" << updated_state << " | target:" << current_target;
if (updated_state == current_target)
return;
}
@@ -215,7 +215,7 @@ namespace state_sync
{
// Reset the counter and re-submit request.
request.waiting_time = 0;
LOG_DBG << "State sync: Resubmitting request...";
LOG_DEBUG << "State sync: Resubmitting request...";
submit_request(request);
}
}
@@ -275,7 +275,7 @@ namespace state_sync
*/
void submit_request(const backlog_item &request)
{
LOG_DBG << "State sync: Submitting request. type:" << request.type
LOG_DEBUG << "State sync: Submitting request. type:" << request.type
<< " path:" << request.path << " block_id:" << request.block_id
<< " hash:" << request.expected_hash;
@@ -293,7 +293,7 @@ namespace state_sync
int handle_fs_entry_response(std::string_view parent_vpath, const msg::fbuf::p2pmsg::Fs_Entry_Response *fs_entry_resp)
{
// Get the parent path of the fs entries we have received.
LOG_DBG << "State sync: Processing fs entries response for " << parent_vpath;
LOG_DEBUG << "State sync: Processing fs entries response for " << parent_vpath;
// Get fs entries we have received.
std::unordered_map<std::string, p2p::state_fs_hash_entry> peer_fs_entry_map;
@@ -341,7 +341,7 @@ namespace state_sync
!ex_entry.is_file && rmdir(child_physical_path.c_str()) == -1)
return -1;
LOG_DBG << "State sync: Deleted " << (ex_entry.is_file ? "file" : "dir") << " path " << child_vpath;
LOG_DEBUG << "State sync: Deleted " << (ex_entry.is_file ? "file" : "dir") << " path " << child_vpath;
}
}
@@ -369,7 +369,7 @@ namespace state_sync
int handle_file_hashmap_response(std::string_view file_vpath, const msg::fbuf::p2pmsg::File_HashMap_Response *file_resp)
{
// Get the file path of the block hashes we have received.
LOG_DBG << "State sync: Processing file block hashes response for " << file_vpath;
LOG_DEBUG << "State sync: Processing file block hashes response for " << file_vpath;
// File block hashes on our side (file might not exist on our side).
std::vector<hpfs::h32> existing_hashes;
@@ -411,7 +411,7 @@ namespace state_sync
const uint32_t block_id = block_msg->block_id();
std::string_view buf = msg::fbuf::flatbuff_bytes_to_sv(block_msg->data());
LOG_DBG << "State sync: Writing block_id " << block_id
LOG_DEBUG << "State sync: Writing block_id " << block_id
<< " (len:" << buf.length()
<< ") of " << file_vpath;
@@ -419,7 +419,7 @@ namespace state_sync
const int fd = open(file_physical_path.c_str(), O_WRONLY | O_CREAT | O_CLOEXEC, FILE_PERMS);
if (fd == -1)
{
LOG_ERR << errno << " Open failed " << file_physical_path;
LOG_ERROR << errno << " Open failed " << file_physical_path;
return -1;
}
@@ -428,7 +428,7 @@ namespace state_sync
close(fd);
if (res < buf.length())
{
LOG_ERR << errno << " Write failed " << file_physical_path;
LOG_ERROR << errno << " Write failed " << file_physical_path;
return -1;
}

View File

@@ -76,7 +76,7 @@ namespace read_req
remove_thread(thread_id);
}
LOG_DBG << completed_threads.size() << " threads cleaned from read requests thread pool.";
LOG_DEBUG << completed_threads.size() << " threads cleaned from read requests thread pool.";
// Clear the completed thread id list once the completed threads are removed from the list.
completed_threads.clear();
@@ -107,7 +107,7 @@ namespace read_req
*/
void read_request_processor()
{
LOG_DBG << "A new read request processing thread started.";
LOG_DEBUG << "A new read request processing thread started.";
util::mask_signal();
@@ -130,7 +130,7 @@ namespace read_req
// Populate execution context data if any read requests are available in the queue.
initialize_execution_context(std::move(read_request), thread_id, *context_itr);
LOG_DBG << "Read request contract execution started.";
LOG_DEBUG << "Read request contract execution started.";
// Process the read requests by executing the contract.
if (sc::execute_contract(*context_itr) != -1)
@@ -160,11 +160,11 @@ namespace read_req
}
}
}
LOG_DBG << "Read request contract execution ended.";
LOG_DEBUG << "Read request contract execution ended.";
}
else
{
LOG_ERR << "Contract execution for read request failed.";
LOG_ERROR << "Contract execution for read request failed.";
}
// Remove successfully executed execution contexts.
@@ -173,7 +173,7 @@ namespace read_req
}
else
{
LOG_DBG << "Thread exits, due to no more read requests.";
LOG_DEBUG << "Thread exits, due to no more read requests.";
// Break while loop if no read request is present in the queue for processing.
break;
}
@@ -183,7 +183,7 @@ namespace read_req
std::scoped_lock<std::mutex> lock(completed_threads_mutex);
completed_threads.push_back(thread_id);
LOG_DBG << "Read request processing thread exited.";
LOG_DEBUG << "Read request processing thread exited.";
}
/**

View File

@@ -17,11 +17,11 @@ int user_session_handler::on_connect(comm::comm_session &session) const
{
if (conf::cfg.pubmaxcons > 0 && ctx.users.size() >= conf::cfg.pubmaxcons)
{
LOG_DBG << "Max user connections reached. Dropped connection " << session.uniqueid.substr(0, 10);
LOG_DEBUG << "Max user connections reached. Dropped connection " << session.uniqueid.substr(0, 10);
return -1;
}
LOG_DBG << "User client connected " << session.uniqueid.substr(0, 10);
LOG_DEBUG << "User client connected " << session.uniqueid.substr(0, 10);
// As soon as a user connects, we issue them a challenge message. We remember the
// challenge we issued and later verify the user's response with it.
@@ -61,13 +61,13 @@ int user_session_handler::on_message(comm::comm_session &session, std::string_vi
if (handle_user_message(user, message) != 0)
{
session.increment_metric(comm::SESSION_THRESHOLDS::MAX_BADMSGS_PER_MINUTE, 1);
LOG_DBG << "Bad message from user " << session.uniqueid.substr(0, 10);
LOG_DEBUG << "Bad message from user " << session.uniqueid.substr(0, 10);
}
}
else
{
session.increment_metric(comm::SESSION_THRESHOLDS::MAX_BADMSGS_PER_MINUTE, 1);
LOG_DBG << "User session id not found: " << session.uniqueid.substr(0, 10);
LOG_DEBUG << "User session id not found: " << session.uniqueid.substr(0, 10);
}
return 0;
@@ -75,7 +75,7 @@ int user_session_handler::on_message(comm::comm_session &session, std::string_vi
// If for any reason we reach this point, we should drop the connection because none of the
// valid cases match.
LOG_DBG << "Dropping the user connection " << session.uniqueid.substr(0, 10);
LOG_DEBUG << "Dropping the user connection " << session.uniqueid.substr(0, 10);
corebill::report_violation(session.address);
return -1;
}

View File

@@ -74,7 +74,7 @@ namespace usr
// The received message must be the challenge response. We need to verify it.
if (session.issued_challenge.empty())
{
LOG_DBG << "No challenge found for the session " << session.uniqueid.substr(0, 10);
LOG_DEBUG << "No challenge found for the session " << session.uniqueid.substr(0, 10);
return -1;
}
@@ -107,18 +107,18 @@ namespace usr
add_user(session, userpubkey, user_protocol); // Add the user to the global authed user list
session.issued_challenge.clear(); // Remove the stored challenge
LOG_DBG << "User connection " << session.uniqueid.substr(0, 10) << " authenticated. Public key "
LOG_DEBUG << "User connection " << session.uniqueid.substr(0, 10) << " authenticated. Public key "
<< userpubkeyhex;
return 0;
}
else
{
LOG_DBG << "Duplicate user public key " << session.uniqueid.substr(0, 10);
LOG_DEBUG << "Duplicate user public key " << session.uniqueid.substr(0, 10);
}
}
else
{
LOG_DBG << "Challenge verification failed " << session.uniqueid.substr(0, 10);
LOG_DEBUG << "Challenge verification failed " << session.uniqueid.substr(0, 10);
}
return -1;
@@ -185,7 +185,7 @@ namespace usr
}
else
{
LOG_DBG << "Invalid user message type: " << msg_type;
LOG_DEBUG << "Invalid user message type: " << msg_type;
send_input_status(parser, user.session, msg::usrmsg::STATUS_REJECTED, msg::usrmsg::REASON_INVALID_MSG_TYPE, "");
return -1;
}

View File

@@ -220,14 +220,14 @@ namespace util
{
if (kill(pid, signal) == -1)
{
LOG_ERR << errno << ": Error issuing signal to pid " << pid;
LOG_ERROR << errno << ": Error issuing signal to pid " << pid;
return -1;
}
const int wait_options = wait ? 0 : WNOHANG;
if (waitpid(pid, NULL, wait_options) == -1)
{
LOG_ERR << errno << ": waitpid after kill failed.";
LOG_ERROR << errno << ": waitpid after kill failed.";
return -1;
}