diff --git a/services/tunnelbroker/src/main.rs b/services/tunnelbroker/src/main.rs --- a/services/tunnelbroker/src/main.rs +++ b/services/tunnelbroker/src/main.rs @@ -2,7 +2,7 @@ pub mod cxx_bridge; pub mod notifications; pub mod server; -mod websockets; +pub mod websockets; use std::io; use tracing; diff --git a/services/tunnelbroker/src/websockets/messages.rs b/services/tunnelbroker/src/websockets/messages.rs new file mode 100644 --- /dev/null +++ b/services/tunnelbroker/src/websockets/messages.rs @@ -0,0 +1,79 @@ +// This file intends to preserve the original structure of the tunnelbroker +// protobuf RPCs. However, this is converted to simple rust datastructures +// to allow for deserialization and serialization into JSON websocket messages + +// Original Tunnelbroker Service definition: +// +// service TunnelbrokerService { +// rpc SessionSignature(SessionSignatureRequest) returns (SessionSignatureResponse) {} +// rpc NewSession(NewSessionRequest) returns (NewSessionResponse) {} +// rpc MessagesStream(stream MessageToTunnelbroker) returns (stream MessageToClient) {} +// } + +// Session +pub struct SessionSignatureRequest { + pub device_id: String, +} +pub struct SessionSignatureResponse { + pub to_sign: String, +} + +pub enum DeviceTypes { + Mobile, + Web, + Keyserver, +} + +pub struct SessionRequest { + pub device_id: String, + pub public_key: String, + pub signature: String, + pub notify_token: Option, + pub device_type: DeviceTypes, + pub device_app_version: String, + pub device_os: String, +} + +pub struct SessionResponse { + pub session_id: String, +} + +// Common messages structures for the MessagesStream +pub struct ProcessedMessages { + pub message_id: Vec, +} + +// The messages from the Client to the Tunnelbroker +pub struct MessageToTunnelbrokerStruct { + pub to_device_id: String, + pub payload: String, + pub blob_hashes: Vec, +} + +pub struct MessagesToSend { + pub messages: Vec, +} + +pub enum MessageToTunnelbroker { + Messages(MessagesToSend), + ProcessedMessages(ProcessedMessages), + NewNotifyToken(String), +} + +// The messages from the Tunnelbroker to the Client +pub struct MessageToClientStruct { + pub message_id: String, + pub from_device_id: String, + pub payload: String, + pub blob_hashes: Vec, +} + +pub struct MessagesToDeliver { + pub messages: Vec, +} + +pub enum MessageToClient { + Messages(MessagesToDeliver), + ProcessedMessages(ProcessedMessages), + NewNotifyTokenRequired, +} diff --git a/services/tunnelbroker/src/websockets/mod.rs b/services/tunnelbroker/src/websockets/mod.rs --- a/services/tunnelbroker/src/websockets/mod.rs +++ b/services/tunnelbroker/src/websockets/mod.rs @@ -1,3 +1,5 @@ +pub mod messages; + use std::{env, io::Error}; use tokio::net::{TcpListener, TcpStream};