Browse Source

perform node discovery when there aren't enough nodes

cl-refactor
subtly 10 years ago
parent
commit
3291bc1d9a
  1. 6
      libp2p/Host.cpp
  2. 4
      libp2p/NodeTable.cpp

6
libp2p/Host.cpp

@ -534,7 +534,8 @@ void Host::run(boost::system::error_code const&)
keepAlivePeers();
disconnectLatePeers();
if (m_idealPeerCount && !peerCount())
auto c = peerCount();
if (m_idealPeerCount && !c)
for (auto p: m_peers)
if (p.second->shouldReconnect())
{
@ -544,6 +545,9 @@ void Host::run(boost::system::error_code const&)
break;
}
if (c < m_idealPeerCount)
m_nodeTable->discover();
auto runcb = [this](boost::system::error_code const& error) { run(error); };
m_timer->expires_from_now(boost::posix_time::milliseconds(c_timerInterval));
m_timer->async_wait(runcb);

4
libp2p/NodeTable.cpp

@ -106,7 +106,9 @@ shared_ptr<NodeEntry> NodeTable::addNode(Node const& _node)
void NodeTable::discover()
{
discover(m_node.id);
static chrono::steady_clock::time_point s_lastDiscover = chrono::steady_clock::now() - std::chrono::seconds(30);
if (chrono::steady_clock::now() > s_lastDiscover + std::chrono::seconds(30))
discover(m_node.id);
}
list<NodeId> NodeTable::nodes() const

Loading…
Cancel
Save