Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow a host to have a path #967

Merged
merged 3 commits into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Recommendation on how to cite in publications (#943)
- Store distance matrices (#956)
- Default radius of 35km for OSRM snapping (#922)
- Support for URL path in host (#966)

### Changed

Expand Down
1 change: 1 addition & 0 deletions scripts/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ if type clang-format-14 2> /dev/null ; then
elif type clang-format 2> /dev/null ; then
# Clang format found, but need to check version
CLANG_FORMAT=clang-format
V=$(clang-format --version)
jcoupey marked this conversation as resolved.
Show resolved Hide resolved
if [[ $V != *14.0* ]] ; then
echo "clang-format is not 14.0 (returned ${V})"
exit 1
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int main(int argc, char** argv) {
.set_tab_expansion()
.add_options("Solving")
("a,host",
"host for the routing profile",
"host for the routing profile, optionally with a URL path, e.g 'routing.openstreetmap.de/routed-car'",
jcoupey marked this conversation as resolved.
Show resolved Hide resolved
cxxopts::value<std::vector<std::string>>(host_args)->default_value({vroom::DEFAULT_PROFILE + ":0.0.0.0"}))
("c,choose-eta",
"choose ETA for custom routes and report violations",
Expand Down
2 changes: 1 addition & 1 deletion src/routing/ors_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ std::string OrsWrapper::build_query(const std::vector<Location>& locations,
body += "}";

// Building query for ORS
std::string query = "POST /ors/v2/" + service + "/" + profile;
std::string query = "POST /" + _server.path + "ors/v2/" + service + "/" + profile;

query += " HTTP/1.0\r\n";
query += "Accept: */*\r\n";
Expand Down
3 changes: 2 additions & 1 deletion src/routing/osrm_routed_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ std::string
OsrmRoutedWrapper::build_query(const std::vector<Location>& locations,
const std::string& service) const {
// Building query for osrm-routed
std::string query = "GET /" + service;
std::string query = "GET /" + _server.path + service;

query += "/v1/" + profile + "/";

// Build query part for snapping restriction.
Expand Down
4 changes: 2 additions & 2 deletions src/routing/valhalla_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ValhallaWrapper::ValhallaWrapper(const std::string& profile,
std::string ValhallaWrapper::get_matrix_query(
const std::vector<Location>& locations) const {
// Building matrix query for Valhalla.
std::string query = "GET /" + _matrix_service + "?json=";
std::string query = "GET /" + _server.path + _matrix_service + "?json=";

// List locations.
std::string all_locations;
Expand All @@ -56,7 +56,7 @@ std::string ValhallaWrapper::get_matrix_query(
std::string
ValhallaWrapper::get_route_query(const std::vector<Location>& locations) const {
// Building matrix query for Valhalla.
std::string query = "GET /" + _route_service + "?json={\"locations\":[";
std::string query = "GET /" + _server.path + _route_service + "?json={\"locations\":[";

for (auto const& location : locations) {
query += "{\"lon\":" + std::to_string(location.lon()) + "," +
Expand Down
17 changes: 17 additions & 0 deletions src/structures/cl_args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ void update_host(Servers& servers, const std::string& value) {
// Determine profile and host from a "car:0.0.0.0"-like value.
std::string profile = DEFAULT_PROFILE;
std::string host;
std::string path = "";

auto index = value.find(':');
if (index == std::string::npos) {
Expand All @@ -26,13 +27,29 @@ void update_host(Servers& servers, const std::string& value) {
host = value.substr(index + 1);
}

if (!host.empty()) {
// remove any trailing slash
if (host.back() == '/') {
host.pop_back();
}

// pull out a path if any and append a trailing slash for query building
index = host.find('/');
if (index != std::string::npos) {
path = host.substr(index + 1) + "/";
host = host.substr(0, index);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicking: this is making a copy while we could simply host.erase(index).

}
}

auto existing_profile = servers.find(profile);
if (existing_profile != servers.end()) {
existing_profile->second.host = host;
existing_profile->second.path = path;
} else {
auto add_result = servers.emplace(profile, Server());
assert(add_result.second);
add_result.first->second.host = host;
add_result.first->second.path = path;
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/structures/typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@ enum class ROUTER { OSRM, LIBOSRM, ORS, VALHALLA };
struct Server {
std::string host;
std::string port;
std::string path;

Server() : host("0.0.0.0"), port("5000") {
Server() : host("0.0.0.0"), port("5000"), path("") {
}

Server(std::string host, std::string port)
: host(std::move(host)), port(std::move(port)) {
: host(std::move(host)), port(std::move(port)), path("") {
}
};

Expand Down