From 66ec8dd9b9d3f1f71ce2158c2603586814cc7b8d Mon Sep 17 00:00:00 2001 From: dec05eba <0xdec05eba@gmail.com> Date: Tue, 15 May 2018 17:11:06 +0200 Subject: Add versioning to request old data structure --- src/Database.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/Database.cpp b/src/Database.cpp index ac5a941..5eedc7a 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -33,6 +33,7 @@ namespace odhtdb const u16 DATABASE_CREATE_PACKET_STRUCTURE_VERSION = 1; const u16 DATABASE_ADD_PACKET_STRUCTURE_VERSION = 1; + const u16 DATABASE_REQUEST_OLD_DATA_STRUCTURE_VERSION = 1; class RequestQuarantineException : public runtime_error { @@ -251,6 +252,12 @@ namespace odhtdb { static_assert(HASH_LEN == OPENDHT_INFOHASH_LEN, "Wrong hashlen size, did it change with opendht upgrade?"); sibs::SafeDeserializer deserializer(value->data.data(), value->data.size()); + u16 requestStructureVersion = deserializer.extract(); + if(requestStructureVersion != DATABASE_REQUEST_OLD_DATA_STRUCTURE_VERSION) + { + Log::warn("Request: structure is version %d but we are at version %d, ignoring request", requestStructureVersion, DATABASE_REQUEST_OLD_DATA_STRUCTURE_VERSION); + return true; + } InfoHash requestResponseInfoHash; deserializer.extract(requestResponseInfoHash.data(), OPENDHT_INFOHASH_LEN); if(*responseKeyShared == requestResponseInfoHash) @@ -324,6 +331,7 @@ namespace odhtdb seedInfoMap[*nodeToSeed.getRequestHash()] = newSeedInfo; sibs::SafeSerializer serializer; + serializer.add(DATABASE_REQUEST_OLD_DATA_STRUCTURE_VERSION); serializer.add(responseKey, OPENDHT_INFOHASH_LEN); bool iHaveCreateNode = databaseStorage.doesNodeExist(*nodeToSeed.getRequestHash()); serializer.add(iHaveCreateNode ? (u8)0 : (u8)1); -- cgit v1.2.3