mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +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;
|
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())
|
if (it == mapAddr.end())
|
||||||
return NULL;
|
return NULL;
|
||||||
if (pnId)
|
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)
|
CAddrInfo* CAddrMan::Create(const CAddress& addr, const CNetAddr& addrSource, int* pnId)
|
||||||
{
|
{
|
||||||
|
CService addr2 = addr;
|
||||||
|
if (!discriminatePorts) {
|
||||||
|
addr2.SetPort(0);
|
||||||
|
}
|
||||||
|
|
||||||
int nId = nIdCount++;
|
int nId = nIdCount++;
|
||||||
mapInfo[nId] = CAddrInfo(addr, addrSource);
|
mapInfo[nId] = CAddrInfo(addr, addrSource);
|
||||||
mapAddr[addr] = nId;
|
mapAddr[addr2] = nId;
|
||||||
mapInfo[nId].nRandomPos = vRandom.size();
|
mapInfo[nId].nRandomPos = vRandom.size();
|
||||||
vRandom.push_back(nId);
|
vRandom.push_back(nId);
|
||||||
if (pnId)
|
if (pnId)
|
||||||
@ -117,9 +127,14 @@ void CAddrMan::Delete(int nId)
|
|||||||
assert(!info.fInTried);
|
assert(!info.fInTried);
|
||||||
assert(info.nRefCount == 0);
|
assert(info.nRefCount == 0);
|
||||||
|
|
||||||
|
CService addr = info;
|
||||||
|
if (!discriminatePorts) {
|
||||||
|
addr.SetPort(0);
|
||||||
|
}
|
||||||
|
|
||||||
SwapRandom(info.nRandomPos, vRandom.size() - 1);
|
SwapRandom(info.nRandomPos, vRandom.size() - 1);
|
||||||
vRandom.pop_back();
|
vRandom.pop_back();
|
||||||
mapAddr.erase(info);
|
mapAddr.erase(addr);
|
||||||
mapInfo.erase(nId);
|
mapInfo.erase(nId);
|
||||||
nNew--;
|
nNew--;
|
||||||
}
|
}
|
||||||
|
@ -187,7 +187,7 @@ private:
|
|||||||
std::map<int, CAddrInfo> mapInfo;
|
std::map<int, CAddrInfo> mapInfo;
|
||||||
|
|
||||||
//! find an nId based on its network address
|
//! find an nId based on its network address
|
||||||
std::map<CNetAddr, int> mapAddr;
|
std::map<CService, int> mapAddr;
|
||||||
|
|
||||||
//! randomly-ordered vector of all nIds
|
//! randomly-ordered vector of all nIds
|
||||||
std::vector<int> vRandom;
|
std::vector<int> vRandom;
|
||||||
@ -207,6 +207,9 @@ private:
|
|||||||
//! last time Good was called (memory only)
|
//! last time Good was called (memory only)
|
||||||
int64_t nLastGood;
|
int64_t nLastGood;
|
||||||
|
|
||||||
|
// discriminate entries based on port. Should be false on mainnet/testnet and can be true on devnet/regtest
|
||||||
|
bool discriminatePorts;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! secret key to randomize bucket select with
|
//! secret key to randomize bucket select with
|
||||||
uint256 nKey;
|
uint256 nKey;
|
||||||
@ -215,7 +218,7 @@ protected:
|
|||||||
FastRandomContext insecure_rand;
|
FastRandomContext insecure_rand;
|
||||||
|
|
||||||
//! Find an entry.
|
//! 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.
|
//! find an entry, creating it if necessary.
|
||||||
//! nTime and nServices of the found node are updated, 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.
|
nLastGood = 1; //Initially at 1 so that "never" is strictly worse.
|
||||||
}
|
}
|
||||||
|
|
||||||
CAddrMan()
|
CAddrMan(bool _discriminatePorts = false) :
|
||||||
|
discriminatePorts(_discriminatePorts)
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
}
|
}
|
||||||
|
@ -366,8 +366,6 @@ public:
|
|||||||
// Testnet Dash BIP44 coin type is '1' (All coin's testnet default)
|
// Testnet Dash BIP44 coin type is '1' (All coin's testnet default)
|
||||||
nExtCoinType = 1;
|
nExtCoinType = 1;
|
||||||
|
|
||||||
vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_test, pnSeed6_test + ARRAYLEN(pnSeed6_test));
|
|
||||||
|
|
||||||
fMiningRequiresPeers = true;
|
fMiningRequiresPeers = true;
|
||||||
fDefaultConsistencyChecks = false;
|
fDefaultConsistencyChecks = false;
|
||||||
fRequireStandard = false;
|
fRequireStandard = false;
|
||||||
@ -503,7 +501,7 @@ public:
|
|||||||
fRequireStandard = false;
|
fRequireStandard = false;
|
||||||
fMineBlocksOnDemand = false;
|
fMineBlocksOnDemand = false;
|
||||||
fAllowMultipleAddressesFromGroup = true;
|
fAllowMultipleAddressesFromGroup = true;
|
||||||
fAllowMultiplePorts = false;
|
fAllowMultiplePorts = true;
|
||||||
|
|
||||||
nPoolMaxTransactions = 3;
|
nPoolMaxTransactions = 3;
|
||||||
nFulfilledRequestExpireTime = 5*60; // fulfilled requests expire in 5 minutes
|
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)
|
CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure)
|
||||||
{
|
{
|
||||||
if (pszDest == NULL) {
|
if (pszDest == NULL) {
|
||||||
if (IsLocal(addrConnect))
|
bool fAllowLocal = Params().AllowMultiplePorts() && addrConnect.GetPort() != GetListenPort();
|
||||||
|
if (!fAllowLocal && IsLocal(addrConnect)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// Look for an existing connection
|
// Look for an existing connection
|
||||||
CNode* pnode = FindNode((CService)addrConnect);
|
CNode* pnode = FindNode((CService)addrConnect);
|
||||||
@ -1786,7 +1788,12 @@ void CConnman::ThreadOpenConnections()
|
|||||||
CAddrInfo addr = addrman.Select(fFeeler);
|
CAddrInfo addr = addrman.Select(fFeeler);
|
||||||
|
|
||||||
// if we selected an invalid address, restart
|
// 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;
|
break;
|
||||||
|
|
||||||
// If we didn't find an appropriate destination after trying 100 addresses fetched from addrman,
|
// 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
|
// 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;
|
continue;
|
||||||
|
|
||||||
addrConnect = addr;
|
addrConnect = addr;
|
||||||
@ -1990,9 +1997,16 @@ bool CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!pszDest) {
|
if (!pszDest) {
|
||||||
if (IsLocal(addrConnect) ||
|
// banned or exact match?
|
||||||
FindNode((CNetAddr)addrConnect) || IsBanned(addrConnect) ||
|
if (IsBanned(addrConnect) || FindNode(addrConnect.ToStringIPPort()))
|
||||||
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;
|
return false;
|
||||||
} else if (FindNode(std::string(pszDest)))
|
} else if (FindNode(std::string(pszDest)))
|
||||||
return false;
|
return false;
|
||||||
@ -2238,7 +2252,9 @@ void CConnman::SetNetworkActive(bool active)
|
|||||||
uiInterface.NotifyNetworkActiveChanged(fNetworkActive);
|
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;
|
fNetworkActive = true;
|
||||||
setBannedIsDirty = false;
|
setBannedIsDirty = false;
|
||||||
|
@ -33,7 +33,7 @@ public:
|
|||||||
return (unsigned int)(state % nMax);
|
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);
|
return CAddrMan::Find(addr, pnId);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user