refresh snode list and rebuild onion path once in a day

pull/1584/head
Audric Ackermann 4 years ago
parent 773da3b02b
commit 87c3fa0c55
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -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<Props> {
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<Props> {
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<Props> {
clearInterval(this.syncInterval);
this.syncInterval = null;
}
if (this.snodeForceRefreshInterval) {
clearInterval(this.snodeForceRefreshInterval);
this.snodeForceRefreshInterval = null;
}
}
public Section = ({

@ -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();

@ -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>> {
if (randomSnodePool.length === 0) {
await refreshRandomPool([]);

Loading…
Cancel
Save