Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32894072
D14740.1768176337.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D14740.1768176337.diff
View Options
diff --git a/lib/tunnelbroker/use-peer-to-peer-message-handler.js b/lib/tunnelbroker/use-peer-to-peer-message-handler.js
--- a/lib/tunnelbroker/use-peer-to-peer-message-handler.js
+++ b/lib/tunnelbroker/use-peer-to-peer-message-handler.js
@@ -1,6 +1,7 @@
// @flow
import invariant from 'invariant';
+import _debounce from 'lodash/debounce.js';
import _isEqual from 'lodash/fp/isEqual.js';
import * as React from 'react';
import uuid from 'uuid';
@@ -10,6 +11,7 @@
import { invalidateTunnelbrokerDeviceTokenActionType } from '../actions/tunnelbroker-actions.js';
import { logOutActionTypes, useBaseLogOut } from '../actions/user-actions.js';
import {
+ type OlmDebugLog,
useDebugLogs,
useOlmDebugLogs,
} from '../components/debug-logs-context.js';
@@ -27,11 +29,15 @@
import { dmOperationSpecificationTypes } from '../shared/dm-ops/dm-op-types.js';
import { useProcessDMOperation } from '../shared/dm-ops/process-dm-ops.js';
import { IdentityClientContext } from '../shared/identity-client-context.js';
-import type { DeviceOlmInboundKeys } from '../types/identity-service-types.js';
+import type {
+ IdentityServiceClient,
+ DeviceOlmInboundKeys,
+} from '../types/identity-service-types';
import {
peerToPeerMessageTypes,
type PeerToPeerMessage,
type SenderInfo,
+ type RefreshKeyRequest,
} from '../types/tunnelbroker/peer-to-peer-message-types.js';
import {
userActionsP2PMessageTypes,
@@ -451,26 +457,7 @@
});
}
} else if (message.type === peerToPeerMessageTypes.REFRESH_KEY_REQUEST) {
- let resultDescription = 'starting',
- success = false;
- try {
- await olmAPI.initializeCryptoAccount();
- resultDescription = 'getting OTKs';
- const oneTimeKeys = await olmAPI.getOneTimeKeys(message.numberOfKeys);
- resultDescription = 'uploading OTKs';
- await identityClient.uploadOneTimeKeys(oneTimeKeys);
- success = true;
- } catch (e) {
- resultDescription = `Error uploading one-time keys: ${
- getMessageForException(e) ?? ''
- }`;
- } finally {
- olmDebugLog({
- operation: 'uploadOneTimeKeys',
- success,
- resultDescription,
- });
- }
+ await debouncedRefreshOneTimeKeys(message, identityClient, olmDebugLog);
} else if (message.type === peerToPeerMessageTypes.DEVICE_LIST_UPDATED) {
try {
const result = await verifyAndGetDeviceList(
@@ -569,4 +556,36 @@
);
}
+const debouncedRefreshOneTimeKeys = _debounce(
+ async (
+ message: RefreshKeyRequest,
+ identityClient: IdentityServiceClient,
+ olmDebugLog: OlmDebugLog => mixed,
+ ) => {
+ const { olmAPI } = getConfig();
+ let resultDescription = 'starting',
+ success = false;
+ try {
+ await olmAPI.initializeCryptoAccount();
+ resultDescription = 'getting OTKs';
+ const oneTimeKeys = await olmAPI.getOneTimeKeys(message.numberOfKeys);
+ resultDescription = 'uploading OTKs';
+ await identityClient.uploadOneTimeKeys(oneTimeKeys);
+ success = true;
+ } catch (e) {
+ resultDescription = `Error uploading one-time keys: ${
+ getMessageForException(e) ?? ''
+ }`;
+ } finally {
+ olmDebugLog({
+ operation: 'uploadOneTimeKeys',
+ success,
+ resultDescription,
+ });
+ }
+ },
+ 5000,
+ { leading: true, trailing: true },
+);
+
export { usePeerToPeerMessageHandler, useHandleOlmMessageToDevice };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Jan 12, 12:05 AM (6 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5921012
Default Alt Text
D14740.1768176337.diff (3 KB)
Attached To
Mode
D14740: [lib] Debounce new OTKs response
Attached
Detach File
Event Timeline
Log In to Comment