Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3347363
D5487.id18187.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D5487.id18187.diff
View Options
diff --git a/services/tunnelbroker/src/cxx_bridge.rs b/services/tunnelbroker/src/cxx_bridge.rs
--- a/services/tunnelbroker/src/cxx_bridge.rs
+++ b/services/tunnelbroker/src/cxx_bridge.rs
@@ -1,7 +1,17 @@
#[cxx::bridge]
pub mod ffi {
+ struct GrpcResult {
+ statusCode: u8,
+ errorText: String,
+ }
+ struct SessionSignatureResult {
+ toSign: String,
+ grpcStatus: GrpcResult,
+ }
+
unsafe extern "C++" {
include!("tunnelbroker/src/libcpp/Tunnelbroker.h");
pub fn initialize();
+ pub fn sessionSignatureHandler(deviceID: &str) -> SessionSignatureResult;
}
}
diff --git a/services/tunnelbroker/src/libcpp/Tunnelbroker.h b/services/tunnelbroker/src/libcpp/Tunnelbroker.h
--- a/services/tunnelbroker/src/libcpp/Tunnelbroker.h
+++ b/services/tunnelbroker/src/libcpp/Tunnelbroker.h
@@ -1,5 +1,7 @@
#pragma once
#include "rust/cxx.h"
+#include "tunnelbroker/src/cxx_bridge.rs.h"
void initialize();
+SessionSignatureResult sessionSignatureHandler(rust::Str deviceID);
diff --git a/services/tunnelbroker/src/libcpp/Tunnelbroker.cpp b/services/tunnelbroker/src/libcpp/Tunnelbroker.cpp
--- a/services/tunnelbroker/src/libcpp/Tunnelbroker.cpp
+++ b/services/tunnelbroker/src/libcpp/Tunnelbroker.cpp
@@ -7,6 +7,7 @@
#include "Tools.h"
#include "rust/cxx.h"
+#include "tunnelbroker/src/cxx_bridge.rs.h"
void initialize() {
comm::network::tools::InitLogging("tunnelbroker");
@@ -35,3 +36,23 @@
};
comm::network::AmqpManager::getInstance().init();
}
+
+SessionSignatureResult sessionSignatureHandler(rust::Str deviceID) {
+ const std::string requestedDeviceID(deviceID);
+ if (!comm::network::tools::validateDeviceID(requestedDeviceID)) {
+ return SessionSignatureResult{
+ .grpcStatus = {
+ .statusCode = 3,
+ .errorText =
+ "Format validation failed for deviceID: " + requestedDeviceID}};
+ }
+ const std::string toSign = comm::network::tools::generateRandomString(
+ comm::network::SIGNATURE_REQUEST_LENGTH);
+ std::shared_ptr<comm::network::database::SessionSignItem> SessionSignItem =
+ std::make_shared<comm::network::database::SessionSignItem>(
+ toSign, requestedDeviceID);
+ comm::network::database::DatabaseManager::getInstance().putSessionSignItem(
+ *SessionSignItem);
+
+ return SessionSignatureResult{.toSign = toSign};
+}
diff --git a/services/tunnelbroker/src/server/mod.rs b/services/tunnelbroker/src/server/mod.rs
--- a/services/tunnelbroker/src/server/mod.rs
+++ b/services/tunnelbroker/src/server/mod.rs
@@ -1,4 +1,5 @@
use super::constants;
+use super::cxx_bridge::ffi::sessionSignatureHandler;
use anyhow::Result;
use futures::Stream;
use std::pin::Pin;
@@ -7,7 +8,7 @@
use tunnelbroker::tunnelbroker_service_server::{
TunnelbrokerService, TunnelbrokerServiceServer,
};
-
+mod tools;
mod tunnelbroker {
tonic::include_proto!("tunnelbroker");
}
@@ -19,9 +20,18 @@
impl TunnelbrokerService for TunnelbrokerServiceHandlers {
async fn session_signature(
&self,
- _request: Request<tunnelbroker::SessionSignatureRequest>,
+ request: Request<tunnelbroker::SessionSignatureRequest>,
) -> Result<Response<tunnelbroker::SessionSignatureResponse>, Status> {
- Err(Status::unimplemented("Not implemented yet"))
+ let result = sessionSignatureHandler(&request.into_inner().device_id);
+ if result.grpcStatus.statusCode > 0 {
+ return Err(tools::create_tonic_status(
+ result.grpcStatus.statusCode,
+ &result.grpcStatus.errorText,
+ ));
+ }
+ Ok(Response::new(tunnelbroker::SessionSignatureResponse {
+ to_sign: result.toSign,
+ }))
}
async fn new_session(
diff --git a/services/tunnelbroker/src/server/tools.rs b/services/tunnelbroker/src/server/tools.rs
new file mode 100644
--- /dev/null
+++ b/services/tunnelbroker/src/server/tools.rs
@@ -0,0 +1,25 @@
+use tonic::{Code, Status};
+
+pub fn create_tonic_status(code: u8, text: &str) -> Status {
+ let status = match code {
+ 0 => Code::Ok,
+ 1 => Code::Cancelled,
+ 2 => Code::Unknown,
+ 3 => Code::InvalidArgument,
+ 4 => Code::DeadlineExceeded,
+ 5 => Code::NotFound,
+ 6 => Code::AlreadyExists,
+ 7 => Code::PermissionDenied,
+ 8 => Code::ResourceExhausted,
+ 9 => Code::FailedPrecondition,
+ 10 => Code::Aborted,
+ 11 => Code::OutOfRange,
+ 12 => Code::Unimplemented,
+ 13 => Code::Internal,
+ 14 => Code::Unavailable,
+ 15 => Code::DataLoss,
+ 16 => Code::Unauthenticated,
+ _ => Code::Internal,
+ };
+ Status::new(status, text)
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 23, 11:57 AM (19 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2570497
Default Alt Text
D5487.id18187.diff (4 KB)
Attached To
Mode
D5487: [services] Tunnelbroker - Adding of gRPC `SessionSignature` implementation
Attached
Detach File
Event Timeline
Log In to Comment