-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Trusted Information Retrieval example (#1049)
This change adds a Trusted Information Retrieval example. Fixes #1024
- Loading branch information
Showing
18 changed files
with
891 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# | ||
# Copyright 2020 The Project Oak Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
load("@rules_cc//cc:defs.bzl", "cc_binary") | ||
|
||
package( | ||
licenses = ["notice"], | ||
) | ||
|
||
cc_binary( | ||
name = "client", | ||
srcs = ["trusted_information_retrieval.cc"], | ||
deps = [ | ||
"//examples/trusted_information_retrieval/proto:trusted_information_retrieval_cc_grpc", | ||
"//oak/client:application_client", | ||
"@com_github_google_glog//:glog", | ||
"@com_github_grpc_grpc//:grpc++", | ||
"@com_google_absl//absl/flags:flag", | ||
"@com_google_absl//absl/flags:parse", | ||
"@com_google_absl//absl/strings", | ||
"@com_google_absl//absl/types:optional", | ||
], | ||
) |
87 changes: 87 additions & 0 deletions
87
examples/trusted_information_retrieval/client/trusted_information_retrieval.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright 2020 The Project Oak Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "absl/flags/flag.h" | ||
#include "absl/flags/parse.h" | ||
#include "absl/strings/numbers.h" | ||
#include "absl/strings/str_split.h" | ||
#include "absl/types/optional.h" | ||
#include "examples/trusted_information_retrieval/proto/trusted_information_retrieval.grpc.pb.h" | ||
#include "examples/trusted_information_retrieval/proto/trusted_information_retrieval.pb.h" | ||
#include "glog/logging.h" | ||
#include "include/grpcpp/grpcpp.h" | ||
#include "oak/client/application_client.h" | ||
|
||
ABSL_FLAG(std::string, address, "localhost:8080", "Address of the Oak application to connect to"); | ||
ABSL_FLAG(std::vector<std::string>, location, std::vector<std::string>{}, | ||
"Requested location (latitude and longitude separated by comma)"); | ||
ABSL_FLAG(std::string, ca_cert, "", "Path to the PEM-encoded CA root certificate"); | ||
|
||
using ::oak::examples::trusted_information_retrieval::ListPointsOfInterestRequest; | ||
using ::oak::examples::trusted_information_retrieval::ListPointsOfInterestResponse; | ||
using ::oak::examples::trusted_information_retrieval::Location; | ||
using ::oak::examples::trusted_information_retrieval::PointOfInterest; | ||
using ::oak::examples::trusted_information_retrieval::TrustedInformationRetrieval; | ||
|
||
void get_nearest_point_of_interest(TrustedInformationRetrieval::Stub* stub, float latitude, | ||
float longitude) { | ||
grpc::ClientContext context; | ||
LOG(INFO) << "Getting nearest point of interest:"; | ||
ListPointsOfInterestRequest request; | ||
Location* location = request.mutable_location(); | ||
location->set_latitude(latitude); | ||
location->set_longitude(longitude); | ||
ListPointsOfInterestResponse response; | ||
grpc::Status status = stub->ListPointsOfInterest(&context, request, &response); | ||
if (!status.ok()) { | ||
LOG(ERROR) << "Could not get nearest point of interest: " << status.error_code() << ": " | ||
<< status.error_message(); | ||
} | ||
LOG(INFO) << "Response:"; | ||
LOG(INFO) << " - name: " << response.point_of_interest().name(); | ||
LOG(INFO) << " - latitude: " << response.point_of_interest().location().latitude(); | ||
LOG(INFO) << " - longitude: " << response.point_of_interest().location().longitude(); | ||
} | ||
|
||
int main(int argc, char** argv) { | ||
absl::ParseCommandLine(argc, argv); | ||
|
||
std::string address = absl::GetFlag(FLAGS_address); | ||
std::string ca_cert = oak::ApplicationClient::LoadRootCert(absl::GetFlag(FLAGS_ca_cert)); | ||
LOG(INFO) << "Connecting to Oak Application: " << address; | ||
|
||
auto stub = TrustedInformationRetrieval::NewStub( | ||
oak::ApplicationClient::CreateTlsChannel(address, ca_cert)); | ||
|
||
// Parse arguments. | ||
auto location = absl::GetFlag(FLAGS_location); | ||
if (location.size() != 2) { | ||
LOG(FATAL) << "Incorrect number of coordinates: " << location.size() << " (expected 2)"; | ||
} | ||
float latitude; | ||
if (!absl::SimpleAtof(location.front(), &latitude) && latitude >= -90.0 && latitude <= 90.0) { | ||
LOG(FATAL) << "Latitude must be a valid floating point number >=-90 and <= 90."; | ||
} | ||
float longitude; | ||
if (!absl::SimpleAtof(location.back(), &longitude) && longitude >= -180.0 && longitude <= 180.0) { | ||
LOG(FATAL) << "Longitude must be a valid floating point number >= -180 and <= 180."; | ||
} | ||
|
||
// Get nearest point of interest from the server. | ||
get_nearest_point_of_interest(stub.get(), latitude, longitude); | ||
|
||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# | ||
# Copyright 2020 The Project Oak Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
load("//oak/common:app_config.bzl", "serialized_config") | ||
|
||
package( | ||
default_visibility = ["//examples/trusted_information_retrieval:__subpackages__"], | ||
licenses = ["notice"], | ||
) | ||
|
||
exports_files(srcs = glob(["*.textproto"])) | ||
|
||
serialized_config( | ||
name = "config", | ||
modules = { | ||
"app": "//:examples/target/wasm32-unknown-unknown/release/trusted_information_retrieval.wasm", | ||
}, | ||
textproto = ":config.textproto", | ||
) |
7 changes: 7 additions & 0 deletions
7
examples/trusted_information_retrieval/config/config.textproto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
initial_node_configuration: { | ||
name: "main" | ||
wasm_config: { | ||
wasm_module_name: "app" | ||
wasm_entrypoint_name: "grpc_oak_main" | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
examples/trusted_information_retrieval/module/rust/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
[package] | ||
name = "trusted_information_retrieval" | ||
version = "0.1.0" | ||
authors = ["Ivan Petrov <[email protected]>"] | ||
edition = "2018" | ||
license = "Apache-2.0" | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
itertools = "*" | ||
log = "*" | ||
oak = "=0.1.0" | ||
oak_abi = "=0.1.0" | ||
prost = "*" | ||
serde = "*" | ||
quick-xml = { version = "*", features = ["serialize"] } | ||
|
||
[dev-dependencies] | ||
assert_matches = "*" | ||
oak_abi = "=0.1.0" | ||
oak_runtime = "=0.1.0" | ||
oak_tests = "=0.1.0" | ||
maplit = "*" | ||
simple_logger = "*" | ||
|
||
[build-dependencies] | ||
oak_utils = "*" |
22 changes: 22 additions & 0 deletions
22
examples/trusted_information_retrieval/module/rust/build.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// Copyright 2020 The Project Oak Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
fn main() { | ||
oak_utils::compile_protos( | ||
&["../../proto/trusted_information_retrieval.proto"], | ||
&["../../proto"], | ||
); | ||
} |
Oops, something went wrong.