httpsdate_config/
httpsdate_config_rust_config_lib_source.rsuse fidl::unpersist;
use fidl_cf_sc_internal_httpsdateconfig::Config as FidlConfig;
use fuchsia_inspect::Node;
use fuchsia_runtime::{take_startup_handle, HandleInfo, HandleType};
#[derive(Debug)]
pub struct Config {
pub first_rtt_time_factor: u16,
pub https_timeout_sec: u8,
pub max_attempts_urgency_high: u32,
pub max_attempts_urgency_low: u32,
pub max_attempts_urgency_medium: u32,
pub num_polls_urgency_high: u32,
pub num_polls_urgency_low: u32,
pub num_polls_urgency_medium: u32,
pub standard_deviation_bound_percentage: u8,
pub time_source_endpoint_url: String,
pub use_pull_api: bool,
}
impl Config {
pub fn take_from_startup_handle() -> Self {
let config_vmo: zx::Vmo =
take_startup_handle(HandleInfo::new(HandleType::ComponentConfigVmo, 0))
.expect("Config VMO handle must be provided and cannot already have been taken.")
.into();
let config_size =
config_vmo.get_content_size().expect("must be able to read config vmo content size");
assert_ne!(config_size, 0, "config vmo must be non-empty");
let config_bytes =
config_vmo.read_to_vec(0, config_size).expect("must be able to read config vmo");
let checksum_length = u16::from_le_bytes([config_bytes[0], config_bytes[1]]) as usize;
let fidl_start = 2 + checksum_length;
let observed_checksum = &config_bytes[2..fidl_start];
let expected_checksum = vec![
0x47, 0x9d, 0xa0, 0xef, 0x6a, 0xf6, 0xb8, 0xac, 0x91, 0xd9, 0x20, 0xb6, 0xe9, 0x78,
0x94, 0xb6, 0x0a, 0xbf, 0x2c, 0x4f, 0x88, 0x4e, 0xa1, 0xdc, 0x15, 0x86, 0xae, 0x9e,
0x97, 0x2f, 0x1c, 0x6f,
];
assert_eq!(
observed_checksum, expected_checksum,
"checksum from config VMO does not match expected checksum"
);
let fidl_config: FidlConfig = unpersist(&config_bytes[fidl_start..])
.expect("must be able to parse bytes as config FIDL");
Self {
first_rtt_time_factor: fidl_config.first_rtt_time_factor,
https_timeout_sec: fidl_config.https_timeout_sec,
max_attempts_urgency_high: fidl_config.max_attempts_urgency_high,
max_attempts_urgency_low: fidl_config.max_attempts_urgency_low,
max_attempts_urgency_medium: fidl_config.max_attempts_urgency_medium,
num_polls_urgency_high: fidl_config.num_polls_urgency_high,
num_polls_urgency_low: fidl_config.num_polls_urgency_low,
num_polls_urgency_medium: fidl_config.num_polls_urgency_medium,
standard_deviation_bound_percentage: fidl_config.standard_deviation_bound_percentage,
time_source_endpoint_url: fidl_config.time_source_endpoint_url,
use_pull_api: fidl_config.use_pull_api,
}
}
pub fn record_inspect(&self, inspector_node: &Node) {
inspector_node.record_uint("first_rtt_time_factor", self.first_rtt_time_factor as u64);
inspector_node.record_uint("https_timeout_sec", self.https_timeout_sec as u64);
inspector_node
.record_uint("max_attempts_urgency_high", self.max_attempts_urgency_high as u64);
inspector_node
.record_uint("max_attempts_urgency_low", self.max_attempts_urgency_low as u64);
inspector_node
.record_uint("max_attempts_urgency_medium", self.max_attempts_urgency_medium as u64);
inspector_node.record_uint("num_polls_urgency_high", self.num_polls_urgency_high as u64);
inspector_node.record_uint("num_polls_urgency_low", self.num_polls_urgency_low as u64);
inspector_node
.record_uint("num_polls_urgency_medium", self.num_polls_urgency_medium as u64);
inspector_node.record_uint(
"standard_deviation_bound_percentage",
self.standard_deviation_bound_percentage as u64,
);
inspector_node.record_string("time_source_endpoint_url", &self.time_source_endpoint_url);
inspector_node.record_bool("use_pull_api", self.use_pull_api);
}
}