mirror of
https://github.com/SChernykh/p2pool.git
synced 2025-01-08 19:59:30 +00:00
P2PServer: connect to peers from the event loop thread
Better thread safety
This commit is contained in:
parent
333cfbefaf
commit
73c8b1294a
2 changed files with 8 additions and 3 deletions
|
@ -41,6 +41,7 @@ P2PServer::P2PServer(p2pool* pool)
|
|||
, m_pool(pool)
|
||||
, m_cache(new BlockCache())
|
||||
, m_cacheLoaded(false)
|
||||
, m_initialPeerList(pool->params().m_p2pPeerList)
|
||||
, m_rd{}
|
||||
, m_rng(m_rd())
|
||||
, m_block(new PoolBlock())
|
||||
|
@ -76,16 +77,14 @@ P2PServer::P2PServer(p2pool* pool)
|
|||
}
|
||||
|
||||
m_timer.data = this;
|
||||
err = uv_timer_start(&m_timer, on_timer, 10000, 2000);
|
||||
err = uv_timer_start(&m_timer, on_timer, 1000, 2000);
|
||||
if (err) {
|
||||
LOGERR(1, "failed to start timer, error " << uv_err_name(err));
|
||||
panic();
|
||||
}
|
||||
|
||||
load_saved_peer_list();
|
||||
|
||||
start_listening(pool->params().m_p2pAddresses);
|
||||
connect_to_peers(pool->params().m_p2pPeerList);
|
||||
}
|
||||
|
||||
P2PServer::~P2PServer()
|
||||
|
@ -579,6 +578,11 @@ void P2PServer::print_status()
|
|||
|
||||
void P2PServer::on_timer()
|
||||
{
|
||||
if (!m_initialPeerList.empty()) {
|
||||
connect_to_peers(m_initialPeerList);
|
||||
m_initialPeerList.clear();
|
||||
}
|
||||
|
||||
flush_cache();
|
||||
download_missing_blocks();
|
||||
update_peer_list();
|
||||
|
|
|
@ -124,6 +124,7 @@ private:
|
|||
p2pool* m_pool;
|
||||
BlockCache* m_cache;
|
||||
bool m_cacheLoaded;
|
||||
std::string m_initialPeerList;
|
||||
|
||||
uv_rwlock_t m_cachedBlocksLock;
|
||||
std::unordered_map<hash, PoolBlock*> m_cachedBlocks;
|
||||
|
|
Loading…
Reference in a new issue