pull/988/head
Ryan Tharp 5 years ago
parent 99679741c1
commit 4bb2e83cb3

@ -152,7 +152,9 @@ class LokiMessageAPI {
'Ran out of swarm nodes to query' 'Ran out of swarm nodes to query'
); );
} }
log.info(`loki_message:::sendMessage - Successfully stored message to ${pubKey}`); log.info(
`loki_message:::sendMessage - Successfully stored message to ${pubKey}`
);
} }
async refreshSendingSwarm(pubKey, timestamp) { async refreshSendingSwarm(pubKey, timestamp) {
@ -340,9 +342,9 @@ class LokiMessageAPI {
nodeData nodeData
); );
log.warn( log.warn(
`loki_message:::_openRetrieveConnection - too many successive failures, removing ${nodeData.ip}:${ `loki_message:::_openRetrieveConnection - too many successive failures, removing ${
nodeData.port nodeData.ip
} from our swarm pool. We have ${ }:${nodeData.port} from our swarm pool. We have ${
Object.keys(this.ourSwarmNodes).length Object.keys(this.ourSwarmNodes).length
} usable swarm nodes left (${ } usable swarm nodes left (${
remainingSwarmSnodes.length remainingSwarmSnodes.length

@ -34,15 +34,12 @@ class LokiSnodeAPI {
]; ];
} }
async refreshRandomPool(seedNodes = [...window.seedNodeList]) {
async refreshRandomPool(
seedNodes = [...window.seedNodeList]
) {
// if currently not in progress // if currently not in progress
if (this.refreshRandomPoolPromise === false) { if (this.refreshRandomPoolPromise === false) {
// set lock // set lock
this.refreshRandomPoolPromise = new Promise(async (resolve, reject) => { this.refreshRandomPoolPromise = new Promise(async (resolve, reject) => {
let timeoutTimer = null let timeoutTimer = null;
// private retry container // private retry container
const trySeedNode = async (consecutiveErrors = 0) => { const trySeedNode = async (consecutiveErrors = 0) => {
const params = { const params = {
@ -61,7 +58,9 @@ class LokiSnodeAPI {
)[0]; )[0];
let snodes = []; let snodes = [];
try { try {
log.info('loki_snodes:::refreshRandomPoolPromise - Refreshing random snode pool'); log.info(
'loki_snodes:::refreshRandomPoolPromise - Refreshing random snode pool'
);
const response = await lokiRpc( const response = await lokiRpc(
`http://${seedNode.ip}`, `http://${seedNode.ip}`,
seedNode.port, seedNode.port,
@ -108,36 +107,44 @@ class LokiSnodeAPI {
trySeedNode(consecutiveErrors + 1); trySeedNode(consecutiveErrors + 1);
}, consecutiveErrors * consecutiveErrors * 5000); }, consecutiveErrors * consecutiveErrors * 5000);
} else { } else {
log.error('loki_snodes:::refreshRandomPoolPromise - Giving up trying to contact seed node'); log.error(
'loki_snodes:::refreshRandomPoolPromise - Giving up trying to contact seed node'
);
if (snodes.length === 0) { if (snodes.length === 0) {
this.refreshRandomPoolPromise = null; // clear lock this.refreshRandomPoolPromise = null; // clear lock
if (timeoutTimer !== null) { if (timeoutTimer !== null) {
clearTimeout(timeoutTimer); clearTimeout(timeoutTimer);
timeoutTimer = null; timeoutTimer = null;
} }
reject() reject();
} }
} }
} }
} };
const delay = (SEED_NODE_RETRIES + 1) * (SEED_NODE_RETRIES + 1) * 5000; const delay = (SEED_NODE_RETRIES + 1) * (SEED_NODE_RETRIES + 1) * 5000;
timeoutTimer = setTimeout(() => { timeoutTimer = setTimeout(() => {
log.warn('loki_snodes:::refreshRandomPoolPromise - TIMEDOUT after', delay, 's'); log.warn(
'loki_snodes:::refreshRandomPoolPromise - TIMEDOUT after',
delay,
's'
);
reject(); reject();
}, delay); }, delay);
trySeedNode() trySeedNode();
}); });
} }
try { try {
await this.refreshRandomPoolPromise; await this.refreshRandomPoolPromise;
} catch(e) { } catch (e) {
// we will throw for each time initialiseRandomPool has been called in parallel // we will throw for each time initialiseRandomPool has been called in parallel
log.error('loki_snodes:::refreshRandomPoolPromise - error', e.code, e.message); log.error(
throw new window.textsecure.SeedNodeError( 'loki_snodes:::refreshRandomPoolPromise - error',
'Failed to contact seed node' e.code,
e.message
); );
throw new window.textsecure.SeedNodeError('Failed to contact seed node');
} }
log.info('loki_snodes:::refreshRandomPoolPromise - RESOLVED') log.info('loki_snodes:::refreshRandomPoolPromise - RESOLVED');
} }
// unreachableNode.url is like 9hrje1bymy7hu6nmtjme9idyu3rm8gr3mkstakjyuw1997t7w4ny.snode // unreachableNode.url is like 9hrje1bymy7hu6nmtjme9idyu3rm8gr3mkstakjyuw1997t7w4ny.snode
@ -223,7 +230,11 @@ class LokiSnodeAPI {
try { try {
newSwarmNodes = await this.getSwarmNodes(pubKey); newSwarmNodes = await this.getSwarmNodes(pubKey);
} catch (e) { } catch (e) {
log.error('loki_snodes:::getFreshSwarmNodes - error', e.code, e.message); log.error(
'loki_snodes:::getFreshSwarmNodes - error',
e.code,
e.message
);
// TODO: Handle these errors sensibly // TODO: Handle these errors sensibly
newSwarmNodes = []; newSwarmNodes = [];
} }

Loading…
Cancel
Save