Hold CDSI lookup ACI & UAK args in one array

This commit is contained in:
akonradi-signal 2023-10-31 15:00:25 -04:00 committed by GitHub
parent fcf2c0a3f0
commit 87659ef2b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 33 deletions

View file

@ -763,8 +763,7 @@ export type WhoamiResultType = z.infer<typeof whoamiResultZod>;
export type CdsLookupOptionsType = Readonly<{
e164s: ReadonlyArray<string>;
acis?: ReadonlyArray<AciString>;
accessKeys?: ReadonlyArray<string>;
acisAndAccessKeys?: ReadonlyArray<{ aci: AciString; accessKey: string }>;
returnAcisWithoutUaks?: boolean;
}>;
@ -3481,14 +3480,12 @@ export function initialize({
async function cdsLookup({
e164s,
acis = [],
accessKeys = [],
acisAndAccessKeys = [],
returnAcisWithoutUaks,
}: CdsLookupOptionsType): Promise<CDSResponseType> {
return cds.request({
e164s,
acis,
accessKeys,
acisAndAccessKeys,
returnAcisWithoutUaks,
});
}

View file

@ -65,8 +65,7 @@ export abstract class CDSSocketBase<
public async request({
e164s,
acis,
accessKeys,
acisAndAccessKeys,
returnAcisWithoutUaks = false,
}: CDSRequestOptionsType): Promise<CDSResponseType> {
const log = this.logger;
@ -81,23 +80,11 @@ export abstract class CDSSocketBase<
'CDS Connection not established'
);
const aciUakPairs = new Array<Uint8Array>();
const version = 2;
strictAssert(
acis.length === accessKeys.length,
`Number of ACIs ${acis.length} is different ` +
`from number of access keys ${accessKeys.length}`
);
for (let i = 0; i < acis.length; i += 1) {
aciUakPairs.push(
Bytes.concatenate([
uuidToBytes(acis[i]),
Bytes.fromBase64(accessKeys[i]),
])
);
}
const aciUakPairs = acisAndAccessKeys.map(({ aci, accessKey }) =>
Bytes.concatenate([uuidToBytes(aci), Bytes.fromBase64(accessKey)])
);
const request = Proto.CDSClientRequest.encode({
newE164s: Buffer.concat(

View file

@ -17,8 +17,7 @@ export type CDSResponseType = ReadonlyMap<string, CDSResponseEntryType>;
export type CDSRequestOptionsType = Readonly<{
e164s: ReadonlyArray<string>;
acis: ReadonlyArray<AciString>;
accessKeys: ReadonlyArray<string>;
acisAndAccessKeys: ReadonlyArray<{ aci: AciString; accessKey: string }>;
returnAcisWithoutUaks?: boolean;
timeout?: number;
}>;

View file

@ -15,8 +15,7 @@ export async function getServiceIdsForE164s(
// Note: these have no relationship to supplied e164s. We just provide
// all available information to the server so that it could return as many
// ACI+PNI+E164 matches as possible.
const acis = new Array<AciString>();
const accessKeys = new Array<string>();
const acisAndAccessKeys = new Array<{ aci: AciString; accessKey: string }>();
for (const convo of window.ConversationController.getAll()) {
if (!isDirectConversation(convo.attributes) || isMe(convo.attributes)) {
@ -34,8 +33,7 @@ export async function getServiceIdsForE164s(
continue;
}
acis.push(aci);
accessKeys.push(accessKey);
acisAndAccessKeys.push({ aci, accessKey });
}
const returnAcisWithoutUaks =
@ -43,13 +41,12 @@ export async function getServiceIdsForE164s(
isEnabled('desktop.cdsi.returnAcisWithoutUaks');
log.info(
`getServiceIdsForE164s(${e164s}): acis=${acis.length} ` +
`accessKeys=${accessKeys.length}`
`getServiceIdsForE164s(${e164s}): acis=${acisAndAccessKeys.length} ` +
`accessKeys=${acisAndAccessKeys.length}`
);
return server.cdsLookup({
e164s,
acis,
accessKeys,
acisAndAccessKeys,
returnAcisWithoutUaks,
});
}