|
|
|
// Copyright (c) 2010 Satoshi Nakamoto
|
|
|
|
// Copyright (c) 2009-2014 The Bitcoin Core developers
|
|
|
|
// Copyright (c) 2016-2022 The Hush developers
|
|
|
|
// Distributed under the GPLv3 software license, see the accompanying
|
|
|
|
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
|
|
|
|
/******************************************************************************
|
|
|
|
* Copyright © 2014-2019 The SuperNET Developers. *
|
|
|
|
* *
|
|
|
|
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
|
|
|
|
* the top-level directory of this distribution for the individual copyright *
|
|
|
|
* holder information and the developer policies on copyright and licensing. *
|
|
|
|
* *
|
|
|
|
* Unless otherwise agreed in a custom licensing agreement, no part of the *
|
|
|
|
* SuperNET software, including this file may be copied, modified, propagated *
|
|
|
|
* or distributed except according to the terms contained in the LICENSE file *
|
|
|
|
* *
|
|
|
|
* Removal or modification of this copyright notice is prohibited. *
|
|
|
|
* *
|
|
|
|
******************************************************************************/
|
|
|
|
#include "alert.h"
|
|
|
|
#include "clientversion.h"
|
|
|
|
#include "net.h"
|
|
|
|
#include "pubkey.h"
|
|
|
|
#include "timedata.h"
|
|
|
|
#include "ui_interface.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <map>
|
|
|
|
#include <boost/algorithm/string/classification.hpp>
|
|
|
|
#include <boost/algorithm/string/replace.hpp>
|
|
|
|
#include <boost/foreach.hpp>
|
Split up util.cpp/h
Split up util.cpp/h into:
- string utilities (hex, base32, base64): no internal dependencies, no dependency on boost (apart from foreach)
- money utilities (parsesmoney, formatmoney)
- time utilities (gettime*, sleep, format date):
- and the rest (logging, argument parsing, config file parsing)
The latter is basically the environment and OS handling,
and is stripped of all utility functions, so we may want to
rename it to something else than util.cpp/h for clarity (Matt suggested
osinterface).
Breaks dependency of sha256.cpp on all the things pulled in by util.
10 years ago
|
|
|
#include <boost/thread.hpp>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
map<uint256, CAlert> mapAlerts;
|
|
|
|
CCriticalSection cs_mapAlerts;
|
|
|
|
|
|
|
|
void CUnsignedAlert::SetNull()
|
|
|
|
{
|
|
|
|
nVersion = 1;
|
|
|
|
nRelayUntil = 0;
|
|
|
|
nExpiration = 0;
|
|
|
|
nID = 0;
|
|
|
|
nCancel = 0;
|
|
|
|
setCancel.clear();
|
|
|
|
nMinVer = 0;
|
|
|
|
nMaxVer = 0;
|
|
|
|
setSubVer.clear();
|
|
|
|
nPriority = 0;
|
|
|
|
|
|
|
|
strComment.clear();
|
|
|
|
strStatusBar.clear();
|
|
|
|
strRPCError.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CUnsignedAlert::ToString() const
|
|
|
|
{
|
|
|
|
std::string strSetCancel;
|
|
|
|
BOOST_FOREACH(int n, setCancel)
|
|
|
|
strSetCancel += strprintf("%d ", n);
|
|
|
|
std::string strSetSubVer;
|
|
|
|
BOOST_FOREACH(const std::string& str, setSubVer)
|
|
|
|
strSetSubVer += "\"" + str + "\" ";
|
|
|
|
return strprintf(
|
|
|
|
"CAlert(\n"
|
|
|
|
" nVersion = %d\n"
|
|
|
|
" nRelayUntil = %d\n"
|
|
|
|
" nExpiration = %d\n"
|
|
|
|
" nID = %d\n"
|
|
|
|
" nCancel = %d\n"
|
|
|
|
" setCancel = %s\n"
|
|
|
|
" nMinVer = %d\n"
|
|
|
|
" nMaxVer = %d\n"
|
|
|
|
" setSubVer = %s\n"
|
|
|
|
" nPriority = %d\n"
|
|
|
|
" strComment = \"%s\"\n"
|
|
|
|
" strStatusBar = \"%s\"\n"
|
|
|
|
" strRPCError = \"%s\"\n"
|
|
|
|
")\n",
|
|
|
|
nVersion,
|
|
|
|
nRelayUntil,
|
|
|
|
nExpiration,
|
|
|
|
nID,
|
|
|
|
nCancel,
|
|
|
|
strSetCancel,
|
|
|
|
nMinVer,
|
|
|
|
nMaxVer,
|
|
|
|
strSetSubVer,
|
|
|
|
nPriority,
|
|
|
|
strComment,
|
|
|
|
strStatusBar,
|
|
|
|
strRPCError);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CAlert::SetNull()
|
|
|
|
{
|
|
|
|
CUnsignedAlert::SetNull();
|
|
|
|
vchMsg.clear();
|
|
|
|
vchSig.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CAlert::IsNull() const
|
|
|
|
{
|
|
|
|
return (nExpiration == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint256 CAlert::GetHash() const
|
|
|
|
{
|
|
|
|
return Hash(this->vchMsg.begin(), this->vchMsg.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CAlert::IsInEffect() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CAlert::Cancels(const CAlert& alert) const
|
|
|
|
{
|
|
|
|
if (!IsInEffect())
|
|
|
|
return false; // this was a no-op before 31403
|
|
|
|
return (alert.nID <= nCancel || setCancel.count(alert.nID));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CAlert::AppliesTo(int nVersion, const std::string& strSubVerIn) const
|
|
|
|
{
|
|
|
|
// TODO: rework for client-version-embedded-in-strSubVer ?
|
|
|
|
return (IsInEffect() &&
|
|
|
|
nMinVer <= nVersion && nVersion <= nMaxVer &&
|
|
|
|
(setSubVer.empty() || setSubVer.count(strSubVerIn)));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CAlert::AppliesToMe() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CAlert::RelayTo(CNode* pnode) const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CAlert::CheckSignature(const std::vector<unsigned char>& alertKey) const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CAlert CAlert::getAlertByHash(const uint256 &hash)
|
|
|
|
{
|
|
|
|
CAlert retval;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CAlert::ProcessAlert(const std::vector<unsigned char>& alertKey, bool fThread)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CAlert::Notify(const std::string& strMessage, bool fThread)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|