Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3266791
D12111.id40618.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D12111.id40618.diff
View Options
diff --git a/lib/handlers/peer-to-peer-message-handler.js b/lib/handlers/peer-to-peer-message-handler.js
--- a/lib/handlers/peer-to-peer-message-handler.js
+++ b/lib/handlers/peer-to-peer-message-handler.js
@@ -13,14 +13,16 @@
} from '../types/tunnelbroker/peer-to-peer-message-types.js';
import { getConfig } from '../utils/config.js';
import { getContentSigningKey } from '../utils/crypto-utils.js';
+import { getMessageForException } from '../utils/errors.js';
import { hasHigherDeviceID, olmSessionErrors } from '../utils/olm-utils.js';
+import { getClientMessageIDFromTunnelbrokerMessageID } from '../utils/peer-to-peer-communication-utils.js';
async function peerToPeerMessageHandler(
message: PeerToPeerMessage,
identityClient: IdentityServiceClient,
messageID: string,
): Promise<void> {
- const { olmAPI } = getConfig();
+ const { olmAPI, sqliteAPI } = getConfig();
if (message.type === peerToPeerMessageTypes.OUTBOUND_SESSION_CREATION) {
const { senderInfo, encryptedData, sessionVersion } = message;
const { userID: senderUserID, deviceID: senderDeviceID } = senderInfo;
@@ -162,6 +164,23 @@
`Error verifying device list for user ${message.userID}: ${e}`,
);
}
+ } else if (message.type === peerToPeerMessageTypes.MESSAGE_PROCESSED) {
+ try {
+ const { deviceID, messageID: tunnelbrokerMessageID } = message;
+ const clientMessageID = getClientMessageIDFromTunnelbrokerMessageID(
+ tunnelbrokerMessageID,
+ );
+ await sqliteAPI.removeOutboundP2PMessagesOlderThan(
+ clientMessageID,
+ deviceID,
+ );
+ } catch (e) {
+ console.log(
+ `Error removing message after processing: ${
+ getMessageForException(e) ?? 'unknown error'
+ }`,
+ );
+ }
}
}
diff --git a/lib/utils/peer-to-peer-communication-utils.js b/lib/utils/peer-to-peer-communication-utils.js
new file mode 100644
--- /dev/null
+++ b/lib/utils/peer-to-peer-communication-utils.js
@@ -0,0 +1,13 @@
+// @flow
+
+function getClientMessageIDFromTunnelbrokerMessageID(
+ tunnelbrokerMessageID: string,
+): string {
+ const ids = tunnelbrokerMessageID.split('#');
+ if (ids.length !== 2) {
+ throw new Error('Invalid tunnelbrokerMessageID');
+ }
+ return ids[1];
+}
+
+export { getClientMessageIDFromTunnelbrokerMessageID };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 17, 2:18 AM (19 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2510727
Default Alt Text
D12111.id40618.diff (2 KB)
Attached To
Mode
D12111: [lib] implement removing OutboundP2P messages after confirmation
Attached
Detach File
Event Timeline
Log In to Comment