Merge pull request #1584 from Bilb/refresh-seednode-list-interval

refresh snode list once in a day
pull/1586/head
Audric Ackermann 4 years ago committed by GitHub
commit b440385aef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,7 +2,7 @@
"name": "session-desktop", "name": "session-desktop",
"productName": "Session", "productName": "Session",
"description": "Private messaging from your desktop", "description": "Private messaging from your desktop",
"version": "1.5.4", "version": "1.5.5",
"license": "GPL-3.0", "license": "GPL-3.0",
"author": { "author": {
"name": "Loki Project", "name": "Loki Project",

@ -14,7 +14,7 @@ import { getTheme } from '../../state/selectors/theme';
import { getOurNumber } from '../../state/selectors/user'; import { getOurNumber } from '../../state/selectors/user';
import { UserUtils } from '../../session/utils'; import { UserUtils } from '../../session/utils';
import { syncConfigurationIfNeeded } from '../../session/utils/syncUtils'; import { syncConfigurationIfNeeded } from '../../session/utils/syncUtils';
import { DAYS } from '../../session/utils/Number'; import { DAYS, MINUTES } from '../../session/utils/Number';
import { import {
getItemById, getItemById,
hasSyncedInitialConfigurationItem, hasSyncedInitialConfigurationItem,
@ -23,6 +23,7 @@ import {
import { OnionPaths } from '../../session/onions'; import { OnionPaths } from '../../session/onions';
import { getMessageQueue } from '../../session/sending'; import { getMessageQueue } from '../../session/sending';
import { clearSessionsAndPreKeys } from '../../util/accountManager'; import { clearSessionsAndPreKeys } from '../../util/accountManager';
import { forceRefreshRandomSnodePool } from '../../session/snode_api/snodePool';
// tslint:disable-next-line: no-import-side-effect no-submodule-imports // tslint:disable-next-line: no-import-side-effect no-submodule-imports
export enum SectionType { export enum SectionType {
@ -50,6 +51,7 @@ interface Props {
*/ */
class ActionsPanelPrivate extends React.Component<Props> { class ActionsPanelPrivate extends React.Component<Props> {
private syncInterval: NodeJS.Timeout | null = null; private syncInterval: NodeJS.Timeout | null = null;
private snodeForceRefreshInterval: NodeJS.Timeout | null = null;
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);
@ -109,6 +111,9 @@ class ActionsPanelPrivate extends React.Component<Props> {
this.syncInterval = global.setInterval(() => { this.syncInterval = global.setInterval(() => {
void syncConfigurationIfNeeded(); void syncConfigurationIfNeeded();
}, DAYS * 2); }, DAYS * 2);
this.snodeForceRefreshInterval = global.setInterval(async () => {
await forceRefreshRandomSnodePool();
}, DAYS * 1);
} }
public componentWillUnmount() { public componentWillUnmount() {
@ -116,6 +121,11 @@ class ActionsPanelPrivate extends React.Component<Props> {
clearInterval(this.syncInterval); clearInterval(this.syncInterval);
this.syncInterval = null; this.syncInterval = null;
} }
if (this.snodeForceRefreshInterval) {
clearInterval(this.snodeForceRefreshInterval);
this.snodeForceRefreshInterval = null;
}
} }
public Section = ({ public Section = ({

@ -244,7 +244,7 @@ const processOnionResponse = async (
return RequestError.BAD_PATH; return RequestError.BAD_PATH;
} }
// detect SNode is not ready (not in swarm; not done syncing) // detect SNode is not ready (not in swarm; not done syncing)
if (response.status === 503) { if (response.status === 503) {
log.warn(`(${reqIdx}) [path] Got 503: snode not ready`); log.warn(`(${reqIdx}) [path] Got 503: snode not ready`);
@ -267,7 +267,11 @@ const processOnionResponse = async (
log.warn( log.warn(
`(${reqIdx}) [path] lokiRpc::processOnionResponse - fetch unhandled error code: ${response.status}` `(${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(); let ciphertext = await response.text();

@ -165,6 +165,16 @@ async function requestVersion(node: any): Promise<void> {
} }
} }
/**
* 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<Array<Snode>> {
await refreshRandomPool([]);
return randomSnodePool;
}
export async function getRandomSnodePool(): Promise<Array<Snode>> { export async function getRandomSnodePool(): Promise<Array<Snode>> {
if (randomSnodePool.length === 0) { if (randomSnodePool.length === 0) {
await refreshRandomPool([]); await refreshRandomPool([]);

Loading…
Cancel
Save