Masternodes should be allowed to annonce ipv4 addresses only from now (#1065)

This commit is contained in:
UdjinM6 2016-10-10 13:13:07 +04:00 committed by GitHub
parent c86439a366
commit 321fd64921
3 changed files with 24 additions and 0 deletions

View File

@ -203,6 +203,14 @@ void CMasternode::Check(bool fForce)
nActiveState = MASTERNODE_ENABLED; // OK
}
bool CMasternode::IsValidNetAddr()
{
// TODO: regtest is fine with any addresses for now,
// should probably be a bit smarter if one day we start to implement tests for this
return Params().NetworkIDString() == CBaseChainParams::REGTEST ||
(addr.IsIPv4() && IsReachable(addr) && addr.IsRoutable());
}
std::string CMasternode::GetStatus()
{
switch(nActiveState) {
@ -333,6 +341,14 @@ bool CMasternodeBroadcast::Create(CTxIn txin, CService service, CKey keyCollater
}
mnbRet = CMasternodeBroadcast(service, txin, pubKeyCollateralAddressNew, pubKeyMasternodeNew, PROTOCOL_VERSION);
if(!mnbRet.IsValidNetAddr()) {
strErrorRet = strprintf("Invalid IP address, masternode=%s", txin.prevout.ToStringShort());
LogPrintf("CMasternodeBroadcast::Create -- %s\n", strErrorRet);
mnbRet = CMasternodeBroadcast();
return false;
}
mnbRet.lastPing = mnp;
if(!mnbRet.Sign(keyCollateralAddressNew)) {
strErrorRet = strprintf("Failed to sign broadcast, masternode=%s", txin.prevout.ToStringShort());

View File

@ -212,6 +212,8 @@ public:
bool IsEnabled() { return nActiveState == MASTERNODE_ENABLED; }
bool IsPreEnabled() { return nActiveState == MASTERNODE_PRE_ENABLED; }
bool IsValidNetAddr();
std::string GetStatus();
int GetCollateralAge();

View File

@ -726,6 +726,12 @@ bool CMasternodeMan::CheckMnbAndUpdateMasternodeList(CMasternodeBroadcast mnb, i
mapSeenMasternodeBroadcast.insert(make_pair(mnb.GetHash(), mnb));
LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList - Masternode broadcast, vin: %s new\n", mnb.vin.ToString());
// We check addr before both initial mnb and update
if(!mnb.IsValidNetAddr()) {
LogPrintf("CMasternodeBroadcast::CheckMnbAndUpdateMasternodeList -- Invalid addr, rejected: masternode=%s sigTime=%lld addr=%s\n",
mnb.vin.prevout.ToStringShort(), mnb.sigTime, mnb.addr.ToString());
return false;
}
if(!mnb.CheckAndUpdate(nDos)){
LogPrint("masternode", "CMasternodeMan::CheckMnbAndUpdateMasternodeList - Masternode broadcast, vin: %s CheckAndUpdate failed\n", mnb.vin.ToString());