mirror of
https://github.com/monero-project/monero.git
synced 2025-08-24 08:49:24 -04:00
2014 network limit 1.0a +utils +toc -doc -drmonero
commands and options for network limiting works very well e.g. for 50 KiB/sec up and down ToS (QoS) flag peer number limit TODO some spikes in ingress/download TODO problems when other up and down limit added "otshell utils" - simple logging (with colors, text files channels)
This commit is contained in:
parent
e728992803
commit
eabb519605
40 changed files with 4016 additions and 206 deletions
|
@ -1,3 +1,7 @@
|
|||
/// @file
|
||||
/// @author rfree (current maintainer/user in monero.cc project - most of code is from CryptoNote)
|
||||
/// @brief This is the orginal cryptonote protocol network-events handler, modified by us
|
||||
|
||||
// Copyright (c) 2014-2015, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
|
@ -28,14 +32,26 @@
|
|||
//
|
||||
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
||||
|
||||
// (may contain code and/or modifications by other developers)
|
||||
// developer rfree: this code is caller of our new network code, and is modded; e.g. for rate limiting
|
||||
|
||||
#include <boost/interprocess/detail/atomic.hpp>
|
||||
#include <list>
|
||||
|
||||
#include "cryptonote_core/cryptonote_format_utils.h"
|
||||
#include "profile_tools.h"
|
||||
#include "../../contrib/otshell_utils/utils.hpp"
|
||||
using namespace nOT::nUtils;
|
||||
|
||||
namespace cryptonote
|
||||
{
|
||||
|
||||
|
||||
// static
|
||||
// template<class t_core> std::ofstream t_cryptonote_protocol_handler<t_core>::m_logreq("logreq.txt"); // static
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------
|
||||
template<class t_core>
|
||||
t_cryptonote_protocol_handler<t_core>::t_cryptonote_protocol_handler(t_core& rcore, nodetool::i_p2p_endpoint<connection_context>* p_net_layout):m_core(rcore),
|
||||
|
@ -100,20 +116,24 @@ namespace cryptonote
|
|||
{
|
||||
std::stringstream ss;
|
||||
|
||||
ss << std::setw(25) << std::left << "Remote Host"
|
||||
ss << std::setw(30) << std::left << "Remote Host"
|
||||
<< std::setw(20) << "Peer id"
|
||||
<< std::setw(25) << "Recv/Sent (inactive,sec)"
|
||||
<< std::setw(25) << "State"
|
||||
<< std::setw(20) << "Livetime(seconds)" << ENDL;
|
||||
|
||||
uint32_t ip;
|
||||
m_p2p->for_each_connection([&](const connection_context& cntxt, nodetool::peerid_type peer_id)
|
||||
{
|
||||
ss << std::setw(25) << std::left << std::string(cntxt.m_is_income ? " [INC]":"[OUT]") +
|
||||
epee::string_tools::get_ip_string_from_int32(cntxt.m_remote_ip) + ":" + std::to_string(cntxt.m_remote_port)
|
||||
ip = ntohl(cntxt.m_remote_ip);
|
||||
ss << std::setw(30) << std::left << std::string(cntxt.m_is_income ? " [INC]":"[OUT]") +
|
||||
epee::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) << ENDL;
|
||||
<< std::setw(20) << std::to_string(time(NULL) - cntxt.m_started)
|
||||
<< std::setw(10) << (ip > 3232235520 && ip < 3232301055 ? " [LAN]" : "") //TODO: local ip in calss A, B
|
||||
<< ENDL;
|
||||
return true;
|
||||
});
|
||||
LOG_PRINT_L0("Connections: " << ENDL << ss.str());
|
||||
|
@ -234,11 +254,11 @@ namespace cryptonote
|
|||
|
||||
block_verification_context bvc = boost::value_initialized<block_verification_context>();
|
||||
m_core.pause_mine();
|
||||
m_core.handle_incoming_block(arg.b.block, bvc);
|
||||
m_core.handle_incoming_block(arg.b.block, bvc); // got block from handle_notify_new_block
|
||||
m_core.resume_mine();
|
||||
if(bvc.m_verifivation_failed)
|
||||
{
|
||||
LOG_PRINT_CCONTEXT_L1("Block verification failed, dropping connection");
|
||||
LOG_PRINT_CCONTEXT_L0("Block verification failed, dropping connection");
|
||||
m_p2p->drop_connection(context);
|
||||
return 1;
|
||||
}
|
||||
|
@ -304,9 +324,19 @@ namespace cryptonote
|
|||
LOG_PRINT_CCONTEXT_L2("-->>NOTIFY_RESPONSE_GET_OBJECTS: blocks.size()=" << rsp.blocks.size() << ", txs.size()=" << rsp.txs.size()
|
||||
<< ", rsp.m_current_blockchain_height=" << rsp.current_blockchain_height << ", missed_ids.size()=" << rsp.missed_ids.size());
|
||||
post_notify<NOTIFY_RESPONSE_GET_OBJECTS>(rsp, context);
|
||||
//handler_response_blocks_now(sizeof(rsp)); // XXX
|
||||
//handler_response_blocks_now(200);
|
||||
return 1;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
template<class t_core>
|
||||
double t_cryptonote_protocol_handler<t_core>::get_avg_block_size( size_t count) const {
|
||||
return m_core.get_blockchain_storage().get_avg_block_size(count);
|
||||
}
|
||||
|
||||
|
||||
template<class t_core>
|
||||
int t_cryptonote_protocol_handler<t_core>::handle_response_get_objects(int command, NOTIFY_RESPONSE_GET_OBJECTS::request& arg, cryptonote_connection_context& context)
|
||||
{
|
||||
|
@ -378,6 +408,7 @@ namespace cryptonote
|
|||
epee::misc_utils::auto_scope_leave_caller scope_exit_handler = epee::misc_utils::create_scope_leave_handler(
|
||||
boost::bind(&t_core::resume_mine, &m_core));
|
||||
|
||||
LOG_PRINT_CCONTEXT_YELLOW( "Got NEW BLOCKS inside of " << __FUNCTION__ << ": size: " << arg.blocks.size() , LOG_LEVEL_0);
|
||||
BOOST_FOREACH(const block_complete_entry& block_entry, arg.blocks)
|
||||
{
|
||||
//process transactions
|
||||
|
@ -419,7 +450,8 @@ namespace cryptonote
|
|||
LOG_PRINT_CCONTEXT_L2("Block process time: " << block_process_time + transactions_process_time << "(" << transactions_process_time << "/" << block_process_time << ")ms");
|
||||
}
|
||||
}
|
||||
|
||||
size_t count_limit = BLOCKS_SYNCHRONIZING_DEFAULT_COUNT;
|
||||
handler_request_blocks_now(count_limit); // XXX
|
||||
request_missing_objects(context, true);
|
||||
return 1;
|
||||
}
|
||||
|
@ -455,6 +487,11 @@ namespace cryptonote
|
|||
size_t count = 0;
|
||||
auto it = context.m_needed_objects.begin();
|
||||
|
||||
size_t count_limit = BLOCKS_SYNCHRONIZING_DEFAULT_COUNT;
|
||||
//handler_request_blocks_now( count_limit ); // change the limit, sleep(?) XXX
|
||||
// XXX
|
||||
count_limit=200; // XXX
|
||||
_note_c("net/req-calc" , "Setting count_limit: " << count_limit);
|
||||
while(it != context.m_needed_objects.end() && count < BLOCKS_SYNCHRONIZING_DEFAULT_COUNT)
|
||||
{
|
||||
if( !(check_having_blocks && m_core.have_block(*it)))
|
||||
|
@ -465,14 +502,16 @@ namespace cryptonote
|
|||
}
|
||||
context.m_needed_objects.erase(it++);
|
||||
}
|
||||
LOG_PRINT_CCONTEXT_L2("-->>NOTIFY_REQUEST_GET_OBJECTS: blocks.size()=" << req.blocks.size() << ", txs.size()=" << req.txs.size());
|
||||
LOG_PRINT_CCONTEXT_L0("-->>NOTIFY_REQUEST_GET_OBJECTS: blocks.size()=" << req.blocks.size() << ", txs.size()=" << req.txs.size()
|
||||
<< "requested blocks count=" << count << " / " << count_limit);
|
||||
post_notify<NOTIFY_REQUEST_GET_OBJECTS>(req, context);
|
||||
}else if(context.m_last_response_height < context.m_remote_blockchain_height-1)
|
||||
{//we have to fetch more objects ids, request blockchain entry
|
||||
|
||||
NOTIFY_REQUEST_CHAIN::request r = boost::value_initialized<NOTIFY_REQUEST_CHAIN::request>();
|
||||
m_core.get_short_chain_history(r.block_ids);
|
||||
LOG_PRINT_CCONTEXT_L2("-->>NOTIFY_REQUEST_CHAIN: m_block_ids.size()=" << r.block_ids.size() );
|
||||
handler_request_blocks_history( r.block_ids ); // change the limit(?), sleep(?)
|
||||
LOG_PRINT_CCONTEXT_L0("-->>NOTIFY_REQUEST_CHAIN: m_block_ids.size()=" << r.block_ids.size() );
|
||||
post_notify<NOTIFY_REQUEST_CHAIN>(r, context);
|
||||
}else
|
||||
{
|
||||
|
@ -575,4 +614,18 @@ namespace cryptonote
|
|||
{
|
||||
return relay_post_notify<NOTIFY_NEW_TRANSACTIONS>(arg, exclude_context);
|
||||
}
|
||||
}
|
||||
|
||||
/// @deprecated
|
||||
template<class t_core> std::ofstream& t_cryptonote_protocol_handler<t_core>::get_logreq() const {
|
||||
static std::ofstream * logreq=NULL;
|
||||
if (!logreq) {
|
||||
LOG_PRINT_RED("LOG OPENED",LOG_LEVEL_0);
|
||||
logreq = new std::ofstream("logreq.txt"); // leak mem (singleton)
|
||||
*logreq << "Opened log" << std::endl;
|
||||
}
|
||||
LOG_PRINT_YELLOW("LOG USED",LOG_LEVEL_0);
|
||||
(*logreq) << "log used" << std::endl;
|
||||
return *logreq;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue