// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-#ifndef __cplusplus
-# error This header can only be compiled as C++.
-#endif
-
#ifndef __INCLUDED_PROTOCOL_H__
#define __INCLUDED_PROTOCOL_H__
#include "netbase.h"
#include <string>
#include <limits>
+#include <vector>
#include "uint256.h"
+extern uint32_t nNetworkID;
extern bool fTestNet;
-inline unsigned short GetDefaultPort()
+inline uint16_t GetDefaultPort()
{
- return static_cast<unsigned short>(fTestNet ? 17777 : 7777);
+ return static_cast<uint16_t>(fTestNet ? 17777 : 7777);
}
-
-extern unsigned char pchMessageStart[4];
-
-/** Message header.
- * (4) message start.
- * (12) command.
- * (4) size.
- * (4) checksum.
- */
+// Message header.
+// (4) network identifier.
+// (12) command.
+// (4) size.
+// (4) checksum.
class CMessageHeader
{
public:
IMPLEMENT_SERIALIZE
(
- READWRITE(FLATDATA(pchMessageStart));
+ READWRITE(nNetworkID);
READWRITE(FLATDATA(pchCommand));
READWRITE(nMessageSize);
READWRITE(nChecksum);
// TODO: make private (improves encapsulation)
public:
enum {
- MESSAGE_START_SIZE=sizeof(::pchMessageStart),
+ MESSAGE_START_SIZE=4,
COMMAND_SIZE=12,
- MESSAGE_SIZE_SIZE=sizeof(int),
- CHECKSUM_SIZE=sizeof(int),
+ MESSAGE_SIZE_SIZE=4,
+ CHECKSUM_SIZE=4,
MESSAGE_SIZE_OFFSET=MESSAGE_START_SIZE+COMMAND_SIZE,
CHECKSUM_OFFSET=MESSAGE_SIZE_OFFSET+MESSAGE_SIZE_SIZE
};
- char pchMessageStart[MESSAGE_START_SIZE];
+ uint32_t nNetworkID;
char pchCommand[COMMAND_SIZE];
- unsigned int nMessageSize;
- unsigned int nChecksum;
+ uint32_t nMessageSize;
+ uint32_t nChecksum;
};
/** nServices flags */
const char* GetCommand() const;
std::string ToString() const;
+ int GetType() const { return type; }
+ uint256 GetHash() const { return hash; }
+
// TODO: make private (improves encapsulation)
- public:
- int type;
- uint256 hash;
+ private:
+ int type = 0;
+ uint256 hash = 0;
};
#endif // __INCLUDED_PROTOCOL_H__