#include "util.h"
#include "netbase.h"
-#ifndef WIN32
-# include <arpa/inet.h>
-#endif
+using namespace std;
-static const std::string forfill[] = { "ERROR", "tx", "block" }; //TODO: Replace with initializer list constructor when c++11 comes
-static const std::vector<std::string> vpszTypeName(forfill, forfill + 3);
+// Network ID, previously known as pchMessageStart
+uint32_t nNetworkID = 0xe5e9e8e4;
-CMessageHeader::CMessageHeader() : nMessageSize(std::numeric_limits<uint32_t>::max()), nChecksum(0)
+static const vector<const char*> vpszTypeName = { "ERROR", "tx", "block" };
+
+CMessageHeader::CMessageHeader() : nNetworkID(::nNetworkID), nMessageSize(numeric_limits<uint32_t>::max()), nChecksum(0)
{
- memcpy(pchMessageStart, ::pchMessageStart, sizeof(pchMessageStart));
- memset(pchCommand, 0, sizeof(pchCommand));
+ fill(begin(pchCommand), end(pchCommand), '\0');
pchCommand[1] = 1;
}
-CMessageHeader::CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn) : nMessageSize(nMessageSizeIn), nChecksum(0)
+CMessageHeader::CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn) : nNetworkID(::nNetworkID), nMessageSize(nMessageSizeIn), nChecksum(0)
{
- memcpy(pchMessageStart, ::pchMessageStart, sizeof(pchMessageStart));
strncpy(pchCommand, pszCommand, COMMAND_SIZE);
}
-std::string CMessageHeader::GetCommand() const
+string CMessageHeader::GetCommand() const
{
if (pchCommand[COMMAND_SIZE-1] == 0)
- return std::string(pchCommand, pchCommand + strlen(pchCommand));
+ return string(pchCommand, pchCommand + strlen(pchCommand));
else
- return std::string(pchCommand, pchCommand + COMMAND_SIZE);
+ return string(pchCommand, pchCommand + COMMAND_SIZE);
}
bool CMessageHeader::IsValid() const
{
// Check start string
- if (memcmp(pchMessageStart, ::pchMessageStart, sizeof(pchMessageStart)) != 0)
+ if (nNetworkID != ::nNetworkID)
return false;
// Check the command string for errors
CAddress::CAddress() : CService(), nServices(NODE_NETWORK), nTime(100000000), nLastTry(0) { }
CAddress::CAddress(CService ipIn, uint64_t nServicesIn) : CService(ipIn), nServices(nServicesIn), nTime(100000000), nLastTry(0) { }
-CInv::CInv() : type(0), hash(0) { }
+CInv::CInv() { }
CInv::CInv(int typeIn, const uint256& hashIn) : type(typeIn), hash(hashIn) { }
-CInv::CInv(const std::string& strType, const uint256& hashIn) : hash(hashIn)
+CInv::CInv(const string& strType, const uint256& hashIn) : hash(hashIn)
{
unsigned int i;
for (i = 1; i < vpszTypeName.size(); ++i)
}
}
if (i == vpszTypeName.size())
- throw std::out_of_range(strprintf("CInv::CInv(string, uint256) : unknown type '%s'", strType.c_str()));
+ throw out_of_range(strprintf("CInv::CInv(string, uint256) : unknown type '%s'", strType.c_str()));
}
bool operator<(const CInv& a, const CInv& b)
const char* CInv::GetCommand() const
{
if (!IsKnownType())
- throw std::out_of_range(strprintf("CInv::GetCommand() : type=%d unknown type", type));
- return vpszTypeName[type].c_str();
+ throw out_of_range(strprintf("CInv::GetCommand() : type=%d unknown type", type));
+ return vpszTypeName[type];
}
-std::string CInv::ToString() const
+string CInv::ToString() const
{
return strprintf("%s %s", GetCommand(), hash.ToString().substr(0,20).c_str());
-}
\ No newline at end of file
+}