diff --git a/keyserver/src/socket/tunnelbroker.js b/keyserver/src/socket/tunnelbroker.js --- a/keyserver/src/socket/tunnelbroker.js +++ b/keyserver/src/socket/tunnelbroker.js @@ -16,9 +16,10 @@ import type { MessageSentStatus } from 'lib/types/tunnelbroker/message-to-device-request-status-types.js'; import type { MessageToDeviceRequest } from 'lib/types/tunnelbroker/message-to-device-request-types.js'; import { - type TunnelbrokerMessage, - tunnelbrokerMessageTypes, - tunnelbrokerMessageValidator, + deviceToTunnelbrokerMessageTypes, + tunnelbrokerToDeviceMessageTypes, + tunnelbrokerToDeviceMessageValidator, + type TunnelbrokerToDeviceMessage, } from 'lib/types/tunnelbroker/messages.js'; import { qrCodeAuthMessageValidator, @@ -214,17 +215,20 @@ return; } - if (!tunnelbrokerMessageValidator.is(rawMessage)) { - console.error('invalid TunnelbrokerMessage: ', rawMessage.toString()); + if (!tunnelbrokerToDeviceMessageValidator.is(rawMessage)) { + console.error( + 'invalid tunnelbrokerToDeviceMessage: ', + rawMessage.toString(), + ); return; } - const message: TunnelbrokerMessage = rawMessage; + const message: TunnelbrokerToDeviceMessage = rawMessage; this.resetHeartbeatTimeout(); if ( message.type === - tunnelbrokerMessageTypes.CONNECTION_INITIALIZATION_RESPONSE + tunnelbrokerToDeviceMessageTypes.CONNECTION_INITIALIZATION_RESPONSE ) { if (message.status.type === 'Success' && !this.connected) { this.connected = true; @@ -264,9 +268,11 @@ message.status.data, ); } - } else if (message.type === tunnelbrokerMessageTypes.MESSAGE_TO_DEVICE) { + } else if ( + message.type === tunnelbrokerToDeviceMessageTypes.MESSAGE_TO_DEVICE + ) { const confirmation: MessageReceiveConfirmation = { - type: tunnelbrokerMessageTypes.MESSAGE_RECEIVE_CONFIRMATION, + type: deviceToTunnelbrokerMessageTypes.MESSAGE_RECEIVE_CONFIRMATION, messageIDs: [message.messageID], }; this.ws.send(JSON.stringify(confirmation)); @@ -330,7 +336,8 @@ ); } } else if ( - message.type === tunnelbrokerMessageTypes.MESSAGE_TO_DEVICE_REQUEST_STATUS + message.type === + tunnelbrokerToDeviceMessageTypes.MESSAGE_TO_DEVICE_REQUEST_STATUS ) { for (const status: MessageSentStatus of message.clientMessageIDs) { if (status.type === 'Success') { @@ -355,9 +362,9 @@ console.log('Tunnelbroker recorded InvalidRequest'); } } - } else if (message.type === tunnelbrokerMessageTypes.HEARTBEAT) { + } else if (message.type === tunnelbrokerToDeviceMessageTypes.HEARTBEAT) { const heartbeat: Heartbeat = { - type: tunnelbrokerMessageTypes.HEARTBEAT, + type: deviceToTunnelbrokerMessageTypes.HEARTBEAT, }; this.ws.send(JSON.stringify(heartbeat)); } @@ -385,7 +392,7 @@ } const clientMessageID = uuid.v4(); const messageToDevice: MessageToDeviceRequest = { - type: tunnelbrokerMessageTypes.MESSAGE_TO_DEVICE_REQUEST, + type: deviceToTunnelbrokerMessageTypes.MESSAGE_TO_DEVICE_REQUEST, clientMessageID, deviceID: message.deviceID, payload: message.payload, diff --git a/lib/components/qr-auth-provider.react.js b/lib/components/qr-auth-provider.react.js --- a/lib/components/qr-auth-provider.react.js +++ b/lib/components/qr-auth-provider.react.js @@ -9,8 +9,8 @@ import { useTunnelbroker } from '../tunnelbroker/tunnelbroker-context.js'; import type { BackupKeys } from '../types/backup-types.js'; import { - tunnelbrokerMessageTypes, - type TunnelbrokerMessage, + tunnelbrokerToDeviceMessageTypes, + type TunnelbrokerToDeviceMessage, } from '../types/tunnelbroker/messages.js'; import { type QRCodeAuthMessage, @@ -135,11 +135,11 @@ ]); const tunnelbrokerMessageListener = React.useCallback( - async (message: TunnelbrokerMessage) => { + async (message: TunnelbrokerToDeviceMessage) => { invariant(identityClient, 'identity context not set'); if ( !qrData?.aesKey || - message.type !== tunnelbrokerMessageTypes.MESSAGE_TO_DEVICE + message.type !== tunnelbrokerToDeviceMessageTypes.MESSAGE_TO_DEVICE ) { return; } diff --git a/lib/tunnelbroker/peer-to-peer-message-handler.js b/lib/tunnelbroker/peer-to-peer-message-handler.js --- a/lib/tunnelbroker/peer-to-peer-message-handler.js +++ b/lib/tunnelbroker/peer-to-peer-message-handler.js @@ -6,8 +6,9 @@ import { usePeerToPeerMessageHandler } from './use-peer-to-peer-message-handler.js'; import type { MessageReceiveConfirmation } from '../types/tunnelbroker/message-receive-confirmation-types.js'; import { - tunnelbrokerMessageTypes, - type TunnelbrokerMessage, + deviceToTunnelbrokerMessageTypes, + type TunnelbrokerToDeviceMessage, + tunnelbrokerToDeviceMessageTypes, } from '../types/tunnelbroker/messages.js'; import { peerToPeerMessageValidator, @@ -28,12 +29,12 @@ const currentlyProcessedMessage = React.useRef>(null); const tunnelbrokerMessageListener = React.useCallback( - async (message: TunnelbrokerMessage) => { - if (message.type !== tunnelbrokerMessageTypes.MESSAGE_TO_DEVICE) { + async (message: TunnelbrokerToDeviceMessage) => { + if (message.type !== tunnelbrokerToDeviceMessageTypes.MESSAGE_TO_DEVICE) { return; } const confirmation: MessageReceiveConfirmation = { - type: tunnelbrokerMessageTypes.MESSAGE_RECEIVE_CONFIRMATION, + type: deviceToTunnelbrokerMessageTypes.MESSAGE_RECEIVE_CONFIRMATION, messageIDs: [message.messageID], }; diff --git a/lib/tunnelbroker/tunnelbroker-context.js b/lib/tunnelbroker/tunnelbroker-context.js --- a/lib/tunnelbroker/tunnelbroker-context.js +++ b/lib/tunnelbroker/tunnelbroker-context.js @@ -16,9 +16,10 @@ import type { MessageToDeviceRequest } from '../types/tunnelbroker/message-to-device-request-types.js'; import type { MessageToTunnelbrokerRequest } from '../types/tunnelbroker/message-to-tunnelbroker-request-types.js'; import { - type TunnelbrokerMessage, - tunnelbrokerMessageTypes, - tunnelbrokerMessageValidator, + deviceToTunnelbrokerMessageTypes, + tunnelbrokerToDeviceMessageTypes, + tunnelbrokerToDeviceMessageValidator, + type TunnelbrokerToDeviceMessage, } from '../types/tunnelbroker/messages.js'; import type { TunnelbrokerAPNsNotif, @@ -41,7 +42,7 @@ }; export type TunnelbrokerSocketListener = ( - message: TunnelbrokerMessage, + message: TunnelbrokerToDeviceMessage, ) => mixed; type PromiseCallbacks = { @@ -238,11 +239,11 @@ return; } - if (!tunnelbrokerMessageValidator.is(rawMessage)) { + if (!tunnelbrokerToDeviceMessageValidator.is(rawMessage)) { console.log('invalid TunnelbrokerMessage'); return; } - const message: TunnelbrokerMessage = rawMessage; + const message: TunnelbrokerToDeviceMessage = rawMessage; resetHeartbeatTimeout(); @@ -253,7 +254,7 @@ // MESSAGE_TO_DEVICE is handled in PeerToPeerMessageHandler if ( message.type === - tunnelbrokerMessageTypes.CONNECTION_INITIALIZATION_RESPONSE + tunnelbrokerToDeviceMessageTypes.CONNECTION_INITIALIZATION_RESPONSE ) { if (message.status.type === 'Success' && !socketState.connected) { setSocketState({ connected: true, isAuthorized }); @@ -277,7 +278,7 @@ } } else if ( message.type === - tunnelbrokerMessageTypes.MESSAGE_TO_DEVICE_REQUEST_STATUS + tunnelbrokerToDeviceMessageTypes.MESSAGE_TO_DEVICE_REQUEST_STATUS ) { for (const status: MessageSentStatus of message.clientMessageIDs) { if (status.type === 'Success') { @@ -292,9 +293,11 @@ console.log('Tunnelbroker recorded InvalidRequest'); } } - } else if (message.type === tunnelbrokerMessageTypes.HEARTBEAT) { + } else if ( + message.type === tunnelbrokerToDeviceMessageTypes.HEARTBEAT + ) { const heartbeat: Heartbeat = { - type: tunnelbrokerMessageTypes.HEARTBEAT, + type: deviceToTunnelbrokerMessageTypes.HEARTBEAT, }; socket.current?.send(JSON.stringify(heartbeat)); } @@ -351,7 +354,7 @@ (message: TunnelbrokerClientMessageToDevice, messageID: ?string) => { const clientMessageID = messageID ?? uuid.v4(); const messageToDevice: MessageToDeviceRequest = { - type: tunnelbrokerMessageTypes.MESSAGE_TO_DEVICE_REQUEST, + type: deviceToTunnelbrokerMessageTypes.MESSAGE_TO_DEVICE_REQUEST, clientMessageID, deviceID: message.deviceID, payload: message.payload, @@ -367,7 +370,7 @@ (payload: string) => { const clientMessageID = uuid.v4(); const messageToTunnelbroker: MessageToTunnelbrokerRequest = { - type: tunnelbrokerMessageTypes.MESSAGE_TO_TUNNELBROKER_REQUEST, + type: deviceToTunnelbrokerMessageTypes.MESSAGE_TO_TUNNELBROKER_REQUEST, clientMessageID, payload, }; diff --git a/lib/types/tunnelbroker/messages.js b/lib/types/tunnelbroker/messages.js --- a/lib/types/tunnelbroker/messages.js +++ b/lib/types/tunnelbroker/messages.js @@ -3,30 +3,24 @@ import type { TUnion } from 'tcomb'; import t from 'tcomb'; -import { - type MessageReceiveConfirmation, - messageReceiveConfirmationValidator, -} from './message-receive-confirmation-types.js'; +import { type MessageReceiveConfirmation } from './message-receive-confirmation-types.js'; import { type MessageToDeviceRequestStatus, messageToDeviceRequestStatusValidator, } from './message-to-device-request-status-types.js'; -import { - type MessageToDeviceRequest, - messageToDeviceRequestValidator, -} from './message-to-device-request-types.js'; +import { type MessageToDeviceRequest } from './message-to-device-request-types.js'; import { type MessageToDevice, messageToDeviceValidator, } from './message-to-device-types.js'; +import { type MessageToTunnelbrokerRequest } from './message-to-tunnelbroker-request-types.js'; import { - type MessageToTunnelbrokerRequest, - messageToTunnelbrokerRequestValidator, -} from './message-to-tunnelbroker-request-types.js'; -import { type TunnelbrokerAPNsNotif } from './notif-types.js'; + type TunnelbrokerAPNsNotif, + type TunnelbrokerFCMNotif, +} from './notif-types.js'; import { + type AnonymousInitializationMessage, type ConnectionInitializationMessage, - connectionInitializationMessageValidator, } from './session-types.js'; import { type ConnectionInitializationResponse, @@ -48,38 +42,46 @@ * */ -export const tunnelbrokerMessageTypes = Object.freeze({ +// Messages sent from Device to Tunnelbroker. +export const deviceToTunnelbrokerMessageTypes = Object.freeze({ CONNECTION_INITIALIZATION_MESSAGE: 'ConnectionInitializationMessage', - CONNECTION_INITIALIZATION_RESPONSE: 'ConnectionInitializationResponse', ANONYMOUS_INITIALIZATION_MESSAGE: 'AnonymousInitializationMessage', TUNNELBROKER_APNS_NOTIF: 'APNsNotif', - MESSAGE_TO_DEVICE_REQUEST_STATUS: 'MessageToDeviceRequestStatus', + TUNNELBROKER_FCM_NOTIF: 'FCMNotif', MESSAGE_TO_DEVICE_REQUEST: 'MessageToDeviceRequest', + MESSAGE_RECEIVE_CONFIRMATION: 'MessageReceiveConfirmation', MESSAGE_TO_TUNNELBROKER_REQUEST: 'MessageToTunnelbrokerRequest', + HEARTBEAT: 'Heartbeat', +}); + +export type DeviceToTunnelbrokerMessage = + | ConnectionInitializationMessage + | AnonymousInitializationMessage + | TunnelbrokerAPNsNotif + | TunnelbrokerFCMNotif + | MessageToDeviceRequest + | MessageReceiveConfirmation + | MessageToTunnelbrokerRequest + | Heartbeat; + +// Messages sent from Tunnelbroker to Device. +export const tunnelbrokerToDeviceMessageTypes = Object.freeze({ + CONNECTION_INITIALIZATION_RESPONSE: 'ConnectionInitializationResponse', + MESSAGE_TO_DEVICE_REQUEST_STATUS: 'MessageToDeviceRequestStatus', MESSAGE_TO_DEVICE: 'MessageToDevice', - MESSAGE_RECEIVE_CONFIRMATION: 'MessageReceiveConfirmation', HEARTBEAT: 'Heartbeat', }); -export const tunnelbrokerMessageValidator: TUnion = +export type TunnelbrokerToDeviceMessage = + | ConnectionInitializationResponse + | MessageToDeviceRequestStatus + | MessageToDevice + | Heartbeat; + +export const tunnelbrokerToDeviceMessageValidator: TUnion = t.union([ - connectionInitializationMessageValidator, connectionInitializationResponseValidator, messageToDeviceRequestStatusValidator, - messageToDeviceRequestValidator, messageToDeviceValidator, - messageReceiveConfirmationValidator, heartbeatValidator, - messageToTunnelbrokerRequestValidator, ]); - -export type TunnelbrokerMessage = - | ConnectionInitializationMessage - | ConnectionInitializationResponse - | MessageToDeviceRequestStatus - | MessageToDeviceRequest - | MessageToDevice - | MessageReceiveConfirmation - | Heartbeat - | MessageToTunnelbrokerRequest - | TunnelbrokerAPNsNotif; diff --git a/native/profile/secondary-device-qr-code-scanner.react.js b/native/profile/secondary-device-qr-code-scanner.react.js --- a/native/profile/secondary-device-qr-code-scanner.react.js +++ b/native/profile/secondary-device-qr-code-scanner.react.js @@ -20,8 +20,8 @@ type BackupKeys, } from 'lib/types/backup-types.js'; import { - tunnelbrokerMessageTypes, - type TunnelbrokerMessage, + tunnelbrokerToDeviceMessageTypes, + type TunnelbrokerToDeviceMessage, } from 'lib/types/tunnelbroker/messages.js'; import { peerToPeerMessageTypes, @@ -53,6 +53,7 @@ +navigation: ProfileNavigationProp<'SecondaryDeviceQRCodeScanner'>, +route: NavigationRoute<'SecondaryDeviceQRCodeScanner'>, }; + // eslint-disable-next-line no-unused-vars function SecondaryDeviceQRCodeScanner(props: Props): React.Node { const [hasPermission, setHasPermission] = React.useState(null); @@ -77,13 +78,13 @@ const { panelForegroundTertiaryLabel } = useColors(); const tunnelbrokerMessageListener = React.useCallback( - async (message: TunnelbrokerMessage) => { + async (message: TunnelbrokerToDeviceMessage) => { const encryptionKey = aes256Key.current; const targetDeviceID = secondaryDeviceID.current; if (!encryptionKey || !targetDeviceID) { return; } - if (message.type !== tunnelbrokerMessageTypes.MESSAGE_TO_DEVICE) { + if (message.type !== tunnelbrokerToDeviceMessageTypes.MESSAGE_TO_DEVICE) { return; } diff --git a/native/profile/tunnelbroker-menu.react.js b/native/profile/tunnelbroker-menu.react.js --- a/native/profile/tunnelbroker-menu.react.js +++ b/native/profile/tunnelbroker-menu.react.js @@ -8,8 +8,8 @@ import { IdentityClientContext } from 'lib/shared/identity-client-context.js'; import { useTunnelbroker } from 'lib/tunnelbroker/tunnelbroker-context.js'; import { - tunnelbrokerMessageTypes, - type TunnelbrokerMessage, + tunnelbrokerToDeviceMessageTypes, + type TunnelbrokerToDeviceMessage, } from 'lib/types/tunnelbroker/messages.js'; import { type EncryptedMessage, @@ -44,7 +44,7 @@ const { socketState, addListener, sendMessage, removeListener } = useTunnelbroker(); - const [messages, setMessages] = useState([]); + const [messages, setMessages] = useState([]); const [recipient, setRecipient] = useState(''); const [message, setMessage] = useState(''); const [deviceID, setDeviceID] = React.useState(); @@ -56,7 +56,7 @@ })(); }, []); - const listener = React.useCallback((msg: TunnelbrokerMessage) => { + const listener = React.useCallback((msg: TunnelbrokerToDeviceMessage) => { setMessages(prev => [...prev, msg]); }, []); @@ -195,7 +195,7 @@ MESSAGES {messages - .filter(msg => msg.type !== tunnelbrokerMessageTypes.HEARTBEAT) + .filter(msg => msg.type !== tunnelbrokerToDeviceMessageTypes.HEARTBEAT) .map((msg, id) => ( {JSON.stringify(msg)} diff --git a/services/commtest/src/tunnelbroker/socket.rs b/services/commtest/src/tunnelbroker/socket.rs --- a/services/commtest/src/tunnelbroker/socket.rs +++ b/services/commtest/src/tunnelbroker/socket.rs @@ -8,7 +8,8 @@ use tunnelbroker_messages::{ ConnectionInitializationMessage, ConnectionInitializationResponse, ConnectionInitializationStatus, DeviceTypes, Heartbeat, MessageSentStatus, - MessageToDeviceRequest, MessageToDeviceRequestStatus, Messages, + MessageToDeviceRequest, MessageToDeviceRequestStatus, + TunnelbrokerToDeviceMessage, }; #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] @@ -93,9 +94,10 @@ while let Some(Ok(response)) = socket.next().await { let message_str = response.to_text().expect("Failed to get response content"); - let message = serde_json::from_str::(message_str).unwrap(); + let message = + serde_json::from_str::(message_str).unwrap(); match message { - Messages::MessageToDevice(msg) => { + TunnelbrokerToDeviceMessage::MessageToDevice(msg) => { let confirmation = tunnelbroker_messages::MessageReceiveConfirmation { message_ids: vec![msg.message_id], }; @@ -104,7 +106,7 @@ socket.send(Message::Text(serialized_confirmation)).await?; return Ok(msg.payload); } - Messages::Heartbeat(Heartbeat {}) => { + TunnelbrokerToDeviceMessage::Heartbeat(Heartbeat {}) => { let msg = Heartbeat {}; let serialized = serde_json::to_string(&msg).unwrap(); socket.send(Message::Text(serialized)).await?; diff --git a/services/tunnelbroker/src/websockets/session.rs b/services/tunnelbroker/src/websockets/session.rs --- a/services/tunnelbroker/src/websockets/session.rs +++ b/services/tunnelbroker/src/websockets/session.rs @@ -22,8 +22,8 @@ use tunnelbroker_messages::{ message_to_device_request_status::Failure, message_to_device_request_status::MessageSentStatus, session::DeviceTypes, - Heartbeat, MessageToDevice, MessageToDeviceRequest, MessageToTunnelbroker, - Messages, + DeviceToTunnelbrokerMessage, Heartbeat, MessageToDevice, + MessageToDeviceRequest, MessageToTunnelbroker, }; use crate::database::{self, DatabaseClient, MessageToDeviceExt}; @@ -75,10 +75,13 @@ pub async fn handle_first_message_from_device( message: &str, ) -> Result { - let serialized_message = serde_json::from_str::(message)?; + let serialized_message = + serde_json::from_str::(message)?; match serialized_message { - Messages::ConnectionInitializationMessage(mut session_info) => { + DeviceToTunnelbrokerMessage::ConnectionInitializationMessage( + mut session_info, + ) => { let device_info = DeviceInfo { device_id: session_info.device_id.clone(), notify_token: session_info.notify_token.take(), @@ -116,7 +119,9 @@ Ok(device_info) } - Messages::AnonymousInitializationMessage(session_info) => { + DeviceToTunnelbrokerMessage::AnonymousInitializationMessage( + session_info, + ) => { debug!( "Starting unauthenticated session with device: {}", &session_info.device_id @@ -286,16 +291,18 @@ &mut self, msg: String, ) -> Option { - let Ok(serialized_message) = serde_json::from_str::(&msg) else { + let Ok(serialized_message) = + serde_json::from_str::(&msg) + else { return Some(MessageSentStatus::SerializationError(msg)); }; match serialized_message { - Messages::Heartbeat(Heartbeat {}) => { + DeviceToTunnelbrokerMessage::Heartbeat(Heartbeat {}) => { trace!("Received heartbeat from: {}", self.device_info.device_id); None } - Messages::MessageReceiveConfirmation(confirmation) => { + DeviceToTunnelbrokerMessage::MessageReceiveConfirmation(confirmation) => { for message_id in confirmation.message_ids { if let Err(e) = self .db_client @@ -308,7 +315,7 @@ None } - Messages::MessageToDeviceRequest(message_request) => { + DeviceToTunnelbrokerMessage::MessageToDeviceRequest(message_request) => { // unauthenticated clients cannot send messages if !self.device_info.is_authenticated { debug!( @@ -325,7 +332,9 @@ result, )) } - Messages::MessageToTunnelbrokerRequest(message_request) => { + DeviceToTunnelbrokerMessage::MessageToTunnelbrokerRequest( + message_request, + ) => { // unauthenticated clients cannot send messages if !self.device_info.is_authenticated { debug!( @@ -352,7 +361,7 @@ result, )) } - Messages::APNsNotif(notif) => { + DeviceToTunnelbrokerMessage::APNsNotif(notif) => { // unauthenticated clients cannot send notifs if !self.device_info.is_authenticated { debug!( @@ -398,7 +407,7 @@ Err(SessionError::MissingAPNsClient), )) } - Messages::FCMNotif(notif) => { + DeviceToTunnelbrokerMessage::FCMNotif(notif) => { // unauthenticated clients cannot send notifs if !self.device_info.is_authenticated { debug!( diff --git a/shared/tunnelbroker_messages/src/messages/mod.rs b/shared/tunnelbroker_messages/src/messages/mod.rs --- a/shared/tunnelbroker_messages/src/messages/mod.rs +++ b/shared/tunnelbroker_messages/src/messages/mod.rs @@ -35,33 +35,41 @@ // If you edit the definitions in one file, // please make sure to update the corresponding definitions in the other. +// Messages sent from Device to Tunnelbroker. #[derive(Serialize, Deserialize, Debug)] #[serde(untagged)] -pub enum Messages { +pub enum DeviceToTunnelbrokerMessage { ConnectionInitializationMessage(ConnectionInitializationMessage), - ConnectionInitializationResponse(ConnectionInitializationResponse), AnonymousInitializationMessage(AnonymousInitializationMessage), - // MessageToDeviceRequestStatus must be placed before MessageToDeviceRequest. - // This is due to serde's pattern matching behavior where it prioritizes - // the first matching pattern it encounters. APNsNotif(APNsNotif), FCMNotif(FCMNotif), - MessageToDeviceRequestStatus(MessageToDeviceRequestStatus), MessageToDeviceRequest(MessageToDeviceRequest), - MessageToDevice(MessageToDevice), MessageReceiveConfirmation(MessageReceiveConfirmation), MessageToTunnelbrokerRequest(MessageToTunnelbrokerRequest), Heartbeat(Heartbeat), - IdentityDeviceListUpdated(IdentityDeviceListUpdated), } +// Messages sent from Tunnelbroker to Device. +#[derive(Serialize, Deserialize, Debug)] +#[serde(untagged)] +pub enum TunnelbrokerToDeviceMessage { + ConnectionInitializationResponse(ConnectionInitializationResponse), + MessageToDeviceRequestStatus(MessageToDeviceRequestStatus), + MessageToDevice(MessageToDevice), + Heartbeat(Heartbeat), +} + +// Messages sent from Services (e.g. Identity) to Device. +// This type is sent to a Device as a payload of MessageToDevice. #[derive(Serialize, Deserialize, Debug)] #[serde(untagged)] -pub enum PeerToPeerMessages { +pub enum ServiceToDeviceMessages { RefreshKeysRequest(RefreshKeyRequest), IdentityDeviceListUpdated(IdentityDeviceListUpdated), } +// Messages sent from Device to Tunnelbroker which Tunnelbroker itself should handle. +// This type is sent to a Tunnelbroker as a payload of MessageToTunnelbrokerRequest. #[derive(Serialize, Deserialize, Debug)] #[serde(untagged)] pub enum MessageToTunnelbroker { diff --git a/web/settings/tunnelbroker-message-list.react.js b/web/settings/tunnelbroker-message-list.react.js --- a/web/settings/tunnelbroker-message-list.react.js +++ b/web/settings/tunnelbroker-message-list.react.js @@ -4,8 +4,8 @@ import type { TunnelbrokerSocketListener } from 'lib/tunnelbroker/tunnelbroker-context.js'; import { - tunnelbrokerMessageTypes, - type TunnelbrokerMessage, + type TunnelbrokerToDeviceMessage, + tunnelbrokerToDeviceMessageTypes, } from 'lib/types/tunnelbroker/messages.js'; import css from './tunnelbroker-message-list.css'; @@ -19,9 +19,11 @@ function TunnelbrokerMessagesScreen(props: Props): React.Node { const { addListener, onClose, removeListener } = props; - const [messages, setMessages] = React.useState([]); + const [messages, setMessages] = React.useState( + [], + ); - const listener = React.useCallback((msg: TunnelbrokerMessage) => { + const listener = React.useCallback((msg: TunnelbrokerToDeviceMessage) => { setMessages(prev => [...prev, msg]); }, []); @@ -37,7 +39,9 @@ ); if (messages.length) { messageList = messages - .filter(message => message.type !== tunnelbrokerMessageTypes.HEARTBEAT) + .filter( + message => message.type !== tunnelbrokerToDeviceMessageTypes.HEARTBEAT, + ) .map((message, id) => (
{JSON.stringify(message)}