66
77#include < algorithm>
88#include < iterator>
9- #include < tuple>
10- #include < unordered_set>
9+ #include < string>
1110
1211namespace osrm ::engine
1312{
1413
15- bool SegmentHint::IsValid (const util::Coordinate new_input_coordinates,
14+ bool SegmentHint::IsValid (const util::Coordinate /* new_input_coordinates*/ ,
1615 const datafacade::BaseDataFacade &facade) const
1716{
18- auto is_same_input_coordinate = new_input_coordinates.lon == phantom.input_location .lon &&
19- new_input_coordinates.lat == phantom.input_location .lat ;
20- // FIXME this does not use the number of nodes to validate the phantom because
21- // GetNumberOfNodes()
22- // depends on the graph which is algorithm dependent
23- return is_same_input_coordinate && phantom.IsValid () && facade.GetCheckSum () == data_checksum;
17+ // Hints are deprecated; only validate via dataset checksum to avoid rejecting
18+ // requests that still include hints from older responses.
19+ return facade.GetCheckSum () == data_checksum;
2420}
2521
2622std::string SegmentHint::ToBase64 () const
@@ -50,7 +46,7 @@ SegmentHint SegmentHint::FromBase64(const std::string &base64Hint)
5046
5147bool operator ==(const SegmentHint &lhs, const SegmentHint &rhs)
5248{
53- return std::tie ( lhs.phantom , lhs.data_checksum ) == std::tie ( rhs.phantom , rhs. data_checksum ) ;
49+ return lhs.deprecated_data == rhs. deprecated_data && lhs.data_checksum == rhs.data_checksum ;
5450}
5551
5652bool operator !=(const SegmentHint &lhs, const SegmentHint &rhs) { return !(lhs == rhs); }
@@ -72,7 +68,6 @@ std::string Hint::ToBase64() const
7268
7369Hint Hint::FromBase64 (const std::string &base64Hint)
7470{
75-
7671 BOOST_ASSERT_MSG (base64Hint.size () % ENCODED_SEGMENT_HINT_SIZE == 0 ,
7772 " SegmentHint has invalid size" );
7873
@@ -90,36 +85,15 @@ Hint Hint::FromBase64(const std::string &base64Hint)
9085 return {std::move (res)};
9186}
9287
93- bool Hint::IsValid (const util::Coordinate new_input_coordinates,
88+ bool Hint::IsValid (const util::Coordinate /* new_input_coordinates*/ ,
9489 const datafacade::BaseDataFacade &facade) const
9590{
96- const auto all_valid = std::all_of (segment_hints.begin (),
97- segment_hints.end (),
98- [&](const auto &seg_hint)
99- { return seg_hint.IsValid (new_input_coordinates, facade); });
100- if (!all_valid)
101- {
102- return false ;
103- }
104-
105- // Check hints do not contain duplicate segment pairs
106- // We can't allow duplicates as search heaps do not support it.
107- std::unordered_set<NodeID> forward_segments;
108- std::unordered_set<NodeID> reverse_segments;
109- for (const auto &seg_hint : segment_hints)
110- {
111- const auto forward_res = forward_segments.insert (seg_hint.phantom .forward_segment_id .id );
112- if (!forward_res.second )
113- {
114- return false ;
115- }
116- const auto backward_res = reverse_segments.insert (seg_hint.phantom .reverse_segment_id .id );
117- if (!backward_res.second )
118- {
119- return false ;
120- }
121- }
122- return true ;
91+ // Hints are deprecated; validate each segment hint via checksum-only check.
92+ const auto all_valid =
93+ std::all_of (segment_hints.begin (),
94+ segment_hints.end (),
95+ [&](const auto &seg_hint) { return seg_hint.IsValid ({}, facade); });
96+ return all_valid;
12397}
12498
12599} // namespace osrm::engine
0 commit comments