Skip to content

Commit

Permalink
Update the comments of ood-control
Browse files Browse the repository at this point in the history
  • Loading branch information
lurenpluto committed May 12, 2023
1 parent baa46cf commit e53ba76
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 53 deletions.
14 changes: 7 additions & 7 deletions src/component/cyfs-util/src/util/system_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ 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,

// total bytes of all networks since last booted
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,
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
16 changes: 8 additions & 8 deletions src/service/ood-control/src/app_bind_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl EventListenerSyncRoutine<(), ()> for BindNotify {
}
}

// 适用于内嵌协议栈的
// For embedded cyfs-stack
#[derive(Clone)]
pub struct AppBindManager {
controller: Controller,
Expand Down Expand Up @@ -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<SocketAddr> {
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(());
Expand All @@ -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();
Expand All @@ -79,29 +79,29 @@ 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(());
}

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!();
Expand Down
12 changes: 6 additions & 6 deletions src/service/ood-control/src/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -83,13 +83,13 @@ pub(super) struct BindStateImpl {

is_bind: bool,

// 绑定的设备描述相关
// The bound device desc related info
device: Option<String>,
device_id: Option<String>,

bind_ext_info: Option<BindExtInfo>,

// 事件
// the event
on_bind: OnBindEventManager,
}

Expand All @@ -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(&());
Expand Down
14 changes: 7 additions & 7 deletions src/service/ood-control/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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={:?}",
Expand Down Expand Up @@ -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 =
Expand All @@ -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!");
Expand All @@ -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={}, {}",
Expand Down Expand Up @@ -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) => {
Expand Down
6 changes: 3 additions & 3 deletions src/service/ood-control/src/device_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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();
Expand All @@ -74,7 +74,7 @@ impl DeviceInfoGen {
}
}

// 本地ip地址
// Local intranet ip address
let private_ip_address: Vec<String> = match cyfs_util::get_system_hosts() {
Ok(addr_list) => addr_list
.private_ip_v4
Expand Down
24 changes: 12 additions & 12 deletions src/service/ood-control/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ControlTCPHost>,
}
Expand All @@ -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)),
Expand Down Expand Up @@ -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<SocketAddr> {
// 在获取不到内网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;
Expand All @@ -200,21 +200,21 @@ impl ControlInterface {
}

fn get_public_hosts() -> Vec<SocketAddr> {
// 在获取不到内网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);
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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<SocketAddr> {
self.tcp_listeners
.iter()
Expand Down
6 changes: 3 additions & 3 deletions src/service/ood-control/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions src/service/ood-control/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, CheckStatus>,

// 设备信息
// 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<BindInfo>,
}

#[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,
}
Expand Down

0 comments on commit e53ba76

Please sign in to comment.