teaclave-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ms...@apache.org
Subject [incubator-teaclave] 01/03: [services] Use single proto project to manage all services protocols
Date Mon, 06 Jan 2020 23:50:07 GMT
This is an automated email from the ASF dual-hosted git repository.

mssun pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave.git

commit dc4475a72ad11e9a0f536d70b5b10dbda8537d91
Author: Mingshen Sun <bob@mssun.me>
AuthorDate: Mon Jan 6 14:03:04 2020 -0800

    [services] Use single proto project to manage all services protocols
---
 services/{teaclave_frontend => }/proto/Cargo.toml  |  8 +--
 services/{teaclave_frontend => }/proto/build.rs    |  9 ++-
 services/{ => proto}/proto_gen/Cargo.toml          |  0
 services/{ => proto}/proto_gen/main.rs             |  0
 services/{ => proto}/proto_gen/templates/proto.j2  |  4 +-
 services/proto/src/lib.rs                          | 68 ++++++++++++++++++++++
 .../src/proto}/teaclave_frontend.proto             |  0
 services/proto/src/teaclave_frontend.rs            | 51 ++++++++++++++++
 services/teaclave_frontend/proto/src/lib.rs        | 66 ---------------------
 services/teaclave_frontend/proto/src/proto.rs      |  3 -
 .../teaclave_frontend/sgx_trusted_lib/Cargo.toml   |  4 +-
 .../teaclave_frontend/sgx_trusted_lib/src/lib.rs   |  2 +-
 .../sgx_trusted_lib/src/service.rs                 |  6 +-
 utils/service_enclave_utils/proc_macro/src/lib.rs  |  4 +-
 14 files changed, 138 insertions(+), 87 deletions(-)

diff --git a/services/teaclave_frontend/proto/Cargo.toml b/services/proto/Cargo.toml
similarity index 83%
rename from services/teaclave_frontend/proto/Cargo.toml
rename to services/proto/Cargo.toml
index db2de69..0e9bdfa 100644
--- a/services/teaclave_frontend/proto/Cargo.toml
+++ b/services/proto/Cargo.toml
@@ -1,8 +1,8 @@
 [package]
-name = "teaclave_frontend_proto"
+name = "teaclave_proto"
 version = "0.1.0"
 authors = ["Teaclave Contributors <dev@teaclave.apache.org>"]
-description = "RPC protocol of Teaclave Frontend."
+description = "RPC protocol of Teaclave services."
 license = "Apache-2.0"
 edition = "2018"
 
@@ -29,5 +29,5 @@ base64       = { version = "0.10.1" }
 sgx_cov      = { version = "1.1.0", optional = true }
 sgx_tstd     = { version = "1.1.0", features = ["net", "backtrace"], optional = true }
 sgx_types    = { version = "1.1.0" }
-teaclave_rpc = { path = "../../../rpc" }
-teaclave_types = { path = "../../../types" }
+teaclave_rpc = { path = "../../rpc" }
+teaclave_types = { path = "../../types" }
diff --git a/services/teaclave_frontend/proto/build.rs b/services/proto/build.rs
similarity index 86%
rename from services/teaclave_frontend/proto/build.rs
rename to services/proto/build.rs
index c13450e..b99d04f 100644
--- a/services/teaclave_frontend/proto/build.rs
+++ b/services/proto/build.rs
@@ -20,22 +20,21 @@ use std::process::Command;
 use std::str;
 
 fn main() {
-    let pkg_name = env!("CARGO_PKG_NAME");
-    let proto_path = format!("src/{}", pkg_name.replace("_proto", ".proto"));
+    let proto_path = format!("src/proto");
     let out_dir = env::var("OUT_DIR").expect("$OUT_DIR not set. Please build with cargo");
     println!("cargo:rerun-if-changed={}", proto_path);
     println!("cargo:rerun-if-changed=build.rs");
-    println!("cargo:rerun-if-changed=templates/proto.j2");
+    println!("cargo:rerun-if-changed=proto_gen/templates/proto.j2");
     let c = Command::new("cargo")
         .args(&[
             "run",
             "--target-dir",
             "/tmp/proto_gen/target",
             "--manifest-path",
-            "../../proto_gen/Cargo.toml",
+            "./proto_gen/Cargo.toml",
             "--",
             "-p",
-            &proto_path,
+            "src/proto/teaclave_frontend.proto",
             "-i",
             ".",
             "-d",
diff --git a/services/proto_gen/Cargo.toml b/services/proto/proto_gen/Cargo.toml
similarity index 100%
rename from services/proto_gen/Cargo.toml
rename to services/proto/proto_gen/Cargo.toml
diff --git a/services/proto_gen/main.rs b/services/proto/proto_gen/main.rs
similarity index 100%
rename from services/proto_gen/main.rs
rename to services/proto/proto_gen/main.rs
diff --git a/services/proto_gen/templates/proto.j2 b/services/proto/proto_gen/templates/proto.j2
similarity index 94%
rename from services/proto_gen/templates/proto.j2
rename to services/proto/proto_gen/templates/proto.j2
index 320f50b..994086f 100644
--- a/services/proto_gen/templates/proto.j2
+++ b/services/proto/proto_gen/templates/proto.j2
@@ -24,13 +24,13 @@ pub enum {{ service.proto_name }}Response {
 
 pub trait {{ service.proto_name }} {
     {% for m in service.methods %}
-    fn {{ m.name }}(request: crate::{{ m.input_type }}) -> Result<crate::{{ m.output_type
}}>;
+    fn {{ m.name }}(request: super::{{ m.input_type }}) -> Result<super::{{ m.output_type
}}>;
     {% endfor %}
     fn dispatch(&self, request: {{ service.proto_name }}Request) -> Result<{{ service.proto_name
}}Response> {
         match request {
             {% for m in service.methods %}
             {{ service.proto_name }}Request::{{ m.proto_name }}(request) => {
-                let request = crate::{{ m.input_type }}::try_from(request)
+                let request = super::{{ m.input_type }}::try_from(request)
                     .map_err(|_| TeaclaveServiceError::InternalError("internal".to_string()))?;
                 let response = Self::{{ m.name }}(request)?;
                 let response = {{ m.output_type }}::from(response);
diff --git a/services/proto/src/lib.rs b/services/proto/src/lib.rs
new file mode 100644
index 0000000..0251063
--- /dev/null
+++ b/services/proto/src/lib.rs
@@ -0,0 +1,68 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#![cfg_attr(feature = "mesalock_sgx", no_std)]
+#[cfg(feature = "mesalock_sgx")]
+extern crate sgx_tstd as std;
+
+// use anyhow::{Error, Result};
+
+// #[derive(serde_derive::Serialize, serde_derive::Deserialize, Debug)]
+// pub struct UserLoginRequest {
+//     pub id: std::string::String,
+//     pub password: std::string::String,
+// }
+
+// #[derive(serde_derive::Serialize, serde_derive::Deserialize, Debug)]
+// pub struct UserLoginResponse {
+//     pub token: std::string::String,
+// }
+
+// impl std::convert::TryFrom<proto::UserLoginRequest> for UserLoginRequest {
+//     type Error = Error;
+
+//     fn try_from(proto: crate::proto::UserLoginRequest) -> Result<Self> {
+//         let ret = Self {
+//             id: proto.id,
+//             password: proto.password,
+//         };
+
+//         Ok(ret)
+//     }
+// }
+
+// impl From<UserLoginRequest> for crate::proto::UserLoginRequest {
+//     fn from(request: UserLoginRequest) -> Self {
+//         Self {
+//             id: request.id,
+//             password: request.password,
+//         }
+//     }
+// }
+
+// impl From<UserLoginResponse> for crate::proto::UserLoginResponse {
+//     fn from(response: UserLoginResponse) -> Self {
+//         Self {
+//             token: response.token,
+//         }
+//     }
+// }
+
+// pub mod proto;
+// pub use proto::TeaclaveFrontend;
+
+pub mod teaclave_frontend;
diff --git a/services/teaclave_frontend/proto/src/teaclave_frontend.proto b/services/proto/src/proto/teaclave_frontend.proto
similarity index 100%
rename from services/teaclave_frontend/proto/src/teaclave_frontend.proto
rename to services/proto/src/proto/teaclave_frontend.proto
diff --git a/services/proto/src/teaclave_frontend.rs b/services/proto/src/teaclave_frontend.rs
new file mode 100644
index 0000000..3be5d72
--- /dev/null
+++ b/services/proto/src/teaclave_frontend.rs
@@ -0,0 +1,51 @@
+use anyhow::{Error, Result};
+
+pub mod proto {
+    #![allow(clippy::all)]
+    include!(concat!(env!("OUT_DIR"), "/teaclave_frontend_proto.rs"));
+}
+
+pub use proto::TeaclaveFrontend;
+pub use proto::TeaclaveFrontendRequest;
+pub use proto::TeaclaveFrontendResponse;
+
+#[derive(serde_derive::Serialize, serde_derive::Deserialize, Debug)]
+pub struct UserLoginRequest {
+    pub id: std::string::String,
+    pub password: std::string::String,
+}
+
+#[derive(serde_derive::Serialize, serde_derive::Deserialize, Debug)]
+pub struct UserLoginResponse {
+    pub token: std::string::String,
+}
+
+impl std::convert::TryFrom<proto::UserLoginRequest> for UserLoginRequest {
+    type Error = Error;
+
+    fn try_from(proto: proto::UserLoginRequest) -> Result<Self> {
+        let ret = Self {
+            id: proto.id,
+            password: proto.password,
+        };
+
+        Ok(ret)
+    }
+}
+
+impl From<UserLoginRequest> for proto::UserLoginRequest {
+    fn from(request: UserLoginRequest) -> Self {
+        Self {
+            id: request.id,
+            password: request.password,
+        }
+    }
+}
+
+impl From<UserLoginResponse> for proto::UserLoginResponse {
+    fn from(response: UserLoginResponse) -> Self {
+        Self {
+            token: response.token,
+        }
+    }
+}
diff --git a/services/teaclave_frontend/proto/src/lib.rs b/services/teaclave_frontend/proto/src/lib.rs
deleted file mode 100644
index cc549e9..0000000
--- a/services/teaclave_frontend/proto/src/lib.rs
+++ /dev/null
@@ -1,66 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#![cfg_attr(feature = "mesalock_sgx", no_std)]
-#[cfg(feature = "mesalock_sgx")]
-extern crate sgx_tstd as std;
-
-use anyhow::{Error, Result};
-
-#[derive(serde_derive::Serialize, serde_derive::Deserialize, Debug)]
-pub struct UserLoginRequest {
-    pub id: std::string::String,
-    pub password: std::string::String,
-}
-
-#[derive(serde_derive::Serialize, serde_derive::Deserialize, Debug)]
-pub struct UserLoginResponse {
-    pub token: std::string::String,
-}
-
-impl std::convert::TryFrom<proto::UserLoginRequest> for UserLoginRequest {
-    type Error = Error;
-
-    fn try_from(proto: crate::proto::UserLoginRequest) -> Result<Self> {
-        let ret = Self {
-            id: proto.id,
-            password: proto.password,
-        };
-
-        Ok(ret)
-    }
-}
-
-impl From<UserLoginRequest> for crate::proto::UserLoginRequest {
-    fn from(request: UserLoginRequest) -> Self {
-        Self {
-            id: request.id,
-            password: request.password,
-        }
-    }
-}
-
-impl From<UserLoginResponse> for crate::proto::UserLoginResponse {
-    fn from(response: UserLoginResponse) -> Self {
-        Self {
-            token: response.token,
-        }
-    }
-}
-
-pub mod proto;
-pub use proto::TeaclaveFrontend;
diff --git a/services/teaclave_frontend/proto/src/proto.rs b/services/teaclave_frontend/proto/src/proto.rs
deleted file mode 100644
index a9745a5..0000000
--- a/services/teaclave_frontend/proto/src/proto.rs
+++ /dev/null
@@ -1,3 +0,0 @@
-#![allow(clippy::all)]
-
-include!(concat!(env!("OUT_DIR"), "/teaclave_frontend_proto.rs"));
diff --git a/services/teaclave_frontend/sgx_trusted_lib/Cargo.toml b/services/teaclave_frontend/sgx_trusted_lib/Cargo.toml
index a733dc8..7a9219b 100644
--- a/services/teaclave_frontend/sgx_trusted_lib/Cargo.toml
+++ b/services/teaclave_frontend/sgx_trusted_lib/Cargo.toml
@@ -15,7 +15,7 @@ default = []
 mesalock_sgx = [
   "sgx_tstd",
   "teaclave_attestation/mesalock_sgx",
-  "teaclave_frontend_proto/mesalock_sgx",
+  "teaclave_proto/mesalock_sgx",
   "teaclave_ipc/mesalock_sgx",
   "teaclave_rpc/mesalock_sgx",
   "teaclave_service_config/mesalock_sgx",
@@ -32,7 +32,7 @@ thiserror   = { version = "1.0.9" }
 
 teaclave_attestation           = { path = "../../../attestation" }
 teaclave_config                = { path = "../../../config" }
-teaclave_frontend_proto        = { path = "../proto" }
+teaclave_proto                 = { path = "../../proto" }
 teaclave_ipc                   = { path = "../../../ipc" }
 teaclave_rpc                   = { path = "../../../rpc" }
 teaclave_service_config        = { path = "../../../utils/service_config" }
diff --git a/services/teaclave_frontend/sgx_trusted_lib/src/lib.rs b/services/teaclave_frontend/sgx_trusted_lib/src/lib.rs
index 56e5911..bac086d 100644
--- a/services/teaclave_frontend/sgx_trusted_lib/src/lib.rs
+++ b/services/teaclave_frontend/sgx_trusted_lib/src/lib.rs
@@ -39,7 +39,7 @@ use teaclave_service_config as config;
 use teaclave_service_enclave_utils::ServiceEnclave;
 
 use teaclave_attestation::RemoteAttestation;
-use teaclave_frontend_proto::proto::{TeaclaveFrontendRequest, TeaclaveFrontendResponse};
+use teaclave_proto::teaclave_frontend::{TeaclaveFrontendRequest, TeaclaveFrontendResponse};
 use teaclave_rpc::config::SgxTrustedTlsServerConfig;
 use teaclave_rpc::server::SgxTrustedTlsServer;
 
diff --git a/services/teaclave_frontend/sgx_trusted_lib/src/service.rs b/services/teaclave_frontend/sgx_trusted_lib/src/service.rs
index bd6745e..3e55c1c 100644
--- a/services/teaclave_frontend/sgx_trusted_lib/src/service.rs
+++ b/services/teaclave_frontend/sgx_trusted_lib/src/service.rs
@@ -1,5 +1,7 @@
 use std::prelude::v1::*;
-use teaclave_frontend_proto::{TeaclaveFrontend, UserLoginRequest, UserLoginResponse};
+use teaclave_proto::teaclave_frontend::{
+    self, TeaclaveFrontend, UserLoginRequest, UserLoginResponse,
+};
 use teaclave_service_enclave_utils::teaclave_service;
 
 use teaclave_types::TeaclaveServiceError;
@@ -20,7 +22,7 @@ impl From<TeaclaveFrontendError> for TeaclaveServiceError {
     }
 }
 
-#[teaclave_service(teaclave_frontend_proto, TeaclaveFrontend, TeaclaveFrontendError)]
+#[teaclave_service(teaclave_frontend, TeaclaveFrontend, TeaclaveFrontendError)]
 #[derive(Copy, Clone)]
 pub(crate) struct TeaclaveFrontendService;
 
diff --git a/utils/service_enclave_utils/proc_macro/src/lib.rs b/utils/service_enclave_utils/proc_macro/src/lib.rs
index 7a9f08c..c4b7d23 100644
--- a/utils/service_enclave_utils/proc_macro/src/lib.rs
+++ b/utils/service_enclave_utils/proc_macro/src/lib.rs
@@ -26,8 +26,8 @@ pub fn teaclave_service(attr: TokenStream, input: TokenStream) -> TokenStream
{
         {
             fn handle_request(
                 &self,
-                request: teaclave_frontend_proto::proto::#request,
-            ) -> std::result::Result<teaclave_frontend_proto::proto::#response, teaclave_types::TeaclaveServiceError>
{
+                request: #crate_name::proto::#request,
+            ) -> std::result::Result<#crate_name::proto::#response, teaclave_types::TeaclaveServiceError>
{
                 use #crate_name::proto::#trait_name_ident;
                 use log::trace;
                 trace!("Dispatching request.");


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org


Mime
View raw message