Fix magic number check for fingerprint

This commit is contained in:
Patrick Niklaus 2015-06-18 18:34:25 +02:00
parent 5fc0d284cb
commit 94b749ab00
8 changed files with 41 additions and 38 deletions

View File

@ -141,9 +141,9 @@ std::size_t Prepare::WriteContractedGraph(unsigned number_of_edge_based_nodes,
SimpleLogger().Write() << "Serializing compacted graph of " << contracted_edge_count
<< " edges";
FingerPrint fingerprint_orig;
const FingerPrint fingerprint = FingerPrint::GetValid();
boost::filesystem::ofstream hsgr_output_stream(config.graph_output_path, std::ios::binary);
hsgr_output_stream.write((char *)&fingerprint_orig, sizeof(FingerPrint));
hsgr_output_stream.write((char *)&fingerprint, sizeof(FingerPrint));
const unsigned max_used_node_id = 1 + [&contracted_edge_list]
{
unsigned tmp_max = 0;

View File

@ -33,7 +33,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../data_structures/query_edge.hpp"
#include "../data_structures/static_graph.hpp"
class FingerPrint;
struct EdgeBasedNode;
struct lua_State;

View File

@ -264,9 +264,10 @@ int main(const int argc, const char *argv[])
boost::filesystem::ifstream hsgr_input_stream(hsgr_path, std::ios::binary);
FingerPrint fingerprint_loaded, fingerprint_orig;
FingerPrint fingerprint_valid = FingerPrint::GetValid();
FingerPrint fingerprint_loaded;
hsgr_input_stream.read((char *)&fingerprint_loaded, sizeof(FingerPrint));
if (fingerprint_loaded.TestGraphUtil(fingerprint_orig))
if (fingerprint_loaded.TestGraphUtil(fingerprint_valid))
{
SimpleLogger().Write(logDEBUG) << "Fingerprint checked out ok";
}

View File

@ -35,6 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../util/osrm_exception.hpp"
#include "../util/simple_logger.hpp"
#include "../util/timing_util.hpp"
#include "../util/fingerprint.hpp"
#include <boost/assert.hpp>
#include <boost/filesystem.hpp>
@ -81,6 +82,7 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name,
{
std::ofstream file_out_stream;
file_out_stream.open(output_file_name.c_str(), std::ios::binary);
const FingerPrint fingerprint = FingerPrint::GetValid();
file_out_stream.write((char *)&fingerprint, sizeof(FingerPrint));
PrepareNodes();
@ -471,6 +473,7 @@ void ExtractionContainers::WriteRestrictions(const std::string& path) const
std::ofstream restrictions_out_stream;
unsigned written_restriction_count = 0;
restrictions_out_stream.open(path.c_str(), std::ios::binary);
const FingerPrint fingerprint = FingerPrint::GetValid();
restrictions_out_stream.write((char *)&fingerprint, sizeof(FingerPrint));
const auto count_position = restrictions_out_stream.tellp();
restrictions_out_stream.write((char *)&written_restriction_count, sizeof(unsigned));

View File

@ -32,7 +32,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "first_and_last_segment_of_way.hpp"
#include "../data_structures/external_memory_node.hpp"
#include "../data_structures/restriction.hpp"
#include "../util/fingerprint.hpp"
#include <stxxl/vector>
#include <unordered_map>
@ -75,7 +74,6 @@ class ExtractionContainers
STXXLRestrictionsVector restrictions_list;
STXXLWayIDStartEndVector way_start_end_id_list;
std::unordered_map<NodeID, NodeID> external_to_internal_node_id_map;
const FingerPrint fingerprint;
ExtractionContainers();

View File

@ -34,18 +34,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
class FingerPrint
{
public:
FingerPrint();
FingerPrint(const FingerPrint &) = delete;
~FingerPrint();
static FingerPrint GetValid();
const boost::uuids::uuid &GetFingerPrint() const;
bool IsMagicNumberOK() const;
bool IsMagicNumberOK(const FingerPrint &other) const;
bool TestGraphUtil(const FingerPrint &other) const;
bool TestPrepare(const FingerPrint &other) const;
bool TestRTree(const FingerPrint &other) const;
bool TestQueryObjects(const FingerPrint &other) const;
private:
const unsigned magic_number;
unsigned magic_number;
char md5_prepare[33];
char md5_tree[33];
char md5_graph[33];

View File

@ -40,35 +40,38 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#cmakedefine MD5GRAPH "${MD5GRAPH}"
#cmakedefine MD5OBJECTS "${MD5OBJECTS}"
FingerPrint::FingerPrint() : magic_number(1297240911)
FingerPrint FingerPrint::GetValid()
{
md5_prepare[32] = md5_tree[32] = md5_graph[32] = md5_objects[32] = '\0';
FingerPrint fingerprint;
boost::uuids::name_generator gen(named_uuid);
fingerprint.magic_number = 1297240911;
fingerprint.md5_prepare[32] = fingerprint.md5_tree[32] = fingerprint.md5_graph[32] = fingerprint.md5_objects[32] = '\0';
boost::uuids::name_generator gen(fingerprint.named_uuid);
std::string temp_string;
std::memcpy(md5_prepare, MD5PREPARE, strlen(MD5PREPARE));
temp_string += md5_prepare;
std::memcpy(md5_tree, MD5RTREE, 32);
temp_string += md5_tree;
std::memcpy(md5_graph, MD5GRAPH, 32);
temp_string += md5_graph;
std::memcpy(md5_objects, MD5OBJECTS, 32);
temp_string += md5_objects;
std::memcpy(fingerprint.md5_prepare, MD5PREPARE, 32);
temp_string += fingerprint.md5_prepare;
std::memcpy(fingerprint.md5_tree, MD5RTREE, 32);
temp_string += fingerprint.md5_tree;
std::memcpy(fingerprint.md5_graph, MD5GRAPH, 32);
temp_string += fingerprint.md5_graph;
std::memcpy(fingerprint.md5_objects, MD5OBJECTS, 32);
temp_string += fingerprint.md5_objects;
named_uuid = gen(temp_string);
has_64_bits = HAS64BITS;
fingerprint.named_uuid = gen(temp_string);
fingerprint.has_64_bits = HAS64BITS;
return fingerprint;
}
FingerPrint::~FingerPrint() {}
const boost::uuids::uuid &FingerPrint::GetFingerPrint() const { return named_uuid; }
bool FingerPrint::IsMagicNumberOK() const { return 1297240911 == magic_number; }
bool FingerPrint::IsMagicNumberOK(const FingerPrint& other) const { return other.magic_number == magic_number; }
bool FingerPrint::TestGraphUtil(const FingerPrint &other) const
{
if (!other.IsMagicNumberOK())
if (!IsMagicNumberOK(other))
{
throw osrm::exception("hsgr input file misses magic number. Check or reprocess the file");
}
@ -77,7 +80,7 @@ bool FingerPrint::TestGraphUtil(const FingerPrint &other) const
bool FingerPrint::TestPrepare(const FingerPrint &other) const
{
if (!other.IsMagicNumberOK())
if (!IsMagicNumberOK(other))
{
throw osrm::exception("osrm input file misses magic number. Check or reprocess the file");
}
@ -86,7 +89,7 @@ bool FingerPrint::TestPrepare(const FingerPrint &other) const
bool FingerPrint::TestRTree(const FingerPrint &other) const
{
if (!other.IsMagicNumberOK())
if (!IsMagicNumberOK(other))
{
throw osrm::exception("r-tree input file misses magic number. Check or reprocess the file");
}
@ -95,7 +98,7 @@ bool FingerPrint::TestRTree(const FingerPrint &other) const
bool FingerPrint::TestQueryObjects(const FingerPrint &other) const
{
if (!other.IsMagicNumberOK())
if (!IsMagicNumberOK(other))
{
throw osrm::exception("missing magic number. Check or reprocess the file");
}

View File

@ -60,11 +60,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
unsigned loadRestrictionsFromFile(std::istream& input_stream,
std::vector<TurnRestriction>& restriction_list)
{
const FingerPrint fingerprint_orig;
const FingerPrint fingerprint_valid = FingerPrint::GetValid();
FingerPrint fingerprint_loaded;
unsigned number_of_usable_restrictions = 0;
input_stream.read((char *)&fingerprint_loaded, sizeof(FingerPrint));
if (!fingerprint_loaded.TestPrepare(fingerprint_orig))
if (!fingerprint_loaded.TestPrepare(fingerprint_valid))
{
SimpleLogger().Write(logWARNING) << ".restrictions was prepared with different build.\n"
"Reprocess to get rid of this warning.";
@ -93,11 +93,11 @@ NodeID loadNodesFromFile(std::istream &input_stream,
std::vector<NodeID> &traffic_light_node_list,
std::vector<QueryNode> &node_array)
{
const FingerPrint fingerprint_orig;
const FingerPrint fingerprint_valid = FingerPrint::GetValid();
FingerPrint fingerprint_loaded;
input_stream.read(reinterpret_cast<char *>(&fingerprint_loaded), sizeof(FingerPrint));
if (!fingerprint_loaded.TestGraphUtil(fingerprint_orig))
if (!fingerprint_loaded.TestPrepare(fingerprint_valid))
{
SimpleLogger().Write(logWARNING) << ".osrm was prepared with different build.\n"
"Reprocess to get rid of this warning.";
@ -187,9 +187,10 @@ unsigned readHSGRFromStream(const boost::filesystem::path &hsgr_file,
boost::filesystem::ifstream hsgr_input_stream(hsgr_file, std::ios::binary);
FingerPrint fingerprint_loaded, fingerprint_orig;
const FingerPrint fingerprint_valid = FingerPrint::GetValid();
FingerPrint fingerprint_loaded;
hsgr_input_stream.read(reinterpret_cast<char *>(&fingerprint_loaded), sizeof(FingerPrint));
if (!fingerprint_loaded.TestGraphUtil(fingerprint_orig))
if (!fingerprint_loaded.TestGraphUtil(fingerprint_valid))
{
SimpleLogger().Write(logWARNING) << ".hsgr was prepared with different build.\n"
"Reprocess to get rid of this warning.";