mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-12-23 03:49:23 +00:00
Don't port forward Stratum port by default
Added a command line parameter to enable it
This commit is contained in:
parent
bb4c7f0298
commit
fe7ef30650
7 changed files with 40 additions and 28 deletions
|
@ -27,6 +27,7 @@
|
||||||
--no-dns Disable DNS queries, use only IP addresses to connect to peers (seed node DNS will be unavailable too)
|
--no-dns Disable DNS queries, use only IP addresses to connect to peers (seed node DNS will be unavailable too)
|
||||||
--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
|
--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
|
||||||
--no-upnp Disable UPnP port forwarding
|
--no-upnp Disable UPnP port forwarding
|
||||||
|
--upnp-stratum Port forward Stratum port (it's not forwarded by default)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Example command line
|
### Example command line
|
||||||
|
|
|
@ -55,6 +55,7 @@ void p2pool_usage()
|
||||||
"--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"
|
"--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
|
#ifdef WITH_UPNP
|
||||||
"--no-upnp Disable UPnP port forwarding\n"
|
"--no-upnp Disable UPnP port forwarding\n"
|
||||||
|
"--upnp-stratum Port forward Stratum port (it's not forwarded by default)\n"
|
||||||
#endif
|
#endif
|
||||||
"--help Show this help message\n\n"
|
"--help Show this help message\n\n"
|
||||||
"Example command line:\n\n"
|
"Example command line:\n\n"
|
||||||
|
|
|
@ -52,7 +52,6 @@ namespace p2pool {
|
||||||
|
|
||||||
p2pool::p2pool(int argc, char* argv[])
|
p2pool::p2pool(int argc, char* argv[])
|
||||||
: m_stopped(false)
|
: m_stopped(false)
|
||||||
, m_params(new Params(argc, argv))
|
|
||||||
, m_updateSeed(true)
|
, m_updateSeed(true)
|
||||||
, m_submitBlockData{}
|
, m_submitBlockData{}
|
||||||
, m_zmqLastActive(0)
|
, m_zmqLastActive(0)
|
||||||
|
@ -60,40 +59,43 @@ p2pool::p2pool(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
LOGINFO(1, log::LightCyan() << VERSION);
|
LOGINFO(1, log::LightCyan() << VERSION);
|
||||||
|
|
||||||
|
Params* p = new Params(argc, argv);
|
||||||
|
m_params = p;
|
||||||
|
|
||||||
#ifdef WITH_UPNP
|
#ifdef WITH_UPNP
|
||||||
if (m_params->m_upnp) {
|
if (p->m_upnp) {
|
||||||
init_upnp();
|
init_upnp();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!m_params->m_wallet.valid()) {
|
if (!p->m_wallet.valid()) {
|
||||||
LOGERR(1, "Invalid wallet address. Try \"p2pool --help\".");
|
LOGERR(1, "Invalid wallet address. Try \"p2pool --help\".");
|
||||||
throw std::exception();
|
throw std::exception();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_hostStr = m_params->m_host;
|
m_hostStr = p->m_host;
|
||||||
|
|
||||||
if (m_params->m_socks5Proxy.empty()) {
|
if (p->m_socks5Proxy.empty()) {
|
||||||
if (m_params->m_dns) {
|
if (p->m_dns) {
|
||||||
bool is_v6;
|
bool is_v6;
|
||||||
if (!resolve_host(m_params->m_host, is_v6)) {
|
if (!resolve_host(p->m_host, is_v6)) {
|
||||||
LOGERR(1, "resolve_host failed for " << m_params->m_host);
|
LOGERR(1, "resolve_host failed for " << p->m_host);
|
||||||
throw std::exception();
|
throw std::exception();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (m_params->m_host.find_first_not_of("0123456789.:") != std::string::npos) {
|
else if (p->m_host.find_first_not_of("0123456789.:") != std::string::npos) {
|
||||||
LOGERR(1, "Can't resolve hostname " << m_params->m_host << " with DNS disabled");
|
LOGERR(1, "Can't resolve hostname " << p->m_host << " with DNS disabled");
|
||||||
throw std::exception();
|
throw std::exception();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const bool changed = (m_params->m_host != m_hostStr);
|
const bool changed = (p->m_host != m_hostStr);
|
||||||
const std::string rpc_port = ':' + std::to_string(m_params->m_rpcPort);
|
const std::string rpc_port = ':' + std::to_string(p->m_rpcPort);
|
||||||
const std::string zmq_port = ":ZMQ:" + std::to_string(m_params->m_zmqPort);
|
const std::string zmq_port = ":ZMQ:" + std::to_string(p->m_zmqPort);
|
||||||
m_hostStr += rpc_port + zmq_port;
|
m_hostStr += rpc_port + zmq_port;
|
||||||
if (changed) {
|
if (changed) {
|
||||||
m_hostStr += " (" + m_params->m_host + ')';
|
m_hostStr += " (" + p->m_host + ')';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,12 +103,12 @@ p2pool::p2pool(int argc, char* argv[])
|
||||||
generate_keys(pub, sec);
|
generate_keys(pub, sec);
|
||||||
|
|
||||||
uint8_t view_tag;
|
uint8_t view_tag;
|
||||||
if (!m_params->m_wallet.get_eph_public_key(sec, 0, eph_public_key, view_tag)) {
|
if (!p->m_wallet.get_eph_public_key(sec, 0, eph_public_key, view_tag)) {
|
||||||
LOGERR(1, "Invalid wallet address: get_eph_public_key failed");
|
LOGERR(1, "Invalid wallet address: get_eph_public_key failed");
|
||||||
throw std::exception();
|
throw std::exception();
|
||||||
}
|
}
|
||||||
|
|
||||||
const NetworkType type = m_params->m_wallet.type();
|
const NetworkType type = p->m_wallet.type();
|
||||||
|
|
||||||
if (type == NetworkType::Testnet) {
|
if (type == NetworkType::Testnet) {
|
||||||
LOGWARN(1, "Mining to a testnet wallet address");
|
LOGWARN(1, "Mining to a testnet wallet address");
|
||||||
|
@ -151,27 +153,27 @@ p2pool::p2pool(int argc, char* argv[])
|
||||||
#endif
|
#endif
|
||||||
uv_mutex_init_checked(&m_submitBlockDataLock);
|
uv_mutex_init_checked(&m_submitBlockDataLock);
|
||||||
|
|
||||||
m_api = m_params->m_apiPath.empty() ? nullptr : new p2pool_api(m_params->m_apiPath, m_params->m_localStats);
|
m_api = p->m_apiPath.empty() ? nullptr : new p2pool_api(p->m_apiPath, p->m_localStats);
|
||||||
|
|
||||||
if (m_params->m_localStats && !m_api) {
|
if (p->m_localStats && !m_api) {
|
||||||
LOGERR(1, "--local-api and --stratum-api command line parameters can't be used without --data-api");
|
LOGERR(1, "--local-api and --stratum-api command line parameters can't be used without --data-api");
|
||||||
throw std::exception();
|
throw std::exception();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_sideChain = new SideChain(this, type, m_params->m_mini ? "mini" : nullptr);
|
m_sideChain = new SideChain(this, type, p->m_mini ? "mini" : nullptr);
|
||||||
|
|
||||||
if (m_params->m_p2pAddresses.empty()) {
|
if (p->m_p2pAddresses.empty()) {
|
||||||
const int p2p_port = m_sideChain->is_mini() ? DEFAULT_P2P_PORT_MINI : DEFAULT_P2P_PORT;
|
const int p2p_port = m_sideChain->is_mini() ? DEFAULT_P2P_PORT_MINI : DEFAULT_P2P_PORT;
|
||||||
|
|
||||||
char buf[log::Stream::BUF_SIZE + 1];
|
char buf[48] = {};
|
||||||
log::Stream s(buf);
|
log::Stream s(buf);
|
||||||
s << "[::]:" << p2p_port << ",0.0.0.0:" << p2p_port << '\0';
|
s << "[::]:" << p2p_port << ",0.0.0.0:" << p2p_port;
|
||||||
|
|
||||||
m_params->m_p2pAddresses = buf;
|
p->m_p2pAddresses = buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WITH_RANDOMX
|
#ifdef WITH_RANDOMX
|
||||||
if (m_params->m_disableRandomX) {
|
if (p->m_disableRandomX) {
|
||||||
m_hasher = new RandomX_Hasher_RPC(this);
|
m_hasher = new RandomX_Hasher_RPC(this);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -114,7 +114,7 @@ private:
|
||||||
std::atomic<bool> m_stopped;
|
std::atomic<bool> m_stopped;
|
||||||
|
|
||||||
std::string m_hostStr;
|
std::string m_hostStr;
|
||||||
Params* m_params;
|
const Params* m_params;
|
||||||
|
|
||||||
p2pool_api* m_api;
|
p2pool_api* m_api;
|
||||||
SideChain* m_sideChain;
|
SideChain* m_sideChain;
|
||||||
|
|
|
@ -158,6 +158,11 @@ Params::Params(int argc, char* argv[])
|
||||||
m_upnp = false;
|
m_upnp = false;
|
||||||
ok = true;
|
ok = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strcmp(argv[i], "--upnp-stratum") == 0) {
|
||||||
|
m_upnpStratum = true;
|
||||||
|
ok = true;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
|
@ -170,9 +175,9 @@ Params::Params(int argc, char* argv[])
|
||||||
if (m_stratumAddresses.empty()) {
|
if (m_stratumAddresses.empty()) {
|
||||||
const int stratum_port = DEFAULT_STRATUM_PORT;
|
const int stratum_port = DEFAULT_STRATUM_PORT;
|
||||||
|
|
||||||
char buf[log::Stream::BUF_SIZE + 1];
|
char buf[48] = {};
|
||||||
log::Stream s(buf);
|
log::Stream s(buf);
|
||||||
s << "[::]:" << stratum_port << ",0.0.0.0:" << stratum_port << '\0';
|
s << "[::]:" << stratum_port << ",0.0.0.0:" << stratum_port;
|
||||||
|
|
||||||
m_stratumAddresses = buf;
|
m_stratumAddresses = buf;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,8 +55,10 @@ struct Params
|
||||||
uint32_t m_p2pExternalPort = 0;
|
uint32_t m_p2pExternalPort = 0;
|
||||||
#ifdef WITH_UPNP
|
#ifdef WITH_UPNP
|
||||||
bool m_upnp = true;
|
bool m_upnp = true;
|
||||||
|
bool m_upnpStratum = false;
|
||||||
#else
|
#else
|
||||||
bool m_upnp = false;
|
bool m_upnp = false;
|
||||||
|
bool m_upnpStratum = false;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,8 @@ StratumServer::StratumServer(p2pool* pool)
|
||||||
uv_async_init_checked(&m_loop, &m_showWorkersAsync, on_show_workers);
|
uv_async_init_checked(&m_loop, &m_showWorkersAsync, on_show_workers);
|
||||||
m_showWorkersAsync.data = this;
|
m_showWorkersAsync.data = this;
|
||||||
|
|
||||||
start_listening(pool->params().m_stratumAddresses, pool->params().m_upnp);
|
const Params& params = pool->params();
|
||||||
|
start_listening(params.m_stratumAddresses, params.m_upnp && params.m_upnpStratum);
|
||||||
}
|
}
|
||||||
|
|
||||||
StratumServer::~StratumServer()
|
StratumServer::~StratumServer()
|
||||||
|
|
Loading…
Reference in a new issue