P2PServer fixes (peer list loading, peer id and other smaller fixes)
C/C++ CI / build-alpine-static (map[arch:aarch64 branch:latest-stable flags:-ffunction-sections -mfix-cortex-a53-835769 -mfix-cortex-a53-843419]) (push) Failing after 31s
C/C++ CI / build-alpine-static (map[arch:riscv64 branch:latest-stable flags:-ffunction-sections]) (push) Failing after 7s
C/C++ CI / build-alpine-static (map[arch:x86_64 branch:latest-stable flags:-ffunction-sections]) (push) Failing after 9s
C/C++ CI / build-ubuntu (map[c:gcc-10 cpp:g++-10 flags: os:ubuntu-22.04]) (push) Failing after 10m28s
C/C++ CI / build-ubuntu (map[c:gcc-11 cpp:g++-11 flags: os:ubuntu-22.04]) (push) Failing after 9m1s
Sync test / sync-test-ubuntu-msan (push) Has been cancelled
Sync test / sync-test-ubuntu-ubsan (push) Has been cancelled
Sync test / sync-test-ubuntu-asan (push) Has been cancelled
Sync test / sync-test-ubuntu-tysan (push) Has been cancelled
Sync test / sync-test-macos (map[flags: os:macos-26-intel]) (push) Has been cancelled
Sync test / sync-test-macos (map[flags:-target arm64-apple-macos-11 os:macos-26]) (push) Has been cancelled
Sync test / sync-test-windows-debug-asan (push) Has been cancelled
Sync test / sync-test-windows-leaks (push) Has been cancelled
clang-tidy / clang-tidy (push) Has been cancelled
CodeQL / Analyze (cpp) (push) Has been cancelled
Code coverage / coverage (push) Has been cancelled
cppcheck / cppcheck-ubuntu (push) Has been cancelled
cppcheck / cppcheck-windows (push) Has been cancelled
C/C++ CI / build-ubuntu (map[c:gcc-13 cpp:g++-13 flags: os:ubuntu-24.04]) (push) Has been cancelled
C/C++ CI / build-ubuntu (map[c:gcc-14 cpp:g++-14 flags: os:ubuntu-24.04]) (push) Has been cancelled
C/C++ CI / build-ubuntu (map[c:gcc-9 cpp:g++-9 flags: os:ubuntu-22.04]) (push) Has been cancelled
C/C++ CI / build-ubuntu-static-libs (map[flags:-fuse-linker-plugin -ffunction-sections]) (push) Has been cancelled
C/C++ CI / build-ubuntu-aarch64 (map[flags:-fuse-linker-plugin -ffunction-sections -mfix-cortex-a53-835769 -mfix-cortex-a53-843419 os:ubuntu-22.04-arm]) (push) Has been cancelled
C/C++ CI / build-windows-msys2 (map[c:gcc cxx:g++ flags:-ffunction-sections -Wno-error=maybe-uninitialized -Wno-error=attributes -Wno-attributes]) (push) Has been cancelled
C/C++ CI / build-windows-msbuild (map[grpc:OFF os:2022 rx:OFF tls:OFF upnp:OFF vs:Visual Studio 17 2022 vspath:C:\Program Files\Microsoft Visual Studio\2022\Enterprise]) (push) Has been cancelled
C/C++ CI / build-windows-msbuild (map[grpc:OFF os:2022 rx:OFF tls:ON upnp:OFF vs:Visual Studio 17 2022 vspath:C:\Program Files\Microsoft Visual Studio\2022\Enterprise]) (push) Has been cancelled
C/C++ CI / build-windows-msbuild (map[grpc:OFF os:2022 rx:OFF tls:ON upnp:ON vs:Visual Studio 17 2022 vspath:C:\Program Files\Microsoft Visual Studio\2022\Enterprise]) (push) Has been cancelled
C/C++ CI / build-windows-msbuild (map[grpc:OFF os:2022 rx:ON tls:ON upnp:ON vs:Visual Studio 17 2022 vspath:C:\Program Files\Microsoft Visual Studio\2022\Enterprise]) (push) Has been cancelled
C/C++ CI / build-windows-msbuild (map[grpc:ON os:2022 rx:ON tls:ON upnp:ON vs:Visual Studio 17 2022 vspath:C:\Program Files\Microsoft Visual Studio\2022\Enterprise]) (push) Has been cancelled
C/C++ CI / build-macos (push) Has been cancelled
C/C++ CI / build-macos-aarch64 (push) Has been cancelled
C/C++ CI / build-freebsd (map[architecture:x86-64 host:ubuntu-latest name:freebsd version:13.3]) (push) Has been cancelled
C/C++ CI / build-openbsd (map[architecture:x86-64 host:ubuntu-latest name:openbsd version:7.4]) (push) Has been cancelled
C/C++ CI / build-ubuntu (map[c:gcc-12 cpp:g++-12 flags: os:ubuntu-22.04]) (push) Has been cancelled
C/C++ CI / build-windows-msys2 (map[c:clang cxx:clang++ flags:-fuse-ld=lld -Wno-unused-command-line-argument -Wno-nan-infinity-disabled -Wno-attributes]) (push) Has been cancelled
Microsoft C++ Code Analysis / Analyze (push) Has been cancelled
source-snapshot / source-snapshot (push) Has been cancelled
Sync test / sync-test-ubuntu-tsan (push) Has been cancelled

This commit is contained in:
SChernykh
2026-04-25 10:25:48 +02:00
parent 85750521bb
commit 7ca1beeb73
2 changed files with 32 additions and 11 deletions
+30 -10
View File
@@ -101,8 +101,10 @@ P2PServer::P2PServer(p2pool* pool)
// Diffuse the initial state in case it has low quality // Diffuse the initial state in case it has low quality
m_rng.discard(10000); m_rng.discard(10000);
m_peerId = m_rng(); // Make sure peer IDs are not 0
m_peerId_TOR = m_rng(); do { m_peerId = m_rng(); } while (!m_peerId);
do { m_peerId_TOR = m_rng(); } while (!m_peerId_TOR);
do { m_peerId_I2P = m_rng(); } while (!m_peerId_I2P);
const Params& params = pool->params(); const Params& params = pool->params();
@@ -795,14 +797,16 @@ void P2PServer::load_peer_list()
std::vector<std::string> paths; std::vector<std::string> paths;
paths.resize(Params::ProxyType::MAX); paths.resize(Params::ProxyType::MAX);
paths[Params::ProxyType::PLAIN] = saved_peer_list_file_name; const Params& params = m_pool->params();
paths[Params::ProxyType::PLAIN] = params.m_dataDir + saved_peer_list_file_name;
if (!m_socks5Proxy.empty() && (m_socks5ProxyType == Params::ProxyType::TOR)) { if (!m_socks5Proxy.empty() && (m_socks5ProxyType == Params::ProxyType::TOR)) {
paths[Params::ProxyType::TOR] = saved_onion_peer_list_file_name; paths[Params::ProxyType::TOR] = params.m_dataDir + saved_onion_peer_list_file_name;
} }
if (!m_socks5Proxy.empty() && (m_socks5ProxyType == Params::ProxyType::I2P)) { if (!m_socks5Proxy.empty() && (m_socks5ProxyType == Params::ProxyType::I2P)) {
paths[Params::ProxyType::I2P] = saved_i2p_peer_list_file_name; paths[Params::ProxyType::I2P] = params.m_dataDir + saved_i2p_peer_list_file_name;
} }
for (int i = Params::ProxyType::PLAIN; i < Params::ProxyType::MAX; ++i) { for (int i = Params::ProxyType::PLAIN; i < Params::ProxyType::MAX; ++i) {
@@ -2102,7 +2106,7 @@ bool P2PServer::P2PClient::on_read(const char* data, uint32_t size)
const MessageId id = static_cast<MessageId>(buf[0]); const MessageId id = static_cast<MessageId>(buf[0]);
// Peer must complete the handshake challenge before sending any other messages // Peer must complete the handshake challenge before sending any other messages
if (!m_handshakeComplete && (id != m_expectedMessage)) { if ((!m_handshakeComplete || m_handshakeInvalid) && (id != m_expectedMessage)) {
LOGWARN(5, "peer " << static_cast<char*>(m_addrString) << " didn't send handshake messages first"); LOGWARN(5, "peer " << static_cast<char*>(m_addrString) << " didn't send handshake messages first");
ban(DEFAULT_BAN_TIME); ban(DEFAULT_BAN_TIME);
server->remove_peer_from_list(this); server->remove_peer_from_list(this);
@@ -2396,7 +2400,18 @@ bool P2PServer::P2PClient::send_handshake_challenge()
k >>= 8; k >>= 8;
} }
k = owner->get_peerId((m_addressType == AddressType::DomainName) && (strstr(m_addrString, ".onion:"))); bool is_tor = false;
if ((m_addressType == AddressType::DomainName) && (strstr(m_addrString, ".onion:"))) {
// We're connecting to an .onion address
is_tor = true;
}
else if (!owner->m_pool->params().m_onionPubkey.empty() && m_isIncoming && (m_addressType != AddressType::DomainName) && m_addr.is_localhost()) {
// We published our .onion address, and it's an incoming connection on localhost interface, so it's likely an incoming tor connection
is_tor = true;
}
k = owner->get_peerId(is_tor, owner->m_isI2P);
memcpy(p, &k, sizeof(uint64_t)); memcpy(p, &k, sizeof(uint64_t));
p += sizeof(uint64_t); p += sizeof(uint64_t);
@@ -2589,7 +2604,7 @@ bool P2PServer::P2PClient::on_handshake_challenge(const uint8_t* buf)
uint64_t peer_id; uint64_t peer_id;
memcpy(&peer_id, buf + CHALLENGE_SIZE, sizeof(uint64_t)); memcpy(&peer_id, buf + CHALLENGE_SIZE, sizeof(uint64_t));
if ((peer_id == server->get_peerId(false)) || (peer_id == server->get_peerId(true))) { if ((peer_id == server->m_peerId) || (peer_id == server->m_peerId_TOR) || (peer_id == server->m_peerId_I2P)) {
LOGWARN(5, "tried to connect to self at " << static_cast<const char*>(m_addrString)); LOGWARN(5, "tried to connect to self at " << static_cast<const char*>(m_addrString));
return false; return false;
} }
@@ -2687,7 +2702,7 @@ bool P2PServer::P2PClient::on_listen_port(const uint8_t* buf)
int32_t port; int32_t port;
memcpy(&port, buf, sizeof(port)); memcpy(&port, buf, sizeof(port));
if ((port < 0) || (port >= 65536)) { if ((port <= 0) || (port >= 65536)) {
LOGWARN(5, "peer " << static_cast<char*>(m_addrString) << " sent an invalid listen port number"); LOGWARN(5, "peer " << static_cast<char*>(m_addrString) << " sent an invalid listen port number");
return false; return false;
} }
@@ -3201,6 +3216,11 @@ bool P2PServer::P2PClient::on_aux_job_donation(const uint8_t* buf, uint32_t size
p += sizeof(int64_t); p += sizeof(int64_t);
// Ignore outdated messages // Ignore outdated messages
if (data_timestamp > std::numeric_limits<int64_t>::max() - AUX_JOB_TIMEOUT) {
LOGWARN(4, "peer " << static_cast<char*>(m_addrString) << " sent an invalid AUX_JOB_DONATION message (timestamp = " << data_timestamp << ')');
return false;
}
if (cur_time >= data_timestamp + AUX_JOB_TIMEOUT) { if (cur_time >= data_timestamp + AUX_JOB_TIMEOUT) {
LOGWARN(4, "peer " << static_cast<char*>(m_addrString) << " sent an outdated AUX_JOB_DONATION message (" << cur_time << " >= " << data_timestamp << " + " << static_cast<int>(AUX_JOB_TIMEOUT) << ')'); LOGWARN(4, "peer " << static_cast<char*>(m_addrString) << " sent an outdated AUX_JOB_DONATION message (" << cur_time << " >= " << data_timestamp << " + " << static_cast<int>(AUX_JOB_TIMEOUT) << ')');
return true; return true;
@@ -3208,7 +3228,7 @@ bool P2PServer::P2PClient::on_aux_job_donation(const uint8_t* buf, uint32_t size
if ((data_end - p) % DATA_ENTRY_SIZE) { if ((data_end - p) % DATA_ENTRY_SIZE) {
LOGWARN(4, "peer " << static_cast<char*>(m_addrString) << " sent an invalid AUX_JOB_DONATION message (" << (data_end - p) << " is not a multiple of " << DATA_ENTRY_SIZE << ')'); LOGWARN(4, "peer " << static_cast<char*>(m_addrString) << " sent an invalid AUX_JOB_DONATION message (" << (data_end - p) << " is not a multiple of " << DATA_ENTRY_SIZE << ')');
return true; return false;
} }
hash digest; hash digest;
+2 -1
View File
@@ -192,7 +192,7 @@ public:
void broadcast(const PoolBlock& block, const PoolBlock* parent); void broadcast(const PoolBlock& block, const PoolBlock* parent);
[[nodiscard]] uint64_t get_random64(); [[nodiscard]] uint64_t get_random64();
[[nodiscard]] uint64_t get_peerId(bool is_tor) const { return is_tor ? m_peerId_TOR : m_peerId; } [[nodiscard]] uint64_t get_peerId(bool is_tor, bool is_i2p) const { return is_tor ? m_peerId_TOR : (is_i2p ? m_peerId_I2P : m_peerId); }
void print_status() override; void print_status() override;
void show_peers_async(); void show_peers_async();
@@ -272,6 +272,7 @@ private:
uint64_t m_peerId; uint64_t m_peerId;
uint64_t m_peerId_TOR; uint64_t m_peerId_TOR;
uint64_t m_peerId_I2P;
mutable uv_mutex_t m_peerListLock; mutable uv_mutex_t m_peerListLock;