Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32168961
D12111.1765055798.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D12111.1765055798.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
Sat, Dec 6, 9:16 PM (19 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5840907
Default Alt Text
D12111.1765055798.diff (2 KB)
Attached To
Mode
D12111: [lib] implement removing OutboundP2P messages after confirmation
Attached
Detach File
Event Timeline
Log In to Comment