diff --git a/src/component/cyfs-group-lib/src/input_request.rs b/src/component/cyfs-group-lib/src/input_request.rs index 54df4dda..c883ca37 100644 --- a/src/component/cyfs-group-lib/src/input_request.rs +++ b/src/component/cyfs-group-lib/src/input_request.rs @@ -1,5 +1,21 @@ +use std::fmt; + use cyfs_base::ObjectId; -use cyfs_lib::NONObjectInfo; +use cyfs_lib::{NONObjectInfo, RequestSourceInfo}; + +#[derive(Clone, Debug)] +pub struct GroupInputRequestCommon { + // the request source info in bundle + pub source: RequestSourceInfo, +} + +impl fmt::Display for GroupInputRequestCommon { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, ", {}", self.source)?; + + Ok(()) + } +} pub struct GroupStartServiceInputRequest { pub group_id: ObjectId, diff --git a/src/component/cyfs-group-lib/src/output_request.rs b/src/component/cyfs-group-lib/src/output_request.rs index 964abcc4..293f8bf7 100644 --- a/src/component/cyfs-group-lib/src/output_request.rs +++ b/src/component/cyfs-group-lib/src/output_request.rs @@ -1,6 +1,30 @@ -use cyfs_base::ObjectId; +use std::fmt; + +use cyfs_base::{DeviceId, ObjectId}; use cyfs_lib::NONObjectInfo; +#[derive(Clone, Debug)] +pub struct GroupOutputRequestCommon { + // source dec-id + pub dec_id: Option, +} + +impl GroupOutputRequestCommon { + pub fn new() -> Self { + Self { dec_id: None } + } +} + +impl fmt::Display for GroupOutputRequestCommon { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + if let Some(dec_id) = &self.dec_id { + write!(f, ", dec_id: {}", dec_id)?; + } + + Ok(()) + } +} + #[derive(Debug)] pub struct GroupStartServiceOutputRequest { pub group_id: ObjectId, diff --git a/src/component/cyfs-group-lib/src/processor.rs b/src/component/cyfs-group-lib/src/processor.rs index 9aec5a35..a9a2edcf 100644 --- a/src/component/cyfs-group-lib/src/processor.rs +++ b/src/component/cyfs-group-lib/src/processor.rs @@ -2,10 +2,9 @@ use std::sync::Arc; use cyfs_base::BuckyResult; use cyfs_core::GroupProposal; -use cyfs_lib::NONOutputRequestCommon; use crate::{ - GroupPushProposalOutputResponse, GroupStartServiceOutputRequest, + GroupOutputRequestCommon, GroupPushProposalOutputResponse, GroupStartServiceOutputRequest, GroupStartServiceOutputResponse, }; @@ -13,12 +12,12 @@ use crate::{ pub trait GroupOutputProcessor: Send + Sync { async fn start_service( &self, - req_common: NONOutputRequestCommon, + req_common: GroupOutputRequestCommon, req: GroupStartServiceOutputRequest, ) -> BuckyResult; async fn push_proposal( &self, - req_common: NONOutputRequestCommon, + req_common: GroupOutputRequestCommon, req: GroupProposal, ) -> BuckyResult; } diff --git a/src/component/cyfs-group-lib/src/requestor.rs b/src/component/cyfs-group-lib/src/requestor.rs index 35d7a36a..94c93af5 100644 --- a/src/component/cyfs-group-lib/src/requestor.rs +++ b/src/component/cyfs-group-lib/src/requestor.rs @@ -2,19 +2,15 @@ use std::sync::Arc; use cyfs_base::{ BuckyError, BuckyResult, JsonCodec, NamedObject, ObjectDesc, ObjectId, RawConvertTo, - CYFS_API_LEVEL, }; use cyfs_core::{GroupProposal, GroupProposalObject}; -use cyfs_lib::{ - HttpRequestorRef, NONAction, NONObjectInfo, NONOutputRequestCommon, NONRequestorHelper, - RequestorHelper, -}; +use cyfs_lib::{HttpRequestorRef, NONObjectInfo, NONRequestorHelper, RequestorHelper}; use http_types::{Method, Request, Url}; use crate::{ output_request::GroupStartServiceOutputRequest, processor::{GroupOutputProcessor, GroupOutputProcessorRef}, - GroupPushProposalOutputResponse, GroupStartServiceOutputResponse, + GroupOutputRequestCommon, GroupPushProposalOutputResponse, GroupStartServiceOutputResponse, }; #[derive(Clone)] @@ -42,43 +38,20 @@ impl GroupRequestor { Arc::new(Box::new(self.clone())) } - fn encode_common_headers(&self, com_req: &NONOutputRequestCommon, http_req: &mut Request) { + fn encode_common_headers(&self, com_req: &GroupOutputRequestCommon, http_req: &mut Request) { let dec_id = com_req.dec_id.as_ref().unwrap_or(&self.dec_id); http_req.insert_header(cyfs_base::CYFS_DEC_ID, dec_id.to_string()); - - RequestorHelper::encode_opt_header_with_encoding( - http_req, - cyfs_base::CYFS_REQ_PATH, - com_req.req_path.as_deref(), - ); - - http_req.insert_header(CYFS_API_LEVEL, com_req.level.to_string()); - - if let Some(target) = &com_req.target { - http_req.insert_header(cyfs_base::CYFS_TARGET, target.to_string()); - } - - if let Some(source) = &com_req.source { - http_req.insert_header(cyfs_base::CYFS_SOURCE, source.to_string()); - } - - http_req.insert_header(cyfs_base::CYFS_FLAGS, com_req.flags.to_string()); } - pub(crate) fn make_default_common(dec_id: ObjectId) -> NONOutputRequestCommon { - NONOutputRequestCommon { - req_path: None, - source: None, + pub(crate) fn make_default_common(dec_id: ObjectId) -> GroupOutputRequestCommon { + GroupOutputRequestCommon { dec_id: Some(dec_id), - level: cyfs_lib::NONAPILevel::NOC, - target: None, - flags: 0, } } pub async fn start_service( &self, - req_common: NONOutputRequestCommon, + req_common: GroupOutputRequestCommon, group_id: &ObjectId, rpath: &str, ) -> BuckyResult { @@ -137,7 +110,7 @@ impl GroupRequestor { pub async fn push_proposal( &self, - req_common: NONOutputRequestCommon, + req_common: GroupOutputRequestCommon, proposal: &GroupProposal, ) -> BuckyResult { let proposal_id = proposal.desc().object_id(); @@ -190,7 +163,7 @@ impl GroupRequestor { impl GroupOutputProcessor for GroupRequestor { async fn start_service( &self, - req_common: NONOutputRequestCommon, + req_common: GroupOutputRequestCommon, req: GroupStartServiceOutputRequest, ) -> BuckyResult { GroupRequestor::start_service(self, req_common, &req.group_id, req.rpath.as_str()).await @@ -198,7 +171,7 @@ impl GroupOutputProcessor for GroupRequestor { async fn push_proposal( &self, - req_common: NONOutputRequestCommon, + req_common: GroupOutputRequestCommon, req: GroupProposal, ) -> BuckyResult { GroupRequestor::push_proposal(self, req_common, &req).await diff --git a/src/component/cyfs-stack/src/group/processor.rs b/src/component/cyfs-stack/src/group/processor.rs index b6fe1544..8ee37ab6 100644 --- a/src/component/cyfs-stack/src/group/processor.rs +++ b/src/component/cyfs-stack/src/group/processor.rs @@ -1,9 +1,9 @@ use cyfs_base::*; use cyfs_core::GroupProposal; use cyfs_group_lib::{ - GroupPushProposalInputResponse, GroupStartServiceInputRequest, GroupStartServiceInputResponse, + GroupInputRequestCommon, GroupPushProposalInputResponse, GroupStartServiceInputRequest, + GroupStartServiceInputResponse, }; -use cyfs_lib::*; use std::sync::Arc; @@ -11,13 +11,13 @@ use std::sync::Arc; pub(crate) trait GroupInputProcessor: Sync + Send { async fn start_service( &self, - req_common: NONInputRequestCommon, + req_common: GroupInputRequestCommon, req: GroupStartServiceInputRequest, ) -> BuckyResult; async fn push_proposal( &self, - req_common: NONInputRequestCommon, + req_common: GroupInputRequestCommon, req: GroupProposal, ) -> BuckyResult; } diff --git a/src/component/cyfs-stack/src/group/transform.rs b/src/component/cyfs-stack/src/group/transform.rs index 74ee64c8..ce1ea558 100644 --- a/src/component/cyfs-stack/src/group/transform.rs +++ b/src/component/cyfs-stack/src/group/transform.rs @@ -1,9 +1,10 @@ use cyfs_base::*; use cyfs_core::GroupProposal; use cyfs_group_lib::{ - GroupOutputProcessor, GroupOutputProcessorRef, GroupPushProposalInputResponse, - GroupPushProposalOutputResponse, GroupStartServiceInputRequest, GroupStartServiceInputResponse, - GroupStartServiceOutputRequest, GroupStartServiceOutputResponse, + GroupInputRequestCommon, GroupOutputProcessor, GroupOutputProcessorRef, + GroupOutputRequestCommon, GroupPushProposalInputResponse, GroupPushProposalOutputResponse, + GroupStartServiceInputRequest, GroupStartServiceInputResponse, GroupStartServiceOutputRequest, + GroupStartServiceOutputResponse, }; use cyfs_lib::*; @@ -22,29 +23,15 @@ impl GroupInputTransformer { Arc::new(ret) } - fn convert_common(common: NONInputRequestCommon) -> NONOutputRequestCommon { - NONOutputRequestCommon { - // 请求路径,可为空 - req_path: common.req_path, - - // 来源DEC + fn convert_common(common: GroupInputRequestCommon) -> GroupOutputRequestCommon { + GroupOutputRequestCommon { dec_id: common.source.get_opt_dec().cloned(), - - // 默认行为 - level: common.level, - - // 用以处理默认行为 - target: common.target, - - flags: common.flags, - - source: common.source.zone.device, } } async fn start_service( &self, - req_common: NONInputRequestCommon, + req_common: GroupInputRequestCommon, req: GroupStartServiceInputRequest, ) -> BuckyResult { let out_req = GroupStartServiceOutputRequest { @@ -64,7 +51,7 @@ impl GroupInputTransformer { async fn push_proposal( &self, - req_common: NONInputRequestCommon, + req_common: GroupInputRequestCommon, req: GroupProposal, ) -> BuckyResult { let out_resp = self @@ -84,7 +71,7 @@ impl GroupInputTransformer { impl GroupInputProcessor for GroupInputTransformer { async fn start_service( &self, - req_common: NONInputRequestCommon, + req_common: GroupInputRequestCommon, req: GroupStartServiceInputRequest, ) -> BuckyResult { GroupInputTransformer::start_service(self, req_common, req).await @@ -92,7 +79,7 @@ impl GroupInputProcessor for GroupInputTransformer { async fn push_proposal( &self, - req_common: NONInputRequestCommon, + req_common: GroupInputRequestCommon, req: GroupProposal, ) -> BuckyResult { GroupInputTransformer::push_proposal(self, req_common, req).await @@ -106,24 +93,13 @@ pub(crate) struct GroupOutputTransformer { } impl GroupOutputTransformer { - fn convert_common(&self, common: NONOutputRequestCommon) -> NONInputRequestCommon { + fn convert_common(&self, common: GroupOutputRequestCommon) -> GroupInputRequestCommon { let mut source = self.source.clone(); if let Some(dec_id) = common.dec_id { source.set_dec(dec_id); } - NONInputRequestCommon { - // 请求路径,可为空 - req_path: common.req_path, - - // 默认行为 - level: common.level, - - // 用以处理默认行为 - target: common.target, - - flags: common.flags, - + GroupInputRequestCommon { source, } } @@ -138,7 +114,7 @@ impl GroupOutputTransformer { async fn push_proposal( &self, - req_common: NONOutputRequestCommon, + req_common: GroupOutputRequestCommon, req: GroupProposal, ) -> BuckyResult { let in_resp = self @@ -155,7 +131,7 @@ impl GroupOutputTransformer { async fn start_service( &self, - req_common: NONOutputRequestCommon, + req_common: GroupOutputRequestCommon, req: GroupStartServiceOutputRequest, ) -> BuckyResult { let in_req = GroupStartServiceInputRequest { @@ -178,7 +154,7 @@ impl GroupOutputTransformer { impl GroupOutputProcessor for GroupOutputTransformer { async fn start_service( &self, - req_common: NONOutputRequestCommon, + req_common: GroupOutputRequestCommon, req: GroupStartServiceOutputRequest, ) -> BuckyResult { GroupOutputTransformer::start_service(self, req_common, req).await @@ -186,7 +162,7 @@ impl GroupOutputProcessor for GroupOutputTransformer { async fn push_proposal( &self, - req_common: NONOutputRequestCommon, + req_common: GroupOutputRequestCommon, req: GroupProposal, ) -> BuckyResult { GroupOutputTransformer::push_proposal(self, req_common, req).await diff --git a/src/component/cyfs-stack/src/group_api/acl/group_acl.rs b/src/component/cyfs-stack/src/group_api/acl/group_acl.rs index 873c253d..7698904d 100644 --- a/src/component/cyfs-stack/src/group_api/acl/group_acl.rs +++ b/src/component/cyfs-stack/src/group_api/acl/group_acl.rs @@ -2,7 +2,8 @@ use crate::group::{GroupInputProcessor, GroupInputProcessorRef}; use cyfs_base::*; use cyfs_core::GroupProposal; use cyfs_group_lib::{ - GroupPushProposalInputResponse, GroupStartServiceInputRequest, GroupStartServiceInputResponse, + GroupInputRequestCommon, GroupPushProposalInputResponse, GroupStartServiceInputRequest, + GroupStartServiceInputResponse, }; use cyfs_lib::*; @@ -43,7 +44,7 @@ impl GroupAclInnerInputProcessor { impl GroupInputProcessor for GroupAclInnerInputProcessor { async fn start_service( &self, - req_common: NONInputRequestCommon, + req_common: GroupInputRequestCommon, req: GroupStartServiceInputRequest, ) -> BuckyResult { self.check_local_zone_permit("group.service", &req_common.source)?; @@ -52,7 +53,7 @@ impl GroupInputProcessor for GroupAclInnerInputProcessor { async fn push_proposal( &self, - req_common: NONInputRequestCommon, + req_common: GroupInputRequestCommon, req: GroupProposal, ) -> BuckyResult { self.check_local_zone_permit("group.proposal", &req_common.source)?; diff --git a/src/component/cyfs-stack/src/group_api/router/group_service_router.rs b/src/component/cyfs-stack/src/group_api/router/group_service_router.rs index 2c1a2841..c61ad9d8 100644 --- a/src/component/cyfs-stack/src/group_api/router/group_service_router.rs +++ b/src/component/cyfs-stack/src/group_api/router/group_service_router.rs @@ -3,10 +3,9 @@ use std::sync::Arc; use cyfs_base::{BuckyResult, DeviceId, ObjectId}; use cyfs_core::GroupProposal; use cyfs_group_lib::{ - GroupPushProposalInputResponse, GroupRequestor, GroupStartServiceInputRequest, - GroupStartServiceInputResponse, + GroupInputRequestCommon, GroupPushProposalInputResponse, GroupRequestor, + GroupStartServiceInputRequest, GroupStartServiceInputResponse, }; -use cyfs_lib::NONInputRequestCommon; use crate::{ forward::ForwardProcessorManager, @@ -86,23 +85,19 @@ impl GroupServiceRouter { pub async fn start_service( &self, - req_common: NONInputRequestCommon, + req_common: GroupInputRequestCommon, req: GroupStartServiceInputRequest, ) -> BuckyResult { - let processor = self - .get_processor(req_common.source.dec, req_common.target.as_ref()) - .await?; + let processor = self.get_processor(req_common.source.dec, None).await?; processor.start_service(req_common, req).await } pub async fn push_proposal( &self, - req_common: NONInputRequestCommon, + req_common: GroupInputRequestCommon, req: GroupProposal, ) -> BuckyResult { - let processor = self - .get_processor(req_common.source.dec, req_common.target.as_ref()) - .await?; + let processor = self.get_processor(req_common.source.dec, None).await?; processor.push_proposal(req_common, req).await } } @@ -111,23 +106,19 @@ impl GroupServiceRouter { impl GroupInputProcessor for GroupServiceRouter { async fn start_service( &self, - req_common: NONInputRequestCommon, + req_common: GroupInputRequestCommon, req: GroupStartServiceInputRequest, ) -> BuckyResult { - let processor = self - .get_processor(req_common.source.dec, req_common.target.as_ref()) - .await?; + let processor = self.get_processor(req_common.source.dec, None).await?; processor.start_service(req_common, req).await } async fn push_proposal( &self, - req_common: NONInputRequestCommon, + req_common: GroupInputRequestCommon, req: GroupProposal, ) -> BuckyResult { - let processor = self - .get_processor(req_common.source.dec, req_common.target.as_ref()) - .await?; + let processor = self.get_processor(req_common.source.dec, None).await?; processor.push_proposal(req_common, req).await } } diff --git a/src/component/cyfs-stack/src/group_api/router/local_service.rs b/src/component/cyfs-stack/src/group_api/router/local_service.rs index a6e65420..e7257a25 100644 --- a/src/component/cyfs-stack/src/group_api/router/local_service.rs +++ b/src/component/cyfs-stack/src/group_api/router/local_service.rs @@ -4,9 +4,9 @@ use cyfs_base::{BuckyError, BuckyErrorCode, BuckyResult, NamedObject, ObjectDesc use cyfs_core::{GroupProposal, GroupProposalObject}; use cyfs_group::GroupManager; use cyfs_group_lib::{ - GroupPushProposalInputResponse, GroupStartServiceInputRequest, GroupStartServiceInputResponse, + GroupInputRequestCommon, GroupPushProposalInputResponse, GroupStartServiceInputRequest, + GroupStartServiceInputResponse, }; -use cyfs_lib::NONInputRequestCommon; use crate::group::{GroupInputProcessor, GroupInputProcessorRef}; @@ -29,7 +29,7 @@ impl LocalGroupService { impl GroupInputProcessor for LocalGroupService { async fn start_service( &self, - req_common: NONInputRequestCommon, + req_common: GroupInputRequestCommon, req: GroupStartServiceInputRequest, ) -> BuckyResult { self.group_manager @@ -55,7 +55,7 @@ impl GroupInputProcessor for LocalGroupService { async fn push_proposal( &self, - req_common: NONInputRequestCommon, + req_common: GroupInputRequestCommon, req: GroupProposal, ) -> BuckyResult { let proposal_id = req.desc().object_id(); diff --git a/src/component/cyfs-stack/src/group_api/service/group_handler.rs b/src/component/cyfs-stack/src/group_api/service/group_handler.rs index d2c2f298..24d8eef5 100644 --- a/src/component/cyfs-stack/src/group_api/service/group_handler.rs +++ b/src/component/cyfs-stack/src/group_api/service/group_handler.rs @@ -1,9 +1,10 @@ use cyfs_base::*; use cyfs_core::GroupProposal; use cyfs_group_lib::{ - GroupPushProposalInputResponse, GroupStartServiceInputRequest, GroupStartServiceInputResponse, + GroupInputRequestCommon, GroupPushProposalInputResponse, GroupStartServiceInputRequest, + GroupStartServiceInputResponse, }; -use cyfs_lib::{NONInputRequestCommon, NONRequestorHelper, RequestorHelper}; +use cyfs_lib::{NONRequestorHelper, RequestorHelper}; use crate::{group::GroupInputProcessorRef, non::NONInputHttpRequest}; @@ -20,30 +21,9 @@ impl GroupRequestHandler { // 解析通用header字段 fn decode_common_headers( req: &NONInputHttpRequest, - ) -> BuckyResult { - // req_path - let req_path = RequestorHelper::decode_optional_header_with_utf8_decoding( - &req.request, - cyfs_base::CYFS_REQ_PATH, - )?; - - // 尝试提取flags - let flags: Option = - RequestorHelper::decode_optional_header(&req.request, cyfs_base::CYFS_FLAGS)?; - - // 尝试提取default_action字段 - let level = - RequestorHelper::decode_optional_header(&req.request, cyfs_base::CYFS_API_LEVEL)?; - - // 尝试提取target字段 - let target = RequestorHelper::decode_optional_header(&req.request, cyfs_base::CYFS_TARGET)?; - - let ret = NONInputRequestCommon { - req_path, + ) -> BuckyResult { + let ret = GroupInputRequestCommon { source: req.source.clone(), - level: level.unwrap_or_default(), - target, - flags: flags.unwrap_or(0), }; Ok(ret)