Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptozoidberg committed Nov 13, 2018
2 parents c0aaf09 + 4dcc296 commit 4a8e225
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 9 deletions.
22 changes: 22 additions & 0 deletions contrib/epee/include/time_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,28 @@ POP_WARNINGS
return tmpbuf;
}

inline
std::string get_date_str(const time_t& time_)
{

char tmpbuf[200] = { 0 };
tm* pt = NULL;
PUSH_WARNINGS
DISABLE_VS_WARNINGS(4996)
pt = localtime(&time_);
POP_WARNINGS

if (pt)
strftime(tmpbuf, 199, "%Y-%m-%d", pt);
else
{
std::stringstream strs;
strs << "[wrong_time: " << std::hex << time_ << "]";
return strs.str();
}
return tmpbuf;
}

inline
std::string get_time_str_v3(const boost::posix_time::ptime& time_)
{
Expand Down
5 changes: 3 additions & 2 deletions src/currency_core/currency_format_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -931,13 +931,13 @@ namespace currency
void print_reward_halwing()
{
std::cout << std::endl << "Reward halving for 10 years:" << std::endl;
std::cout << std::setw(10) << std::left << "day" << std::setw(19) << "block reward" << std::setw(19) << "generated coins" << std::endl;
std::cout << std::setw(10) << std::left << "day" << std::setw(19) << std::left << "date" << std::setw(19) << "block reward" << std::setw(19) << "generated coins" << std::endl;

uint64_t already_generated_coins = 0;
uint64_t already_donated_coins = 0;

uint64_t total_money_supply = TOTAL_MONEY_SUPPLY;
for(uint64_t day = 0; day != 365*10; ++day)
for(uint64_t day = 0; day != 365*30; ++day)
{
uint64_t emission_reward = 0;
uint64_t stub = 0;
Expand All @@ -946,6 +946,7 @@ namespace currency
{
std::cout << std::left
<< std::setw(10) << day
<< std::setw(19) << epee::misc_utils::get_date_str(1400342511 + (day * 86400))
<< std::setw(19) << print_money(emission_reward)
<< std::setw(4) << std::string(std::to_string(GET_PERECENTS_BIG_NUMBERS((already_generated_coins + already_donated_coins), total_money_supply)) + "%")
<< print_money(already_generated_coins + already_donated_coins)
Expand Down
1 change: 1 addition & 0 deletions src/currency_protocol/currency_protocol_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ namespace currency
bool request_missing_objects(currency_connection_context& context, bool check_having_blocks);
size_t get_synchronizing_connections_count();
bool on_connection_synchronized();
bool do_force_handshake_idle_connections();
bool check_stop_flag_and_exit(currency_connection_context& context);
t_core& m_core;

Expand Down
22 changes: 22 additions & 0 deletions src/currency_protocol/currency_protocol_handler.inl
Original file line number Diff line number Diff line change
Expand Up @@ -696,10 +696,32 @@ namespace currency
LOG_PRINT_CCONTEXT_MAGENTA("[REQUEST_MISSING_OBJECTS] m_state set state_normal", LOG_LEVEL_0);
context.m_state = currency_connection_context::state_normal;
LOG_PRINT_CCONTEXT_GREEN(" SYNCHRONIZED OK", LOG_LEVEL_0);
do_force_handshake_idle_connections();
}
return true;
}
//------------------------------------------------------------------------------------------------------------------------
template<class t_core>
bool t_currency_protocol_handler<t_core>::do_force_handshake_idle_connections()
{
nodetool::connections_list_type peer_list;
size_t count = 0;
m_p2p->for_each_connection([&](currency_connection_context& context, nodetool::peerid_type peer_id)->bool{
if (context.m_state == currency_connection_context::state_idle)
{
peer_list.push_back(std::make_pair(static_cast<net_utils::connection_context_base>(context), peer_id));
}
return true;
});
if (peer_list.size())
{
LOG_PRINT_CCONTEXT_MAGENTA("[ON_SYNCHRONIZED] Explicit resync idle connections (" << peer_list.size() << ")", LOG_LEVEL_0);
return m_p2p->do_idle_sync_with_peers(peer_list);
}
else
return true;
}
//------------------------------------------------------------------------------------------------------------------------
template<class t_core>
bool t_currency_protocol_handler<t_core>::on_connection_synchronized()
{
Expand Down
3 changes: 3 additions & 0 deletions src/p2p/net_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace nodetool
typedef COMMAND_TIMED_SYNC_T<typename t_payload_net_handler::payload_type> COMMAND_TIMED_SYNC;

public:

typedef t_payload_net_handler payload_net_handler;
// Some code
node_server(t_payload_net_handler& payload_handler):m_payload_handler(payload_handler),
Expand Down Expand Up @@ -150,6 +151,7 @@ namespace nodetool
virtual bool block_ip(uint32_t adress);
virtual bool add_ip_fail(uint32_t address);
virtual bool is_stop_signal_sent();
virtual bool do_idle_sync_with_peers(const nodetool::connections_list_type& concts);
//----------------- i_connection_filter --------------------------------------------------------
virtual bool is_remote_ip_allowed(uint32_t adress);
//-----------------------------------------------------------------------------------------------
Expand All @@ -165,6 +167,7 @@ namespace nodetool

bool connections_maker();
bool peer_sync_idle_maker();

bool do_handshake_with_peer(peerid_type& pi, p2p_connection_context& context, bool just_take_peerlist = false);
bool do_peer_timed_sync(const net_utils::connection_context_base& context, peerid_type peer_id);

Expand Down
18 changes: 11 additions & 7 deletions src/p2p/net_node.inl
Original file line number Diff line number Diff line change
Expand Up @@ -900,19 +900,23 @@ namespace nodetool
//-----------------------------------------------------------------------------------
template<class t_payload_net_handler>
bool node_server<t_payload_net_handler>::peer_sync_idle_maker()
{
LOG_PRINT_L2("STARTED PEERLIST IDLE HANDSHAKE");
typedef std::list<std::pair<net_utils::connection_context_base, peerid_type> > local_connects_type;
local_connects_type cncts;
{
connections_list_type cncts;
m_net_server.get_config_object().foreach_connection([&](const p2p_connection_context& cntxt)
{
if(cntxt.peer_id)
cncts.push_back(local_connects_type::value_type(cntxt, cntxt.peer_id));//do idle sync only with handshaked connections
cncts.push_back(connections_list_type::value_type(cntxt, cntxt.peer_id));//do idle sync only with handshaked connections
return true;
});

std::for_each(cncts.begin(), cncts.end(), [&](const typename local_connects_type::value_type& vl){do_peer_timed_sync(vl.first, vl.second);});

return do_idle_sync_with_peers(cncts);
}
//-----------------------------------------------------------------------------------
template<class t_payload_net_handler>
bool node_server<t_payload_net_handler>::do_idle_sync_with_peers(const nodetool::connections_list_type& cncts)
{
LOG_PRINT_L2("STARTED PEERLIST IDLE HANDSHAKE");
std::for_each(cncts.begin(), cncts.end(), [&](const typename nodetool::connections_list_type::value_type& vl){do_peer_timed_sync(vl.first, vl.second); });
LOG_PRINT_L2("FINISHED PEERLIST IDLE HANDSHAKE");
return true;
}
Expand Down
8 changes: 8 additions & 0 deletions src/p2p/net_node_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ namespace nodetool
typedef boost::uuids::uuid uuid;
typedef boost::uuids::uuid net_connection_id;


typedef std::list<std::pair<epee::net_utils::connection_context_base, peerid_type> > connections_list_type;

template<class t_connection_context>
struct i_p2p_endpoint
{
Expand All @@ -27,6 +30,7 @@ namespace nodetool
virtual bool block_ip(uint32_t adress)=0;
virtual bool add_ip_fail(uint32_t adress)=0;
virtual bool is_stop_signal_sent()=0;
virtual bool do_idle_sync_with_peers(const connections_list_type& concts) = 0;
};

template<class t_connection_context>
Expand Down Expand Up @@ -72,5 +76,9 @@ namespace nodetool
{
return true;
}
virtual bool do_idle_sync_with_peers(const connections_list_type& concts)
{
return true;
}
};
}
1 change: 1 addition & 0 deletions src/wallet/wallet2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ bool wallet2::deinit()
//----------------------------------------------------------------------------------------------------
bool wallet2::clear()
{
LOG_PRINT_L0("clear internal wallet structures...");
m_blockchain.clear();
m_transfers.clear();
m_payments.clear();
Expand Down

0 comments on commit 4a8e225

Please sign in to comment.