Improve incapsulation. Yep, finally.
[novacoin.git] / src / protocol.cpp
index c9b0086..676718d 100644 (file)
@@ -7,23 +7,21 @@
 #include "util.h"
 #include "netbase.h"
 
-#ifndef WIN32
-# include <arpa/inet.h>
-#endif
+// Network ID, previously known as pchMessageStart
+uint32_t nNetworkID = 0xe5e9e8e4;
 
-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);
+static const std::vector<const char*> vpszTypeName = { "ERROR", "tx", "block" };
 
 CMessageHeader::CMessageHeader() : nMessageSize(std::numeric_limits<uint32_t>::max()), nChecksum(0)
 {
-    memcpy(pchMessageStart, ::pchMessageStart, sizeof(pchMessageStart));
+    nNetworkID = ::nNetworkID;
     memset(pchCommand, 0, sizeof(pchCommand));
     pchCommand[1] = 1;
 }
 
 CMessageHeader::CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn) : nMessageSize(nMessageSizeIn), nChecksum(0)
 {
-    memcpy(pchMessageStart, ::pchMessageStart, sizeof(pchMessageStart));
+    nNetworkID = ::nNetworkID;
     strncpy(pchCommand, pszCommand, COMMAND_SIZE);
 }
 
@@ -38,7 +36,7 @@ std::string CMessageHeader::GetCommand() const
 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
@@ -67,7 +65,7 @@ bool CMessageHeader::IsValid() const
 
 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)
 {
@@ -97,10 +95,10 @@ 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();
+    return vpszTypeName[type];
 }
 
 std::string CInv::ToString() const
 {
     return strprintf("%s %s", GetCommand(), hash.ToString().substr(0,20).c_str());
-}
\ No newline at end of file
+}