Skip to content

Commit

Permalink
Address further review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
conradgrobler committed Jun 8, 2020
1 parent dc9e186 commit b39489b
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 34 deletions.
2 changes: 1 addition & 1 deletion examples/abitest/module_0/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl FrontendNode {
}),
misconfigured_roughtime: oak::roughtime::Roughtime::new(
&RoughtimeClientConfiguration {
min_overlapping_intervals: 99,
min_overlapping_intervals: Some(99),
..Default::default()
},
),
Expand Down
1 change: 1 addition & 0 deletions oak/proto/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ package(
proto_library(
name = "application_proto",
srcs = ["application.proto"],
deps = ["@com_google_protobuf//:wrappers_proto"],
)

cc_proto_library(
Expand Down
12 changes: 7 additions & 5 deletions oak/proto/application.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions oak/proto/roughtime_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
39 changes: 16 additions & 23 deletions oak/server/rust/oak_runtime/src/node/roughtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use oak_abi::{
oak::{
application::RoughtimeClientConfiguration,
encap::GrpcResponse,
roughtime::{RoughtimeRequest, RoughtimeResponse},
roughtime::{GetRoughtimeRequest, Roughtime},
},
},
OakStatus,
Expand All @@ -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 {
Expand Down Expand Up @@ -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.",
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions sdk/rust/oak/src/roughtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<std::time::Duration> {
let rsp = self.client.get_roughtime(RoughtimeRequest {})?;
let rsp = self.client.get_roughtime(GetRoughtimeRequest {})?;
Ok(std::time::Duration::from_micros(rsp.roughtime_usec))
}
}

0 comments on commit b39489b

Please sign in to comment.