Add I2P support
This commit is contained in:
+12
-5
@@ -213,7 +213,7 @@ void BlockTemplate::update(const MinerData& data, const Mempool& mempool, const
|
||||
|
||||
// Block template construction is relatively slow, but it's better to keep the lock the whole time
|
||||
// instead of using temporary variables and making a quick swap in the end
|
||||
//
|
||||
//
|
||||
// All readers will line up for the new template instead of using the outdated template
|
||||
WriteLock lock(m_lock);
|
||||
|
||||
@@ -617,7 +617,7 @@ void BlockTemplate::update(const MinerData& data, const Mempool& mempool, const
|
||||
m_poolBlockTemplate->m_auxNonce = data.aux_nonce;
|
||||
|
||||
m_poolBlockTemplate->m_mergeMiningExtra.clear();
|
||||
|
||||
|
||||
for (const AuxChainData& c : data.aux_chains) {
|
||||
std::vector<uint8_t> v;
|
||||
v.reserve(HASH_SIZE + 16);
|
||||
@@ -644,6 +644,13 @@ void BlockTemplate::update(const MinerData& data, const Mempool& mempool, const
|
||||
m_poolBlockTemplate->m_mergeMiningExtra.emplace(keccak_onion_address_v3, std::vector(buf, buf + sizeof(buf)));
|
||||
}
|
||||
|
||||
if (!params.m_i2pDestinationHash.empty()) {
|
||||
uint8_t buf[HASH_SIZE + 2] = {};
|
||||
memcpy(buf, params.m_i2pDestinationHash.h, HASH_SIZE);
|
||||
|
||||
m_poolBlockTemplate->m_mergeMiningExtra.emplace(keccak_i2p_b32_address, std::vector(buf, buf + sizeof(buf)));
|
||||
}
|
||||
|
||||
init_merge_mining_merkle_proof();
|
||||
|
||||
const std::vector<uint8_t> sidechain_data = m_poolBlockTemplate->serialize_sidechain_data();
|
||||
@@ -752,7 +759,7 @@ void BlockTemplate::fill_optimal_knapsack(const MinerData& data, uint64_t base_r
|
||||
{
|
||||
// Find the maximum possible fee for every weight value and remember which tx leads to this fee/weight
|
||||
// Run time is O(N*W) where N is the number of transactions and W is the maximum block weight
|
||||
//
|
||||
//
|
||||
// Actual run time is 0.02-0.05 seconds on real full blocks
|
||||
// It's too slow and uses too much memory to be practical
|
||||
|
||||
@@ -975,7 +982,7 @@ int BlockTemplate::create_miner_tx(const MinerData& data, const std::vector<Mine
|
||||
LOGINFO(4, "increased EXTRA_NONCE from " << EXTRA_NONCE_SIZE << " to " << corrected_extra_nonce_size << " bytes to maintain miner tx weight");
|
||||
}
|
||||
writeVarint(corrected_extra_nonce_size, m_minerTxExtra);
|
||||
|
||||
|
||||
uint64_t extraNonceOffsetInMinerTx = m_minerTxExtra.size();
|
||||
m_minerTxExtra.insert(m_minerTxExtra.end(), corrected_extra_nonce_size, 0);
|
||||
|
||||
@@ -1406,7 +1413,7 @@ bool BlockTemplate::get_aux_proof(const uint32_t template_id, uint32_t extra_non
|
||||
uint32_t path2 = 0;
|
||||
|
||||
const bool result2 = get_merkle_proof(tree, h, proof2, path2);
|
||||
|
||||
|
||||
if ((result2 != result) || (proof2 != proof) || (path2 != path)) {
|
||||
LOGERR(1, "get_aux_proof: merkle_hash_with_proof and get_merkle_proof returned different results. Fix the code!");
|
||||
}
|
||||
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* This file is part of the Monero P2Pool <https://github.com/SChernykh/p2pool>
|
||||
* Copyright (c) 2021-2026 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2026 jpk68
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdexcept>
|
||||
#include <curl/curl.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "i2p.h"
|
||||
#include "log.h"
|
||||
|
||||
LOG_CATEGORY(I2P)
|
||||
|
||||
namespace p2pool {
|
||||
|
||||
hash from_i2p_b32(const std::string& address)
|
||||
{
|
||||
if ((address.length() < 8) || (address.find(".b32.i2p") != address.length() - 8)) {
|
||||
LOGWARN(3, "Invalid I2P address \"" << address << "\": doesn't end with \".b32.i2p\"");
|
||||
return {};
|
||||
}
|
||||
|
||||
if (address.length() != 60) {
|
||||
LOGWARN(3, "Invalid I2P address \"" << address << "\": expected length 60, got " << address.length());
|
||||
return {};
|
||||
}
|
||||
|
||||
size_t pos = address.find('.');
|
||||
const std::string dest_hash = address.substr(0, pos);
|
||||
const hash result = from_i2p_b32_const(dest_hash.c_str());
|
||||
|
||||
if (result.empty()) {
|
||||
LOGWARN(3, "Invalid I2P address \"" << address << "\": has invalid character(s)");
|
||||
return {};
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string to_i2p_b32(const hash& dest_hash)
|
||||
{
|
||||
uint8_t buf[HASH_SIZE + 1];
|
||||
memcpy(buf, dest_hash.h, HASH_SIZE);
|
||||
buf[HASH_SIZE] = 0;
|
||||
|
||||
std::string result;
|
||||
result.reserve(60);
|
||||
|
||||
uint64_t data = 0;
|
||||
uint64_t bit_size = 0;
|
||||
|
||||
for (size_t i = 0; i < HASH_SIZE + 1; ++i) {
|
||||
data = (data << 8) | buf[i];
|
||||
bit_size += 8;
|
||||
|
||||
while (bit_size >= 5) {
|
||||
bit_size -= 5;
|
||||
result += "abcdefghijklmnopqrstuvwxyz234567"[(data >> bit_size) & 31];
|
||||
}
|
||||
}
|
||||
|
||||
result.append(".b32.i2p");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace p2pool
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* This file is part of the Monero P2Pool <https://github.com/SChernykh/p2pool>
|
||||
* Copyright (c) 2021-2026 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2026 jpk68
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
#include <string>
|
||||
#include <uv.h>
|
||||
|
||||
namespace p2pool {
|
||||
|
||||
static FORCEINLINE constexpr hash from_i2p_b32_const(const char* dest_hash)
|
||||
{
|
||||
uint8_t buf[HASH_SIZE + 4] = {};
|
||||
uint8_t* p = buf;
|
||||
|
||||
uint64_t data = 0;
|
||||
uint64_t bit_size = 0;
|
||||
|
||||
for (size_t i = 0; i < 52; ++i) {
|
||||
const char c = dest_hash[i];
|
||||
uint64_t digit = 0;
|
||||
|
||||
if ('a' <= c && c <= 'z') {
|
||||
digit = static_cast<uint64_t>(c - 'a');
|
||||
}
|
||||
else if ('A' <= c && c <= 'Z') {
|
||||
digit = static_cast<uint64_t>(c - 'A');
|
||||
}
|
||||
else if ('2' <= c && c <= '7') {
|
||||
digit = static_cast<uint64_t>(c - '2') + 26;
|
||||
}
|
||||
else {
|
||||
return {};
|
||||
}
|
||||
|
||||
data = (data << 5) | digit;
|
||||
bit_size += 5;
|
||||
|
||||
while (bit_size >= 8) {
|
||||
bit_size -= 8;
|
||||
*(p++) = static_cast<uint8_t>(data >> bit_size);
|
||||
}
|
||||
}
|
||||
|
||||
hash result;
|
||||
|
||||
for (size_t i = 0; i < HASH_SIZE; ++i) {
|
||||
result.h[i] = buf[i];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
hash from_i2p_b32(const std::string& address);
|
||||
std::string to_i2p_b32(const hash& dest_hash);
|
||||
|
||||
} // namespace p2pool
|
||||
@@ -25,14 +25,14 @@ namespace ConstexprKeccak
|
||||
template<int ROUNDS>
|
||||
static FORCEINLINE constexpr void keccakf(std::array<uint64_t, 25>& st)
|
||||
{
|
||||
constexpr uint64_t round_constants[24] =
|
||||
constexpr uint64_t round_constants[24] =
|
||||
{
|
||||
0x0000000000000001, 0x0000000000008082, 0x800000000000808a,
|
||||
0x8000000080008000, 0x000000000000808b, 0x0000000080000001,
|
||||
0x8000000080008081, 0x8000000000008009, 0x000000000000008a,
|
||||
0x0000000000000088, 0x0000000080008009, 0x000000008000000a,
|
||||
0x000000008000808b, 0x800000000000008b, 0x8000000000008089,
|
||||
0x8000000000008003, 0x8000000000008002, 0x8000000000000080,
|
||||
0x8000000000008003, 0x8000000000008002, 0x8000000000000080,
|
||||
0x000000000000800a, 0x800000008000000a, 0x8000000080008081,
|
||||
0x8000000000008080, 0x0000000080000001, 0x8000000080008008
|
||||
};
|
||||
@@ -107,6 +107,7 @@ static constexpr hash keccak(const char (&input)[len])
|
||||
constexpr hash keccak_0x00 = keccak("\0");
|
||||
constexpr hash keccak_subaddress_viewpub = keccak("subaddress_viewpub");
|
||||
constexpr hash keccak_onion_address_v3 = keccak("onion_address_v3");
|
||||
constexpr hash keccak_i2p_b32_address = keccak("i2p_b32_address");
|
||||
|
||||
static_assert(keccak_0x00.u64<0>() == 0x14281E7A9E7836BCULL, "constexpr keccak code check failed");
|
||||
|
||||
|
||||
+3
-1
@@ -64,6 +64,7 @@ void p2pool_usage()
|
||||
"--host IP address of your Monero node, default is 127.0.0.1\n"
|
||||
"--rpc-port monerod RPC API port number, default is 18081\n"
|
||||
"--zmq-port monerod ZMQ pub port number, default is 18083 (same port as in monerod's \"--zmq-pub\" command line parameter)\n"
|
||||
"--sam-port I2P router SAM bridge port number, default is 7656\n"
|
||||
"--stratum Comma-separated list of IP:port for stratum server to listen on\n"
|
||||
"--p2p Comma-separated list of IP:port for p2p server to listen on\n"
|
||||
"--addpeers Comma-separated list of IP:port of other p2pool nodes to connect to\n"
|
||||
@@ -89,7 +90,7 @@ void p2pool_usage()
|
||||
"--no-autodiff Disable automatic difficulty adjustment for miners connected to stratum (WARNING: incompatible with Nicehash and MRR)\n"
|
||||
"--rpc-login Specify username[:password] required for Monero RPC server\n"
|
||||
"--socks5 Specify IP:port of a SOCKS5 proxy to use for outgoing connections\n"
|
||||
"--socks5-proxy-type The type of SOCKS5 proxy. Can be one of the following values: auto, plain, tor. Default is auto (auto-detect by the port number)\n"
|
||||
"--socks5-proxy-type The type of SOCKS5 proxy. Can be one of the following values: auto, plain, tor, i2p. Default is auto (auto-detected by the port number)\n"
|
||||
"--no-dns Disable DNS queries, use only IP addresses to connect to peers (seed node DNS will be unavailable too)\n"
|
||||
"--p2p-external-port Port number that your router uses for mapping to your local p2p port. Use it if you are behind a NAT and still want to accept incoming connections\n"
|
||||
#ifdef WITH_UPNP
|
||||
@@ -110,6 +111,7 @@ void p2pool_usage()
|
||||
"--no-stratum-http Disable HTTP on Stratum ports\n"
|
||||
"--full-validation Enables full share validation / increases CPU usage\n"
|
||||
"--onion-address Tell other peers to use this .onion address to connect to this node through TOR\n"
|
||||
"--i2p-address Tell other peers to use this .b32.i2p address to connect to this node through I2P\n"
|
||||
"--no-clearnet-p2p Forces P2P server to listen on 127.0.0.1 and to not connect to clearnet IPs\n"
|
||||
"--params-file File name to load parameters from. It can't be used together with any other command line parameters\n"
|
||||
"--help Show this help message\n\n"
|
||||
|
||||
@@ -89,7 +89,7 @@ MergeMiningClientTari::MergeMiningClientTari(p2pool* pool, std::string host, con
|
||||
s << "127.0.0.1:" << m_server->external_listen_port();
|
||||
|
||||
m_channelArgs.SetInt(GRPC_ARG_INITIAL_RECONNECT_BACKOFF_MS, 1000);
|
||||
|
||||
|
||||
m_channelArgs.SetInt(GRPC_ARG_MIN_RECONNECT_BACKOFF_MS, 1000);
|
||||
m_channelArgs.SetInt(GRPC_ARG_MAX_RECONNECT_BACKOFF_MS, 10000);
|
||||
|
||||
@@ -248,7 +248,7 @@ void MergeMiningClientTari::on_external_block(const PoolBlock& block)
|
||||
|
||||
for (const auto& i : block.m_mergeMiningExtra) {
|
||||
// Filter aux chain data only
|
||||
if ((i.first == keccak_subaddress_viewpub) || (i.first == keccak_onion_address_v3)) {
|
||||
if ((i.first == keccak_subaddress_viewpub) || (i.first == keccak_onion_address_v3) || (i.first == keccak_i2p_b32_address)) {
|
||||
continue;
|
||||
}
|
||||
++mm_extra_size;
|
||||
@@ -352,7 +352,7 @@ void MergeMiningClientTari::on_external_block(const PoolBlock& block)
|
||||
|
||||
std::vector<uint8_t> coinbase_merkle_proof;
|
||||
coinbase_merkle_proof.reserve(proof.size() * HASH_SIZE);
|
||||
|
||||
|
||||
for (const hash& h : proof) {
|
||||
coinbase_merkle_proof.insert(coinbase_merkle_proof.end(), h.h, h.h + HASH_SIZE);
|
||||
}
|
||||
|
||||
+98
-8
@@ -33,6 +33,7 @@
|
||||
#include "rapidjson_wrapper.h"
|
||||
#include "merge_mining_client.h"
|
||||
#include "sha256.h"
|
||||
#include "i2p.h"
|
||||
|
||||
#ifdef WITH_TLS
|
||||
#include <openssl/curve25519.h>
|
||||
@@ -48,6 +49,7 @@ LOG_CATEGORY(P2PServer)
|
||||
|
||||
static constexpr char saved_peer_list_file_name[] = "p2pool_peers.txt";
|
||||
static constexpr char saved_onion_peer_list_file_name[] = "p2pool_onion_peers.txt";
|
||||
static constexpr char saved_i2p_peer_list_file_name[] = "p2pool_i2p_peers.txt";
|
||||
static const char* seed_nodes[] = { "seeds.p2pool.io", "main.p2poolpeers.net", "" };
|
||||
static const char* seed_nodes_mini[] = { "seeds-mini.p2pool.io", "mini.p2poolpeers.net", "" };
|
||||
static const char* seed_nodes_nano[] = { "seeds-nano.p2pool.io", "nano.p2poolpeers.net", ""};
|
||||
@@ -63,6 +65,10 @@ static constexpr hash seed_onion_nodes[] = {
|
||||
from_onion_v3_const("p2pseedtwyepi4crkf4akceen4twejcptnsbm6gjmzdfgxua57hiijid.onion")
|
||||
};
|
||||
|
||||
static constexpr hash seed_i2p_nodes[] = {
|
||||
from_i2p_b32_const("mwrwtarc2x6ea2qrzo737nnxv2gg5mo5atk24f5omy3j74xtwkqa")
|
||||
};
|
||||
|
||||
P2PServer::P2PServer(p2pool* pool)
|
||||
: TCPServer(DEFAULT_BACKLOG, P2PClient::allocate, pool->params().m_socks5Proxy, pool->params().m_socks5ProxyType, pool->params().m_p2pProxyProtocol)
|
||||
, m_pool(pool)
|
||||
@@ -79,6 +85,8 @@ P2PServer::P2PServer(p2pool* pool)
|
||||
, m_seenGoodPeers(false)
|
||||
, m_peerListLastSaved(0)
|
||||
, m_numOnionConnections(0)
|
||||
, m_numI2PConnections(0)
|
||||
, m_isI2P(pool->params().m_socks5ProxyType == Params::ProxyType::I2P)
|
||||
, m_lookForMissingBlocks(true)
|
||||
, m_fastestPeer(nullptr)
|
||||
, m_newP2PoolVersionDetected(false)
|
||||
@@ -459,6 +467,39 @@ void P2PServer::update_peer_connections()
|
||||
}
|
||||
}
|
||||
|
||||
// Try to have at least N/2 (or N if clearnet P2P is disabled) outgoing I2P connections
|
||||
if (!m_socks5Proxy.empty() && (m_socks5ProxyType == Params::ProxyType::I2P)) {
|
||||
std::vector<hash> dest_hashes = m_pool->side_chain().seen_i2p_dest_hashes();
|
||||
|
||||
// Add seed nodes
|
||||
dest_hashes.insert(dest_hashes.end(), seed_i2p_nodes, seed_i2p_nodes + array_size(seed_i2p_nodes));
|
||||
|
||||
const uint32_t n = m_pool->params().m_noClearnetP2P ? N : (N / 2);
|
||||
|
||||
for (uint32_t i = m_numI2PConnections; (i < n) && !dest_hashes.empty();) {
|
||||
const uint64_t k = get_random64() % dest_hashes.size();
|
||||
const std::string addr = to_i2p_b32(dest_hashes[k]);
|
||||
|
||||
int port = DEFAULT_P2P_PORT_I2P;
|
||||
|
||||
for (const hash& seed_i2p : seed_i2p_nodes) {
|
||||
if (dest_hashes[k] == seed_i2p) {
|
||||
const SideChain& s = m_pool->side_chain();
|
||||
port = s.is_mini() ? DEFAULT_P2P_PORT_MINI : (s.is_nano() ? DEFAULT_P2P_PORT_NANO : DEFAULT_P2P_PORT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((connected_clients_domain.find(addr) == connected_clients_domain.end()) && connect_to_peer(addr, port)) {
|
||||
++i;
|
||||
++num_outgoing;
|
||||
}
|
||||
|
||||
dest_hashes[k] = dest_hashes.back();
|
||||
dest_hashes.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
// Try to have at least N outgoing connections (N defaults to 10, can be set via --out-peers command line parameter)
|
||||
if (!m_pool->params().m_noClearnetP2P) {
|
||||
while ((num_outgoing < N) && !peer_list.empty()) {
|
||||
@@ -631,6 +672,28 @@ void P2PServer::save_peer_list()
|
||||
}
|
||||
}
|
||||
|
||||
if (s.i2p_dest_hashes_count() > 0) {
|
||||
const std::string i2p_path = params.m_dataDir + saved_i2p_peer_list_file_name;
|
||||
|
||||
f.open(i2p_path, std::ios::binary);
|
||||
|
||||
if (!f.is_open()) {
|
||||
LOGERR(1, "failed to save I2P peer list " << i2p_path << ": error " << errno);
|
||||
}
|
||||
else {
|
||||
const std::vector<hash> dest_hashes = s.seen_i2p_dest_hashes();
|
||||
|
||||
for (const hash& h : dest_hashes) {
|
||||
f << to_i2p_b32(h) << '\n';
|
||||
}
|
||||
|
||||
f.flush();
|
||||
f.close();
|
||||
|
||||
LOGINFO(5, "I2P peer list saved (" << dest_hashes.size() << " peers)");
|
||||
}
|
||||
}
|
||||
|
||||
m_peerListLastSaved = seconds_since_epoch();
|
||||
}
|
||||
|
||||
@@ -738,6 +801,10 @@ void P2PServer::load_peer_list()
|
||||
paths[Params::ProxyType::TOR] = saved_onion_peer_list_file_name;
|
||||
}
|
||||
|
||||
if (!m_socks5Proxy.empty() && (m_socks5ProxyType == Params::ProxyType::I2P)) {
|
||||
paths[Params::ProxyType::I2P] = saved_i2p_peer_list_file_name;
|
||||
}
|
||||
|
||||
for (int i = Params::ProxyType::PLAIN; i < Params::ProxyType::MAX; ++i) {
|
||||
const std::string& path = paths[i];
|
||||
|
||||
@@ -761,6 +828,12 @@ void P2PServer::load_peer_list()
|
||||
pubkeys.emplace_back(h);
|
||||
}
|
||||
}
|
||||
else if (i == Params::ProxyType::I2P) {
|
||||
const hash h = from_i2p_b32(address);
|
||||
if (!h.empty()) {
|
||||
pubkeys.emplace_back(h);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!saved_list.empty()) {
|
||||
saved_list += ',';
|
||||
@@ -774,6 +847,9 @@ void P2PServer::load_peer_list()
|
||||
if (i == Params::ProxyType::TOR) {
|
||||
s.add_onion_pubkeys(pubkeys);
|
||||
}
|
||||
else if (i == Params::ProxyType::I2P) {
|
||||
s.add_i2p_dest_hashes(pubkeys);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1214,13 +1290,17 @@ uint64_t P2PServer::get_random64()
|
||||
void P2PServer::print_status()
|
||||
{
|
||||
const uint64_t onion_list_size = m_pool->side_chain().onion_pubkeys_count();
|
||||
const uint64_t i2p_list_size = m_pool->side_chain().i2p_dest_hashes_count();
|
||||
|
||||
MutexLock lock(m_peerListLock);
|
||||
|
||||
LOGINFO(0, "status" <<
|
||||
"\nConnections = " << m_numConnections.load() << " (" << m_numIncomingConnections.load() << " incoming, " << m_numOnionConnections.load() << " onion)"
|
||||
"\nConnections = " << m_numConnections.load() <<
|
||||
" (" << m_numIncomingConnections.load() <<
|
||||
" incoming, " << m_numOnionConnections.load() << " onion, " << m_numI2PConnections.load() << " I2P)" <<
|
||||
"\nPeer list size = " << m_peerList.size() <<
|
||||
"\nOnion list size = " << onion_list_size <<
|
||||
"\nI2P list size = " << i2p_list_size <<
|
||||
"\nUptime = " << log::Duration(seconds_since_epoch() - m_pool->start_time())
|
||||
);
|
||||
}
|
||||
@@ -1911,7 +1991,13 @@ void P2PServer::P2PClient::reset()
|
||||
server->m_fastestPeer = nullptr;
|
||||
}
|
||||
if ((m_addressType == AddressType::DomainName) && m_connectedTime) {
|
||||
--server->m_numOnionConnections;
|
||||
if (m_addressType == AddressType::DomainName) {
|
||||
if (server->m_isI2P == true) {
|
||||
--server->m_numI2PConnections;
|
||||
} else {
|
||||
--server->m_numOnionConnections;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1971,7 +2057,11 @@ bool P2PServer::P2PClient::on_connect()
|
||||
}
|
||||
|
||||
if (m_addressType == AddressType::DomainName) {
|
||||
++server->m_numOnionConnections;
|
||||
if (server->m_isI2P == true) {
|
||||
++server->m_numI2PConnections;
|
||||
} else {
|
||||
++server->m_numOnionConnections;
|
||||
}
|
||||
}
|
||||
|
||||
const uint64_t cur_time = seconds_since_epoch();
|
||||
@@ -3043,7 +3133,7 @@ bool P2PServer::P2PClient::on_aux_job_donation(const uint8_t* buf, uint32_t size
|
||||
const time_t cur_time = time(nullptr);
|
||||
|
||||
// Layout of the message:
|
||||
//
|
||||
//
|
||||
// 32 bytes | Secondary public key
|
||||
// 8 bytes | Secondary public key's expiration timestamp
|
||||
// 64 bytes | Master key signature signing the above 40 bytes
|
||||
@@ -3062,11 +3152,11 @@ bool P2PServer::P2PClient::on_aux_job_donation(const uint8_t* buf, uint32_t size
|
||||
}
|
||||
|
||||
// Layout of the data:
|
||||
//
|
||||
//
|
||||
// 8 bytes | timestamp
|
||||
//
|
||||
//
|
||||
// Next come one or multiple data entries:
|
||||
//
|
||||
//
|
||||
// 32 bytes | aux_id
|
||||
// 32 bytes | aux_hash
|
||||
// 16 bytes | aux_diff
|
||||
@@ -3262,7 +3352,7 @@ bool P2PServer::P2PClient::on_monero_block_broadcast(const uint8_t* buf, uint32_
|
||||
|
||||
std::vector<uint8_t> blob;
|
||||
blob.reserve(data.header_size + HASH_SIZE + 2);
|
||||
|
||||
|
||||
blob.insert(blob.end(), buf, buf + data.header_size);
|
||||
blob.insert(blob.end(), root.h, root.h + HASH_SIZE);
|
||||
writeVarint(num_transactions + 1, blob);
|
||||
|
||||
+5
-2
@@ -37,6 +37,7 @@ static constexpr int DEFAULT_P2P_PORT_MINI = 37888;
|
||||
static constexpr int DEFAULT_P2P_PORT_NANO = 37890;
|
||||
|
||||
static constexpr int DEFAULT_P2P_PORT_ONION = 28722;
|
||||
static constexpr int DEFAULT_P2P_PORT_I2P = 28723;
|
||||
|
||||
static constexpr uint32_t PROTOCOL_VERSION_1_0 = 0x00010000UL;
|
||||
static constexpr uint32_t PROTOCOL_VERSION_1_1 = 0x00010001UL;
|
||||
@@ -95,9 +96,9 @@ public:
|
||||
// Both peers send handshake challenge immediately after a connection is established
|
||||
// Both peers must have the same consensus ID for handshake to succeed
|
||||
// Consensus ID is never sent over the network
|
||||
//
|
||||
//
|
||||
// Handshake sequence:
|
||||
//
|
||||
//
|
||||
// - Both peers send 8-byte random challenges (and 8 bytes of peer ID) to each other
|
||||
// - Each peer receives 8-byte challenge, chooses 8-byte random SALT and calculates H = KECCAK(CHALLENGE|CONSENSUS_ID|SALT)
|
||||
// - Both peers send their H and SALT, calculate H of the other peer and check if it matches with what other peer calculated
|
||||
@@ -291,6 +292,8 @@ private:
|
||||
std::atomic<uint64_t> m_peerListLastSaved;
|
||||
|
||||
std::atomic<uint32_t> m_numOnionConnections;
|
||||
std::atomic<uint32_t> m_numI2PConnections;
|
||||
bool m_isI2P;
|
||||
|
||||
uv_mutex_t m_broadcastLock;
|
||||
uv_async_t m_broadcastAsync;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "params.h"
|
||||
#include "stratum_server.h"
|
||||
#include "p2p_server.h"
|
||||
#include "i2p.h"
|
||||
#include <fstream>
|
||||
|
||||
#ifdef WITH_GRPC
|
||||
@@ -59,6 +60,15 @@ Params::Params(const std::vector<std::vector<std::string>>& args)
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_i2pAddress.empty()) {
|
||||
m_i2pDestinationHash = from_i2p_b32(m_i2pAddress);
|
||||
|
||||
if (m_i2pDestinationHash.empty()) {
|
||||
LOGERR(1, "Failed to parse \"" << m_i2pAddress << '"');
|
||||
throw std::exception();
|
||||
}
|
||||
}
|
||||
|
||||
auto invalid_host = [](const Host& h)
|
||||
{
|
||||
if (!h.valid()) {
|
||||
@@ -180,6 +190,10 @@ Params::Params(const std::vector<std::vector<std::string>>& args)
|
||||
m_socks5ProxyType = ProxyType::TOR;
|
||||
break;
|
||||
|
||||
case 4447:
|
||||
m_socks5ProxyType = ProxyType::I2P;
|
||||
break;
|
||||
|
||||
default:
|
||||
m_socks5ProxyType = ProxyType::PLAIN;
|
||||
break;
|
||||
@@ -460,6 +474,16 @@ bool Params::process_arg(const std::vector<std::string>& arg)
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((arg[0] == "i2p-address") && has1(arg)) {
|
||||
m_i2pAddress = arg[1];
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((arg[0] == "sam-port") && has1(arg)) {
|
||||
m_samPort = static_cast<int32_t>(std::min(std::max(strtoul(arg[1].c_str(), nullptr, 10), 1UL), 65535UL));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (arg[0] == "no-clearnet-p2p") {
|
||||
m_noClearnetP2P = true;
|
||||
return true;
|
||||
|
||||
+10
-1
@@ -116,7 +116,8 @@ struct Params
|
||||
AUTO = 0,
|
||||
PLAIN = 1,
|
||||
TOR = 2,
|
||||
MAX = 3,
|
||||
I2P = 3,
|
||||
MAX = 4,
|
||||
} m_socks5ProxyType = ProxyType::AUTO;
|
||||
|
||||
bool m_dns = true;
|
||||
@@ -148,6 +149,14 @@ struct Params
|
||||
|
||||
std::string m_onionAddress;
|
||||
hash m_onionPubkey;
|
||||
|
||||
// Hidden service address provided by the user
|
||||
std::string m_i2pAddress;
|
||||
// Raw hash of the destination info; decoded Base32 address with suffix removed
|
||||
hash m_i2pDestinationHash;
|
||||
|
||||
uint16_t m_samPort = 7656;
|
||||
|
||||
bool m_noClearnetP2P = false;
|
||||
bool m_stratumProxyProtocol = false;
|
||||
bool m_p2pProxyProtocol = false;
|
||||
|
||||
+42
-2
@@ -702,6 +702,13 @@ bool SideChain::add_block(const PoolBlock& block)
|
||||
m_seenOnionPubkeys[h] = new_block->m_localTimestamp;
|
||||
}
|
||||
|
||||
auto it2 = new_block->m_mergeMiningExtra.find(keccak_i2p_b32_address);
|
||||
if ((it2 != new_block->m_mergeMiningExtra.end()) && (it2->second.size() >= HASH_SIZE)) {
|
||||
hash h;
|
||||
memcpy(h.h, it2->second.data(), HASH_SIZE);
|
||||
m_seenI2PDestHashes[h] = new_block->m_localTimestamp;
|
||||
}
|
||||
|
||||
prune_seen_data();
|
||||
}
|
||||
|
||||
@@ -1156,7 +1163,7 @@ void SideChain::prune_seen_data()
|
||||
{
|
||||
const uint64_t cur_time = seconds_since_epoch();
|
||||
|
||||
// Every 5 minutes, delete wallets that weren't seen for more than 72 hours and onion pubkeys that weren't seen for more than 12 hours
|
||||
// Every 5 minutes, delete wallets that haven't been seen for more than 72 hours and onion/I2P identifiers that haven't been seen for more than 12 hours
|
||||
if (m_seenWalletsLastPruneTime + 5ul * 60ul <= cur_time) {
|
||||
auto prune = [cur_time](auto& data, uint64_t timeout) {
|
||||
for (auto it = data.begin(); it != data.end();) {
|
||||
@@ -1173,6 +1180,7 @@ void SideChain::prune_seen_data()
|
||||
|
||||
prune(m_seenWallets, 72 * hour);
|
||||
prune(m_seenOnionPubkeys, 12 * hour);
|
||||
prune(m_seenI2PDestHashes, 12 * hour);
|
||||
|
||||
m_seenWalletsLastPruneTime = cur_time;
|
||||
}
|
||||
@@ -1401,6 +1409,38 @@ void SideChain::add_onion_pubkeys(const std::vector<hash>& pubkeys)
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<hash> SideChain::seen_i2p_dest_hashes() const
|
||||
{
|
||||
std::vector<hash> result;
|
||||
|
||||
ReadLock lock(m_seenDataLock);
|
||||
|
||||
result.reserve(m_seenI2PDestHashes.size());
|
||||
|
||||
for (const auto& it : m_seenI2PDestHashes) {
|
||||
result.push_back(it.first);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void SideChain::add_i2p_dest_hashes(const std::vector<hash>& dest_hashes)
|
||||
{
|
||||
if (dest_hashes.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const uint64_t cur_time = seconds_since_epoch();
|
||||
|
||||
WriteLock lock(m_seenDataLock);
|
||||
|
||||
for (const hash& h : dest_hashes) {
|
||||
if (!h.empty()) {
|
||||
m_seenI2PDestHashes[h] = cur_time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SideChain::verify_loop(PoolBlock* block)
|
||||
{
|
||||
// PoW is already checked at this point
|
||||
@@ -2445,7 +2485,7 @@ void SideChain::precalc_worker()
|
||||
|
||||
do {
|
||||
const PoolBlock* job;
|
||||
|
||||
|
||||
{
|
||||
MutexLock lock(m_precalcJobsMutex);
|
||||
|
||||
|
||||
@@ -76,6 +76,7 @@ public:
|
||||
[[nodiscard]] uint64_t block_time() const { return m_targetBlockTime; }
|
||||
[[nodiscard]] FORCEINLINE uint64_t miner_count() const { ReadLock lock(m_seenDataLock); return m_seenWallets.size(); }
|
||||
[[nodiscard]] FORCEINLINE uint64_t onion_pubkeys_count() const { ReadLock lock(m_seenDataLock); return m_seenOnionPubkeys.size(); }
|
||||
[[nodiscard]] FORCEINLINE uint64_t i2p_dest_hashes_count() const { ReadLock lock(m_seenDataLock); return m_seenI2PDestHashes.size(); }
|
||||
[[nodiscard]] uint64_t last_updated() const;
|
||||
[[nodiscard]] bool is_default() const;
|
||||
[[nodiscard]] bool is_mini() const;
|
||||
@@ -90,6 +91,9 @@ public:
|
||||
[[nodiscard]] std::vector<hash> seen_onion_pubkeys() const;
|
||||
void add_onion_pubkeys(const std::vector<hash>& pubkeys);
|
||||
|
||||
[[nodiscard]] std::vector<hash> seen_i2p_dest_hashes() const;
|
||||
void add_i2p_dest_hashes(const std::vector<hash>& dest_hashes);
|
||||
|
||||
#ifdef P2POOL_UNIT_TESTS
|
||||
difficulty_type m_testMainChainDiff;
|
||||
const unordered_map<hash, PoolBlock*>& blocksById() const { return m_blocksById; }
|
||||
@@ -129,6 +133,7 @@ private:
|
||||
mutable ReadWriteLock m_seenDataLock;
|
||||
unordered_map<hash, uint64_t> m_seenWallets;
|
||||
unordered_map<hash, uint64_t> m_seenOnionPubkeys;
|
||||
unordered_map<hash, uint64_t> m_seenI2PDestHashes;
|
||||
uint64_t m_seenWalletsLastPruneTime;
|
||||
|
||||
// Used to quickly cut off multiple broadcasts of the same block by different peers. Only the first broadcast will be processed.
|
||||
|
||||
Reference in New Issue
Block a user