diff options
author | Vasil Dimov <vd@FreeBSD.org> | 2021-05-31 17:30:18 +0200 |
---|---|---|
committer | Vasil Dimov <vd@FreeBSD.org> | 2021-07-09 11:19:36 +0200 |
commit | 1f096f091ebd88efb18154b8894a38122c39624f (patch) | |
tree | 5c1883100bfd0705e1d40ab1144d56ee0fe18fa9 /src/net.cpp | |
parent | aeac3bce3ead1f24ca782079ef0defa86fd8cb98 (diff) |
net: distinguish default port per network
Change `CChainParams::GetDefaultPort()` to return 0 if the network is
I2P.
Diffstat (limited to 'src/net.cpp')
-rw-r--r-- | src/net.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/net.cpp b/src/net.cpp index 60059249ed..a6f439674f 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -402,7 +402,8 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo pszDest ? 0.0 : (double)(GetAdjustedTime() - addrConnect.nTime)/3600.0); // Resolve - const uint16_t default_port{Params().GetDefaultPort()}; + const uint16_t default_port{pszDest != nullptr ? Params().GetDefaultPort(pszDest) : + Params().GetDefaultPort()}; if (pszDest) { std::vector<CService> resolved; 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 // port, causing a DoS attack as nodes around the network attempt // to connect to it fruitlessly. - if (addr.GetPort() != Params().GetDefaultPort() && nTries < 50) + if (addr.GetPort() != Params().GetDefaultPort(addr.GetNetwork()) && nTries < 50) { continue; + } addrConnect = addr; break; @@ -2123,7 +2125,7 @@ std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo() const } 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}; if (service.IsValid()) { // strAddNode is an IP:port |