Replace pchMessageStart with nNetworkID
[novacoin.git] / src / protocol.h
index 30f9714..06165d8 100644 (file)
 #include "serialize.h"
 #include "netbase.h"
 #include <string>
+#include <limits>
+#include <vector>
 #include "uint256.h"
 
-#define PPCOIN_PORT  9901
-#define RPC_PORT     9902
-#define TESTNET_PORT 9903
-
+extern uint32_t nNetworkID;
 extern bool fTestNet;
-
-static inline unsigned short GetDefaultPort(const bool testnet = fTestNet)
+inline uint16_t GetDefaultPort()
 {
-    return testnet ? TESTNET_PORT : PPCOIN_PORT;
+    return static_cast<uint16_t>(fTestNet ? 17777 : 7777);
 }
 
-
-extern unsigned char pchMessageStart[4];
-
 /** Message header.
- * (4) message start.
+ * (4) network identifier.
  * (12) command.
  * (4) size.
  * (4) checksum.
@@ -46,7 +41,7 @@ class CMessageHeader
 
         IMPLEMENT_SERIALIZE
             (
-             READWRITE(FLATDATA(pchMessageStart));
+             READWRITE(nNetworkID);
              READWRITE(FLATDATA(pchCommand));
              READWRITE(nMessageSize);
              READWRITE(nChecksum);
@@ -54,17 +49,25 @@ class CMessageHeader
 
     // TODO: make private (improves encapsulation)
     public:
-        enum { COMMAND_SIZE=12 };
-        char pchMessageStart[sizeof(::pchMessageStart)];
+        enum {
+            MESSAGE_START_SIZE=4,
+            COMMAND_SIZE=12,
+            MESSAGE_SIZE_SIZE=4,
+            CHECKSUM_SIZE=4,
+
+            MESSAGE_SIZE_OFFSET=MESSAGE_START_SIZE+COMMAND_SIZE,
+            CHECKSUM_OFFSET=MESSAGE_SIZE_OFFSET+MESSAGE_SIZE_SIZE
+        };
+        uint32_t nNetworkID;
         char pchCommand[COMMAND_SIZE];
-        unsigned int nMessageSize;
-        unsigned int nChecksum;
+        uint32_t nMessageSize;
+        uint32_t nChecksum;
 };
 
 /** nServices flags */
 enum
 {
-    NODE_NETWORK = (1 << 0),
+    NODE_NETWORK = (1 << 0)
 };
 
 /** A CService with information about it as peer */
@@ -72,9 +75,7 @@ class CAddress : public CService
 {
     public:
         CAddress();
-        explicit CAddress(CService ipIn, uint64 nServicesIn=NODE_NETWORK);
-
-        void Init();
+        explicit CAddress(CService ipIn, uint64_t nServicesIn=NODE_NETWORK);
 
         IMPLEMENT_SERIALIZE
             (
@@ -91,17 +92,15 @@ class CAddress : public CService
              READWRITE(*pip);
             )
 
-        void print() const;
-
     // TODO: make private (improves encapsulation)
     public:
-        uint64 nServices;
+        uint64_t nServices;
 
         // disk and network only
         unsigned int nTime;
 
         // memory only
-        int64 nLastTry;
+        int64_t nLastTry;
 };
 
 /** inv message data */
@@ -123,7 +122,6 @@ class CInv
         bool IsKnownType() const;
         const char* GetCommand() const;
         std::string ToString() const;
-        void print() const;
 
     // TODO: make private (improves encapsulation)
     public: