diff --git a/examples/abitest/module_0/rust/src/lib.rs b/examples/abitest/module_0/rust/src/lib.rs index 6bf989b2c61..d8c1863d7de 100644 --- a/examples/abitest/module_0/rust/src/lib.rs +++ b/examples/abitest/module_0/rust/src/lib.rs @@ -122,7 +122,7 @@ impl FrontendNode { }), misconfigured_roughtime: oak::roughtime::Roughtime::new( &RoughtimeClientConfiguration { - min_overlapping_intervals: 99, + min_overlapping_intervals: Some(99), ..Default::default() }, ), diff --git a/oak/proto/BUILD b/oak/proto/BUILD index c8595859396..6a719e62ab8 100644 --- a/oak/proto/BUILD +++ b/oak/proto/BUILD @@ -27,6 +27,7 @@ package( proto_library( name = "application_proto", srcs = ["application.proto"], + deps = ["@com_google_protobuf//:wrappers_proto"], ) cc_proto_library( diff --git a/oak/proto/application.proto b/oak/proto/application.proto index d8dedd1c50c..b940d56aae1 100644 --- a/oak/proto/application.proto +++ b/oak/proto/application.proto @@ -18,6 +18,8 @@ syntax = "proto3"; package oak.application; +import "google/protobuf/wrappers.proto"; + // An ApplicationConfiguration represents a unit of deployment in Oak. // // A running Oak Application instance is built from a collection of @@ -118,11 +120,11 @@ message RoughtimeClientConfiguration { // will be used if this is empty. repeated RoughtimeServer servers = 1; // Connection parameters; default values will be used if any parameter is - // zero. - uint32 min_overlapping_intervals = 2; - uint32 timeout_seconds = 3; - uint32 server_retries = 4; - uint32 max_radius_microseconds = 5; + // unset. + google.protobuf.UInt32Value min_overlapping_intervals = 2; + google.protobuf.UInt32Value timeout_seconds = 3; + google.protobuf.UInt32Value server_retries = 4; + google.protobuf.UInt32Value max_radius_microseconds = 5; } // Information to identify a particular Roughtime server. diff --git a/oak/proto/roughtime_service.proto b/oak/proto/roughtime_service.proto index ffcce1dc0d6..c4cef8eec5e 100644 --- a/oak/proto/roughtime_service.proto +++ b/oak/proto/roughtime_service.proto @@ -18,9 +18,9 @@ syntax = "proto3"; package oak.roughtime; -message RoughtimeRequest {} +message GetRoughtimeRequest {} -message RoughtimeResponse { +message Roughtime { // Time is UTC and is given as microseconds since the UNIX epoch (00:00:00 UTC // on 1 January 1970). Leap seconds are linearly smeared over a 24-hour // period. That is, the smear extends from UTC noon to noon over 86,401 or @@ -31,5 +31,5 @@ message RoughtimeResponse { // Interface exposed by the Roughtime client pseudo-Node to other nodes over a // pair of Oak Channels. service RoughtimeService { - rpc GetRoughtime(RoughtimeRequest) returns (RoughtimeResponse); + rpc GetRoughtime(GetRoughtimeRequest) returns (Roughtime); } diff --git a/oak/server/rust/oak_runtime/src/node/roughtime.rs b/oak/server/rust/oak_runtime/src/node/roughtime.rs index 38dbb4b9259..f2752f190bf 100644 --- a/oak/server/rust/oak_runtime/src/node/roughtime.rs +++ b/oak/server/rust/oak_runtime/src/node/roughtime.rs @@ -32,7 +32,7 @@ use oak_abi::{ oak::{ application::RoughtimeClientConfiguration, encap::GrpcResponse, - roughtime::{RoughtimeRequest, RoughtimeResponse}, + roughtime::{GetRoughtimeRequest, Roughtime}, }, }, OakStatus, @@ -49,26 +49,18 @@ pub struct RoughtimeClientNode { impl RoughtimeClientNode { /// Creates a new [`RoughtimeClientNode`] instance, but does not start it. pub fn new(node_name: &str, config: &RoughtimeClientConfiguration) -> Self { - let timeout_seconds = if config.timeout_seconds == 0 { - DEFAULT_TIMEOUT_SECONDS - } else { - config.timeout_seconds as u64 - }; - let server_retries = if config.server_retries == 0 { - DEFAULT_SERVER_RETRIES - } else { - config.server_retries as usize - }; - let min_overlapping_intervals = if config.min_overlapping_intervals == 0 { - DEFAULT_MIN_OVERLAPPING_INTERVALS - } else { - config.min_overlapping_intervals as usize - }; - let max_radius_microseconds = if config.max_radius_microseconds == 0 { - DEFAULT_MAX_RADIUS_MICROSECONDS - } else { - config.max_radius_microseconds - }; + let timeout_seconds = config + .timeout_seconds + .map_or(DEFAULT_TIMEOUT_SECONDS, |value| value as u64); + let server_retries = config + .server_retries + .map_or(DEFAULT_SERVER_RETRIES, |value| value as usize); + let min_overlapping_intervals = config + .min_overlapping_intervals + .map_or(DEFAULT_MIN_OVERLAPPING_INTERVALS, |value| value as usize); + let max_radius_microseconds = config + .max_radius_microseconds + .unwrap_or(DEFAULT_MAX_RADIUS_MICROSECONDS); let servers = if config.servers.is_empty() { get_default_servers() } else { @@ -102,11 +94,12 @@ impl RoughtimeClientNode { fn process_invocation(&self, runtime: &RuntimeProxy, invocation: &Invocation) { match invocation.receive_request(runtime) { Ok(request) => { + // TODO(#1113): Generate this code automatically. if request.method_name != "/oak.roughtime.RoughtimeService/GetRoughtime" { let message = format!("Unknown method_name: {}", request.method_name); invocation.send_error(Code::NotFound, &message, runtime); } - if RoughtimeRequest::decode(request.req_msg.as_slice()).is_err() { + if GetRoughtimeRequest::decode(request.req_msg.as_slice()).is_err() { invocation.send_error( Code::InvalidArgument, "Could not parse request.", @@ -122,7 +115,7 @@ impl RoughtimeClientNode { match self.client.get_roughtime() { Ok(time) => { - let response = RoughtimeResponse { + let response = Roughtime { roughtime_usec: time, }; let mut message = Vec::new(); diff --git a/sdk/rust/oak/src/roughtime/mod.rs b/sdk/rust/oak/src/roughtime/mod.rs index c1ab272cbae..274b61386e3 100644 --- a/sdk/rust/oak/src/roughtime/mod.rs +++ b/sdk/rust/oak/src/roughtime/mod.rs @@ -18,7 +18,7 @@ use crate::{ grpc, - proto::oak::roughtime::{RoughtimeRequest, RoughtimeServiceClient}, + proto::oak::roughtime::{GetRoughtimeRequest, RoughtimeServiceClient}, }; use oak_abi::proto::oak::application::{ node_configuration::ConfigType, NodeConfiguration, RoughtimeClientConfiguration, @@ -44,7 +44,7 @@ impl Roughtime { /// Get the current Roughtime value as a Duration since UNIX epoch. /// Note that leap seconds are linearly smeared over 24h. pub fn get_roughtime(&self) -> grpc::Result { - let rsp = self.client.get_roughtime(RoughtimeRequest {})?; + let rsp = self.client.get_roughtime(GetRoughtimeRequest {})?; Ok(std::time::Duration::from_micros(rsp.roughtime_usec)) } }