From: Sunny King Date: Tue, 28 Aug 2012 03:05:20 +0000 (+0100) Subject: PPCoin: pchMessageStart switch X-Git-Tag: v0.4.0-unstable~79 X-Git-Url: https://git.novaco.in/?a=commitdiff_plain;h=6b0e5bf1425e8d96732cc7133aee048c2a35d17c;hp=c92c001769447619f77841511fd022000af71988;p=novacoin.git PPCoin: pchMessageStart switch network protocol version 60002 client version v0.2.0 --- diff --git a/src/main.cpp b/src/main.cpp index bc0bdd9..da773ce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2244,10 +2244,6 @@ bool LoadBlockIndex(bool fAllowNew) { hashGenesisBlock = hashGenesisBlockTestNet; bnProofOfWorkLimit = CBigNum(~uint256(0) >> 28); - pchMessageStart[0] = 0x9b; - pchMessageStart[1] = 0xa1; - pchMessageStart[2] = 0xb2; - pchMessageStart[3] = 0xb6; nStakeMinAge = 60 * 60 * 24; // test net min age is 1 day nCoinbaseMaturity = 60; bnInitialHashTarget = CBigNum(~uint256(0) >> 29); @@ -2589,12 +2585,6 @@ bool static AlreadyHave(CTxDB& txdb, const CInv& inv) -// The message start string is designed to be unlikely to occur in normal data. -// The characters are rarely used upper ascii, not valid as UTF-8, and produce -// a large 4-byte int at any alignment. -unsigned char pchMessageStart[4] = { 0xf9, 0xbe, 0xb4, 0xd9 }; - - bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) { static map > mapReuseKey; @@ -3225,6 +3215,17 @@ bool ProcessMessages(CNode* pfrom) // (x) data // + unsigned char pchMessageStart[4]; + GetMessageStart(pchMessageStart); + static int64 nTimeLastPrintMessageStart = 0; + if (fDebug && GetBoolArg("-printmessagestart") && nTimeLastPrintMessageStart + 30 < GetAdjustedTime()) + { + string strMessageStart((const char *)pchMessageStart); + vector vchMessageStart(strMessageStart.begin(), strMessageStart.end()); + printf("ProcessMessages : AdjustedTime=%"PRI64d" MessageStart=%s\n", GetAdjustedTime(), HexStr(vchMessageStart).c_str()); + nTimeLastPrintMessageStart = GetAdjustedTime(); + } + loop { // Scan for message start diff --git a/src/main.h b/src/main.h index 0bd9ab4..34ec560 100644 --- a/src/main.h +++ b/src/main.h @@ -1037,6 +1037,8 @@ public: return error("CBlock::WriteToDisk() : AppendBlockFile failed"); // Write index header + unsigned char pchMessageStart[4]; + GetMessageStart(pchMessageStart, true); unsigned int nSize = fileout.GetSerializeSize(*this); fileout << FLATDATA(pchMessageStart) << nSize; diff --git a/src/protocol.cpp b/src/protocol.cpp index d6e340e..08f753a 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -11,6 +11,29 @@ # include #endif +// The message start string is designed to be unlikely to occur in normal data. +// The characters are rarely used upper ascii, not valid as UTF-8, and produce +// a large 4-byte int at any alignment. + +// Public testnet message start +// unsigned char pchMessageStartTestBitcoin[4] = { 0x9b, 0xa1, 0xb2, 0xb6 }; +static unsigned char pchMessageStartTestOld[4] = { 0xdb, 0xe1, 0xf2, 0xf6 }; +static unsigned char pchMessageStartTestNew[4] = { 0xcb, 0xf2, 0xc0, 0xef }; +static unsigned int nMessageStartTestSwitchTime = 1346200000; + +// PPCoin message start (switch from Bitcoin's in v0.2) +static unsigned char pchMessageStartBitcoin[4] = { 0xf9, 0xbe, 0xb4, 0xd9 }; +static unsigned char pchMessageStartPPCoin[4] = { 0xe6, 0xe8, 0xe9, 0xe5 }; +static unsigned int nMessageStartSwitchTime = 1347300000; + +void GetMessageStart(unsigned char pchMessageStart[], bool fPersistent) +{ + if (fTestNet) + memcpy(pchMessageStart, (fPersistent || GetAdjustedTime() > nMessageStartTestSwitchTime)? pchMessageStartTestNew : pchMessageStartTestOld, sizeof(pchMessageStartTestNew)); + else + memcpy(pchMessageStart, (fPersistent || GetAdjustedTime() > nMessageStartSwitchTime)? pchMessageStartPPCoin : pchMessageStartBitcoin, sizeof(pchMessageStartPPCoin)); +} + static const char* ppszTypeName[] = { "ERROR", @@ -20,7 +43,7 @@ static const char* ppszTypeName[] = CMessageHeader::CMessageHeader() { - memcpy(pchMessageStart, ::pchMessageStart, sizeof(pchMessageStart)); + GetMessageStart(pchMessageStart); memset(pchCommand, 0, sizeof(pchCommand)); pchCommand[1] = 1; nMessageSize = -1; @@ -29,7 +52,7 @@ CMessageHeader::CMessageHeader() CMessageHeader::CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn) { - memcpy(pchMessageStart, ::pchMessageStart, sizeof(pchMessageStart)); + GetMessageStart(pchMessageStart); strncpy(pchCommand, pszCommand, COMMAND_SIZE); nMessageSize = nMessageSizeIn; nChecksum = 0; @@ -46,7 +69,9 @@ std::string CMessageHeader::GetCommand() const bool CMessageHeader::IsValid() const { // Check start string - if (memcmp(pchMessageStart, ::pchMessageStart, sizeof(pchMessageStart)) != 0) + unsigned char pchMessageStartProtocol[4]; + GetMessageStart(pchMessageStartProtocol); + if (memcmp(pchMessageStart, pchMessageStartProtocol, sizeof(pchMessageStart)) != 0) return false; // Check the command string for errors diff --git a/src/protocol.h b/src/protocol.h index 30f9714..c4861e6 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -21,14 +21,14 @@ extern bool fTestNet; +void GetMessageStart(unsigned char pchMessageStart[], bool fPersistent = false); + static inline unsigned short GetDefaultPort(const bool testnet = fTestNet) { return testnet ? TESTNET_PORT : PPCOIN_PORT; } -extern unsigned char pchMessageStart[4]; - /** Message header. * (4) message start. * (12) command. @@ -55,7 +55,7 @@ class CMessageHeader // TODO: make private (improves encapsulation) public: enum { COMMAND_SIZE=12 }; - char pchMessageStart[sizeof(::pchMessageStart)]; + unsigned char pchMessageStart[4]; char pchCommand[COMMAND_SIZE]; unsigned int nMessageSize; unsigned int nChecksum; diff --git a/src/version.h b/src/version.h index bccea96..deea37c 100644 --- a/src/version.h +++ b/src/version.h @@ -28,7 +28,7 @@ extern const std::string CLIENT_DATE; // ppcoin version - intended for display purpose ONLY #define PPCOIN_VERSION_MAJOR 0 -#define PPCOIN_VERSION_MINOR 1 +#define PPCOIN_VERSION_MINOR 2 #define PPCOIN_VERSION_REVISION 0 #define PPCOIN_VERSION_BUILD 0 @@ -36,7 +36,7 @@ extern const std::string CLIENT_DATE; // network protocol versioning // -static const int PROTOCOL_VERSION = 60001; +static const int PROTOCOL_VERSION = 60002; // earlier versions not supported as of Feb 2012, and are disconnected // NOTE: as of bitcoin v0.6 message serialization (vSend, vRecv) still