Start moving protocol-specific code to protocol.[ch]pp
[novacoin.git] / src / net.h
index 52568ef..7a4706d 100644 (file)
--- a/src/net.h
+++ b/src/net.h
@@ -14,7 +14,8 @@
 #include <arpa/inet.h>
 #endif
 
-class CMessageHeader;
+#include "protocol.h"
+
 class CAddress;
 class CAddrDB;
 class CInv;
@@ -54,101 +55,6 @@ bool BindListenPort(std::string& strError=REF(std::string()));
 void StartNode(void* parg);
 bool StopNode();
 
-
-
-
-
-
-
-
-//
-// Message header
-//  (4) message start
-//  (12) command
-//  (4) size
-//  (4) checksum
-
-extern unsigned char pchMessageStart[4];
-
-class CMessageHeader
-{
-public:
-    enum { COMMAND_SIZE=12 };
-    char pchMessageStart[sizeof(::pchMessageStart)];
-    char pchCommand[COMMAND_SIZE];
-    unsigned int nMessageSize;
-    unsigned int nChecksum;
-
-    CMessageHeader()
-    {
-        memcpy(pchMessageStart, ::pchMessageStart, sizeof(pchMessageStart));
-        memset(pchCommand, 0, sizeof(pchCommand));
-        pchCommand[1] = 1;
-        nMessageSize = -1;
-        nChecksum = 0;
-    }
-
-    CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn)
-    {
-        memcpy(pchMessageStart, ::pchMessageStart, sizeof(pchMessageStart));
-        strncpy(pchCommand, pszCommand, COMMAND_SIZE);
-        nMessageSize = nMessageSizeIn;
-        nChecksum = 0;
-    }
-
-    IMPLEMENT_SERIALIZE
-    (
-        READWRITE(FLATDATA(pchMessageStart));
-        READWRITE(FLATDATA(pchCommand));
-        READWRITE(nMessageSize);
-        if (nVersion >= 209)
-            READWRITE(nChecksum);
-    )
-
-    std::string GetCommand()
-    {
-        if (pchCommand[COMMAND_SIZE-1] == 0)
-            return std::string(pchCommand, pchCommand + strlen(pchCommand));
-        else
-            return std::string(pchCommand, pchCommand + COMMAND_SIZE);
-    }
-
-    bool IsValid()
-    {
-        // Check start string
-        if (memcmp(pchMessageStart, ::pchMessageStart, sizeof(pchMessageStart)) != 0)
-            return false;
-
-        // Check the command string for errors
-        for (char* p1 = pchCommand; p1 < pchCommand + COMMAND_SIZE; p1++)
-        {
-            if (*p1 == 0)
-            {
-                // Must be all zeros after the first zero
-                for (; p1 < pchCommand + COMMAND_SIZE; p1++)
-                    if (*p1 != 0)
-                        return false;
-            }
-            else if (*p1 < ' ' || *p1 > 0x7E)
-                return false;
-        }
-
-        // Message size
-        if (nMessageSize > MAX_SIZE)
-        {
-            printf("CMessageHeader::IsValid() : (%s, %u bytes) nMessageSize > MAX_SIZE\n", GetCommand().c_str(), nMessageSize);
-            return false;
-        }
-
-        return true;
-    }
-};
-
-
-
-
-
-
 static const unsigned char pchIPv4[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff };
 
 class CAddress