diff --git a/keyserver/src/socket/tunnelbroker-socket.js b/keyserver/src/socket/tunnelbroker-socket.js --- a/keyserver/src/socket/tunnelbroker-socket.js +++ b/keyserver/src/socket/tunnelbroker-socket.js @@ -6,10 +6,6 @@ import { tunnelbrokerHeartbeatTimeout } from 'lib/shared/timeouts.js'; import type { ClientMessageToDevice } from 'lib/tunnelbroker/tunnelbroker-context.js'; import type { Heartbeat } from 'lib/types/tunnelbroker/heartbeat-types.js'; -import { - type RefreshKeyRequest, - refreshKeysRequestValidator, -} from 'lib/types/tunnelbroker/keys-types.js'; import type { MessageReceiveConfirmation } from 'lib/types/tunnelbroker/message-receive-confirmation-types.js'; 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'; @@ -18,6 +14,10 @@ tunnelbrokerMessageTypes, tunnelbrokerMessageValidator, } from 'lib/types/tunnelbroker/messages.js'; +import { + type RefreshKeyRequest, + refreshKeysRequestValidator, +} from 'lib/types/tunnelbroker/peer-to-peer-message-types.js'; import type { ConnectionInitializationMessage } from 'lib/types/tunnelbroker/session-types.js'; import { uploadNewOneTimeKeys } from '../utils/olm-utils.js'; diff --git a/lib/types/tunnelbroker/keys-types.js b/lib/types/tunnelbroker/keys-types.js deleted file mode 100644 --- a/lib/types/tunnelbroker/keys-types.js +++ /dev/null @@ -1,19 +0,0 @@ -// @flow - -import type { TInterface } from 'tcomb'; -import t from 'tcomb'; - -import { tShape, tString } from '../../utils/validation-utils.js'; - -export type RefreshKeyRequest = { - +type: 'RefreshKeyRequest', - +deviceID: string, - +numberOfKeys: number, -}; - -export const refreshKeysRequestValidator: TInterface = - tShape({ - type: tString('RefreshKeyRequest'), - deviceID: t.String, - numberOfKeys: t.Number, - }); 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 @@ -8,10 +8,6 @@ connectionInitializationResponseValidator, } from './connection-initialization-response-types.js'; import { type Heartbeat, heartbeatValidator } from './heartbeat-types.js'; -import { - type RefreshKeyRequest, - refreshKeysRequestValidator, -} from './keys-types.js'; import { type MessageReceiveConfirmation, messageReceiveConfirmationValidator, @@ -45,7 +41,6 @@ */ export const tunnelbrokerMessageTypes = Object.freeze({ - REFRESH_KEYS_REQUEST: 'RefreshKeyRequest', CONNECTION_INITIALIZATION_MESSAGE: 'ConnectionInitializationMessage', CONNECTION_INITIALIZATION_RESPONSE: 'ConnectionInitializationResponse', MESSAGE_TO_DEVICE_REQUEST_STATUS: 'MessageToDeviceRequestStatus', @@ -57,7 +52,6 @@ export const tunnelbrokerMessageValidator: TUnion = t.union([ - refreshKeysRequestValidator, connectionInitializationMessageValidator, connectionInitializationResponseValidator, messageToDeviceRequestStatusValidator, @@ -68,7 +62,6 @@ ]); export type TunnelbrokerMessage = - | RefreshKeyRequest | ConnectionInitializationMessage | ConnectionInitializationResponse | MessageToDeviceRequestStatus diff --git a/lib/types/tunnelbroker/peer-to-peer-message-types.js b/lib/types/tunnelbroker/peer-to-peer-message-types.js --- a/lib/types/tunnelbroker/peer-to-peer-message-types.js +++ b/lib/types/tunnelbroker/peer-to-peer-message-types.js @@ -3,7 +3,7 @@ import type { TInterface, TUnion } from 'tcomb'; import t from 'tcomb'; -import { tNumber, tShape } from '../../utils/validation-utils.js'; +import { tNumber, tShape, tString } from '../../utils/validation-utils.js'; export type SenderInfo = { +userID: string, @@ -17,6 +17,7 @@ export const peerToPeerMessageTypes = Object.freeze({ OUTBOUND_SESSION_CREATION: 0, ENCRYPTED_MESSAGE: 1, + REFRESH_KEY_REQUEST: 'RefreshKeyRequest', }); export type OutboundSessionCreation = { @@ -43,8 +44,25 @@ encryptedContent: t.String, }); -export type PeerToPeerMessage = OutboundSessionCreation | EncryptedMessage; +export type RefreshKeyRequest = { + +type: 'RefreshKeyRequest', + +deviceID: string, + +numberOfKeys: number, +}; +export const refreshKeysRequestValidator: TInterface = + tShape({ + type: tString('RefreshKeyRequest'), + deviceID: t.String, + numberOfKeys: t.Number, + }); + +export type PeerToPeerMessage = + | OutboundSessionCreation + | EncryptedMessage + | RefreshKeyRequest; + export const peerToPeerMessageValidator: TUnion = t.union([ outboundSessionCreationValidator, encryptedMessageValidator, + refreshKeysRequestValidator, ]); 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 @@ -31,7 +31,6 @@ #[derive(Serialize, Deserialize, Debug)] #[serde(untagged)] pub enum Messages { - RefreshKeysRequest(RefreshKeyRequest), ConnectionInitializationMessage(ConnectionInitializationMessage), ConnectionInitializationResponse(ConnectionInitializationResponse), // MessageToDeviceRequestStatus must be placed before MessageToDeviceRequest. @@ -43,3 +42,9 @@ MessageReceiveConfirmation(MessageReceiveConfirmation), Heartbeat(Heartbeat), } + +#[derive(Serialize, Deserialize, Debug)] +#[serde(untagged)] +pub enum PeerToPeerMessages { + RefreshKeysRequest(RefreshKeyRequest), +}