From 5a5f069cca6f2027a3b90048bd4d648ea9994807 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Fri, 2 Jun 2023 14:48:55 +1000 Subject: [PATCH] fix: add tracking of expiration timer for nts through libsession --- .github/workflows/build-binaries.yml | 2 +- package.json | 2 +- ts/node/migration/sessionMigrations.ts | 14 ++++++++++---- ts/receiver/configMessage.ts | 6 +++--- ts/session/apis/snode_api/SNodeAPI.ts | 8 ++++++-- ts/session/apis/snode_api/swarmPolling.ts | 7 +++++++ .../libsession/libsession_utils_user_profile.ts | 16 +++++++++++----- .../browser/libsession_worker_interface.ts | 14 ++++++++++---- yarn.lock | 6 +++--- 9 files changed, 52 insertions(+), 23 deletions(-) diff --git a/.github/workflows/build-binaries.yml b/.github/workflows/build-binaries.yml index daf07e1ff..844b31730 100644 --- a/.github/workflows/build-binaries.yml +++ b/.github/workflows/build-binaries.yml @@ -47,7 +47,7 @@ jobs: - name: Setup node for windows if: runner.os == 'Windows' run: | - npm install --global node-gyp@latest + npm install --global yarn node-gyp@latest npm config set msvs_version 2022 - name: Install Desktop node_modules diff --git a/package.json b/package.json index 9f166bea7..fb49c0701 100644 --- a/package.json +++ b/package.json @@ -100,7 +100,7 @@ "glob": "7.1.2", "image-type": "^4.1.0", "ip2country": "1.0.1", - "libsession_util_nodejs": "https://github.com/oxen-io/libsession-util-nodejs/releases/download/v0.1.16/libsession_util_nodejs-v0.1.16.tar.gz", + "libsession_util_nodejs": "https://github.com/oxen-io/libsession-util-nodejs/releases/download/v0.1.17/libsession_util_nodejs-v0.1.17.tar.gz", "libsodium-wrappers-sumo": "^0.7.9", "linkify-it": "3.0.2", "lodash": "^4.17.21", diff --git a/ts/node/migration/sessionMigrations.ts b/ts/node/migration/sessionMigrations.ts index be682b929..24cbc14ce 100644 --- a/ts/node/migration/sessionMigrations.ts +++ b/ts/node/migration/sessionMigrations.ts @@ -1625,11 +1625,17 @@ function updateToSessionSchemaVersion31(currentVersion: number, db: BetterSqlite const ourDbProfileUrl = ourConversation.avatarPointer || ''; const ourDbProfileKey = fromHexToArray(ourConversation.profileKey || ''); const ourConvoPriority = ourConversation.priority; + const ourConvoExpire = ourConversation.expireTimer || 0; if (ourDbProfileUrl && !isEmpty(ourDbProfileKey)) { - userProfileWrapper.setUserInfo(ourDbName, ourConvoPriority, { - url: ourDbProfileUrl, - key: ourDbProfileKey, - }); + userProfileWrapper.setUserInfo( + ourDbName, + ourConvoPriority, + { + url: ourDbProfileUrl, + key: ourDbProfileKey, + }, + ourConvoExpire + ); } insertContactIntoContactWrapper( diff --git a/ts/receiver/configMessage.ts b/ts/receiver/configMessage.ts index 0d814306a..8c51c87e8 100644 --- a/ts/receiver/configMessage.ts +++ b/ts/receiver/configMessage.ts @@ -103,10 +103,10 @@ async function mergeConfigsWithIncomingUpdates( StringUtils.toHex(await GenericWrapperActions.dump(variant)) ); - for (let index = 0; index < toMerge.length; index++) { - const element = toMerge[index]; + for (let dumpIndex = 0; dumpIndex < toMerge.length; dumpIndex++) { + const element = toMerge[dumpIndex]; window.log.info( - `printDumpsForDebugging: toMerge of ${index}:${element.hash}: ${StringUtils.toHex( + `printDumpsForDebugging: toMerge of ${dumpIndex}:${element.hash}: ${StringUtils.toHex( element.data )} `, StringUtils.toHex(await GenericWrapperActions.dump(variant)) diff --git a/ts/session/apis/snode_api/SNodeAPI.ts b/ts/session/apis/snode_api/SNodeAPI.ts index 19b2773c9..c666dd56f 100644 --- a/ts/session/apis/snode_api/SNodeAPI.ts +++ b/ts/session/apis/snode_api/SNodeAPI.ts @@ -115,12 +115,16 @@ const forceNetworkDeletion = async (): Promise | null> => { const deletedObj = snodeJson.deleted as Record>; const hashes: Array = []; + + // tslint:disable: no-for-in for (const key in deletedObj) { - hashes.push(...deletedObj[key]); + if (deletedObj.hasOwnProperty(key)) { + hashes.push(...deletedObj[key]); + } } const sortedHashes = hashes.sort(); const signatureSnode = snodeJson.signature as string; - // The signature format is (with sortedHashes) ( PUBKEY_HEX || TIMESTAMP || DELETEDHASH[0] || ... || DELETEDHASH[N] ) + // The signature format is (with sortedHashes accross all namespaces) ( PUBKEY_HEX || TIMESTAMP || DELETEDHASH[0] || ... || DELETEDHASH[N] ) const dataToVerify = `${userX25519PublicKey}${ signOpts.timestamp }${sortedHashes.join('')}`; diff --git a/ts/session/apis/snode_api/swarmPolling.ts b/ts/session/apis/snode_api/swarmPolling.ts index 6797d7178..d2a3ac945 100644 --- a/ts/session/apis/snode_api/swarmPolling.ts +++ b/ts/session/apis/snode_api/swarmPolling.ts @@ -64,6 +64,7 @@ export const getSwarmPollingInstance = () => { export class SwarmPolling { private groupPolling: Array<{ pubkey: PubKey; lastPolledTimestamp: number }>; private readonly lastHashes: Record>>; + private hasStarted = false; constructor() { this.groupPolling = []; @@ -71,6 +72,11 @@ export class SwarmPolling { } public async start(waitForFirstPoll = false): Promise { + // when restoring from seed we have to start polling before we get on the mainPage, hence this check here to make sure we do not start twice + if (this.hasStarted) { + return; + } + this.hasStarted = true; this.loadGroupIds(); if (waitForFirstPoll) { await this.pollForAllKeys(); @@ -86,6 +92,7 @@ export class SwarmPolling { */ public resetSwarmPolling() { this.groupPolling = []; + this.hasStarted = false; } public forcePolledTimestamp(pubkey: PubKey, lastPoll: number) { diff --git a/ts/session/utils/libsession/libsession_utils_user_profile.ts b/ts/session/utils/libsession/libsession_utils_user_profile.ts index 8a7cfefc5..8faafc275 100644 --- a/ts/session/utils/libsession/libsession_utils_user_profile.ts +++ b/ts/session/utils/libsession/libsession_utils_user_profile.ts @@ -26,13 +26,19 @@ async function insertUserProfileIntoWrapper(convoId: string) { { url: dbProfileUrl, key: dbProfileKey } )} ` ); + const expirySeconds = ourConvo.get('expireTimer') || 0; if (dbProfileUrl && !isEmpty(dbProfileKey)) { - await UserConfigWrapperActions.setUserInfo(dbName, priority, { - url: dbProfileUrl, - key: dbProfileKey, - }); + await UserConfigWrapperActions.setUserInfo( + dbName, + priority, + { + url: dbProfileUrl, + key: dbProfileKey, + }, + expirySeconds + ); } else { - await UserConfigWrapperActions.setUserInfo(dbName, priority, null); + await UserConfigWrapperActions.setUserInfo(dbName, priority, null, expirySeconds); } } diff --git a/ts/webworker/workers/browser/libsession_worker_interface.ts b/ts/webworker/workers/browser/libsession_worker_interface.ts index 0d746ea08..0256e9bb9 100644 --- a/ts/webworker/workers/browser/libsession_worker_interface.ts +++ b/ts/webworker/workers/browser/libsession_worker_interface.ts @@ -104,11 +104,17 @@ export const UserConfigWrapperActions: UserConfigWrapperActionsCalls = { setUserInfo: async ( name: string, priority: number, - profilePic: { url: string; key: Uint8Array } | null + profilePic: { url: string; key: Uint8Array } | null, + expireSeconds: number ) => - callLibSessionWorker(['UserConfig', 'setUserInfo', name, priority, profilePic]) as Promise< - ReturnType - >, + callLibSessionWorker([ + 'UserConfig', + 'setUserInfo', + name, + priority, + profilePic, + expireSeconds, + ]) as Promise>, }; export const ContactsWrapperActions: ContactsWrapperActionsCalls = { diff --git a/yarn.lock b/yarn.lock index 09062071d..6501a3746 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5148,9 +5148,9 @@ levn@~0.3.0: prelude-ls "~1.1.2" type-check "~0.3.2" -"libsession_util_nodejs@https://github.com/oxen-io/libsession-util-nodejs/releases/download/v0.1.16/libsession_util_nodejs-v0.1.16.tar.gz": - version "0.1.16" - resolved "https://github.com/oxen-io/libsession-util-nodejs/releases/download/v0.1.16/libsession_util_nodejs-v0.1.16.tar.gz#2a526154b7d0f4235895f3a788704a56d6573339" +"libsession_util_nodejs@https://github.com/oxen-io/libsession-util-nodejs/releases/download/v0.1.17/libsession_util_nodejs-v0.1.17.tar.gz": + version "0.1.17" + resolved "https://github.com/oxen-io/libsession-util-nodejs/releases/download/v0.1.17/libsession_util_nodejs-v0.1.17.tar.gz#e79b8900a62fcf3798a43aeef0e99d5fc52674a2" dependencies: cmake-js "^7.2.1" node-addon-api "^6.1.0"