mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
net: distinguish default port per network
Change `CChainParams::GetDefaultPort()` to return 0 if the network is I2P.
This commit is contained in:
parent
aeac3bce3e
commit
1f096f091e
2 changed files with 16 additions and 3 deletions
|
@ -8,11 +8,13 @@
|
||||||
|
|
||||||
#include <chainparamsbase.h>
|
#include <chainparamsbase.h>
|
||||||
#include <consensus/params.h>
|
#include <consensus/params.h>
|
||||||
|
#include <netaddress.h>
|
||||||
#include <primitives/block.h>
|
#include <primitives/block.h>
|
||||||
#include <protocol.h>
|
#include <protocol.h>
|
||||||
#include <util/hash_type.h>
|
#include <util/hash_type.h>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
typedef std::map<int, uint256> MapCheckpoints;
|
typedef std::map<int, uint256> MapCheckpoints;
|
||||||
|
@ -80,6 +82,15 @@ public:
|
||||||
const Consensus::Params& GetConsensus() const { return consensus; }
|
const Consensus::Params& GetConsensus() const { return consensus; }
|
||||||
const CMessageHeader::MessageStartChars& MessageStart() const { return pchMessageStart; }
|
const CMessageHeader::MessageStartChars& MessageStart() const { return pchMessageStart; }
|
||||||
uint16_t GetDefaultPort() const { return nDefaultPort; }
|
uint16_t GetDefaultPort() const { return nDefaultPort; }
|
||||||
|
uint16_t GetDefaultPort(Network net) const
|
||||||
|
{
|
||||||
|
return net == NET_I2P ? I2P_SAM31_PORT : GetDefaultPort();
|
||||||
|
}
|
||||||
|
uint16_t GetDefaultPort(const std::string& addr) const
|
||||||
|
{
|
||||||
|
CNetAddr a;
|
||||||
|
return a.SetSpecial(addr) ? GetDefaultPort(a.GetNetwork()) : GetDefaultPort();
|
||||||
|
}
|
||||||
|
|
||||||
const CBlock& GenesisBlock() const { return genesis; }
|
const CBlock& GenesisBlock() const { return genesis; }
|
||||||
/** Default value for -checkmempool and -checkblockindex argument */
|
/** Default value for -checkmempool and -checkblockindex argument */
|
||||||
|
|
|
@ -402,7 +402,8 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
|
||||||
pszDest ? 0.0 : (double)(GetAdjustedTime() - addrConnect.nTime)/3600.0);
|
pszDest ? 0.0 : (double)(GetAdjustedTime() - addrConnect.nTime)/3600.0);
|
||||||
|
|
||||||
// Resolve
|
// Resolve
|
||||||
const uint16_t default_port{Params().GetDefaultPort()};
|
const uint16_t default_port{pszDest != nullptr ? Params().GetDefaultPort(pszDest) :
|
||||||
|
Params().GetDefaultPort()};
|
||||||
if (pszDest) {
|
if (pszDest) {
|
||||||
std::vector<CService> resolved;
|
std::vector<CService> resolved;
|
||||||
if (Lookup(pszDest, resolved, default_port, fNameLookup && !HaveNameProxy(), 256) && !resolved.empty()) {
|
if (Lookup(pszDest, resolved, default_port, fNameLookup && !HaveNameProxy(), 256) && !resolved.empty()) {
|
||||||
|
@ -2059,8 +2060,9 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
||||||
// from advertising themselves as a service on another host and
|
// from advertising themselves as a service on another host and
|
||||||
// port, causing a DoS attack as nodes around the network attempt
|
// port, causing a DoS attack as nodes around the network attempt
|
||||||
// to connect to it fruitlessly.
|
// to connect to it fruitlessly.
|
||||||
if (addr.GetPort() != Params().GetDefaultPort() && nTries < 50)
|
if (addr.GetPort() != Params().GetDefaultPort(addr.GetNetwork()) && nTries < 50) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
addrConnect = addr;
|
addrConnect = addr;
|
||||||
break;
|
break;
|
||||||
|
@ -2123,7 +2125,7 @@ std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo() const
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const std::string& strAddNode : lAddresses) {
|
for (const std::string& strAddNode : lAddresses) {
|
||||||
CService service(LookupNumeric(strAddNode, Params().GetDefaultPort()));
|
CService service(LookupNumeric(strAddNode, Params().GetDefaultPort(strAddNode)));
|
||||||
AddedNodeInfo addedNode{strAddNode, CService(), false, false};
|
AddedNodeInfo addedNode{strAddNode, CService(), false, false};
|
||||||
if (service.IsValid()) {
|
if (service.IsValid()) {
|
||||||
// strAddNode is an IP:port
|
// strAddNode is an IP:port
|
||||||
|
|
Loading…
Add table
Reference in a new issue