mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
A few devnet related fixes (#2168)
* Remove testnet seeds from devnet * Lift multiple ports restriction on devnet when considering new nodes Allow to connect to multiple nodes behind the same IP * Don't skip addresses with non-default port if it matches -port If the user specified -port, he very likely intends to connect to nodes with the same port. * Don't pass false to CAddrMan constructor as it is already the default * Make if statements easier to read
This commit is contained in:
parent
050cabdf52
commit
2c303cdb11
@ -65,9 +65,14 @@ double CAddrInfo::GetChance(int64_t nNow) const
|
||||
return fChance;
|
||||
}
|
||||
|
||||
CAddrInfo* CAddrMan::Find(const CNetAddr& addr, int* pnId)
|
||||
CAddrInfo* CAddrMan::Find(const CService& addr, int* pnId)
|
||||
{
|
||||
std::map<CNetAddr, int>::iterator it = mapAddr.find(addr);
|
||||
CService addr2 = addr;
|
||||
if (!discriminatePorts) {
|
||||
addr2.SetPort(0);
|
||||
}
|
||||
|
||||
std::map<CService, int>::iterator it = mapAddr.find(addr2);
|
||||
if (it == mapAddr.end())
|
||||
return NULL;
|
||||
if (pnId)
|
||||
@ -80,9 +85,14 @@ CAddrInfo* CAddrMan::Find(const CNetAddr& addr, int* pnId)
|
||||
|
||||
CAddrInfo* CAddrMan::Create(const CAddress& addr, const CNetAddr& addrSource, int* pnId)
|
||||
{
|
||||
CService addr2 = addr;
|
||||
if (!discriminatePorts) {
|
||||
addr2.SetPort(0);
|
||||
}
|
||||
|
||||
int nId = nIdCount++;
|
||||
mapInfo[nId] = CAddrInfo(addr, addrSource);
|
||||
mapAddr[addr] = nId;
|
||||
mapAddr[addr2] = nId;
|
||||
mapInfo[nId].nRandomPos = vRandom.size();
|
||||
vRandom.push_back(nId);
|
||||
if (pnId)
|
||||
@ -117,9 +127,14 @@ void CAddrMan::Delete(int nId)
|
||||
assert(!info.fInTried);
|
||||
assert(info.nRefCount == 0);
|
||||
|
||||
CService addr = info;
|
||||
if (!discriminatePorts) {
|
||||
addr.SetPort(0);
|
||||
}
|
||||
|
||||
SwapRandom(info.nRandomPos, vRandom.size() - 1);
|
||||
vRandom.pop_back();
|
||||
mapAddr.erase(info);
|
||||
mapAddr.erase(addr);
|
||||
mapInfo.erase(nId);
|
||||
nNew--;
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ private:
|
||||
std::map<int, CAddrInfo> mapInfo;
|
||||
|
||||
//! find an nId based on its network address
|
||||
std::map<CNetAddr, int> mapAddr;
|
||||
std::map<CService, int> mapAddr;
|
||||
|
||||
//! randomly-ordered vector of all nIds
|
||||
std::vector<int> vRandom;
|
||||
@ -207,6 +207,9 @@ private:
|
||||
//! last time Good was called (memory only)
|
||||
int64_t nLastGood;
|
||||
|
||||
// discriminate entries based on port. Should be false on mainnet/testnet and can be true on devnet/regtest
|
||||
bool discriminatePorts;
|
||||
|
||||
protected:
|
||||
//! secret key to randomize bucket select with
|
||||
uint256 nKey;
|
||||
@ -215,7 +218,7 @@ protected:
|
||||
FastRandomContext insecure_rand;
|
||||
|
||||
//! Find an entry.
|
||||
CAddrInfo* Find(const CNetAddr& addr, int *pnId = NULL);
|
||||
CAddrInfo* Find(const CService& addr, int *pnId = NULL);
|
||||
|
||||
//! find an entry, creating it if necessary.
|
||||
//! nTime and nServices of the found node are updated, if necessary.
|
||||
@ -469,7 +472,8 @@ public:
|
||||
nLastGood = 1; //Initially at 1 so that "never" is strictly worse.
|
||||
}
|
||||
|
||||
CAddrMan()
|
||||
CAddrMan(bool _discriminatePorts = false) :
|
||||
discriminatePorts(_discriminatePorts)
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
@ -366,8 +366,6 @@ public:
|
||||
// Testnet Dash BIP44 coin type is '1' (All coin's testnet default)
|
||||
nExtCoinType = 1;
|
||||
|
||||
vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_test, pnSeed6_test + ARRAYLEN(pnSeed6_test));
|
||||
|
||||
fMiningRequiresPeers = true;
|
||||
fDefaultConsistencyChecks = false;
|
||||
fRequireStandard = false;
|
||||
@ -503,7 +501,7 @@ public:
|
||||
fRequireStandard = false;
|
||||
fMineBlocksOnDemand = false;
|
||||
fAllowMultipleAddressesFromGroup = true;
|
||||
fAllowMultiplePorts = false;
|
||||
fAllowMultiplePorts = true;
|
||||
|
||||
nPoolMaxTransactions = 3;
|
||||
nFulfilledRequestExpireTime = 5*60; // fulfilled requests expire in 5 minutes
|
||||
|
30
src/net.cpp
30
src/net.cpp
@ -348,8 +348,10 @@ bool CConnman::CheckIncomingNonce(uint64_t nonce)
|
||||
CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure)
|
||||
{
|
||||
if (pszDest == NULL) {
|
||||
if (IsLocal(addrConnect))
|
||||
bool fAllowLocal = Params().AllowMultiplePorts() && addrConnect.GetPort() != GetListenPort();
|
||||
if (!fAllowLocal && IsLocal(addrConnect)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Look for an existing connection
|
||||
CNode* pnode = FindNode((CService)addrConnect);
|
||||
@ -1786,7 +1788,12 @@ void CConnman::ThreadOpenConnections()
|
||||
CAddrInfo addr = addrman.Select(fFeeler);
|
||||
|
||||
// if we selected an invalid address, restart
|
||||
if (!addr.IsValid() || setConnected.count(addr.GetGroup()) || IsLocal(addr))
|
||||
if (!addr.IsValid() || setConnected.count(addr.GetGroup()))
|
||||
break;
|
||||
|
||||
// if we selected a local address, restart (local addresses are allowed in regtest and devnet)
|
||||
bool fAllowLocal = Params().AllowMultiplePorts() && addrConnect.GetPort() != GetListenPort();
|
||||
if (!fAllowLocal && IsLocal(addrConnect))
|
||||
break;
|
||||
|
||||
// If we didn't find an appropriate destination after trying 100 addresses fetched from addrman,
|
||||
@ -1818,7 +1825,7 @@ void CConnman::ThreadOpenConnections()
|
||||
}
|
||||
|
||||
// do not allow non-default ports, unless after 50 invalid addresses selected already
|
||||
if (addr.GetPort() != Params().GetDefaultPort() && nTries < 50)
|
||||
if (addr.GetPort() != Params().GetDefaultPort() && addr.GetPort() != GetListenPort() && nTries < 50)
|
||||
continue;
|
||||
|
||||
addrConnect = addr;
|
||||
@ -1990,9 +1997,16 @@ bool CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai
|
||||
return false;
|
||||
}
|
||||
if (!pszDest) {
|
||||
if (IsLocal(addrConnect) ||
|
||||
FindNode((CNetAddr)addrConnect) || IsBanned(addrConnect) ||
|
||||
FindNode(addrConnect.ToStringIPPort()))
|
||||
// banned or exact match?
|
||||
if (IsBanned(addrConnect) || FindNode(addrConnect.ToStringIPPort()))
|
||||
return false;
|
||||
// local and not a connection to itself?
|
||||
bool fAllowLocal = Params().AllowMultiplePorts() && addrConnect.GetPort() != GetListenPort();
|
||||
if (!fAllowLocal && IsLocal(addrConnect))
|
||||
return false;
|
||||
// if multiple ports for same IP are allowed, search for IP:PORT match, otherwise search for IP-only match
|
||||
if ((!Params().AllowMultiplePorts() && FindNode((CNetAddr)addrConnect)) ||
|
||||
(Params().AllowMultiplePorts() && FindNode((CService)addrConnect)))
|
||||
return false;
|
||||
} else if (FindNode(std::string(pszDest)))
|
||||
return false;
|
||||
@ -2238,7 +2252,9 @@ void CConnman::SetNetworkActive(bool active)
|
||||
uiInterface.NotifyNetworkActiveChanged(fNetworkActive);
|
||||
}
|
||||
|
||||
CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In) : nSeed0(nSeed0In), nSeed1(nSeed1In)
|
||||
CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In) :
|
||||
nSeed0(nSeed0In), nSeed1(nSeed1In),
|
||||
addrman(Params().AllowMultiplePorts())
|
||||
{
|
||||
fNetworkActive = true;
|
||||
setBannedIsDirty = false;
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
return (unsigned int)(state % nMax);
|
||||
}
|
||||
|
||||
CAddrInfo* Find(const CNetAddr& addr, int* pnId = NULL)
|
||||
CAddrInfo* Find(const CService& addr, int* pnId = NULL)
|
||||
{
|
||||
return CAddrMan::Find(addr, pnId);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user