mirror of
https://github.com/SChernykh/p2pool.git
synced 2025-01-24 19:25:51 +00:00
P2PServer: load peers from DNS
This commit is contained in:
parent
3244925c66
commit
a332ac7d26
6 changed files with 71 additions and 6 deletions
|
@ -35,7 +35,7 @@ static void usage()
|
||||||
"--data-api Path to the p2pool JSON data (use it in tandem with an external web-server)\n"
|
"--data-api Path to the p2pool JSON data (use it in tandem with an external web-server)\n"
|
||||||
"--help Show this help message\n\n"
|
"--help Show this help message\n\n"
|
||||||
"Example command line:\n\n"
|
"Example command line:\n\n"
|
||||||
"%s --host 127.0.0.1 --rpc-port 18081 --zmq-port 18083 --wallet YOUR_WALLET_ADDRESS --stratum [::]:3333,0.0.0.0:3333 --p2p [::]:37890,0.0.0.0:37890\n\n",
|
"%s --host 127.0.0.1 --rpc-port 18081 --zmq-port 18083 --wallet YOUR_WALLET_ADDRESS --stratum [::]:3333,0.0.0.0:3333 --p2p [::]:37889,0.0.0.0:37889\n\n",
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
"p2pool.exe"
|
"p2pool.exe"
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -28,9 +28,13 @@
|
||||||
|
|
||||||
static constexpr char log_category_prefix[] = "P2PServer ";
|
static constexpr char log_category_prefix[] = "P2PServer ";
|
||||||
static constexpr char saved_peer_list_file_name[] = "p2pool_peers.txt";
|
static constexpr char saved_peer_list_file_name[] = "p2pool_peers.txt";
|
||||||
|
static const char* seed_nodes[] = {
|
||||||
|
"seeds.p2pool.io"
|
||||||
|
};
|
||||||
|
|
||||||
static constexpr int DEFAULT_BACKLOG = 16;
|
static constexpr int DEFAULT_BACKLOG = 16;
|
||||||
static constexpr uint64_t DEFAULT_BAN_TIME = 600;
|
static constexpr uint64_t DEFAULT_BAN_TIME = 600;
|
||||||
|
static constexpr int DEFAULT_LISTEN_PORT = 37889;
|
||||||
|
|
||||||
#include "tcp_server.inl"
|
#include "tcp_server.inl"
|
||||||
|
|
||||||
|
@ -83,7 +87,7 @@ P2PServer::P2PServer(p2pool* pool)
|
||||||
panic();
|
panic();
|
||||||
}
|
}
|
||||||
|
|
||||||
load_saved_peer_list();
|
load_peer_list();
|
||||||
start_listening(pool->params().m_p2pAddresses);
|
start_listening(pool->params().m_p2pAddresses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,10 +311,61 @@ void P2PServer::save_peer_list()
|
||||||
m_peerListLastSaved = time(nullptr);
|
m_peerListLastSaved = time(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void P2PServer::load_saved_peer_list()
|
void P2PServer::load_peer_list()
|
||||||
{
|
{
|
||||||
|
// First take peers from the command line
|
||||||
std::string saved_list = m_pool->params().m_p2pPeerList;
|
std::string saved_list = m_pool->params().m_p2pPeerList;
|
||||||
|
|
||||||
|
// Then load peers from seed nodes if we're on the default sidechain
|
||||||
|
if (m_pool->side_chain().is_default()) {
|
||||||
|
for (size_t i = 0; i < array_size(seed_nodes); ++i) {
|
||||||
|
LOGINFO(4, "loading peers from " << seed_nodes[i]);
|
||||||
|
|
||||||
|
addrinfo hints{};
|
||||||
|
hints.ai_family = AF_UNSPEC;
|
||||||
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
hints.ai_flags = AI_V4MAPPED | AI_ADDRCONFIG;
|
||||||
|
|
||||||
|
addrinfo* result;
|
||||||
|
const int err = getaddrinfo(seed_nodes[i], nullptr, &hints, &result);
|
||||||
|
if (err == 0) {
|
||||||
|
for (addrinfo* r = result; r != NULL; r = r->ai_next) {
|
||||||
|
const char* addr_str;
|
||||||
|
char addr_str_buf[64];
|
||||||
|
|
||||||
|
char buf[log::Stream::BUF_SIZE + 1];
|
||||||
|
log::Stream s(buf);
|
||||||
|
|
||||||
|
if (r->ai_family == AF_INET6) {
|
||||||
|
addr_str = inet_ntop(AF_INET6, &reinterpret_cast<sockaddr_in6*>(r->ai_addr)->sin6_addr, addr_str_buf, sizeof(addr_str_buf));
|
||||||
|
if (addr_str) {
|
||||||
|
s << '[' << addr_str << "]:" << DEFAULT_LISTEN_PORT << '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
addr_str = inet_ntop(AF_INET, &reinterpret_cast<sockaddr_in*>(r->ai_addr)->sin_addr, addr_str_buf, sizeof(addr_str_buf));
|
||||||
|
if (addr_str) {
|
||||||
|
s << addr_str << ':' << DEFAULT_LISTEN_PORT << '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s.m_pos) {
|
||||||
|
LOGINFO(4, "added " << static_cast<char*>(buf) << " from " << seed_nodes[i]);
|
||||||
|
if (!saved_list.empty()) {
|
||||||
|
saved_list += ',';
|
||||||
|
}
|
||||||
|
saved_list += buf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
freeaddrinfo(result);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LOGWARN(4, "getaddrinfo failed for " << seed_nodes[i] << ": " << gai_strerror(err));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Finally load peers from p2pool_peers.txt
|
||||||
std::ifstream f(saved_peer_list_file_name);
|
std::ifstream f(saved_peer_list_file_name);
|
||||||
if (f.is_open()) {
|
if (f.is_open()) {
|
||||||
std::string address;
|
std::string address;
|
||||||
|
@ -377,7 +432,7 @@ void P2PServer::load_saved_peer_list()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
LOGINFO(5, "peer list loaded (" << m_peerList.size() << " peers)");
|
LOGINFO(4, "peer list loaded (" << m_peerList.size() << " peers)");
|
||||||
}
|
}
|
||||||
|
|
||||||
void P2PServer::update_peer_in_list(bool is_v6, const raw_ip& ip, int port)
|
void P2PServer::update_peer_in_list(bool is_v6, const raw_ip& ip, int port)
|
||||||
|
|
|
@ -139,7 +139,7 @@ private:
|
||||||
void update_peer_list();
|
void update_peer_list();
|
||||||
void save_peer_list_async();
|
void save_peer_list_async();
|
||||||
void save_peer_list();
|
void save_peer_list();
|
||||||
void load_saved_peer_list();
|
void load_peer_list();
|
||||||
void update_peer_in_list(bool is_v6, const raw_ip& ip, int port);
|
void update_peer_in_list(bool is_v6, const raw_ip& ip, int port);
|
||||||
void remove_peer_from_list(P2PClient* client);
|
void remove_peer_from_list(P2PClient* client);
|
||||||
void remove_peer_from_list(const raw_ip& ip);
|
void remove_peer_from_list(const raw_ip& ip);
|
||||||
|
|
|
@ -33,7 +33,7 @@ struct Params
|
||||||
bool m_lightMode = false;
|
bool m_lightMode = false;
|
||||||
Wallet m_wallet{ nullptr };
|
Wallet m_wallet{ nullptr };
|
||||||
std::string m_stratumAddresses{ "[::]:3333,0.0.0.0:3333" };
|
std::string m_stratumAddresses{ "[::]:3333,0.0.0.0:3333" };
|
||||||
std::string m_p2pAddresses{ "[::]:37890,0.0.0.0:37890" };
|
std::string m_p2pAddresses{ "[::]:37889,0.0.0.0:37889" };
|
||||||
std::string m_p2pPeerList;
|
std::string m_p2pPeerList;
|
||||||
std::string m_config;
|
std::string m_config;
|
||||||
std::string m_apiPath;
|
std::string m_apiPath;
|
||||||
|
|
|
@ -704,6 +704,15 @@ uint64_t SideChain::miner_count()
|
||||||
return m_seenWallets.size();
|
return m_seenWallets.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SideChain::is_default() const
|
||||||
|
{
|
||||||
|
constexpr uint8_t default_consensus_id[HASH_SIZE] = {
|
||||||
|
34,175,126,231,181,11,104,146,227,153,218,107,44,108,68,39,178,81,4,212,169,4,142,0,177,110,157,240,68,7,249,24
|
||||||
|
};
|
||||||
|
|
||||||
|
return (memcmp(m_consensusId.data(), default_consensus_id, HASH_SIZE) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
bool SideChain::split_reward(uint64_t reward, const std::vector<MinerShare>& shares, std::vector<uint64_t>& rewards)
|
bool SideChain::split_reward(uint64_t reward, const std::vector<MinerShare>& shares, std::vector<uint64_t>& rewards)
|
||||||
{
|
{
|
||||||
const size_t num_shares = shares.size();
|
const size_t num_shares = shares.size();
|
||||||
|
|
|
@ -69,6 +69,7 @@ public:
|
||||||
difficulty_type total_hashes() const;
|
difficulty_type total_hashes() const;
|
||||||
uint64_t block_time() const { return m_targetBlockTime; }
|
uint64_t block_time() const { return m_targetBlockTime; }
|
||||||
uint64_t miner_count();
|
uint64_t miner_count();
|
||||||
|
bool is_default() const;
|
||||||
|
|
||||||
static bool split_reward(uint64_t reward, const std::vector<MinerShare>& shares, std::vector<uint64_t>& rewards);
|
static bool split_reward(uint64_t reward, const std::vector<MinerShare>& shares, std::vector<uint64_t>& rewards);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue