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

Move generated protos into oak_abi #834

Merged
merged 3 commits into from
Apr 9, 2020
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
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 16 additions & 3 deletions docs/abi.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ specific entrypoints which form the **Oak ABI**:

These host functions provided by the Oak TCB revolve around the creation of
other Nodes, and the use of [channels](concepts.md#channels) for inter-node
communication. To communicate with the outside world beyond the Oak system, a
Node may also create and communicate with
[pseudo-Nodes](concepts.md#pseudo-nodes).
communication.

To communicate with the outside world beyond the Oak system, a Node may also
create and communicate with [pseudo-Nodes](concepts.md#pseudo-nodes). The
messages exchanged with pseudo-Nodes are encoded as serialized protocol buffer
messages.

Note also that the Oak ABI interactions are quite low-level; for example, they
involve manual management of linear memory. Oak Applications will typically use
Expand Down Expand Up @@ -197,3 +200,13 @@ If creating the specified node would violate
- arg 0: Destination buffer
- arg 1: Destination buffer size in bytes
- return 0: Status of operation

## Protocol Buffer Messages

The host functions described in the previous section allow opaque blobs of data
to be exchanged (along with handles to other channels). When communicating with
the pseudo-Nodes provided by the Oak system, these opaque blobs of data are
defined to take the form of serialized protocol buffer messages. These include:

- [Structured logging messages](../oak/proto/log.proto).
- [Encapsulated gRPC requests and responses](../oak/proto/grpc_encap.proto).
6 changes: 3 additions & 3 deletions examples/abitest/module_0/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1182,8 +1182,8 @@ impl FrontendNode {
.expect("could not write to channel");

let mut bytes = Vec::new();
oak::proto::oak::log::LogMessage {
level: oak::proto::oak::log::Level::Info as i32,
oak_abi::proto::oak::log::LogMessage {
level: oak_abi::proto::oak::log::Level::Info as i32,
file: "abitest".to_string(),
line: 1988,
message: "Wellformed message sent direct to logging channel!".to_string(),
Expand Down Expand Up @@ -1502,7 +1502,7 @@ impl FrontendNode {
}

// Helper for storage error conversion.
fn from_proto(status: oak::proto::google::rpc::Status) -> Box<dyn std::error::Error> {
fn from_proto(status: oak::grpc::Status) -> Box<dyn std::error::Error> {
Box::new(std::io::Error::new(
std::io::ErrorKind::Other,
format!("status code {} message '{}'", status.code, status.message),
Expand Down
9 changes: 4 additions & 5 deletions oak/proto/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,16 @@ cc_proto_library(
)

proto_library(
name = "storage_channel_proto",
srcs = ["storage_channel.proto"],
name = "storage_service_proto",
srcs = ["storage_service.proto"],
deps = [
":label_proto",
"//third_party/google/rpc:status_proto",
],
)

cc_proto_library(
name = "storage_channel_cc_proto",
deps = [":storage_channel_proto"],
name = "storage_service_cc_proto",
deps = [":storage_service_proto"],
)

proto_library(
Expand Down
2 changes: 1 addition & 1 deletion oak/proto/grpc_encap.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

syntax = "proto3";

package oak;
package oak.encap;

import "google/protobuf/any.proto";
import "third_party/google/rpc/status.proto";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

syntax = "proto3";

package oak;
package oak.storage;

import "oak/proto/label.proto";

Expand Down Expand Up @@ -86,7 +86,7 @@ message StorageChannelRollbackResponse {

// Interface exposed by the Storage Node to other nodes over a pair of Oak Channels.
// Methods in this interface map 1:1 with those in storage.proto.
service StorageNode {
service StorageService {
rpc Read(StorageChannelReadRequest) returns (StorageChannelReadResponse);
rpc Write(StorageChannelWriteRequest) returns (StorageChannelWriteResponse);
rpc Delete(StorageChannelDeleteRequest) returns (StorageChannelDeleteResponse);
Expand Down
6 changes: 3 additions & 3 deletions oak/server/grpc_client_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bool GrpcClientNode::HandleInvocation(Handle invocation_handle) {
OAK_LOG(ERROR) << "Unexpectedly received channel handles in request channel";
return false;
}
GrpcRequest grpc_req;
oak::encap::GrpcRequest grpc_req;
grpc_req.ParseFromString(std::string(req_result.msg->data.data(), req_result.msg->data.size()));
std::string method_name = grpc_req.method_name();
const grpc::string& req_data = grpc_req.req_msg().value();
Expand Down Expand Up @@ -115,7 +115,7 @@ bool GrpcClientNode::HandleInvocation(Handle invocation_handle) {
}

// Build an encapsulation of the gRPC response and put it in an Oak Message.
oak::GrpcResponse grpc_rsp;
oak::encap::GrpcResponse grpc_rsp;
grpc_rsp.set_last(false);
google::protobuf::Any* any = new google::protobuf::Any();
any->set_value(rsp_data.data(), rsp_data.size());
Expand All @@ -140,7 +140,7 @@ bool GrpcClientNode::HandleInvocation(Handle invocation_handle) {
}
if (!status.ok()) {
// Final status includes an error, so pass it back on the response channel.
oak::GrpcResponse grpc_rsp;
oak::encap::GrpcResponse grpc_rsp;
grpc_rsp.set_last(true);
grpc_rsp.mutable_status()->set_code(status.error_code());
grpc_rsp.mutable_status()->set_message(status.error_message());
Expand Down
4 changes: 2 additions & 2 deletions oak/server/module_invocation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void ModuleInvocation::ProcessRequest(bool ok) {
}

// Build an encapsulation of the gRPC request invocation and put it in a Message.
oak::GrpcRequest grpc_request;
oak::encap::GrpcRequest grpc_request;
grpc_request.set_method_name(context_.method());
google::protobuf::Any* any = new google::protobuf::Any();
any->set_value(request_msg->data.data(), request_msg->data.size());
Expand Down Expand Up @@ -200,7 +200,7 @@ void ModuleInvocation::BlockingSendResponse() {
OAK_LOG(INFO) << "invocation#" << stream_id_
<< " SendResponse: Read encapsulated message of size "
<< rsp_result.msg->data.size() << " from gRPC output channel";
oak::GrpcResponse grpc_response;
oak::encap::GrpcResponse grpc_response;
if (!grpc_response.ParseFromString(
std::string(rsp_result.msg->data.data(), rsp_result.msg->data.size()))) {
OAK_LOG(ERROR) << "invocation#" << stream_id_
Expand Down
4 changes: 3 additions & 1 deletion oak/server/rust/oak_abi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ edition = "2018"
license = "Apache-2.0"

[dependencies]
prost = "*"
hashbrown = "*"
log = "*"
prost = "*"
prost-types = "*"

[build-dependencies]
oak_utils = "*"
Expand Down
8 changes: 6 additions & 2 deletions oak/server/rust/oak_abi/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
fn main() {
oak_utils::compile_protos(
&[
"../../../../oak/proto/oak_abi.proto",
"../../../../oak/proto/grpc_encap.proto",
"../../../../oak/proto/label.proto",
"../../../../oak/proto/log.proto",
"../../../../oak/proto/oak_abi.proto",
"../../../../third_party/google/rpc/code.proto",
"../../../../third_party/google/rpc/status.proto",
],
&["../../../../oak/proto"],
&["../../../.."],
);
}
41 changes: 41 additions & 0 deletions oak/server/rust/oak_abi/src/grpc/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Copyright 2019 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.
//

use crate::proto::oak::encap::GrpcRequest;
use log::warn;

/// Encapsulate a protocol buffer message in a GrpcRequest wrapper using the
/// given method name.
pub fn encap_request<T: prost::Message>(
req: &T,
req_type_url: Option<&str>,
method_name: &str,
) -> Option<GrpcRequest> {
// Put the request in a GrpcRequest wrapper and serialize it.
let mut grpc_req = GrpcRequest::default();
grpc_req.method_name = method_name.to_string();
let mut any = prost_types::Any::default();
if let Err(e) = req.encode(&mut any.value) {
warn!("failed to serialize gRPC request: {}", e);
return None;
};
if let Some(type_url) = req_type_url {
any.type_url = type_url.to_string();
}
grpc_req.req_msg = Some(any);
grpc_req.last = true;
Some(grpc_req)
}
4 changes: 2 additions & 2 deletions oak/server/rust/oak_abi/src/label/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
use hashbrown::HashSet;
use prost::Message;

pub use crate::proto::label::*;
pub use crate::proto::oak::label::*;

#[cfg(test)]
mod tests;

/// Add helper methods to the `Label` struct that is auto-generated from
/// the protobuf message definition.
impl crate::proto::label::Label {
impl crate::proto::oak::label::Label {
/// Convert a label to bytes.
pub fn serialize(&self) -> Vec<u8> {
let mut bytes = Vec::new();
Expand Down
6 changes: 4 additions & 2 deletions oak/server/rust/oak_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

//! Type, constant and Wasm host function definitions for the Oak application
//! binary interface (ABI).
mod proto;
pub use proto::*;

pub mod grpc;
pub mod label;
pub mod proto;

pub use proto::oak::{ChannelReadStatus, OakStatus};

/// Handle used to identify read or write channel halves.
///
Expand Down
22 changes: 19 additions & 3 deletions oak/server/rust/oak_abi/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,24 @@
// limitations under the License.
//

include!(concat!(env!("OUT_DIR"), "/oak_abi.rs"));
pub mod google {
pub mod rpc {
include!(concat!(env!("OUT_DIR"), "/google.rpc.rs"));
}
}

pub mod oak {
include!(concat!(env!("OUT_DIR"), "/oak_abi.rs"));

pub mod label {
include!(concat!(env!("OUT_DIR"), "/oak.label.rs"));
}

pub mod encap {
include!(concat!(env!("OUT_DIR"), "/oak.encap.rs"));
}

pub mod label {
include!(concat!(env!("OUT_DIR"), "/oak.label.rs"));
pub mod log {
include!(concat!(env!("OUT_DIR"), "/oak.log.rs"));
}
}
1 change: 0 additions & 1 deletion oak/server/rust/oak_runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ http = "*"
hyper = "*"
itertools = "*"
log = { version = "*" }
oak = "0.1.0"
oak_abi = "=0.1.0"
prost = "*"
prost-types = "*"
Expand Down
5 changes: 1 addition & 4 deletions oak/server/rust/oak_runtime/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

fn main() {
oak_utils::compile_protos(
&[
"../../../../oak/proto/application.proto",
"../../../../oak/proto/log.proto",
],
&["../../../../oak/proto/application.proto"],
&["../../../../oak/proto"],
);
}
3 changes: 2 additions & 1 deletion oak/server/rust/oak_runtime/src/node/grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ use std::{
thread::{self, JoinHandle},
};

use oak::grpc::{encap_request, GrpcRequest};
use oak_abi::grpc::encap_request;
use oak_abi::proto::oak::encap::GrpcRequest;
use oak_abi::{label::Label, ChannelReadStatus, OakStatus};

use crate::{pretty_name_for_thread, runtime::RuntimeProxy, Handle};
Expand Down
2 changes: 1 addition & 1 deletion oak/server/rust/oak_runtime/src/node/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ use oak_abi::OakStatus;
use std::thread::{self, JoinHandle};

use crate::pretty_name_for_thread;
use crate::proto::log::{Level, LogMessage};
use crate::runtime::Handle;
use crate::runtime::RuntimeProxy;
use oak_abi::proto::oak::log::{Level, LogMessage};
use prost::Message;

pub struct LogNode {
Expand Down
4 changes: 0 additions & 4 deletions oak/server/rust/oak_runtime/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,3 @@
//

include!(concat!(env!("OUT_DIR"), "/oak.rs"));

pub mod log {
include!(concat!(env!("OUT_DIR"), "/oak.log.rs"));
}
3 changes: 1 addition & 2 deletions oak/server/storage/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ cc_library(
"//oak/common:handles",
"//oak/common:logging",
"//oak/proto:grpc_encap_cc_proto",
"//oak/proto:storage_channel_cc_proto",
"//oak/proto:storage_service_cc_proto",
"//oak/server:invocation",
"//oak/server:node_thread",
"//third_party/asylo:statusor",
Expand All @@ -68,7 +68,6 @@ cc_library(
deps = [
"//oak/common:logging",
"//oak/proto:storage_cc_grpc",
"//oak/proto:storage_channel_cc_proto",
"//third_party/asylo:status_macros",
"//third_party/asylo:statusor",
"@boringssl//:crypto",
Expand Down
Loading