forked from lthn/blockchain
minor log improvements in currency protocol and epee's net_utils_base
This commit is contained in:
parent
9d829d2cb3
commit
b398de6e9f
3 changed files with 34 additions and 23 deletions
|
|
@ -117,34 +117,34 @@ namespace net_utils
|
|||
//some helpers
|
||||
|
||||
|
||||
inline
|
||||
std::string print_connection_context(const connection_context_base& ctx)
|
||||
inline std::string print_connection_context(const connection_context_base& ctx)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << epee::string_tools::get_ip_string_from_int32(ctx.m_remote_ip) << ":" << ctx.m_remote_port << " " << epee::string_tools::get_str_from_guid_a(ctx.m_connection_id) << (ctx.m_is_income ? " INC":" OUT");
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
inline
|
||||
void print_connection_context_short(const connection_context_base& ctx, std::stringstream& ss)
|
||||
inline std::ostream &operator <<(std::ostream &o, const connection_context_base& ctx)
|
||||
{
|
||||
ss << epee::string_tools::get_ip_string_from_int32(ctx.m_remote_ip) << ":" << ctx.m_remote_port << (ctx.m_is_income ? " INC" : " OUT");
|
||||
}
|
||||
o << epee::string_tools::get_ip_string_from_int32(ctx.m_remote_ip) << ":" << ctx.m_remote_port << (ctx.m_is_income ? " INC" : " OUT");
|
||||
return o;
|
||||
}
|
||||
|
||||
inline
|
||||
std::string print_connection_context_short(const connection_context_base& ctx)
|
||||
inline std::string print_connection_context_short(const connection_context_base& ctx)
|
||||
{
|
||||
std::stringstream ss;
|
||||
print_connection_context_short(ctx, ss);
|
||||
ss << ctx;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
inline std::string print_connection_context_list(const std::list<connection_context_base>& contexts)
|
||||
inline std::string print_connection_context_list(const std::list<connection_context_base>& contexts, const std::string& delim = std::string("\n"))
|
||||
{
|
||||
std::stringstream ss;
|
||||
for (auto& c : contexts)
|
||||
{
|
||||
ss << epee::string_tools::get_ip_string_from_int32(c.m_remote_ip) << ":" << c.m_remote_port << (c.m_is_income ? " INC" : " OUT") << ENDL;
|
||||
if (ss.tellp())
|
||||
ss << delim;
|
||||
ss << c;
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
|
@ -179,7 +179,7 @@ namespace net_utils
|
|||
|
||||
#define CHECK_AND_ASSERT_MES_CC(condition, return_val, err_message) CHECK_AND_ASSERT_MES(condition, return_val, "[" << epee::net_utils::print_connection_context_short(context) << "]" << err_message)
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace net_utils
|
||||
} // namespace epee
|
||||
|
||||
#endif //_NET_UTILS_BASE_H_
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ namespace currency
|
|||
template<class t_parametr>
|
||||
bool post_notify(typename t_parametr::request& arg, currency_connection_context& context)
|
||||
{
|
||||
LOG_PRINT_L2("[POST]" << typeid(t_parametr).name());
|
||||
LOG_PRINT_L2("[POST]" << typeid(t_parametr).name() << " to " << context);
|
||||
std::string blob;
|
||||
epee::serialization::store_t_to_binary(arg, blob);
|
||||
return m_p2p->invoke_notify_to_peer(t_parametr::ID, blob, context);
|
||||
|
|
@ -133,7 +133,7 @@ namespace currency
|
|||
std::list<epee::net_utils::connection_context_base> relayed_peers;
|
||||
bool r = m_p2p->relay_notify_to_all(t_parametr::ID, arg_buff, exlude_context, relayed_peers);
|
||||
|
||||
LOG_PRINT_GREEN("[POST RELAY] " << typeid(t_parametr).name() << " relayed contexts list: " << ENDL << print_connection_context_list(relayed_peers), LOG_LEVEL_2);
|
||||
LOG_PRINT_GREEN("[POST RELAY] " << typeid(t_parametr).name() << " relayed contexts list: " << print_connection_context_list(relayed_peers, ", "), LOG_LEVEL_2);
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -94,22 +94,32 @@ namespace currency
|
|||
<< std::setw(20) << "Peer id"
|
||||
<< std::setw(25) << "Recv/Sent (idle,sec)"
|
||||
<< std::setw(25) << "State"
|
||||
<< std::setw(20) << "Livetime(seconds)"
|
||||
<< std::setw(20) << "Livetime"
|
||||
<< std::setw(20) << "Client version" << ENDL;
|
||||
|
||||
size_t incoming_count = 0, outgoing_count = 0;
|
||||
std::multimap<time_t, std::string> conn_map;
|
||||
m_p2p->for_each_connection([&](const connection_context& cntxt, nodetool::peerid_type peer_id)
|
||||
{
|
||||
ss << std::setw(29) << std::left << std::string(cntxt.m_is_income ? "[INC]":"[OUT]") +
|
||||
std::stringstream conn_ss;
|
||||
time_t livetime = time(NULL) - cntxt.m_started;
|
||||
conn_ss << std::setw(29) << std::left << std::string(cntxt.m_is_income ? "[INC]":"[OUT]") +
|
||||
string_tools::get_ip_string_from_int32(cntxt.m_remote_ip) + ":" + std::to_string(cntxt.m_remote_port)
|
||||
<< std::setw(20) << std::hex << peer_id
|
||||
<< std::setw(25) << std::to_string(cntxt.m_recv_cnt)+ "(" + std::to_string(time(NULL) - cntxt.m_last_recv) + ")" + "/" + std::to_string(cntxt.m_send_cnt) + "(" + std::to_string(time(NULL) - cntxt.m_last_send) + ")"
|
||||
<< std::setw(25) << get_protocol_state_string(cntxt.m_state)
|
||||
<< std::setw(20) << std::to_string(time(NULL) - cntxt.m_started)
|
||||
<< std::setw(20) << epee::misc_utils::get_time_interval_string(livetime)
|
||||
<< std::setw(20) << cntxt.m_remote_version
|
||||
<< ENDL;
|
||||
conn_map.insert(std::make_pair(livetime, conn_ss.str()));
|
||||
(cntxt.m_is_income ? incoming_count : outgoing_count) += 1;
|
||||
return true;
|
||||
});
|
||||
LOG_PRINT_L0("Connections: " << ENDL << ss.str());
|
||||
|
||||
for(auto it = conn_map.rbegin(); it != conn_map.rend(); ++it)
|
||||
ss << it->second;
|
||||
|
||||
LOG_PRINT_L0("Connections (" << incoming_count << " in, " << outgoing_count << " out, " << incoming_count + outgoing_count << " total):" << ENDL << ss.str());
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------
|
||||
template<class t_core>
|
||||
|
|
@ -723,13 +733,14 @@ namespace currency
|
|||
if (req.txs.size())
|
||||
{
|
||||
post_notify<NOTIFY_NEW_TRANSACTIONS>(req, cc);
|
||||
print_connection_context_short(cc, debug_ss);
|
||||
debug_ss << ": " << req.txs.size() << ENDL;
|
||||
|
||||
if (debug_ss.tellp())
|
||||
debug_ss << ", ";
|
||||
debug_ss << cc << ": " << req.txs.size();
|
||||
}
|
||||
}
|
||||
TIME_MEASURE_FINISH_MS(ms);
|
||||
LOG_PRINT_GREEN("[POST RELAY] NOTIFY_NEW_TRANSACTIONS relayed (" << ms << "ms)contexts list: " << debug_ss.str(), LOG_LEVEL_2);
|
||||
|
||||
LOG_PRINT_GREEN("[POST RELAY] NOTIFY_NEW_TRANSACTIONS relayed (" << ms << "ms) to: " << debug_ss.str(), LOG_LEVEL_2);
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------
|
||||
template<class t_core>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue