fix: improve retrieve timeout to 10s

also:
- add comments about not adding the limit:256 on snode list fetch
- fix an issue when no audio are found when starting a webrtc call
pull/3080/head
Audric Ackermann 1 year ago
parent 4589bde672
commit 42bea0264c

@ -1,4 +1,4 @@
import { fromPairs, isBoolean, map } from 'lodash'; import { fromPairs, map } from 'lodash';
import moment from 'moment'; import moment from 'moment';
import React from 'react'; import React from 'react';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
@ -87,13 +87,6 @@ function createSessionInboxStore() {
return createStore(initialState); return createStore(initialState);
} }
function getBoolFromStorageOrFalse(settingsKey: string): boolean {
const got = Storage.get(settingsKey, false);
if (isBoolean(got)) {
return got;
}
return false;
}
function setupLeftPane(forceUpdateInboxComponent: () => void) { function setupLeftPane(forceUpdateInboxComponent: () => void) {
window.openConversationWithMessages = openConversationWithMessages; window.openConversationWithMessages = openConversationWithMessages;
@ -101,15 +94,13 @@ function setupLeftPane(forceUpdateInboxComponent: () => void) {
window.inboxStore.dispatch( window.inboxStore.dispatch(
updateAllOnStorageReady({ updateAllOnStorageReady({
hasBlindedMsgRequestsEnabled: getBoolFromStorageOrFalse( hasBlindedMsgRequestsEnabled: Storage.getBoolOrFalse(
SettingsKey.hasBlindedMsgRequestsEnabled SettingsKey.hasBlindedMsgRequestsEnabled
), ),
someDeviceOutdatedSyncing: getBoolFromStorageOrFalse(SettingsKey.someDeviceOutdatedSyncing), someDeviceOutdatedSyncing: Storage.getBoolOrFalse(SettingsKey.someDeviceOutdatedSyncing),
settingsLinkPreview: getBoolFromStorageOrFalse(SettingsKey.settingsLinkPreview), settingsLinkPreview: Storage.getBoolOrFalse(SettingsKey.settingsLinkPreview),
hasFollowSystemThemeEnabled: getBoolFromStorageOrFalse( hasFollowSystemThemeEnabled: Storage.getBoolOrFalse(SettingsKey.hasFollowSystemThemeEnabled),
SettingsKey.hasFollowSystemThemeEnabled hasShiftSendEnabled: Storage.getBoolOrFalse(SettingsKey.hasShiftSendEnabled),
),
hasShiftSendEnabled: getBoolFromStorageOrFalse(SettingsKey.hasShiftSendEnabled),
}) })
); );
forceUpdateInboxComponent(); forceUpdateInboxComponent();

@ -60,7 +60,6 @@ const uploadProfileAvatar = async (scaledAvatarUrl: string | null) => {
} }
}; };
export const EditProfilePictureModal = (props: EditProfilePictureModalProps) => { export const EditProfilePictureModal = (props: EditProfilePictureModalProps) => {
const dispatch = useDispatch(); const dispatch = useDispatch();

@ -11,7 +11,6 @@ import { SessionToggle } from '../basic/SessionToggle';
import { SessionConfirmDialogProps } from '../dialog/SessionConfirm'; import { SessionConfirmDialogProps } from '../dialog/SessionConfirm';
import { SessionIconButton } from '../icon'; import { SessionIconButton } from '../icon';
type ButtonSettingsProps = { type ButtonSettingsProps = {
title?: string; title?: string;
description?: string; description?: string;

@ -230,6 +230,9 @@ async function getSnodesFromSeedUrl(urlObj: URL): Promise<Array<any>> {
const params = { const params = {
active_only: true, active_only: true,
// If you are thinking of adding the `limit` field here: don't.
// We fetch the full list because when we retrieve it we also remove from all the swarms we already know, any snode not part of that fetched list.
// If the limit was set, we would remove a lot of valid snodes from the swarms we've already fetched.
fields: { fields: {
public_ip: true, public_ip: true,
storage_port: true, storage_port: true,

@ -73,6 +73,9 @@ export type GetServiceNodesSubRequest = {
endpoint: 'get_service_nodes'; endpoint: 'get_service_nodes';
params: { params: {
active_only: true; active_only: true;
// If you are thinking of adding the `limit` field here: don't.
// We fetch the full list because when we retrieve it we also remove from all the swarms we already know, any snode not part of that fetched list.
// If the limit was set, we would remove a lot of valid snodes from the swarms we've already fetched.
fields: { fields: {
public_ip: true; public_ip: true;
storage_port: true; storage_port: true;

@ -13,6 +13,9 @@ function buildSnodeListRequests(): Array<GetServiceNodesSubRequest> {
endpoint: 'get_service_nodes', endpoint: 'get_service_nodes',
params: { params: {
active_only: true, active_only: true,
// If you are thinking of adding the `limit` field here: don't.
// We fetch the full list because when we retrieve it we also remove from all the swarms we already know, any snode not part of that fetched list.
// If the limit was set, we would remove a lot of valid snodes from the swarms we've already fetched.
fields: { fields: {
public_ip: true, public_ip: true,
storage_port: true, storage_port: true,

@ -11,7 +11,7 @@ import { AbortSignal as AbortSignalNode } from 'node-fetch/externals';
import { dropSnodeFromSnodePool, dropSnodeFromSwarmIfNeeded, updateSwarmFor } from './snodePool'; import { dropSnodeFromSnodePool, dropSnodeFromSwarmIfNeeded, updateSwarmFor } from './snodePool';
import { OnionPaths } from '../../onions'; import { OnionPaths } from '../../onions';
import { incrementBadPathCountOrDrop } from '../../onions/onionPath'; import { incrementBadPathCountOrDrop } from '../../onions/onionPath';
import { ed25519Str, toHex } from '../../utils/String'; import { ed25519Str, toHex } from '../../utils/String';
import { Snode } from '../../../data/data'; import { Snode } from '../../../data/data';

@ -1,4 +1,4 @@
import { isArray, omit, sortBy } from 'lodash'; import { isArray, omit } from 'lodash';
import { Snode } from '../../../data/data'; import { Snode } from '../../../data/data';
import { updateIsOnline } from '../../../state/ducks/onion'; import { updateIsOnline } from '../../../state/ducks/onion';
import { doSnodeBatchRequest } from './batchRequest'; import { doSnodeBatchRequest } from './batchRequest';
@ -124,7 +124,7 @@ async function retrieveNextMessages(
); );
// let exceptions bubble up // let exceptions bubble up
// no retry for this one as this a call we do every few seconds while polling for messages // no retry for this one as this a call we do every few seconds while polling for messages
const timeOutMs = 10 * 1000; // yes this is a long timeout for just messages, but 4s timeout way to often... const timeOutMs = 10 * 1000; // yes this is a long timeout for just messages, but 4s timeouts way to often...
const timeoutPromise = async () => sleepFor(timeOutMs); const timeoutPromise = async () => sleepFor(timeOutMs);
const fetchPromise = async () => const fetchPromise = async () =>
doSnodeBatchRequest(retrieveRequestsParams, targetNode, timeOutMs, associatedWith); doSnodeBatchRequest(retrieveRequestsParams, targetNode, timeOutMs, associatedWith);
@ -166,19 +166,13 @@ async function retrieveNextMessages(
GetNetworkTime.handleTimestampOffsetFromNetwork('retrieve', bodyFirstResult.t); GetNetworkTime.handleTimestampOffsetFromNetwork('retrieve', bodyFirstResult.t);
// merge results with their corresponding namespaces // NOTE: We don't want to sort messages here because the ordering depends on the snode and when it received each messages.
return results.map((result, index) => { // The last_hash for that snode has to be the last one we've received from that same snode, othwerwise we end up fetching the same messages over and over again.
const messages = result.body as RetrieveMessagesResultsContent; return results.map((result, index) => ({
// Not sure if that makes sense, but we probably want those messages sorted. code: result.code,
const sortedMessages = sortBy(messages.messages, m => m.timestamp); messages: result.body as RetrieveMessagesResultsContent,
messages.messages = sortedMessages; namespace: namespaces[index],
}));
return {
code: result.code,
messages,
namespace: namespaces[index],
};
});
} catch (e) { } catch (e) {
window?.log?.warn('exception while parsing json of nextMessage:', e); window?.log?.warn('exception while parsing json of nextMessage:', e);
if (!window.inboxStore?.getState().onionPaths.isOnline) { if (!window.inboxStore?.getState().onionPaths.isOnline) {

@ -415,6 +415,7 @@ async function createOfferAndSendIt(recipient: string, msgIdentifier: string | n
if (offer && offer.sdp) { if (offer && offer.sdp) {
const lines = offer.sdp.split(/\r?\n/); const lines = offer.sdp.split(/\r?\n/);
const lineWithFtmpIndex = lines.findIndex(f => f.startsWith('a=fmtp:111')); const lineWithFtmpIndex = lines.findIndex(f => f.startsWith('a=fmtp:111'));
// If webrtc does not find any audio input when initializing, the offer will not have a line with `a=fmtp:111` at all, `lineWithFtmpIndex` will be invalid.
if (lineWithFtmpIndex > -1) { if (lineWithFtmpIndex > -1) {
const partBeforeComma = lines[lineWithFtmpIndex].split(';'); const partBeforeComma = lines[lineWithFtmpIndex].split(';');
lines[lineWithFtmpIndex] = `${partBeforeComma[0]};cbr=1`; lines[lineWithFtmpIndex] = `${partBeforeComma[0]};cbr=1`;

@ -160,4 +160,13 @@ export async function saveRecentReations(reactions: Array<string>) {
return Storage.put('recent_reactions', reactions.join(' ')); return Storage.put('recent_reactions', reactions.join(' '));
} }
export const Storage = { fetch, put, get, remove, onready, reset };
function getBoolOrFalse(settingsKey: string): boolean {
const got = Storage.get(settingsKey, false);
if (isBoolean(got)) {
return got;
}
return false;
}
export const Storage = { fetch, put, get, getBoolOrFalse, remove, onready, reset };

Loading…
Cancel
Save