BIP155 (addrv2)
Tor v3 + i2p
This commit is contained in:
189
src/main.cpp
189
src/main.cpp
@@ -33,6 +33,7 @@
|
||||
#include "metrics.h"
|
||||
#include "notarizationdb.h"
|
||||
#include "net.h"
|
||||
#include "netmessagemaker.h"
|
||||
#include "pow.h"
|
||||
#include "script/interpreter.h"
|
||||
#include "txdb.h"
|
||||
@@ -981,7 +982,7 @@ bool IsStandardTx(const CTransaction& tx, string& reason, const int nHeight)
|
||||
if (!::IsStandard(txout.scriptPubKey, whichType))
|
||||
{
|
||||
reason = "scriptpubkey";
|
||||
//fprintf(stderr,">>>>>>>>>>>>>>> vout.%d nDataout.%d\n",v,nDataOut);
|
||||
//fprintf(stderr," vout.%d nDataout.%d\n",v,nDataOut);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -3770,7 +3771,7 @@ void static UpdateTip(CBlockIndex *pindexNew) {
|
||||
mempool.AddTransactionsUpdated(1);
|
||||
HUSH_NEWBLOCKS++;
|
||||
double progress;
|
||||
if ( SMART_CHAIN_SYMBOL[0] == 0 ) {
|
||||
if ( ishush3 ) {
|
||||
progress = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.LastTip());
|
||||
} else {
|
||||
int32_t longestchain = hush_longestchain();
|
||||
@@ -4330,6 +4331,9 @@ bool ActivateBestChain(bool fSkipdpow, CValidationState &state, CBlock *pblock)
|
||||
do {
|
||||
boost::this_thread::interruption_point();
|
||||
|
||||
if (ShutdownRequested())
|
||||
break;
|
||||
|
||||
bool fInitialDownload;
|
||||
{
|
||||
LOCK(cs_main);
|
||||
@@ -6773,7 +6777,7 @@ void static ProcessGetData(CNode* pfrom)
|
||||
//for (z=31; z>=0; z--)
|
||||
// fprintf(stderr,"%02x",((uint8_t *)&hash)[z]);
|
||||
//fprintf(stderr," send block %d\n",hush_block2height(&block));
|
||||
pfrom->PushMessage("block", block);
|
||||
pfrom->PushMessage(NetMsgType::BLOCK, block);
|
||||
}
|
||||
else // MSG_FILTERED_BLOCK)
|
||||
{
|
||||
@@ -6781,7 +6785,7 @@ void static ProcessGetData(CNode* pfrom)
|
||||
if (pfrom->pfilter)
|
||||
{
|
||||
CMerkleBlock merkleBlock(block, *pfrom->pfilter);
|
||||
pfrom->PushMessage("merkleblock", merkleBlock);
|
||||
pfrom->PushMessage(NetMsgType::MERKLEBLOCK, merkleBlock);
|
||||
// CMerkleBlock just contains hashes, so also push any transactions in the block the client did not see
|
||||
// This avoids hurting performance by pointlessly requiring a round-trip
|
||||
// Note that there is currently no way for a node to request any single transactions we didn't send here -
|
||||
@@ -6791,7 +6795,7 @@ void static ProcessGetData(CNode* pfrom)
|
||||
typedef std::pair<unsigned int, uint256> PairType;
|
||||
BOOST_FOREACH(PairType& pair, merkleBlock.vMatchedTxn)
|
||||
if (!pfrom->setInventoryKnown.count(CInv(MSG_TX, pair.second)))
|
||||
pfrom->PushMessage("tx", block.vtx[pair.first]);
|
||||
pfrom->PushMessage(NetMsgType::TX, block.vtx[pair.first]);
|
||||
}
|
||||
// else
|
||||
// no response
|
||||
@@ -6805,7 +6809,7 @@ void static ProcessGetData(CNode* pfrom)
|
||||
// wait for other stuff first.
|
||||
vector<CInv> vInv;
|
||||
vInv.push_back(CInv(MSG_BLOCK, chainActive.Tip()->GetBlockHash()));
|
||||
pfrom->PushMessage("inv", vInv);
|
||||
pfrom->PushMessage(NetMsgType::INV, vInv);
|
||||
pfrom->hashContinue.SetNull();
|
||||
}
|
||||
}
|
||||
@@ -6828,7 +6832,7 @@ void static ProcessGetData(CNode* pfrom)
|
||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ss.reserve(1000);
|
||||
ss << tx;
|
||||
pfrom->PushMessage("tx", ss);
|
||||
pfrom->PushMessage(NetMsgType::TX, ss);
|
||||
pushed = true;
|
||||
}
|
||||
}
|
||||
@@ -6855,7 +6859,7 @@ void static ProcessGetData(CNode* pfrom)
|
||||
// do that because they want to know about (and store and rebroadcast and
|
||||
// risk analyze) the dependencies of transactions relevant to them, without
|
||||
// having to download the entire memory pool.
|
||||
pfrom->PushMessage("notfound", vNotFound);
|
||||
pfrom->PushMessage(NetMsgType::NOTFOUND, vNotFound);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6882,7 +6886,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
if(p2pdebug)
|
||||
fprintf(stderr,"%s: netmsg: %s from %s\n", __func__, strCommand.c_str(), pfrom->addr.ToString().c_str() );
|
||||
|
||||
if (strCommand == "version") {
|
||||
if (strCommand == NetMsgType::VERSION) {
|
||||
// Feeler connections exist only to verify if node is online
|
||||
if (pfrom->fFeeler) {
|
||||
assert(pfrom->fInbound == false);
|
||||
@@ -6894,7 +6898,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
// Each connection can only send one version message
|
||||
if (pfrom->nVersion != 0)
|
||||
{
|
||||
pfrom->PushMessage("reject", strCommand, REJECT_DUPLICATE, string("Duplicate version message"));
|
||||
pfrom->PushMessage(NetMsgType::REJECT, strCommand, REJECT_DUPLICATE, string("Duplicate version message"));
|
||||
Misbehaving(pfrom->GetId(), 1);
|
||||
return false;
|
||||
}
|
||||
@@ -6912,7 +6916,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
{
|
||||
// disconnect from peers older than this proto version
|
||||
LogPrintf("Disconnecting peer=%d at %s using obsolete version %i < %i\n", pfrom->id, pfrom->addr.ToString().c_str(), nVersion, minVersion);
|
||||
pfrom->PushMessage("reject", strCommand, REJECT_OBSOLETE, strprintf("Version must be %d or greater", minVersion));
|
||||
pfrom->PushMessage(NetMsgType::REJECT, strCommand, REJECT_OBSOLETE, strprintf("Version must be %d or greater", minVersion));
|
||||
pfrom->fDisconnect = true;
|
||||
return false;
|
||||
}
|
||||
@@ -6923,7 +6927,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
if (nVersion < params.vUpgrades[currentEpoch].nProtocolVersion)
|
||||
{
|
||||
LogPrintf("Disconnecting peer=%d at %s using obsolete epoch version %i\n", pfrom->id, pfrom->addr.ToString().c_str(), nVersion);
|
||||
pfrom->PushMessage("reject", strCommand, REJECT_OBSOLETE,
|
||||
pfrom->PushMessage(NetMsgType::REJECT, strCommand, REJECT_OBSOLETE,
|
||||
strprintf("Version must be %d or greater",
|
||||
params.vUpgrades[currentEpoch].nProtocolVersion));
|
||||
pfrom->fDisconnect = true;
|
||||
@@ -6967,6 +6971,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
// Potentially mark this peer as a preferred download peer.
|
||||
UpdatePreferredDownload(pfrom, State(pfrom->GetId()));
|
||||
|
||||
//Ask for Address Format Version 2
|
||||
pfrom->PushMessage(NetMsgType::SENDADDRV2);
|
||||
|
||||
// Change version
|
||||
pfrom->PushMessage("verack");
|
||||
pfrom->ssSend.SetVersion(min(pfrom->nVersion, PROTOCOL_VERSION));
|
||||
@@ -6991,7 +6998,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
// Get recent addresses
|
||||
if (pfrom->fOneShot || pfrom->nVersion >= CADDR_TIME_VERSION || addrman.size() < 1000)
|
||||
{
|
||||
pfrom->PushMessage("getaddr");
|
||||
pfrom->PushMessage(NetMsgType::GETADDR);
|
||||
pfrom->fGetAddr = true;
|
||||
}
|
||||
addrman.Good(pfrom->addr);
|
||||
@@ -7022,7 +7029,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
// Must have a version message before anything else
|
||||
Misbehaving(pfrom->GetId(), 1);
|
||||
return false;
|
||||
} else if ( strCommand == "events" ) {
|
||||
} else if ( strCommand == NetMsgType::EVENTS ) {
|
||||
if ( ASSETCHAINS_CCLIB != "gamescc" )
|
||||
{
|
||||
Misbehaving(pfrom->GetId(), 1);
|
||||
@@ -7032,7 +7039,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
vRecv >> payload;
|
||||
hush_netevent(payload);
|
||||
return(true);
|
||||
} else if (strCommand == "verack") {
|
||||
} else if (strCommand == NetMsgType::VERACK) {
|
||||
pfrom->SetRecvVersion(min(pfrom->nVersion, PROTOCOL_VERSION));
|
||||
|
||||
if ( HUSH_NSPV_SUPERLITE )
|
||||
@@ -7048,6 +7055,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
if (pfrom->fNetworkNode) {
|
||||
LOCK(cs_main);
|
||||
State(pfrom->GetId())->fCurrentlyConnected = true;
|
||||
AddressCurrentlyConnected(State(pfrom->GetId())->address);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7056,15 +7064,29 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
// 2. Peer version is below the minimum version for the current epoch
|
||||
else if (pfrom->nVersion < chainparams.GetConsensus().vUpgrades[CurrentEpoch(GetHeight(), chainparams.GetConsensus())].nProtocolVersion) {
|
||||
LogPrintf("Disconnecting peer=%d at %s using obsolete version %i vs %d\n", pfrom->id, pfrom->addr.ToString().c_str(), pfrom->nVersion,(int32_t)chainparams.GetConsensus().vUpgrades[CurrentEpoch(GetHeight(), chainparams.GetConsensus())].nProtocolVersion);
|
||||
pfrom->PushMessage("reject", strCommand, REJECT_OBSOLETE,
|
||||
pfrom->PushMessage(NetMsgType::REJECT, strCommand, REJECT_OBSOLETE,
|
||||
strprintf("Version must be %d or greater",
|
||||
chainparams.GetConsensus().vUpgrades[
|
||||
CurrentEpoch(GetHeight(), chainparams.GetConsensus())].nProtocolVersion));
|
||||
|
||||
pfrom->fDisconnect = true;
|
||||
return false;
|
||||
} else if (strCommand == "addr") {
|
||||
} else if (strCommand == NetMsgType::SENDADDRV2) {
|
||||
pfrom->m_wants_addrv2 = true;
|
||||
return true;
|
||||
} else if (strCommand == NetMsgType::ADDR || strCommand == NetMsgType::ADDRV2) {
|
||||
int stream_version = vRecv.GetVersion();
|
||||
int tempStream_version = vRecv.GetVersion();
|
||||
tempStream_version |= ADDRV2_FORMAT;
|
||||
|
||||
if (strCommand == NetMsgType::ADDRV2) {
|
||||
// Add ADDRV2_FORMAT to the version so that the CNetAddr and CAddress
|
||||
// unserialize methods know that an address in v2 format is coming.
|
||||
stream_version |= ADDRV2_FORMAT;
|
||||
}
|
||||
OverrideStream<CDataStream> s(&vRecv, vRecv.GetType(), stream_version);
|
||||
vector<CAddress> vAddr;
|
||||
vRecv >> vAddr;
|
||||
s >> vAddr;
|
||||
if(p2pdebug)
|
||||
fprintf(stderr,"%s: processing add with vAddr.size=%lu\n", __func__, vAddr.size() );
|
||||
|
||||
@@ -7074,7 +7096,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
if (vAddr.size() > 1000)
|
||||
{
|
||||
Misbehaving(pfrom->GetId(), 20);
|
||||
return error("message addr size() = %u", vAddr.size());
|
||||
return error("%s message size() = %u", strCommand, vAddr.size());
|
||||
}
|
||||
|
||||
// Store the new addresses
|
||||
@@ -7133,7 +7155,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
pfrom->fGetAddr = false;
|
||||
if (pfrom->fOneShot)
|
||||
pfrom->fDisconnect = true;
|
||||
} else if (strCommand == "ping") {
|
||||
} else if (strCommand == NetMsgType::PING) {
|
||||
if (pfrom->nVersion > BIP0031_VERSION)
|
||||
{
|
||||
uint64_t nonce = 0;
|
||||
@@ -7149,9 +7171,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
// it, if the remote node sends a ping once per second and this node takes 5
|
||||
// seconds to respond to each, the 5th ping the remote sends would appear to
|
||||
// return very quickly.
|
||||
pfrom->PushMessage("pong", nonce);
|
||||
pfrom->PushMessage(NetMsgType::PONG, nonce);
|
||||
}
|
||||
} else if (strCommand == "pong") {
|
||||
} else if (strCommand == NetMsgType::PONG) {
|
||||
int64_t pingUsecEnd = nTimeReceived;
|
||||
uint64_t nonce = 0;
|
||||
size_t nAvail = vRecv.in_avail();
|
||||
@@ -7204,6 +7226,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
}
|
||||
if (bPingFinished) {
|
||||
pfrom->nPingNonceSent = 0;
|
||||
pfrom->nPingRetry = 0;
|
||||
}
|
||||
}
|
||||
// This asymmetric behavior for inbound and outbound connections was introduced
|
||||
@@ -7211,7 +7234,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
// to users' AddrMan and later request them by sending getaddr messages.
|
||||
// Making nodes which are behind NAT and can only make outgoing connections ignore
|
||||
// the getaddr message mitigates the attack.
|
||||
else if ((strCommand == "getaddr") && (pfrom->fInbound))
|
||||
else if ((strCommand == NetMsgType::GETADDR) && (pfrom->fInbound))
|
||||
{
|
||||
// Only send one GetAddr response per connection to reduce resource waste
|
||||
// and discourage addr stamping of INV announcements.
|
||||
@@ -7222,10 +7245,11 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
pfrom->fSentAddr = true;
|
||||
|
||||
pfrom->vAddrToSend.clear();
|
||||
vector<CAddress> vAddr = addrman.GetAddr();
|
||||
vector<CAddress> vAddr = addrman.GetAddr(pfrom->m_wants_addrv2);
|
||||
BOOST_FOREACH(const CAddress &addr, vAddr)
|
||||
pfrom->PushAddress(addr);
|
||||
} else if (strCommand == "getnSPV") {
|
||||
} else if (GetBoolArg("-nspv_msg", DEFAULT_NSPV_PROCESSING) &&
|
||||
(strCommand == NetMsgType::GETNSPV)) {
|
||||
if ( HUSH_NSPV == 0 )//&& HUSH_INSYNC != 0 )
|
||||
{
|
||||
std::vector<uint8_t> payload;
|
||||
@@ -7233,7 +7257,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
hush_nSPVreq(pfrom,payload);
|
||||
}
|
||||
return(true);
|
||||
} else if (strCommand == "nSPV") {
|
||||
} else if (GetBoolArg("-nspv_msg", DEFAULT_NSPV_PROCESSING) &&
|
||||
(strCommand == NetMsgType::GETNSPV)) {
|
||||
if ( HUSH_NSPV_SUPERLITE )
|
||||
{
|
||||
std::vector<uint8_t> payload;
|
||||
@@ -7241,10 +7266,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
hush_nSPVresp(pfrom,payload);
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
else if ( HUSH_NSPV_SUPERLITE )
|
||||
} else if ( HUSH_NSPV_SUPERLITE ) {
|
||||
return(true);
|
||||
else if (strCommand == "inv") {
|
||||
} else if (strCommand == NetMsgType::INV) {
|
||||
vector<CInv> vInv;
|
||||
vRecv >> vInv;
|
||||
if(p2pdebug)
|
||||
@@ -7283,7 +7307,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
// time the block arrives, the header chain leading up to it is already validated. Not
|
||||
// doing this will result in the received block being rejected as an orphan in case it is
|
||||
// not a direct successor.
|
||||
pfrom->PushMessage("getheaders", chainActive.GetLocator(pindexBestHeader), inv.hash);
|
||||
pfrom->PushMessage(NetMsgType::GETHEADERS, chainActive.GetLocator(pindexBestHeader), inv.hash);
|
||||
CNodeState *nodestate = State(pfrom->GetId());
|
||||
if (chainActive.Tip()->GetBlockTime() > GetTime() - chainparams.GetConsensus().nPowTargetSpacing * 20 &&
|
||||
nodestate->nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
|
||||
@@ -7306,8 +7330,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
}
|
||||
|
||||
if (!vToFetch.empty())
|
||||
pfrom->PushMessage("getdata", vToFetch);
|
||||
} else if (strCommand == "getdata") {
|
||||
pfrom->PushMessage(NetMsgType::GETDATA, vToFetch);
|
||||
} else if (strCommand == NetMsgType::GETDATA) {
|
||||
vector<CInv> vInv;
|
||||
vRecv >> vInv;
|
||||
if(p2pdebug)
|
||||
@@ -7326,7 +7350,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
|
||||
pfrom->vRecvGetData.insert(pfrom->vRecvGetData.end(), vInv.begin(), vInv.end());
|
||||
ProcessGetData(pfrom);
|
||||
} else if (strCommand == "getblocks") {
|
||||
} else if (strCommand == NetMsgType::GETBLOCKS) {
|
||||
CBlockLocator locator;
|
||||
uint256 hashStop;
|
||||
vRecv >> locator >> hashStop;
|
||||
@@ -7358,7 +7382,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (strCommand == "getheaders") {
|
||||
} else if (strCommand == NetMsgType::GETHEADERS) {
|
||||
CBlockLocator locator;
|
||||
uint256 hashStop;
|
||||
vRecv >> locator >> hashStop;
|
||||
@@ -7409,7 +7433,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
if (--nLimit <= 0 || pindex->GetBlockHash() == hashStop)
|
||||
break;
|
||||
}
|
||||
pfrom->PushMessage("headers", vHeaders);
|
||||
pfrom->PushMessage(NetMsgType::HEADERS, vHeaders);
|
||||
}
|
||||
/*else if ( IS_HUSH_NOTARY != 0 )
|
||||
{
|
||||
@@ -7417,7 +7441,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
if ( counter++ < 3 )
|
||||
fprintf(stderr,"you can ignore redundant getheaders from peer.%d %d prev.%d\n",(int32_t)pfrom->id,(int32_t)(pindex ? pindex->GetHeight() : -1),pfrom->lasthdrsreq);
|
||||
}*/
|
||||
} else if (strCommand == "tx") {
|
||||
} else if (strCommand == NetMsgType::TX) {
|
||||
if (IsInitialBlockDownload())
|
||||
return true;
|
||||
|
||||
@@ -7545,12 +7569,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
LogPrint("mempool", "%s from peer=%d %s was not accepted into the memory pool: %s\n", tx.GetHash().ToString(),
|
||||
pfrom->id, pfrom->cleanSubVer,
|
||||
state.GetRejectReason());
|
||||
pfrom->PushMessage("reject", strCommand, state.GetRejectCode(),
|
||||
pfrom->PushMessage(NetMsgType::REJECT, strCommand, state.GetRejectCode(),
|
||||
state.GetRejectReason().substr(0, MAX_REJECT_MESSAGE_LENGTH), inv.hash);
|
||||
if (nDoS > 0)
|
||||
Misbehaving(pfrom->GetId(), nDoS);
|
||||
}
|
||||
} else if (strCommand == "headers" && !fImporting && !fReindex) // Ignore headers received while importing
|
||||
} else if (strCommand == NetMsgType::HEADERS && !fImporting && !fReindex) // Ignore headers received while importing
|
||||
{
|
||||
std::vector<CBlockHeader> headers;
|
||||
|
||||
@@ -7608,12 +7632,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
{
|
||||
pfrom->sendhdrsreq = (int32_t)pindexLast->GetHeight();
|
||||
LogPrint("net", "more getheaders (%d) to end to peer=%d (startheight:%d)\n", pindexLast->GetHeight(), pfrom->id, pfrom->nStartingHeight);
|
||||
pfrom->PushMessage("getheaders", chainActive.GetLocator(pindexLast), uint256());
|
||||
pfrom->PushMessage(NetMsgType::GETHEADERS, chainActive.GetLocator(pindexLast), uint256());
|
||||
}
|
||||
}
|
||||
|
||||
CheckBlockIndex();
|
||||
} else if (strCommand == "block" && !fImporting && !fReindex) // Ignore blocks received while importing
|
||||
} else if (strCommand == NetMsgType::BLOCK && !fImporting && !fReindex) // Ignore blocks received while importing
|
||||
{
|
||||
CBlock block;
|
||||
vRecv >> block;
|
||||
@@ -7632,7 +7656,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
ProcessNewBlock(0,0,state, pfrom, &block, forceProcessing, NULL);
|
||||
int nDoS;
|
||||
if (state.IsInvalid(nDoS)) {
|
||||
pfrom->PushMessage("reject", strCommand, state.GetRejectCode(),
|
||||
pfrom->PushMessage(NetMsgType::REJECT, strCommand, state.GetRejectCode(),
|
||||
state.GetRejectReason().substr(0, MAX_REJECT_MESSAGE_LENGTH), inv.hash);
|
||||
if (nDoS > 0) {
|
||||
LOCK(cs_main);
|
||||
@@ -7640,7 +7664,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
}
|
||||
}
|
||||
|
||||
} else if (strCommand == "mempool") {
|
||||
} else if (strCommand == NetMsgType::MEMPOOL) {
|
||||
LOCK2(cs_main, pfrom->cs_filter);
|
||||
//LogPrintf("%s: mempool request from %s",__func__, pfrom->addr.ToString().c_str());
|
||||
// TODO: limit mempool requests per time and per peer
|
||||
@@ -7658,18 +7682,20 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
}
|
||||
vInv.push_back(inv);
|
||||
if (vInv.size() == MAX_INV_SZ) {
|
||||
pfrom->PushMessage("inv", vInv);
|
||||
pfrom->PushMessage(NetMsgType::INV, vInv);
|
||||
vInv.clear();
|
||||
}
|
||||
}
|
||||
if (vInv.size() > 0)
|
||||
pfrom->PushMessage("inv", vInv);
|
||||
} else if (strCommand == "alert") {
|
||||
// Do not process alert p2p messages
|
||||
// Misbehaving(pfrom->GetId(), 10);
|
||||
pfrom->PushMessage(NetMsgType::INV, vInv);
|
||||
} else if (strCommand == NetMsgType::ALERT) {
|
||||
// Small DoS penalty so peers that send us lots of
|
||||
// duplicate/expired/invalid-signature/whatever alerts
|
||||
// eventually get banned.
|
||||
Misbehaving(pfrom->GetId(), 10);
|
||||
} else if (!(nLocalServices & NODE_BLOOM) &&
|
||||
(strCommand == "filterload" ||
|
||||
strCommand == "filteradd")) {
|
||||
(strCommand == NetMsgType::FILTERLOAD ||
|
||||
strCommand == NetMsgType::FILTERADD)) {
|
||||
if (pfrom->nVersion >= NO_BLOOM_VERSION) {
|
||||
Misbehaving(pfrom->GetId(), 100);
|
||||
return false;
|
||||
@@ -7677,7 +7703,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
pfrom->fDisconnect = true;
|
||||
return false;
|
||||
}
|
||||
} else if (strCommand == "filterload") {
|
||||
} else if (strCommand == NetMsgType::FILTERLOAD) {
|
||||
CBloomFilter filter;
|
||||
vRecv >> filter;
|
||||
|
||||
@@ -7692,7 +7718,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
pfrom->pfilter->UpdateEmptyFull();
|
||||
}
|
||||
pfrom->fRelayTxes = true;
|
||||
} else if (strCommand == "filteradd") {
|
||||
} else if (strCommand == NetMsgType::FILTERADD) {
|
||||
vector<unsigned char> vData;
|
||||
vRecv >> vData;
|
||||
|
||||
@@ -7708,14 +7734,14 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
else
|
||||
Misbehaving(pfrom->GetId(), 100);
|
||||
}
|
||||
} else if (strCommand == "filterclear") {
|
||||
} else if (strCommand == NetMsgType::FILTERCLEAR) {
|
||||
LOCK(pfrom->cs_filter);
|
||||
if (nLocalServices & NODE_BLOOM) {
|
||||
delete pfrom->pfilter;
|
||||
pfrom->pfilter = new CBloomFilter();
|
||||
}
|
||||
pfrom->fRelayTxes = true;
|
||||
} else if (strCommand == "reject") {
|
||||
} else if (strCommand == NetMsgType::REJECT) {
|
||||
if (fDebug) {
|
||||
try {
|
||||
string strMsg; unsigned char ccode; string strReason;
|
||||
@@ -7736,7 +7762,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
LogPrint("net", "Unparseable reject message received\n");
|
||||
}
|
||||
}
|
||||
} else if (strCommand == "notfound") {
|
||||
} else if (strCommand == NetMsgType::NOTFOUND) {
|
||||
// We do not care about the NOTFOUND message, but logging an Unknown Command
|
||||
// message would be undesirable as we transmit it ourselves.
|
||||
} else {
|
||||
@@ -7829,7 +7855,7 @@ bool ProcessMessages(CNode* pfrom)
|
||||
}
|
||||
catch (const std::ios_base::failure& e)
|
||||
{
|
||||
pfrom->PushMessage("reject", strCommand, REJECT_MALFORMED, string("error parsing message"));
|
||||
pfrom->PushMessage(NetMsgType::REJECT, strCommand, REJECT_MALFORMED, string("error parsing message"));
|
||||
if (strstr(e.what(), "end of data"))
|
||||
{
|
||||
// Allow exceptions from under-length message on vRecv
|
||||
@@ -7881,9 +7907,12 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
|
||||
// RPC ping request by user
|
||||
pingSend = true;
|
||||
}
|
||||
if (pto->nPingNonceSent == 0 && pto->nPingUsecStart + PING_INTERVAL * 1000000 < GetTimeMicros()) {
|
||||
if (pto->nPingUsecStart + PING_INTERVAL * 1000000 < GetTimeMicros()) {
|
||||
// Ping automatically sent as a latency probe & keepalive.
|
||||
pingSend = true;
|
||||
if (pto->nPingNonceSent != 0) {
|
||||
pto->nPingRetry++;
|
||||
}
|
||||
}
|
||||
if (pingSend) {
|
||||
uint64_t nonce = 0;
|
||||
@@ -7894,12 +7923,12 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
|
||||
pto->nPingUsecStart = GetTimeMicros();
|
||||
if (pto->nVersion > BIP0031_VERSION) {
|
||||
pto->nPingNonceSent = nonce;
|
||||
pto->PushMessage("ping", nonce);
|
||||
} else {
|
||||
pto->PushMessage(NetMsgType::PING, nonce);
|
||||
} // else {
|
||||
// Peer is too old to support ping command with nonce, pong will never arrive.
|
||||
pto->nPingNonceSent = 0;
|
||||
pto->PushMessage("ping");
|
||||
}
|
||||
// pto->nPingNonceSent = 0;
|
||||
// pto->PushMessage("ping");
|
||||
// }
|
||||
}
|
||||
|
||||
TRY_LOCK(cs_main, lockMain); // Acquire cs_main for IsInitialBlockDownload() and CNodeState()
|
||||
@@ -7935,17 +7964,29 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
|
||||
{
|
||||
pto->addrKnown.insert(addr.GetKey());
|
||||
vAddr.push_back(addr);
|
||||
// receiver rejects addr messages larger than 1000
|
||||
if (vAddr.size() >= 1000)
|
||||
|
||||
if (vAddr.size() >= MAX_ADDR_TO_SEND)
|
||||
{
|
||||
pto->PushMessage("addr", vAddr);
|
||||
vAddr.clear();
|
||||
// Should be impossible since we always check size before adding to
|
||||
// vAddrToSend. Recover by trimming the vector.
|
||||
vAddr.resize(MAX_ADDR_TO_SEND);
|
||||
}
|
||||
const char* msg_type;
|
||||
int make_flags;
|
||||
if (pto->m_wants_addrv2) {
|
||||
msg_type = NetMsgType::ADDRV2;
|
||||
make_flags = ADDRV2_FORMAT;
|
||||
} else {
|
||||
msg_type = NetMsgType::ADDR;
|
||||
make_flags = 0;
|
||||
}
|
||||
pto->PushAddrMessage(CNetMsgMaker(std::min(pto->nVersion, PROTOCOL_VERSION)).Make(make_flags, msg_type, pto->vAddrToSend));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
pto->vAddrToSend.clear();
|
||||
if (!vAddr.empty())
|
||||
pto->PushMessage("addr", vAddr);
|
||||
vAddr.clear();
|
||||
}
|
||||
|
||||
CNodeState &state = *State(pto->GetId());
|
||||
@@ -7958,7 +7999,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
|
||||
LogPrintf("Warning: not banning local peer %s!\n", pto->addr.ToString());
|
||||
else
|
||||
{
|
||||
CNode::Ban(pto->addr);
|
||||
CNode::Ban(pto->addr, BanReasonNodeMisbehaving);
|
||||
}
|
||||
}
|
||||
state.fShouldBan = false;
|
||||
@@ -7969,7 +8010,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
|
||||
return(true);
|
||||
}
|
||||
BOOST_FOREACH(const CBlockReject& reject, state.rejects)
|
||||
pto->PushMessage("reject", (string)"block", reject.chRejectCode, reject.strRejectReason, reject.hashBlock);
|
||||
pto->PushMessage(NetMsgType::REJECT, (string)"block", reject.chRejectCode, reject.strRejectReason, reject.hashBlock);
|
||||
state.rejects.clear();
|
||||
|
||||
// Start block sync
|
||||
@@ -7983,7 +8024,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
|
||||
nSyncStarted++;
|
||||
CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader;
|
||||
LogPrint("net", "initial getheaders (%d) to peer=%d (startheight:%d)\n", pindexStart->GetHeight(), pto->id, pto->nStartingHeight);
|
||||
pto->PushMessage("getheaders", chainActive.GetLocator(pindexStart), uint256());
|
||||
pto->PushMessage(NetMsgType::GETHEADERS, chainActive.GetLocator(pindexStart), uint256());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8031,7 +8072,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
|
||||
vInv.push_back(inv);
|
||||
if (vInv.size() >= 1000)
|
||||
{
|
||||
pto->PushMessage("inv", vInv);
|
||||
pto->PushMessage(NetMsgType::INV, vInv);
|
||||
vInv.clear();
|
||||
}
|
||||
}
|
||||
@@ -8039,7 +8080,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
|
||||
pto->vInventoryToSend = vInvWait;
|
||||
}
|
||||
if (!vInv.empty())
|
||||
pto->PushMessage("inv", vInv);
|
||||
pto->PushMessage(NetMsgType::INV, vInv);
|
||||
|
||||
// Detect whether we're stalling
|
||||
int64_t nNow = GetTimeMicros();
|
||||
@@ -8104,7 +8145,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
|
||||
vGetData.push_back(inv);
|
||||
if (vGetData.size() >= 1000)
|
||||
{
|
||||
pto->PushMessage("getdata", vGetData);
|
||||
pto->PushMessage(NetMsgType::GETDATA, vGetData);
|
||||
vGetData.clear();
|
||||
}
|
||||
} else {
|
||||
@@ -8114,7 +8155,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
|
||||
pto->mapAskFor.erase(pto->mapAskFor.begin());
|
||||
}
|
||||
if (!vGetData.empty())
|
||||
pto->PushMessage("getdata", vGetData);
|
||||
pto->PushMessage(NetMsgType::GETDATA, vGetData);
|
||||
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user