From 377e90bafe7ccddd0e06a9009c81b0408f617606 Mon Sep 17 00:00:00 2001 From: Beaudan Date: Thu, 11 Apr 2019 15:31:00 +1000 Subject: [PATCH] Include long polling header for retrieve messages, extend retrieveMessages timeout to 40 seconds, reduce default tmeout to 5 seconds, remove dev/prod poll time difference --- js/modules/loki_message_api.js | 10 +++++++++- js/modules/loki_rpc.js | 2 +- libtextsecure/http-resources.js | 5 ++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/js/modules/loki_message_api.js b/js/modules/loki_message_api.js index ef09bb19e..175fdc479 100644 --- a/js/modules/loki_message_api.js +++ b/js/modules/loki_message_api.js @@ -7,6 +7,7 @@ const { rpc } = require('./loki_rpc'); // Will be raised (to 3?) when we get more nodes const MINIMUM_SUCCESSFUL_REQUESTS = 2; +const LOKI_LONGPOLL_HEADER = 'X-Loki-Long-Poll'; class LokiMessageAPI { constructor({ snodeServerPort }) { @@ -171,13 +172,20 @@ class LokiMessageAPI { pubKey: ourKey, lastHash: nodeData.lastHash || '', }; + const options = { + timeout: 40000, + headers: { + [LOKI_LONGPOLL_HEADER]: true, + }, + }; try { const result = await rpc( `http://${nodeUrl}`, this.snodeServerPort, 'retrieve', - params + params, + options ); nodeComplete(nodeUrl); diff --git a/js/modules/loki_rpc.js b/js/modules/loki_rpc.js index 19e54b71a..03f971bc0 100644 --- a/js/modules/loki_rpc.js +++ b/js/modules/loki_rpc.js @@ -8,7 +8,7 @@ const endpointBase = '/v1/storage_rpc'; // A small wrapper around node-fetch which deserializes response const fetch = async (url, options = {}) => { - const timeout = options.timeout || 10000; + const timeout = options.timeout || 5000; const method = options.method || 'GET'; const address = parse(url).hostname; diff --git a/libtextsecure/http-resources.js b/libtextsecure/http-resources.js index 8c3387963..65237f750 100644 --- a/libtextsecure/http-resources.js +++ b/libtextsecure/http-resources.js @@ -3,8 +3,7 @@ // eslint-disable-next-line func-names (function() { let server; - const development = window.getEnvironment() !== 'production'; - const pollTime = development ? 100 : 5000; + const POLL_TIME = 100; function stringToArrayBufferBase64(string) { return dcodeIO.ByteBuffer.wrap(string, 'base64').toArrayBuffer(); @@ -115,7 +114,7 @@ callback(connected); setTimeout(() => { pollServer(callback); - }, pollTime); + }, POLL_TIME); }; this.isConnected = function isConnected() {