X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fprotocol.cpp;h=9933452d4f6353b767c8d933d516d955adff7add;hb=a93ab877877925c60b2dbf56bdde8aa46b6b7391;hp=8d2dbfdd2d76b6de1d45a962686b2879614640d4;hpb=33e28c9948336784324cf5c7248ce608b93dbfde;p=novacoin.git diff --git a/src/protocol.cpp b/src/protocol.cpp index 8d2dbfd..9933452 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -6,7 +6,7 @@ #include "protocol.h" #include "util.h" -#ifndef __WXMSW__ +#ifndef WIN32 # include #endif @@ -15,6 +15,12 @@ bool Lookup(const char *pszName, std::vector& vaddr, int nServices, in bool Lookup(const char *pszName, CAddress& addr, int nServices, bool fAllowLookup = false, int portDefault = 0, bool fAllowPort = false); static const unsigned char pchIPv4[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff }; +static const char* ppszTypeName[] = +{ + "ERROR", + "tx", + "block", +}; CMessageHeader::CMessageHeader() { @@ -249,3 +255,58 @@ void CAddress::print() const { printf("CAddress(%s)\n", ToString().c_str()); } + +CInv::CInv() +{ + type = 0; + hash = 0; +} + +CInv::CInv(int typeIn, const uint256& hashIn) +{ + type = typeIn; + hash = hashIn; +} + +CInv::CInv(const std::string& strType, const uint256& hashIn) +{ + unsigned int i; + for (i = 1; i < ARRAYLEN(ppszTypeName); i++) + { + if (strType == ppszTypeName[i]) + { + type = i; + break; + } + } + if (i == ARRAYLEN(ppszTypeName)) + throw std::out_of_range(strprintf("CInv::CInv(string, uint256) : unknown type '%s'", strType.c_str())); + hash = hashIn; +} + +bool operator<(const CInv& a, const CInv& b) +{ + return (a.type < b.type || (a.type == b.type && a.hash < b.hash)); +} + +bool CInv::IsKnownType() const +{ + return (type >= 1 && type < ARRAYLEN(ppszTypeName)); +} + +const char* CInv::GetCommand() const +{ + if (!IsKnownType()) + throw std::out_of_range(strprintf("CInv::GetCommand() : type=%d unknown type", type)); + return ppszTypeName[type]; +} + +std::string CInv::ToString() const +{ + return strprintf("%s %s", GetCommand(), hash.ToString().substr(0,20).c_str()); +} + +void CInv::print() const +{ + printf("CInv(%s)\n", ToString().c_str()); +}