Skip to content

Commit

Permalink
Remove unusefull fields in RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
streetycat committed May 16, 2023
1 parent ceada20 commit 533e8e7
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 137 deletions.
18 changes: 17 additions & 1 deletion src/component/cyfs-group-lib/src/input_request.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
26 changes: 25 additions & 1 deletion src/component/cyfs-group-lib/src/output_request.rs
Original file line number Diff line number Diff line change
@@ -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<ObjectId>,
}

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,
Expand Down
7 changes: 3 additions & 4 deletions src/component/cyfs-group-lib/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@ use std::sync::Arc;

use cyfs_base::BuckyResult;
use cyfs_core::GroupProposal;
use cyfs_lib::NONOutputRequestCommon;

use crate::{
GroupPushProposalOutputResponse, GroupStartServiceOutputRequest,
GroupOutputRequestCommon, GroupPushProposalOutputResponse, GroupStartServiceOutputRequest,
GroupStartServiceOutputResponse,
};

#[async_trait::async_trait]
pub trait GroupOutputProcessor: Send + Sync {
async fn start_service(
&self,
req_common: NONOutputRequestCommon,
req_common: GroupOutputRequestCommon,
req: GroupStartServiceOutputRequest,
) -> BuckyResult<GroupStartServiceOutputResponse>;
async fn push_proposal(
&self,
req_common: NONOutputRequestCommon,
req_common: GroupOutputRequestCommon,
req: GroupProposal,
) -> BuckyResult<GroupPushProposalOutputResponse>;
}
Expand Down
45 changes: 9 additions & 36 deletions src/component/cyfs-group-lib/src/requestor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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<GroupStartServiceOutputResponse> {
Expand Down Expand Up @@ -137,7 +110,7 @@ impl GroupRequestor {

pub async fn push_proposal(
&self,
req_common: NONOutputRequestCommon,
req_common: GroupOutputRequestCommon,
proposal: &GroupProposal,
) -> BuckyResult<GroupPushProposalOutputResponse> {
let proposal_id = proposal.desc().object_id();
Expand Down Expand Up @@ -190,15 +163,15 @@ impl GroupRequestor {
impl GroupOutputProcessor for GroupRequestor {
async fn start_service(
&self,
req_common: NONOutputRequestCommon,
req_common: GroupOutputRequestCommon,
req: GroupStartServiceOutputRequest,
) -> BuckyResult<GroupStartServiceOutputResponse> {
GroupRequestor::start_service(self, req_common, &req.group_id, req.rpath.as_str()).await
}

async fn push_proposal(
&self,
req_common: NONOutputRequestCommon,
req_common: GroupOutputRequestCommon,
req: GroupProposal,
) -> BuckyResult<GroupPushProposalOutputResponse> {
GroupRequestor::push_proposal(self, req_common, &req).await
Expand Down
8 changes: 4 additions & 4 deletions src/component/cyfs-stack/src/group/processor.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
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;

#[async_trait::async_trait]
pub(crate) trait GroupInputProcessor: Sync + Send {
async fn start_service(
&self,
req_common: NONInputRequestCommon,
req_common: GroupInputRequestCommon,
req: GroupStartServiceInputRequest,
) -> BuckyResult<GroupStartServiceInputResponse>;

async fn push_proposal(
&self,
req_common: NONInputRequestCommon,
req_common: GroupInputRequestCommon,
req: GroupProposal,
) -> BuckyResult<GroupPushProposalInputResponse>;
}
Expand Down
56 changes: 16 additions & 40 deletions src/component/cyfs-stack/src/group/transform.rs
Original file line number Diff line number Diff line change
@@ -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::*;

Expand All @@ -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<GroupStartServiceInputResponse> {
let out_req = GroupStartServiceOutputRequest {
Expand All @@ -64,7 +51,7 @@ impl GroupInputTransformer {

async fn push_proposal(
&self,
req_common: NONInputRequestCommon,
req_common: GroupInputRequestCommon,
req: GroupProposal,
) -> BuckyResult<GroupPushProposalInputResponse> {
let out_resp = self
Expand All @@ -84,15 +71,15 @@ impl GroupInputTransformer {
impl GroupInputProcessor for GroupInputTransformer {
async fn start_service(
&self,
req_common: NONInputRequestCommon,
req_common: GroupInputRequestCommon,
req: GroupStartServiceInputRequest,
) -> BuckyResult<GroupStartServiceInputResponse> {
GroupInputTransformer::start_service(self, req_common, req).await
}

async fn push_proposal(
&self,
req_common: NONInputRequestCommon,
req_common: GroupInputRequestCommon,
req: GroupProposal,
) -> BuckyResult<GroupPushProposalInputResponse> {
GroupInputTransformer::push_proposal(self, req_common, req).await
Expand All @@ -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,
}
}
Expand All @@ -138,7 +114,7 @@ impl GroupOutputTransformer {

async fn push_proposal(
&self,
req_common: NONOutputRequestCommon,
req_common: GroupOutputRequestCommon,
req: GroupProposal,
) -> BuckyResult<GroupPushProposalOutputResponse> {
let in_resp = self
Expand All @@ -155,7 +131,7 @@ impl GroupOutputTransformer {

async fn start_service(
&self,
req_common: NONOutputRequestCommon,
req_common: GroupOutputRequestCommon,
req: GroupStartServiceOutputRequest,
) -> BuckyResult<GroupStartServiceOutputResponse> {
let in_req = GroupStartServiceInputRequest {
Expand All @@ -178,15 +154,15 @@ impl GroupOutputTransformer {
impl GroupOutputProcessor for GroupOutputTransformer {
async fn start_service(
&self,
req_common: NONOutputRequestCommon,
req_common: GroupOutputRequestCommon,
req: GroupStartServiceOutputRequest,
) -> BuckyResult<GroupStartServiceOutputResponse> {
GroupOutputTransformer::start_service(self, req_common, req).await
}

async fn push_proposal(
&self,
req_common: NONOutputRequestCommon,
req_common: GroupOutputRequestCommon,
req: GroupProposal,
) -> BuckyResult<GroupPushProposalOutputResponse> {
GroupOutputTransformer::push_proposal(self, req_common, req).await
Expand Down
7 changes: 4 additions & 3 deletions src/component/cyfs-stack/src/group_api/acl/group_acl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down Expand Up @@ -43,7 +44,7 @@ impl GroupAclInnerInputProcessor {
impl GroupInputProcessor for GroupAclInnerInputProcessor {
async fn start_service(
&self,
req_common: NONInputRequestCommon,
req_common: GroupInputRequestCommon,
req: GroupStartServiceInputRequest,
) -> BuckyResult<GroupStartServiceInputResponse> {
self.check_local_zone_permit("group.service", &req_common.source)?;
Expand All @@ -52,7 +53,7 @@ impl GroupInputProcessor for GroupAclInnerInputProcessor {

async fn push_proposal(
&self,
req_common: NONInputRequestCommon,
req_common: GroupInputRequestCommon,
req: GroupProposal,
) -> BuckyResult<GroupPushProposalInputResponse> {
self.check_local_zone_permit("group.proposal", &req_common.source)?;
Expand Down
Loading

0 comments on commit 533e8e7

Please sign in to comment.