fix: add tracking of expiration timer for nts through libsession

pull/2756/head
Audric Ackermann 2 years ago
parent db9fa14213
commit 5a5f069cca

@ -47,7 +47,7 @@ jobs:
- name: Setup node for windows - name: Setup node for windows
if: runner.os == 'Windows' if: runner.os == 'Windows'
run: | run: |
npm install --global node-gyp@latest npm install --global yarn node-gyp@latest
npm config set msvs_version 2022 npm config set msvs_version 2022
- name: Install Desktop node_modules - name: Install Desktop node_modules

@ -100,7 +100,7 @@
"glob": "7.1.2", "glob": "7.1.2",
"image-type": "^4.1.0", "image-type": "^4.1.0",
"ip2country": "1.0.1", "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", "libsodium-wrappers-sumo": "^0.7.9",
"linkify-it": "3.0.2", "linkify-it": "3.0.2",
"lodash": "^4.17.21", "lodash": "^4.17.21",

@ -1625,11 +1625,17 @@ function updateToSessionSchemaVersion31(currentVersion: number, db: BetterSqlite
const ourDbProfileUrl = ourConversation.avatarPointer || ''; const ourDbProfileUrl = ourConversation.avatarPointer || '';
const ourDbProfileKey = fromHexToArray(ourConversation.profileKey || ''); const ourDbProfileKey = fromHexToArray(ourConversation.profileKey || '');
const ourConvoPriority = ourConversation.priority; const ourConvoPriority = ourConversation.priority;
const ourConvoExpire = ourConversation.expireTimer || 0;
if (ourDbProfileUrl && !isEmpty(ourDbProfileKey)) { if (ourDbProfileUrl && !isEmpty(ourDbProfileKey)) {
userProfileWrapper.setUserInfo(ourDbName, ourConvoPriority, { userProfileWrapper.setUserInfo(
url: ourDbProfileUrl, ourDbName,
key: ourDbProfileKey, ourConvoPriority,
}); {
url: ourDbProfileUrl,
key: ourDbProfileKey,
},
ourConvoExpire
);
} }
insertContactIntoContactWrapper( insertContactIntoContactWrapper(

@ -103,10 +103,10 @@ async function mergeConfigsWithIncomingUpdates(
StringUtils.toHex(await GenericWrapperActions.dump(variant)) StringUtils.toHex(await GenericWrapperActions.dump(variant))
); );
for (let index = 0; index < toMerge.length; index++) { for (let dumpIndex = 0; dumpIndex < toMerge.length; dumpIndex++) {
const element = toMerge[index]; const element = toMerge[dumpIndex];
window.log.info( window.log.info(
`printDumpsForDebugging: toMerge of ${index}:${element.hash}: ${StringUtils.toHex( `printDumpsForDebugging: toMerge of ${dumpIndex}:${element.hash}: ${StringUtils.toHex(
element.data element.data
)} `, )} `,
StringUtils.toHex(await GenericWrapperActions.dump(variant)) StringUtils.toHex(await GenericWrapperActions.dump(variant))

@ -115,12 +115,16 @@ const forceNetworkDeletion = async (): Promise<Array<string> | null> => {
const deletedObj = snodeJson.deleted as Record<number, Array<string>>; const deletedObj = snodeJson.deleted as Record<number, Array<string>>;
const hashes: Array<string> = []; const hashes: Array<string> = [];
// tslint:disable: no-for-in
for (const key in deletedObj) { for (const key in deletedObj) {
hashes.push(...deletedObj[key]); if (deletedObj.hasOwnProperty(key)) {
hashes.push(...deletedObj[key]);
}
} }
const sortedHashes = hashes.sort(); const sortedHashes = hashes.sort();
const signatureSnode = snodeJson.signature as string; 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}${ const dataToVerify = `${userX25519PublicKey}${
signOpts.timestamp signOpts.timestamp
}${sortedHashes.join('')}`; }${sortedHashes.join('')}`;

@ -64,6 +64,7 @@ export const getSwarmPollingInstance = () => {
export class SwarmPolling { export class SwarmPolling {
private groupPolling: Array<{ pubkey: PubKey; lastPolledTimestamp: number }>; private groupPolling: Array<{ pubkey: PubKey; lastPolledTimestamp: number }>;
private readonly lastHashes: Record<string, Record<string, Record<number, string>>>; private readonly lastHashes: Record<string, Record<string, Record<number, string>>>;
private hasStarted = false;
constructor() { constructor() {
this.groupPolling = []; this.groupPolling = [];
@ -71,6 +72,11 @@ export class SwarmPolling {
} }
public async start(waitForFirstPoll = false): Promise<void> { public async start(waitForFirstPoll = false): Promise<void> {
// 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(); this.loadGroupIds();
if (waitForFirstPoll) { if (waitForFirstPoll) {
await this.pollForAllKeys(); await this.pollForAllKeys();
@ -86,6 +92,7 @@ export class SwarmPolling {
*/ */
public resetSwarmPolling() { public resetSwarmPolling() {
this.groupPolling = []; this.groupPolling = [];
this.hasStarted = false;
} }
public forcePolledTimestamp(pubkey: PubKey, lastPoll: number) { public forcePolledTimestamp(pubkey: PubKey, lastPoll: number) {

@ -26,13 +26,19 @@ async function insertUserProfileIntoWrapper(convoId: string) {
{ url: dbProfileUrl, key: dbProfileKey } { url: dbProfileUrl, key: dbProfileKey }
)} ` )} `
); );
const expirySeconds = ourConvo.get('expireTimer') || 0;
if (dbProfileUrl && !isEmpty(dbProfileKey)) { if (dbProfileUrl && !isEmpty(dbProfileKey)) {
await UserConfigWrapperActions.setUserInfo(dbName, priority, { await UserConfigWrapperActions.setUserInfo(
url: dbProfileUrl, dbName,
key: dbProfileKey, priority,
}); {
url: dbProfileUrl,
key: dbProfileKey,
},
expirySeconds
);
} else { } else {
await UserConfigWrapperActions.setUserInfo(dbName, priority, null); await UserConfigWrapperActions.setUserInfo(dbName, priority, null, expirySeconds);
} }
} }

@ -104,11 +104,17 @@ export const UserConfigWrapperActions: UserConfigWrapperActionsCalls = {
setUserInfo: async ( setUserInfo: async (
name: string, name: string,
priority: number, priority: number,
profilePic: { url: string; key: Uint8Array } | null profilePic: { url: string; key: Uint8Array } | null,
expireSeconds: number
) => ) =>
callLibSessionWorker(['UserConfig', 'setUserInfo', name, priority, profilePic]) as Promise< callLibSessionWorker([
ReturnType<UserConfigWrapperActionsCalls['setUserInfo']> 'UserConfig',
>, 'setUserInfo',
name,
priority,
profilePic,
expireSeconds,
]) as Promise<ReturnType<UserConfigWrapperActionsCalls['setUserInfo']>>,
}; };
export const ContactsWrapperActions: ContactsWrapperActionsCalls = { export const ContactsWrapperActions: ContactsWrapperActionsCalls = {

@ -5148,9 +5148,9 @@ levn@~0.3.0:
prelude-ls "~1.1.2" prelude-ls "~1.1.2"
type-check "~0.3.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": "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.16" version "0.1.17"
resolved "https://github.com/oxen-io/libsession-util-nodejs/releases/download/v0.1.16/libsession_util_nodejs-v0.1.16.tar.gz#2a526154b7d0f4235895f3a788704a56d6573339" resolved "https://github.com/oxen-io/libsession-util-nodejs/releases/download/v0.1.17/libsession_util_nodejs-v0.1.17.tar.gz#e79b8900a62fcf3798a43aeef0e99d5fc52674a2"
dependencies: dependencies:
cmake-js "^7.2.1" cmake-js "^7.2.1"
node-addon-api "^6.1.0" node-addon-api "^6.1.0"

Loading…
Cancel
Save