return which snode was used to send/storage message, pass fetchHashes to getSwarmNodesForPubKey, indicate if we were requested to be stopped or not, log level adjustments

pull/1061/head
Ryan Tharp 5 years ago
parent b3278a4edf
commit 6dca83a972

@ -108,10 +108,10 @@ class LokiMessageAPI {
promises.push(connectionPromise); promises.push(connectionPromise);
} }
let success; let snode;
try { try {
// eslint-disable-next-line more/no-then // eslint-disable-next-line more/no-then
success = await primitives.firstTrue(promises); snode = await primitives.firstTrue(promises);
} catch (e) { } catch (e) {
if (e instanceof textsecure.WrongDifficultyError) { if (e instanceof textsecure.WrongDifficultyError) {
// Force nonce recalculation // Force nonce recalculation
@ -124,14 +124,16 @@ class LokiMessageAPI {
} }
throw e; throw e;
} }
if (!success) { if (!snode) {
throw new window.textsecure.EmptySwarmError( throw new window.textsecure.EmptySwarmError(
pubKey, pubKey,
'Ran out of swarm nodes to query' 'Ran out of swarm nodes to query'
); );
} }
log.info( log.info(
`loki_message:::sendMessage - Successfully stored message to ${pubKey}` `loki_message:::sendMessage - Successfully stored message to ${pubKey} via ${
snode.ip
}:${snode.port}`
); );
} }
@ -320,6 +322,7 @@ class LokiMessageAPI {
if (e instanceof textsecure.WrongSwarmError) { if (e instanceof textsecure.WrongSwarmError) {
const { newSwarm } = e; const { newSwarm } = e;
await lokiSnodeAPI.updateSwarmNodes(this.ourKey, newSwarm); await lokiSnodeAPI.updateSwarmNodes(this.ourKey, newSwarm);
// FIXME: restart all openRetrieves when this happens...
// FIXME: lokiSnode should handle this // FIXME: lokiSnode should handle this
for (let i = 0; i < newSwarm.length; i += 1) { for (let i = 0; i < newSwarm.length; i += 1) {
const lastHash = await window.Signal.Data.getLastHashBySnode( const lastHash = await window.Signal.Data.getLastHashBySnode(
@ -407,7 +410,9 @@ class LokiMessageAPI {
// we don't throw or catch here // we don't throw or catch here
async startLongPolling(numConnections, stopPolling, callback) { async startLongPolling(numConnections, stopPolling, callback) {
// load from local DB // load from local DB
let nodes = await lokiSnodeAPI.getSwarmNodesForPubKey(this.ourKey); let nodes = await lokiSnodeAPI.getSwarmNodesForPubKey(this.ourKey, {
fetchHashes: true,
});
if (nodes.length < numConnections) { if (nodes.length < numConnections) {
log.warn( log.warn(
'loki_message:::startLongPolling - Not enough SwarmNodes for our pubkey in local database, getting current list from blockchain' 'loki_message:::startLongPolling - Not enough SwarmNodes for our pubkey in local database, getting current list from blockchain'
@ -449,12 +454,11 @@ class LokiMessageAPI {
promises.push( promises.push(
// eslint-disable-next-line more/no-then // eslint-disable-next-line more/no-then
this._openRetrieveConnection(pools[i], stopPolling, callback).then( this._openRetrieveConnection(pools[i], stopPolling, callback).then(
() => { stoppedPolling => {
unresolved -= 1; unresolved -= 1;
log.info( log.info(
'loki_message:::startLongPolling - There are', `loki_message:::startLongPolling - There are ${unresolved}`,
unresolved, `open retrieve connections left. Stopped? ${stoppedPolling}`
'open retrieve connections left'
); );
} }
) )
@ -465,7 +469,7 @@ class LokiMessageAPI {
// less than numConnections being active is fine, only need to restart if none per Niels 20/02/13 // less than numConnections being active is fine, only need to restart if none per Niels 20/02/13
// or if there is network issues (ENOUTFOUND due to lokinet) // or if there is network issues (ENOUTFOUND due to lokinet)
await Promise.all(promises); await Promise.all(promises);
log.error( log.warn(
'loki_message:::startLongPolling - All our long poll swarm connections have been removed' 'loki_message:::startLongPolling - All our long poll swarm connections have been removed'
); );
// should we just call ourself again? // should we just call ourself again?

Loading…
Cancel
Save