Replace several network protocol version numbers with named constants
stored in version.h. Also, a minor CAddress code reformat while we're in there, fixing some incorrect indentation.
This commit is contained in:
parent
b87c0fc440
commit
8b09cd3a4d
4 changed files with 23 additions and 10 deletions
11
src/main.cpp
11
src/main.cpp
|
@ -2185,7 +2185,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
||||||
CAddress addrFrom;
|
CAddress addrFrom;
|
||||||
uint64 nNonce = 1;
|
uint64 nNonce = 1;
|
||||||
vRecv >> pfrom->nVersion >> pfrom->nServices >> nTime >> addrMe;
|
vRecv >> pfrom->nVersion >> pfrom->nServices >> nTime >> addrMe;
|
||||||
if (pfrom->nVersion < 209)
|
if (pfrom->nVersion < MIN_PROTO_VERSION)
|
||||||
{
|
{
|
||||||
// Since February 20, 2012, the protocol is initiated at version 209,
|
// Since February 20, 2012, the protocol is initiated at version 209,
|
||||||
// and earlier versions are no longer supported
|
// and earlier versions are no longer supported
|
||||||
|
@ -2235,7 +2235,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get recent addresses
|
// Get recent addresses
|
||||||
if (pfrom->nVersion >= 31402 || addrman.size() < 1000)
|
if (pfrom->nVersion >= CADDR_TIME_VERSION || addrman.size() < 1000)
|
||||||
{
|
{
|
||||||
pfrom->PushMessage("getaddr");
|
pfrom->PushMessage("getaddr");
|
||||||
pfrom->fGetAddr = true;
|
pfrom->fGetAddr = true;
|
||||||
|
@ -2252,7 +2252,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
||||||
// Ask the first connected node for block updates
|
// Ask the first connected node for block updates
|
||||||
static int nAskedForBlocks = 0;
|
static int nAskedForBlocks = 0;
|
||||||
if (!pfrom->fClient &&
|
if (!pfrom->fClient &&
|
||||||
(pfrom->nVersion < 32000 || pfrom->nVersion >= 32400) &&
|
(pfrom->nVersion < NOBLKS_VERSION_START ||
|
||||||
|
pfrom->nVersion >= NOBLKS_VERSION_END) &&
|
||||||
(nAskedForBlocks < 1 || vNodes.size() <= 1))
|
(nAskedForBlocks < 1 || vNodes.size() <= 1))
|
||||||
{
|
{
|
||||||
nAskedForBlocks++;
|
nAskedForBlocks++;
|
||||||
|
@ -2294,7 +2295,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
||||||
vRecv >> vAddr;
|
vRecv >> vAddr;
|
||||||
|
|
||||||
// Don't want addr from older versions unless seeding
|
// Don't want addr from older versions unless seeding
|
||||||
if (pfrom->nVersion < 31402 && addrman.size() > 1000)
|
if (pfrom->nVersion < CADDR_TIME_VERSION && addrman.size() > 1000)
|
||||||
return true;
|
return true;
|
||||||
if (vAddr.size() > 1000)
|
if (vAddr.size() > 1000)
|
||||||
{
|
{
|
||||||
|
@ -2331,7 +2332,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
||||||
multimap<uint256, CNode*> mapMix;
|
multimap<uint256, CNode*> mapMix;
|
||||||
BOOST_FOREACH(CNode* pnode, vNodes)
|
BOOST_FOREACH(CNode* pnode, vNodes)
|
||||||
{
|
{
|
||||||
if (pnode->nVersion < 31402)
|
if (pnode->nVersion < CADDR_TIME_VERSION)
|
||||||
continue;
|
continue;
|
||||||
unsigned int nPointer;
|
unsigned int nPointer;
|
||||||
memcpy(&nPointer, &pnode, sizeof(nPointer));
|
memcpy(&nPointer, &pnode, sizeof(nPointer));
|
||||||
|
|
|
@ -163,8 +163,8 @@ public:
|
||||||
hSocket = hSocketIn;
|
hSocket = hSocketIn;
|
||||||
vSend.SetType(SER_NETWORK);
|
vSend.SetType(SER_NETWORK);
|
||||||
vRecv.SetType(SER_NETWORK);
|
vRecv.SetType(SER_NETWORK);
|
||||||
vSend.SetVersion(209);
|
vSend.SetVersion(MIN_PROTO_VERSION);
|
||||||
vRecv.SetVersion(209);
|
vRecv.SetVersion(MIN_PROTO_VERSION);
|
||||||
nLastSend = 0;
|
nLastSend = 0;
|
||||||
nLastRecv = 0;
|
nLastRecv = 0;
|
||||||
nLastSendEmpty = GetTime();
|
nLastSendEmpty = GetTime();
|
||||||
|
|
|
@ -79,9 +79,10 @@ class CAddress : public CService
|
||||||
if (fRead)
|
if (fRead)
|
||||||
pthis->Init();
|
pthis->Init();
|
||||||
if (nType & SER_DISK)
|
if (nType & SER_DISK)
|
||||||
READWRITE(nVersion);
|
READWRITE(nVersion);
|
||||||
if ((nType & SER_DISK) || (nVersion >= 31402 && !(nType & SER_GETHASH)))
|
if ((nType & SER_DISK) ||
|
||||||
READWRITE(nTime);
|
(nVersion >= CADDR_TIME_VERSION && !(nType & SER_GETHASH)))
|
||||||
|
READWRITE(nTime);
|
||||||
READWRITE(nServices);
|
READWRITE(nServices);
|
||||||
READWRITE(*pip);
|
READWRITE(*pip);
|
||||||
)
|
)
|
||||||
|
|
|
@ -31,6 +31,17 @@ extern const std::string CLIENT_DATE;
|
||||||
|
|
||||||
static const int PROTOCOL_VERSION = 60000;
|
static const int PROTOCOL_VERSION = 60000;
|
||||||
|
|
||||||
|
// earlier versions not supported as of Feb 2012, and are disconnected
|
||||||
|
static const int MIN_PROTO_VERSION = 209;
|
||||||
|
|
||||||
|
// nTime field added to CAddress, starting with this version;
|
||||||
|
// if possible, avoid requesting addresses nodes older than this
|
||||||
|
static const int CADDR_TIME_VERSION = 31402;
|
||||||
|
|
||||||
|
// only request blocks from nodes outside this range of versions
|
||||||
|
static const int NOBLKS_VERSION_START = 32000;
|
||||||
|
static const int NOBLKS_VERSION_END = 32400;
|
||||||
|
|
||||||
// BIP 0031, pong message, is enabled for all versions AFTER this one
|
// BIP 0031, pong message, is enabled for all versions AFTER this one
|
||||||
static const int BIP0031_VERSION = 60000;
|
static const int BIP0031_VERSION = 60000;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue