Fix magic number check for fingerprint
This commit is contained in:
parent
5fc0d284cb
commit
94b749ab00
@ -141,9 +141,9 @@ std::size_t Prepare::WriteContractedGraph(unsigned number_of_edge_based_nodes,
|
|||||||
SimpleLogger().Write() << "Serializing compacted graph of " << contracted_edge_count
|
SimpleLogger().Write() << "Serializing compacted graph of " << contracted_edge_count
|
||||||
<< " edges";
|
<< " edges";
|
||||||
|
|
||||||
FingerPrint fingerprint_orig;
|
const FingerPrint fingerprint = FingerPrint::GetValid();
|
||||||
boost::filesystem::ofstream hsgr_output_stream(config.graph_output_path, std::ios::binary);
|
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]
|
const unsigned max_used_node_id = 1 + [&contracted_edge_list]
|
||||||
{
|
{
|
||||||
unsigned tmp_max = 0;
|
unsigned tmp_max = 0;
|
||||||
|
@ -33,7 +33,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include "../data_structures/query_edge.hpp"
|
#include "../data_structures/query_edge.hpp"
|
||||||
#include "../data_structures/static_graph.hpp"
|
#include "../data_structures/static_graph.hpp"
|
||||||
|
|
||||||
class FingerPrint;
|
|
||||||
struct EdgeBasedNode;
|
struct EdgeBasedNode;
|
||||||
struct lua_State;
|
struct lua_State;
|
||||||
|
|
||||||
|
@ -264,9 +264,10 @@ int main(const int argc, const char *argv[])
|
|||||||
|
|
||||||
boost::filesystem::ifstream hsgr_input_stream(hsgr_path, std::ios::binary);
|
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));
|
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";
|
SimpleLogger().Write(logDEBUG) << "Fingerprint checked out ok";
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include "../util/osrm_exception.hpp"
|
#include "../util/osrm_exception.hpp"
|
||||||
#include "../util/simple_logger.hpp"
|
#include "../util/simple_logger.hpp"
|
||||||
#include "../util/timing_util.hpp"
|
#include "../util/timing_util.hpp"
|
||||||
|
#include "../util/fingerprint.hpp"
|
||||||
|
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
@ -81,6 +82,7 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name,
|
|||||||
{
|
{
|
||||||
std::ofstream file_out_stream;
|
std::ofstream file_out_stream;
|
||||||
file_out_stream.open(output_file_name.c_str(), std::ios::binary);
|
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));
|
file_out_stream.write((char *)&fingerprint, sizeof(FingerPrint));
|
||||||
|
|
||||||
PrepareNodes();
|
PrepareNodes();
|
||||||
@ -471,6 +473,7 @@ void ExtractionContainers::WriteRestrictions(const std::string& path) const
|
|||||||
std::ofstream restrictions_out_stream;
|
std::ofstream restrictions_out_stream;
|
||||||
unsigned written_restriction_count = 0;
|
unsigned written_restriction_count = 0;
|
||||||
restrictions_out_stream.open(path.c_str(), std::ios::binary);
|
restrictions_out_stream.open(path.c_str(), std::ios::binary);
|
||||||
|
const FingerPrint fingerprint = FingerPrint::GetValid();
|
||||||
restrictions_out_stream.write((char *)&fingerprint, sizeof(FingerPrint));
|
restrictions_out_stream.write((char *)&fingerprint, sizeof(FingerPrint));
|
||||||
const auto count_position = restrictions_out_stream.tellp();
|
const auto count_position = restrictions_out_stream.tellp();
|
||||||
restrictions_out_stream.write((char *)&written_restriction_count, sizeof(unsigned));
|
restrictions_out_stream.write((char *)&written_restriction_count, sizeof(unsigned));
|
||||||
|
@ -32,7 +32,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include "first_and_last_segment_of_way.hpp"
|
#include "first_and_last_segment_of_way.hpp"
|
||||||
#include "../data_structures/external_memory_node.hpp"
|
#include "../data_structures/external_memory_node.hpp"
|
||||||
#include "../data_structures/restriction.hpp"
|
#include "../data_structures/restriction.hpp"
|
||||||
#include "../util/fingerprint.hpp"
|
|
||||||
|
|
||||||
#include <stxxl/vector>
|
#include <stxxl/vector>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
@ -75,7 +74,6 @@ class ExtractionContainers
|
|||||||
STXXLRestrictionsVector restrictions_list;
|
STXXLRestrictionsVector restrictions_list;
|
||||||
STXXLWayIDStartEndVector way_start_end_id_list;
|
STXXLWayIDStartEndVector way_start_end_id_list;
|
||||||
std::unordered_map<NodeID, NodeID> external_to_internal_node_id_map;
|
std::unordered_map<NodeID, NodeID> external_to_internal_node_id_map;
|
||||||
const FingerPrint fingerprint;
|
|
||||||
|
|
||||||
ExtractionContainers();
|
ExtractionContainers();
|
||||||
|
|
||||||
|
@ -34,18 +34,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
class FingerPrint
|
class FingerPrint
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FingerPrint();
|
static FingerPrint GetValid();
|
||||||
FingerPrint(const FingerPrint &) = delete;
|
|
||||||
~FingerPrint();
|
|
||||||
const boost::uuids::uuid &GetFingerPrint() const;
|
const boost::uuids::uuid &GetFingerPrint() const;
|
||||||
bool IsMagicNumberOK() const;
|
bool IsMagicNumberOK(const FingerPrint &other) const;
|
||||||
bool TestGraphUtil(const FingerPrint &other) const;
|
bool TestGraphUtil(const FingerPrint &other) const;
|
||||||
bool TestPrepare(const FingerPrint &other) const;
|
bool TestPrepare(const FingerPrint &other) const;
|
||||||
bool TestRTree(const FingerPrint &other) const;
|
bool TestRTree(const FingerPrint &other) const;
|
||||||
bool TestQueryObjects(const FingerPrint &other) const;
|
bool TestQueryObjects(const FingerPrint &other) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const unsigned magic_number;
|
unsigned magic_number;
|
||||||
char md5_prepare[33];
|
char md5_prepare[33];
|
||||||
char md5_tree[33];
|
char md5_tree[33];
|
||||||
char md5_graph[33];
|
char md5_graph[33];
|
||||||
|
@ -40,35 +40,38 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#cmakedefine MD5GRAPH "${MD5GRAPH}"
|
#cmakedefine MD5GRAPH "${MD5GRAPH}"
|
||||||
#cmakedefine MD5OBJECTS "${MD5OBJECTS}"
|
#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::string temp_string;
|
||||||
|
|
||||||
std::memcpy(md5_prepare, MD5PREPARE, strlen(MD5PREPARE));
|
std::memcpy(fingerprint.md5_prepare, MD5PREPARE, 32);
|
||||||
temp_string += md5_prepare;
|
temp_string += fingerprint.md5_prepare;
|
||||||
std::memcpy(md5_tree, MD5RTREE, 32);
|
std::memcpy(fingerprint.md5_tree, MD5RTREE, 32);
|
||||||
temp_string += md5_tree;
|
temp_string += fingerprint.md5_tree;
|
||||||
std::memcpy(md5_graph, MD5GRAPH, 32);
|
std::memcpy(fingerprint.md5_graph, MD5GRAPH, 32);
|
||||||
temp_string += md5_graph;
|
temp_string += fingerprint.md5_graph;
|
||||||
std::memcpy(md5_objects, MD5OBJECTS, 32);
|
std::memcpy(fingerprint.md5_objects, MD5OBJECTS, 32);
|
||||||
temp_string += md5_objects;
|
temp_string += fingerprint.md5_objects;
|
||||||
|
|
||||||
named_uuid = gen(temp_string);
|
fingerprint.named_uuid = gen(temp_string);
|
||||||
has_64_bits = HAS64BITS;
|
fingerprint.has_64_bits = HAS64BITS;
|
||||||
|
|
||||||
|
return fingerprint;
|
||||||
}
|
}
|
||||||
|
|
||||||
FingerPrint::~FingerPrint() {}
|
|
||||||
|
|
||||||
const boost::uuids::uuid &FingerPrint::GetFingerPrint() const { return named_uuid; }
|
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
|
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");
|
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
|
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");
|
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
|
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");
|
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
|
bool FingerPrint::TestQueryObjects(const FingerPrint &other) const
|
||||||
{
|
{
|
||||||
if (!other.IsMagicNumberOK())
|
if (!IsMagicNumberOK(other))
|
||||||
{
|
{
|
||||||
throw osrm::exception("missing magic number. Check or reprocess the file");
|
throw osrm::exception("missing magic number. Check or reprocess the file");
|
||||||
}
|
}
|
||||||
|
@ -60,11 +60,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
unsigned loadRestrictionsFromFile(std::istream& input_stream,
|
unsigned loadRestrictionsFromFile(std::istream& input_stream,
|
||||||
std::vector<TurnRestriction>& restriction_list)
|
std::vector<TurnRestriction>& restriction_list)
|
||||||
{
|
{
|
||||||
const FingerPrint fingerprint_orig;
|
const FingerPrint fingerprint_valid = FingerPrint::GetValid();
|
||||||
FingerPrint fingerprint_loaded;
|
FingerPrint fingerprint_loaded;
|
||||||
unsigned number_of_usable_restrictions = 0;
|
unsigned number_of_usable_restrictions = 0;
|
||||||
input_stream.read((char *)&fingerprint_loaded, sizeof(FingerPrint));
|
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"
|
SimpleLogger().Write(logWARNING) << ".restrictions was prepared with different build.\n"
|
||||||
"Reprocess to get rid of this warning.";
|
"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<NodeID> &traffic_light_node_list,
|
||||||
std::vector<QueryNode> &node_array)
|
std::vector<QueryNode> &node_array)
|
||||||
{
|
{
|
||||||
const FingerPrint fingerprint_orig;
|
const FingerPrint fingerprint_valid = FingerPrint::GetValid();
|
||||||
FingerPrint fingerprint_loaded;
|
FingerPrint fingerprint_loaded;
|
||||||
input_stream.read(reinterpret_cast<char *>(&fingerprint_loaded), sizeof(FingerPrint));
|
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"
|
SimpleLogger().Write(logWARNING) << ".osrm was prepared with different build.\n"
|
||||||
"Reprocess to get rid of this warning.";
|
"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);
|
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));
|
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"
|
SimpleLogger().Write(logWARNING) << ".hsgr was prepared with different build.\n"
|
||||||
"Reprocess to get rid of this warning.";
|
"Reprocess to get rid of this warning.";
|
||||||
|
Loading…
Reference in New Issue
Block a user