Infer libsignal environment from service url

This commit is contained in:
Fedor Indutny 2024-06-07 11:17:52 -07:00 committed by GitHub
parent b3196425af
commit 53b8f5f152
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 5 additions and 17 deletions

View file

@ -2498,9 +2498,6 @@ ipc.on('get-config', async event => {
preferredSystemLocales: getPreferredSystemLocales(),
localeOverride: getLocaleOverride(),
version: app.getVersion(),
libsignalNetEnvironment: config.has('libsignalNetEnvironment')
? config.get<string>('libsignalNetEnvironment')
: undefined,
buildCreation: config.get<number>('buildCreation'),
buildExpiration: config.get<number>('buildExpiration'),
challengeUrl: config.get<string>('challengeUrl'),

View file

@ -82,7 +82,7 @@ const DEFAULT_TIMEOUT = 30 * SECOND;
// (and other connectivity params) of the services.
function resolveLibsignalNetEnvironment(
appEnv: Environment,
libsignalNetEnv: string | undefined
url: string
): Net.Environment {
switch (appEnv) {
case Environment.Production:
@ -91,12 +91,10 @@ function resolveLibsignalNetEnvironment(
// In the case of the `Development` Desktop env,
// we should be checking the provided string value
// of `libsignalNetEnv`
switch (libsignalNetEnv) {
case 'production':
return Net.Environment.Production;
default:
return Net.Environment.Staging;
if (/staging/i.test(url)) {
return Net.Environment.Staging;
}
return Net.Environment.Production;
case Environment.Test:
case Environment.Staging:
default:
@ -654,7 +652,6 @@ type InitializeOptionsType = {
proxyUrl: string | undefined;
version: string;
directoryConfig: DirectoryConfigType;
libsignalNetEnvironment: string | undefined;
disableIPv6: boolean;
};
@ -1498,7 +1495,6 @@ export function initialize({
contentProxyUrl,
proxyUrl,
version,
libsignalNetEnvironment,
disableIPv6,
}: InitializeOptionsType): WebAPIConnectType {
if (!isString(url)) {
@ -1542,10 +1538,7 @@ export function initialize({
// for providing network layer API and related functionality.
// It's important to have a single instance of this class as it holds
// resources that are shared across all other use cases.
const env = resolveLibsignalNetEnvironment(
getEnvironment(),
libsignalNetEnvironment
);
const env = resolveLibsignalNetEnvironment(getEnvironment(), url);
log.info(`libsignal net environment resolved to [${Net.Environment[env]}]`);
const libsignalNet = new Net.Net(env, getUserAgent(version));
libsignalNet.setIpv6Enabled(!disableIPv6);

View file

@ -73,7 +73,6 @@ export const rendererConfigSchema = z.object({
resourcesUrl: configRequiredStringSchema,
userDataPath: configRequiredStringSchema,
version: configRequiredStringSchema,
libsignalNetEnvironment: configOptionalStringSchema,
directoryConfig: directoryConfigSchema,
// Only used by main window

View file

@ -37,7 +37,6 @@ window.WebAPI = window.textsecure.WebAPI.initialize({
contentProxyUrl: config.contentProxyUrl,
proxyUrl: config.proxyUrl,
version: config.version,
libsignalNetEnvironment: config.libsignalNetEnvironment,
disableIPv6: config.disableIPv6,
});