diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-05-15 17:11:06 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-08-18 23:25:46 +0200 |
commit | 0f95a9de53f23db735b7f1d1ecdb7acdd59bba0d (patch) | |
tree | 7146360bf1dafbc445aa77bbe86529d363fe4031 | |
parent | 8a030b5e77031c8b3347170d28758097bca1f15e (diff) |
Add versioning to request old data structure
-rw-r--r-- | src/Database.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
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<u16>(); + 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); |