net: Add alternative port for onion service

This change allows to distinguish incoming Tor connections from others.
pull/764/head
Hennadii Stepanov 4 years ago
parent b3273cf403
commit a5266d4546
No known key found for this signature in database
GPG Key ID: 410108112E7EA81F

@ -37,16 +37,20 @@ const CBaseChainParams& BaseParams()
return *globalChainBaseParams;
}
/**
* Port numbers for incoming Tor connections (8334, 18334, 38334, 18445) have
* been chosen arbitrarily to keep ranges of used ports tight.
*/
std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain)
{
if (chain == CBaseChainParams::MAIN) {
return MakeUnique<CBaseChainParams>("", 8332);
return MakeUnique<CBaseChainParams>("", 8332, 8334);
} else if (chain == CBaseChainParams::TESTNET) {
return MakeUnique<CBaseChainParams>("testnet3", 18332);
return MakeUnique<CBaseChainParams>("testnet3", 18332, 18334);
} else if (chain == CBaseChainParams::SIGNET) {
return MakeUnique<CBaseChainParams>("signet", 38332);
return MakeUnique<CBaseChainParams>("signet", 38332, 38334);
} else if (chain == CBaseChainParams::REGTEST) {
return MakeUnique<CBaseChainParams>("regtest", 18443);
return MakeUnique<CBaseChainParams>("regtest", 18443, 18445);
}
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
}

@ -27,12 +27,15 @@ public:
const std::string& DataDir() const { return strDataDir; }
int RPCPort() const { return nRPCPort; }
uint16_t OnionServiceTargetPort() const { return m_onion_service_target_port; }
CBaseChainParams() = delete;
CBaseChainParams(const std::string& data_dir, int rpc_port) : nRPCPort(rpc_port), strDataDir(data_dir) {}
CBaseChainParams(const std::string& data_dir, int rpc_port, uint16_t onion_service_target_port)
: nRPCPort(rpc_port), m_onion_service_target_port(onion_service_target_port), strDataDir(data_dir) {}
private:
int nRPCPort;
const uint16_t m_onion_service_target_port;
std::string strDataDir;
};

Loading…
Cancel
Save