Skip to content

Commit

Permalink
Display software name in peers list
Browse files Browse the repository at this point in the history
  • Loading branch information
SChernykh committed Dec 2, 2022
1 parent 1b60134 commit 3e4f877
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#ifdef _MSC_VER

#pragma warning(disable : 4005 4061 4324 4365 4464 4625 4626 4668 4710 4711 4804 4820 5039 5045 5220 5246)
#pragma warning(disable : 4005 4061 4324 4365 4464 4619 4625 4626 4668 4710 4711 4804 4820 5039 5045 5220 5246 5264)
#define FORCEINLINE __forceinline
#define NOINLINE __declspec(noinline)
#define LIKELY(expression) expression
Expand Down
36 changes: 24 additions & 12 deletions src/p2p_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -963,17 +963,14 @@ void P2PServer::show_peers()

for (P2PClient* client = static_cast<P2PClient*>(m_connectedClientsList->m_next); client != m_connectedClientsList; client = static_cast<P2PClient*>(client->m_next)) {
if (client->m_listenPort >= 0) {
char buf[32];
char buf[32] = {};
log::Stream s(buf);
if (client->m_P2PoolVersion) {
s << "\tv" << (client->m_P2PoolVersion >> 16) << '.' << (client->m_P2PoolVersion & 0xFFFF) << "\t\0";
}
else {
s << "\t \t\0";
if (client->m_SoftwareVersion) {
s << client->software_name() << " v" << (client->m_SoftwareVersion >> 16) << '.' << (client->m_SoftwareVersion & 0xFFFF);
}
LOGINFO(0, (client->m_isIncoming ? "I\t" : "O\t")
<< log::pad_right(client->m_pingTime, 4) << " ms\t"
<< static_cast<const char*>(buf)
<< log::pad_right(client->m_pingTime, 4) << " ms\t\t"
<< log::pad_right(static_cast<const char*>(buf), 20) << '\t'
<< static_cast<char*>(client->m_addrString));
++n;
}
Expand Down Expand Up @@ -1183,7 +1180,8 @@ P2PServer::P2PClient::P2PClient()
, m_lastPeerListRequestTime{}
, m_peerListPendingRequests(0)
, m_protocolVersion(PROTOCOL_VERSION_1_0)
, m_P2PoolVersion(0)
, m_SoftwareVersion(0)
, m_SoftwareID(0)
, m_pingTime(-1)
, m_blockPendingRequests(0)
, m_chainTipBlockRequest(false)
Expand Down Expand Up @@ -1230,7 +1228,8 @@ void P2PServer::P2PClient::reset()
m_lastPeerListRequestTime = {};
m_peerListPendingRequests = 0;
m_protocolVersion = PROTOCOL_VERSION_1_0;
m_P2PoolVersion = 0;
m_SoftwareVersion = 0;
m_SoftwareID = 0;
m_pingTime = -1;
m_blockPendingRequests = 0;
m_chainTipBlockRequest = false;
Expand Down Expand Up @@ -2140,10 +2139,11 @@ bool P2PServer::P2PClient::on_peer_list_response(const uint8_t* buf)
// Check for protocol version message
if ((*reinterpret_cast<uint32_t*>(ip.data + 12) == 0xFFFFFFFFU) && (port == 0xFFFF)) {
m_protocolVersion = *reinterpret_cast<uint32_t*>(ip.data);
m_P2PoolVersion = *reinterpret_cast<uint32_t*>(ip.data + 4);
m_SoftwareVersion = *reinterpret_cast<uint32_t*>(ip.data + 4);
m_SoftwareID = *reinterpret_cast<uint32_t*>(ip.data + 8);
LOGINFO(5, "peer " << log::Gray() << static_cast<char*>(m_addrString) << log::NoColor()
<< " supports protocol version " << (m_protocolVersion >> 16) << '.' << (m_protocolVersion & 0xFFFF)
<< ", runs P2Pool version " << (m_P2PoolVersion >> 16) << '.' << (m_P2PoolVersion & 0xFFFF)
<< ", runs " << software_name() << " v" << (m_SoftwareVersion >> 16) << '.' << (m_SoftwareVersion & 0xFFFF)
);
}
continue;
Expand Down Expand Up @@ -2346,4 +2346,16 @@ void P2PServer::P2PClient::post_handle_incoming_block(const uint32_t reset_count
}
}

const char* P2PServer::P2PClient::software_name() const
{
switch (m_SoftwareID) {
case 0:
return "P2Pool";
case 0x624F6F47UL:
return "GoObserver";
default:
return "Unknown";
}
}

} // namespace p2pool
5 changes: 4 additions & 1 deletion src/p2p_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ class P2PServer : public TCPServer<P2P_BUF_SIZE, P2P_BUF_SIZE>

bool is_good() const { return m_handshakeComplete && !m_handshakeInvalid && (m_listenPort >= 0); }

const char* software_name() const;

uint64_t m_peerId;
MessageId m_expectedMessage;
uint64_t m_handshakeChallenge;
Expand All @@ -125,7 +127,8 @@ class P2PServer : public TCPServer<P2P_BUF_SIZE, P2P_BUF_SIZE>
int m_peerListPendingRequests;

uint32_t m_protocolVersion;
uint32_t m_P2PoolVersion;
uint32_t m_SoftwareVersion;
uint32_t m_SoftwareID;

int64_t m_pingTime;

Expand Down

0 comments on commit 3e4f877

Please sign in to comment.