Skip to content

Commit

Permalink
Check for updates in status and version commands
Browse files Browse the repository at this point in the history
  • Loading branch information
SChernykh committed Oct 8, 2023
1 parent 4e55f53 commit de3cdc0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
18 changes: 15 additions & 3 deletions src/console_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,20 @@ static void do_status(p2pool *m_pool, const char * /* args */)
if (m_pool->stratum_server()) {
m_pool->stratum_server()->print_status();
}
if (m_pool->p2p_server()) {
m_pool->p2p_server()->print_status();

P2PServer* p2p = m_pool->p2p_server();
if (p2p) {
p2p->print_status();
}

#ifdef WITH_RANDOMX
m_pool->print_miner_status();
#endif
bkg_jobs_tracker.print_status();

if (p2p) {
p2p->check_for_updates(true);
}
}

static void do_loglevel(p2pool * /* m_pool */, const char *args)
Expand Down Expand Up @@ -312,9 +319,14 @@ static void do_exit(p2pool *m_pool, const char * /* args */)
m_pool->stop();
}

static void do_version(p2pool* /* m_pool */, const char* /* args */)
static void do_version(p2pool* m_pool, const char* /* args */)
{
LOGINFO(0, log::LightCyan() << VERSION);

const P2PServer* p2p = m_pool->p2p_server();
if (p2p) {
p2p->check_for_updates(true);
}
}

void ConsoleCommands::allocCallback(uv_handle_t* handle, size_t /*suggested_size*/, uv_buf_t* buf)
Expand Down
6 changes: 3 additions & 3 deletions src/p2p_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1256,15 +1256,15 @@ void P2PServer::check_block_template()
}
}

void P2PServer::check_for_updates() const
void P2PServer::check_for_updates(bool forced) const
{
if (m_timerCounter % (3600 / m_timerInterval) != 0) {
if (!forced && (m_timerCounter % (3600 / m_timerInterval) != 0)) {
return;
}

const SideChain& s = m_pool->side_chain();

if (s.precalcFinished() && s.p2pool_update_available()) {
if ((forced || s.precalcFinished()) && s.p2pool_update_available()) {
LOGINFO(0, log::LightCyan() << "********************************************************************************");
LOGINFO(0, log::LightCyan() << "* An updated P2Pool version is available, visit p2pool.io for more information *");
LOGINFO(0, log::LightCyan() << "********************************************************************************");
Expand Down
3 changes: 2 additions & 1 deletion src/p2p_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ class P2PServer : public TCPServer

const PoolBlock* find_block(const hash& id) const;

void check_for_updates(bool forced = false) const;

private:
const char* get_log_category() const override;

Expand All @@ -198,7 +200,6 @@ class P2PServer : public TCPServer
void download_missing_blocks();
void check_host();
void check_block_template();
void check_for_updates() const;
void update_peer_connections();
void update_peer_list();
void send_peer_list_request(P2PClient* client, uint64_t cur_time);
Expand Down

0 comments on commit de3cdc0

Please sign in to comment.