From 87c3fa0c55f186d3af93e5973c4616d307f7287c Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Fri, 30 Apr 2021 15:15:59 +1000 Subject: [PATCH 1/3] refresh snode list and rebuild onion path once in a day --- ts/components/session/ActionsPanel.tsx | 13 ++++++++++++- ts/session/snode_api/onions.ts | 8 ++++++-- ts/session/snode_api/snodePool.ts | 10 ++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/ts/components/session/ActionsPanel.tsx b/ts/components/session/ActionsPanel.tsx index 1223b7116..c56436537 100644 --- a/ts/components/session/ActionsPanel.tsx +++ b/ts/components/session/ActionsPanel.tsx @@ -14,7 +14,7 @@ import { getTheme } from '../../state/selectors/theme'; import { getOurNumber } from '../../state/selectors/user'; import { UserUtils } from '../../session/utils'; import { syncConfigurationIfNeeded } from '../../session/utils/syncUtils'; -import { DAYS } from '../../session/utils/Number'; +import { DAYS, MINUTES } from '../../session/utils/Number'; import { getItemById, hasSyncedInitialConfigurationItem, @@ -23,6 +23,7 @@ import { import { OnionPaths } from '../../session/onions'; import { getMessageQueue } from '../../session/sending'; import { clearSessionsAndPreKeys } from '../../util/accountManager'; +import { forceRefreshRandomSnodePool } from '../../session/snode_api/snodePool'; // tslint:disable-next-line: no-import-side-effect no-submodule-imports export enum SectionType { @@ -50,6 +51,7 @@ interface Props { */ class ActionsPanelPrivate extends React.Component { private syncInterval: NodeJS.Timeout | null = null; + private snodeForceRefreshInterval: NodeJS.Timeout | null = null; constructor(props: Props) { super(props); @@ -109,6 +111,10 @@ class ActionsPanelPrivate extends React.Component { this.syncInterval = global.setInterval(() => { void syncConfigurationIfNeeded(); }, DAYS * 2); + this.snodeForceRefreshInterval = global.setInterval(async () => { + await forceRefreshRandomSnodePool(); + await OnionPaths.getInstance().buildNewOnionPaths(); + }, DAYS * 1); } public componentWillUnmount() { @@ -116,6 +122,11 @@ class ActionsPanelPrivate extends React.Component { clearInterval(this.syncInterval); this.syncInterval = null; } + + if (this.snodeForceRefreshInterval) { + clearInterval(this.snodeForceRefreshInterval); + this.snodeForceRefreshInterval = null; + } } public Section = ({ diff --git a/ts/session/snode_api/onions.ts b/ts/session/snode_api/onions.ts index 0f0c46d10..266861c3a 100644 --- a/ts/session/snode_api/onions.ts +++ b/ts/session/snode_api/onions.ts @@ -244,7 +244,7 @@ const processOnionResponse = async ( return RequestError.BAD_PATH; } - + // detect SNode is not ready (not in swarm; not done syncing) if (response.status === 503) { log.warn(`(${reqIdx}) [path] Got 503: snode not ready`); @@ -267,7 +267,11 @@ const processOnionResponse = async ( log.warn( `(${reqIdx}) [path] lokiRpc::processOnionResponse - fetch unhandled error code: ${response.status}` ); - return RequestError.OTHER; + // FIXME audric + // this is pretty strong but on the current setup. + // we have to increase a snode invididually and only mark later the path as bad + // the way it works on mobile is that we treat a node as bad in that case, and if it then reaches a failure count of 3 or so we kick it out and rebuild the path + return RequestError.BAD_PATH; } let ciphertext = await response.text(); diff --git a/ts/session/snode_api/snodePool.ts b/ts/session/snode_api/snodePool.ts index d4bec192b..b7f004ce5 100644 --- a/ts/session/snode_api/snodePool.ts +++ b/ts/session/snode_api/snodePool.ts @@ -165,6 +165,16 @@ async function requestVersion(node: any): Promise { } } +/** + * This function force the snode poll to be refreshed from a random seed node again. + * This should be called once in a day or so for when the app it kept on. + */ +export async function forceRefreshRandomSnodePool(): Promise> { + await refreshRandomPool([]); + + return randomSnodePool; +} + export async function getRandomSnodePool(): Promise> { if (randomSnodePool.length === 0) { await refreshRandomPool([]); From ddce21dbc7c0d20b69d1a7ef23fc1fd3b630972c Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Fri, 30 Apr 2021 15:16:58 +1000 Subject: [PATCH 2/3] bump to v1.4.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fcd86d8f7..b61abdca1 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "session-desktop", "productName": "Session", "description": "Private messaging from your desktop", - "version": "1.5.4", + "version": "1.5.5", "license": "GPL-3.0", "author": { "name": "Loki Project", From 5c4f544b1a13b9a5a4b14ce8bd32fd1146992a88 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Fri, 30 Apr 2021 16:12:36 +1000 Subject: [PATCH 3/3] Do not rebuild onion path everyday --- ts/components/session/ActionsPanel.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/ts/components/session/ActionsPanel.tsx b/ts/components/session/ActionsPanel.tsx index c56436537..82af69ec8 100644 --- a/ts/components/session/ActionsPanel.tsx +++ b/ts/components/session/ActionsPanel.tsx @@ -113,7 +113,6 @@ class ActionsPanelPrivate extends React.Component { }, DAYS * 2); this.snodeForceRefreshInterval = global.setInterval(async () => { await forceRefreshRandomSnodePool(); - await OnionPaths.getInstance().buildNewOnionPaths(); }, DAYS * 1); }