improve bad path handling when snode not in path

pull/1692/head
Audric Ackermann 4 years ago
parent 5bf844241b
commit 3c80869418
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -5,6 +5,7 @@ import { default as insecureNodeFetch } from 'node-fetch';
import { UserUtils } from '../utils'; import { UserUtils } from '../utils';
import { incrementBadSnodeCountOrDrop, snodeHttpsAgent } from '../snode_api/onions'; import { incrementBadSnodeCountOrDrop, snodeHttpsAgent } from '../snode_api/onions';
import { allowOnlyOneAtATime } from '../utils/Promise'; import { allowOnlyOneAtATime } from '../utils/Promise';
import pRetry from 'p-retry';
const desiredGuardCount = 3; const desiredGuardCount = 3;
const minimumGuardCount = 2; const minimumGuardCount = 2;
@ -91,8 +92,7 @@ export async function dropSnodeFromPath(snodeEd25519: string) {
window?.log?.warn( window?.log?.warn(
`Could not drop ${ed25519Str(snodeEd25519)} from path index: ${pathWithSnodeIndex}` `Could not drop ${ed25519Str(snodeEd25519)} from path index: ${pathWithSnodeIndex}`
); );
throw new Error(`Could not drop snode ${ed25519Str(snodeEd25519)} from path: not in any paths`);
return;
} }
window?.log?.info( window?.log?.info(
`dropping snode ${ed25519Str(snodeEd25519)} from path index: ${pathWithSnodeIndex}` `dropping snode ${ed25519Str(snodeEd25519)} from path index: ${pathWithSnodeIndex}`
@ -156,20 +156,28 @@ export async function getOnionPath(toExclude?: Snode): Promise<Array<Snode>> {
/** /**
* If we don't know which nodes is causing trouble, increment the issue with this full path. * If we don't know which nodes is causing trouble, increment the issue with this full path.
*/ */
export async function incrementBadPathCountOrDrop(guardNodeEd25519: string) { export async function incrementBadPathCountOrDrop(sndeEd25519: string) {
const pathIndex = onionPaths.findIndex(p => p[0].pubkey_ed25519 === guardNodeEd25519); const pathWithSnodeIndex = onionPaths.findIndex(path =>
window?.log?.info( path.some(snode => snode.pubkey_ed25519 === sndeEd25519)
`\t\tincrementBadPathCountOrDrop starting with guard ${ed25519Str(guardNodeEd25519)}`
); );
if (pathIndex === -1) { if (pathWithSnodeIndex === -1) {
(window?.log?.info || console.warn)('Did not find path with this guard node'); (window?.log?.info || console.warn)('Did not find any path containing this snode');
return; // this can only be bad. throw an abortError so we use another path if needed
throw new pRetry.AbortError(
'incrementBadPathCountOrDrop: Did not find any path containing this snode'
);
} }
const pathWithIssues = onionPaths[pathIndex]; const guardNodeEd25519 = onionPaths[pathWithSnodeIndex][0].pubkey_ed25519;
window?.log?.info(
`\t\tincrementBadPathCountOrDrop starting with guard ${ed25519Str(guardNodeEd25519)}`
);
const pathWithIssues = onionPaths[pathWithSnodeIndex];
window?.log?.info('handling bad path for path index', pathIndex); window?.log?.info('handling bad path for path index', pathWithSnodeIndex);
const oldPathFailureCount = pathFailureCount[guardNodeEd25519] || 0; const oldPathFailureCount = pathFailureCount[guardNodeEd25519] || 0;
// tslint:disable: prefer-for-of // tslint:disable: prefer-for-of

@ -591,7 +591,7 @@ export async function incrementBadSnodeCountOrDrop({
await OnionPaths.dropSnodeFromPath(snodeEd25519); await OnionPaths.dropSnodeFromPath(snodeEd25519);
} catch (e) { } catch (e) {
window?.log?.warn( window?.log?.warn(
'dropSnodeFromPath, got error while patchingup... incrementing the whole path as bad', 'dropSnodeFromPath, got error while patching up... incrementing the whole path as bad',
e e
); );
// if dropSnodeFromPath throws, it means there is an issue patching up the path, increment the whole path issues count // if dropSnodeFromPath throws, it means there is an issue patching up the path, increment the whole path issues count

Loading…
Cancel
Save