From e53ba76a662c47fa77ee11561efcfb38a6162fff Mon Sep 17 00:00:00 2001 From: liyaxing Date: Thu, 11 May 2023 17:27:21 +0800 Subject: [PATCH] Update the comments of ood-control --- .../cyfs-util/src/util/system_info.rs | 14 +++++------ .../ood-control/src/app_bind_manager.rs | 16 ++++++------- src/service/ood-control/src/bind.rs | 12 +++++----- src/service/ood-control/src/controller.rs | 14 +++++------ src/service/ood-control/src/device_info.rs | 6 ++--- src/service/ood-control/src/interface.rs | 24 +++++++++---------- src/service/ood-control/src/lib.rs | 6 ++--- src/service/ood-control/src/request.rs | 14 +++++------ 8 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/component/cyfs-util/src/util/system_info.rs b/src/component/cyfs-util/src/util/system_info.rs index 4c9983728..014567847 100644 --- a/src/component/cyfs-util/src/util/system_info.rs +++ b/src/component/cyfs-util/src/util/system_info.rs @@ -19,7 +19,7 @@ pub struct SystemInfo { pub total_memory: u64, pub used_memory: u64, - // 每个刷新周期之间的传输的bytes + // Bytes transferred between each refresh cycle pub received_bytes: u64, pub transmitted_bytes: u64, @@ -27,11 +27,11 @@ pub struct SystemInfo { pub total_received_bytes: u64, pub total_transmitted_bytes: u64, - // SSD硬盘容量和可用容量,包括Unknown, in bytes + // SSD drive capacity and available capacity, including Unknown, in bytes pub ssd_disk_total: u64, pub ssd_disk_avail: u64, - // HDD硬盘容量和可用容量, in bytes + // HDD capacity and available capacity, in bytes pub hdd_disk_total: u64, pub hdd_disk_avail: u64, } @@ -151,9 +151,9 @@ impl SystemInfoManagerInner { self.info_inner.ssd_disk_total += disk.total_space(); self.info_inner.ssd_disk_avail += disk.available_space(); } - // 在linux+docker环境下,每个docker container挂载的路径会被认作一个单独的磁盘,导致OODsystem info返回错误 - // 这里先保证OOD的正确性,不把Unknown的磁盘认为是ssd - // 影响:在WSL1下运行的OOD,磁盘大小是0,移动端的协议栈,磁盘大小是0,这些原来都是Unknown的 + // In a linux+docker environment, each docker container mount path will be recognized as a separate disk, causing OOD's system info to return an error + // Here first ensure the correctness of OOD, not to consider the unknown disk as ssd + // Impact: OOD running under WSL1, the disk size is 0, the mobile stack, the disk size is 0, these turned out to be Unknown DiskType::Unknown(_) => { // self.info_inner.ssd_disk_total += disk.total_space(); // self.info_inner.ssd_disk_avail += disk.available_space(); @@ -279,7 +279,7 @@ impl SystemInfoManager { } } -// 这里使用全局单例模式,避免runtime和non-stack不同的接口分别持有两个实例 +// The global singleton pattern is used here to avoid the cyfs-runtime and cyfs-stack components holding two separate instances lazy_static::lazy_static! { pub static ref SYSTEM_INFO_MANAGER: SystemInfoManager = SystemInfoManager::new(); } diff --git a/src/service/ood-control/src/app_bind_manager.rs b/src/service/ood-control/src/app_bind_manager.rs index 4ec5f4a90..4715d0855 100644 --- a/src/service/ood-control/src/app_bind_manager.rs +++ b/src/service/ood-control/src/app_bind_manager.rs @@ -23,7 +23,7 @@ impl EventListenerSyncRoutine<(), ()> for BindNotify { } } -// 适用于内嵌协议栈的 +// For embedded cyfs-stack #[derive(Clone)] pub struct AppBindManager { controller: Controller, @@ -55,12 +55,12 @@ impl AppBindManager { self.controller.is_bind() } - // start成功后,返回本地tcp的绑定端口,用以展示二维码等操作 + // After a successful start, the local tcp bind port is returned, which can be used to display QR codes and other operations. pub fn get_tcp_addr_list(&self) -> Vec { self.control_interface.get_tcp_addr_list() } - //启动本地绑定服务器,必须is_bind返回false才可以调用! + // Start local binding server, must be called only if is_bind returns false! pub async fn start(&self) -> BuckyResult<()> { if self.is_bind() { return Ok(()); @@ -70,7 +70,7 @@ impl AppBindManager { self.control_interface.start().await } - // 不等待绑定完成,直接停止整个绑定流程 + // Stop the whole binding process directly without waiting for the binding to complete pub fn stop(&self) { if let Some(handle) = self.abort_handle.lock().unwrap().take() { handle.abort(); @@ -79,7 +79,7 @@ impl AppBindManager { self.control_interface.stop(); } - // start成功后,等待绑定完成 + // After a successful start, wait for the binding to complete pub async fn wait_util_bind(&self) -> BuckyResult<()> { if self.controller.is_bind() { return Ok(()); @@ -87,21 +87,21 @@ impl AppBindManager { let (abort_handle, abort_registration) = AbortHandle::new_pair(); - // 保留abort—handle用以取消 + // Keep abort-handle for later cancellation { let mut handle = self.abort_handle.lock().unwrap(); assert!(handle.is_none()); *handle = Some(abort_handle); } - // 关注绑定事件 + // Focus on the binding events let notify = BindNotify { abort_handle: self.abort_handle.clone(), }; self.controller.bind_event().on(Box::new(notify.clone())); - // 等待绑定结束 + // Wait for binding to end match Abortable::new(async_std::future::pending::<()>(), abort_registration).await { Ok(_) => { unreachable!(); diff --git a/src/service/ood-control/src/bind.rs b/src/service/ood-control/src/bind.rs index 4b70cbb28..e4c7dd7ff 100644 --- a/src/service/ood-control/src/bind.rs +++ b/src/service/ood-control/src/bind.rs @@ -7,13 +7,13 @@ use std::path::{Path, PathBuf}; use std::sync::Arc; use cyfs_debug::Mutex; -// 保存的扩展信息 +// Saved extension information on binding #[derive(Serialize, Deserialize)] pub(super) struct BindExtInfo { - // 绑定的people + // bound people owner: String, - // 绑定设备对应people的索引 + // Index of the corresponding people of current device index: i32, } @@ -83,13 +83,13 @@ pub(super) struct BindStateImpl { is_bind: bool, - // 绑定的设备描述相关 + // The bound device desc related info device: Option, device_id: Option, bind_ext_info: Option, - // 事件 + // the event on_bind: OnBindEventManager, } @@ -108,7 +108,7 @@ impl BindStateImpl { } fn emit_bind_event(&self) { - // 触发事件 + // emit the binding event async let event = self.on_bind.clone(); async_std::task::spawn(async move { let _ = event.emit(&()); diff --git a/src/service/ood-control/src/controller.rs b/src/service/ood-control/src/controller.rs index 2ed66cda7..331918f16 100644 --- a/src/service/ood-control/src/controller.rs +++ b/src/service/ood-control/src/controller.rs @@ -121,14 +121,14 @@ impl ControllerImpl { fn verify_zone(owner: &People, device: &Device) -> BuckyResult<()> { let owner_id = owner.desc().calculate_id(); - // 检查people的ood_list是否为空 + // Check if ood_list of people is empty if owner.ood_list().is_empty() { let msg = format!("device's owner's ood_list is empty! owner={}", owner_id); error!("{}", msg); return Err(BuckyError::new(BuckyErrorCode::ErrorState, msg)); } - // 检查device的owner是否正确 + // Check if the owner of the device is correct if device.desc().owner() != &Some(owner_id) { let msg = format!( "device's owner is unmatch! owner={}, device's owner={:?}", @@ -164,7 +164,7 @@ impl ControllerImpl { BuckyError::new(BuckyErrorCode::InvalidFormat, msg) })?; - // 确保owner已经绑定了ood + // Make sure the owner has bound OOD Self::verify_zone(&owner, &device)?; let private_key = @@ -175,7 +175,7 @@ impl ControllerImpl { BuckyError::new(BuckyErrorCode::InvalidFormat, msg) })?; - // 校验owner签名是否有效 + // Verify that the owner's signature is valid let verifier_ret = Self::verify_sign(&owner, &device).await; if !verifier_ret { let msg = format!("verify device sign by owner failed!"); @@ -184,10 +184,10 @@ impl ControllerImpl { return Err(BuckyError::new(BuckyErrorCode::InvalidSignature, msg)); } - // 尝试重命名已有的 + // Try to rename the existing ones, don't delete the old data however self.rename_current(); - // 保存到文件 + // Save device desc and private key to target file device.encode_to_file(&self.desc_file, false).map_err(|e| { let msg = format!( "save device.desc to file error! file={}, {}", @@ -249,7 +249,7 @@ impl ControllerImpl { return false; } - // 校验签名 + // Verify signature for sign in signs.iter() { match cyfs_base::verify_object_desc_sign(&verifier, device, sign).await { Ok(result) => { diff --git a/src/service/ood-control/src/device_info.rs b/src/service/ood-control/src/device_info.rs index 2fb927b89..dece9fac3 100644 --- a/src/service/ood-control/src/device_info.rs +++ b/src/service/ood-control/src/device_info.rs @@ -22,7 +22,7 @@ impl DeviceInfoGen { } pub fn new() -> DeviceInfo { - // 获取第一个网卡地址 + // Get the first NIC address #[cfg(all(not(target_os = "android"), not(target_os = "ios")))] let mac_address = match mac_address::get_mac_address() { Ok(Some(v)) => v.to_string(), @@ -62,7 +62,7 @@ impl DeviceInfoGen { let disk_list = system.disks(); for disk in disk_list { match disk.type_() { - // 移动设备和未知设备归入hdd + // Mobile devices and unknown devices are classified as hdd DiskType::HDD | DiskType::Unknown(_) => { hdd_total_disk_space += disk.total_space(); hdd_available_disk_space += disk.available_space(); @@ -74,7 +74,7 @@ impl DeviceInfoGen { } } - // 本地ip地址 + // Local intranet ip address let private_ip_address: Vec = match cyfs_util::get_system_hosts() { Ok(addr_list) => addr_list .private_ip_v4 diff --git a/src/service/ood-control/src/interface.rs b/src/service/ood-control/src/interface.rs index 460ac0a03..c9f2eedf5 100644 --- a/src/service/ood-control/src/interface.rs +++ b/src/service/ood-control/src/interface.rs @@ -29,7 +29,7 @@ pub struct ControlInterfaceParam { pub addr_type: ControlInterfaceAddrType, - // 是否需要访问权限,如果提供了,那么会尝试绑定公网ip + // Whether access is required, if it is provided, then it will try to bind the public ip pub require_access_token: bool, pub tcp_host: Option, } @@ -40,7 +40,7 @@ pub struct ControlInterface { } impl ControlInterface { - // tcp_port tcp监听的本地端口,传None表示使用默认值(取决于mode) + // tcp_port local port for tcp listening, pass None to use default value (depends on mode) pub fn new(param: ControlInterfaceParam, controller: &Controller) -> Self { let access_token = match param.require_access_token { true => Some(AccessTokenGen::new().gen_access_token(12)), @@ -174,14 +174,14 @@ impl ControlInterface { OODControlMode::Runtime => cyfs_base::CYFS_RUNTIME_DAEMON_CONTROL_PORT, OODControlMode::Installer => cyfs_base::OOD_INSTALLER_CONTROL_PORT, OODControlMode::App => { - // 对于app,采用随机端口 + // For app, random ports are used (set to 0 to identify that random ports are used) 0 } } } fn get_local_hosts() -> Vec { - // 在获取不到内网ipv4情况下,只能使用127.0.0.1,避免绑定了外网端口导致安全问题 + // If we can't get the intranet ipv4, you can only use 127.0.0.1 loopback to avoid the security problem caused by binding the external port. match cyfs_util::get_system_hosts() { Ok(info) => { let mut private_ip_v4 = info.private_ip_v4; @@ -200,21 +200,21 @@ impl ControlInterface { } fn get_public_hosts() -> Vec { - // 在获取不到内网ipv4情况下,只能使用127.0.0.1,避免绑定了外网端口导致安全问题 + // Get the public network ipv4 and ipv6 addresses match cyfs_util::get_system_hosts() { Ok(mut info) => { - let mut public_ip_v4 = info.public_ip_v4; + let mut list = info.public_ip_v4; - if public_ip_v4.is_empty() { + if list.is_empty() { error!("retrieve system hosts but public ipv4 addrs not found!"); // public_ip_v4.push("0.0.0.0".to_string()); } if info.ip_v6.len() > 0 { - public_ip_v4.append(&mut info.ip_v6); + list.append(&mut info.ip_v6); } - public_ip_v4 + list } Err(e) => { error!("retrieve system hosts failed, now will use default: {}", e); @@ -229,7 +229,7 @@ impl ControlInterface { } pub async fn start(&self) -> BuckyResult<()> { - // 只有标准daemon和runtime模式,开启本地http控制接口 + // Local http control interface is enabled only in standard daemon and runtime mode let mut count = 0; for listener in &self.tcp_listeners { let ret = listener.start().await; @@ -238,7 +238,7 @@ impl ControlInterface { } } - // 全部绑定失败才认为失败 + // The operation is considered to have failed only after all bindings have failed if count == 0 { let msg = format!("cyfs-control bind local address failed!"); error!("{}", msg); @@ -254,7 +254,7 @@ impl ControlInterface { } } - // 获取所有tcp监听的本地地址和端口 + // Get the local address and port of all tcp listeners pub fn get_tcp_addr_list(&self) -> Vec { self.tcp_listeners .iter() diff --git a/src/service/ood-control/src/lib.rs b/src/service/ood-control/src/lib.rs index 84abc719b..637349b5f 100644 --- a/src/service/ood-control/src/lib.rs +++ b/src/service/ood-control/src/lib.rs @@ -31,13 +31,13 @@ pub enum InterfaceProtocol { #[derive(Debug, PartialEq, Eq, Clone, Copy)] pub enum OODControlMode { - // ood-daemon模式 + // ood-daemon mode Daemon = 0, - // cyfs-runtime模式 + // cyfs-runtime mode Runtime = 1, - // 第三方app模式,端口随机 + // Third party app mode with random ports App = 2, // ood-installer mode diff --git a/src/service/ood-control/src/request.rs b/src/service/ood-control/src/request.rs index a14502685..1a7a2ee28 100644 --- a/src/service/ood-control/src/request.rs +++ b/src/service/ood-control/src/request.rs @@ -45,31 +45,31 @@ pub struct ControlInterfaceAccessInfo { #[derive(Serialize, Deserialize, Debug)] pub struct CheckResponse { - // 是否已经绑定了device.desc和device.sec + // Is it already bound with device.desc & device.sec pub activation: bool, pub check_status: HashMap, - // 设备信息 + // Current device info pub device_info: DeviceInfo, - // ood-control访问信息 + // ood-control service access and permission configuration pub access_info: ControlInterfaceAccessInfo, - // 已经绑定的ood的device.desc + // device.desc of the already bound ood or runtime pub bind_info: Option, } #[derive(Serialize, Deserialize, Debug)] pub struct ActivateInfo { - // 绑定的people + // bound people pub owner: String, - // 对应的device的索引 + // Index of the corresponding device pub index: i32, - // device描述文件和密钥 + // device object's desc file and private key pub desc: String, pub sec: String, }