#define MTHASHSET_FILE_SIGNATURE 0x4d544853 // 'MTHS' /* Minetest Hashset File Format All values are stored in big-endian byte order. [u32] signature: 'MTHS' [u16] version: 1 For each hash in set: [u8*20] SHA1 hash Version changes: 1 - Initial version */ bool ClientMediaDownloader::loadHashSet(const std::string &data, std::set &result) { if (data.size() % 20 != 6) { errorstream << "loadHashSet: invalid hash set file" << std::endl; return false; } u32 signature = readU32(&data[0]); if (signature != MTHASHSET_FILE_SIGNATURE) { errorstream << "loadHashSet: invalid hash set file" << std::endl; return false; } u16 version = readU16(&data[4]); if (version != 1) { errorstream << "loadHashSet: unsupported hash set " "file version" << std::endl; return false; } for (u32 pos = 6; pos < data.size(); pos += 20) { result.push_back(data.substr(pos, 20)); } return true; } bool ClientMediaDownloader::saveHashSet(const std::set &hashset, std::ostream &os) { writeU32(os, MTHASHSET_FILE_SIGNATURE); // signature writeU16(os, 1); // version // list of hashes for (std::set::const_iterator it = hashset.begin(); it != hashset.end(); ++it) { assert(it->size() == 20); os << (*it); } return true; }