Fix generating random long

This commit is contained in:
Eduard Kuzmenko 2021-07-21 15:16:15 +03:00
parent cf7c6991ed
commit 9afa9584ae
5 changed files with 30 additions and 20 deletions

View File

@ -16,5 +16,5 @@ export function nextRandomUint(bits: 8 | 16 | 32) {
}
export function randomLong() {
return '' + nextRandomUint(32) + nextRandomUint(32);
return '' + nextRandomUint(32) + nextRandomUint(32) % 0xFFFFFF;
}

5
src/layer.d.ts vendored
View File

@ -856,7 +856,10 @@ export namespace Message {
random_id?: string,
rReply?: string,
viaBotId?: number,
clear_history?: boolean
clear_history?: boolean,
pending?: boolean,
error?: any,
send?: () => Promise<any>
};
export type messageService = {

View File

@ -480,7 +480,7 @@ export class AppMessagesManager {
};
}
const toggleError = (on: any) => {
const toggleError = (on: boolean) => {
if(on) {
message.error = true;
} else {
@ -525,7 +525,9 @@ export class AppMessagesManager {
} */
//this.log('sendText', message.mid);
apiPromise.then((updates: Updates) => {
this.pendingAfterMsgs[peerId] = sentRequestOptions;
return apiPromise.then((updates: Updates) => {
//this.log('sendText sent', message.mid);
//if(is<Updates.updateShortSentMessage>(updates, updates._ === 'updateShortSentMessage')) {
if(updates._ === 'updateShortSentMessage') {
@ -579,9 +581,7 @@ export class AppMessagesManager {
delete this.pendingAfterMsgs[peerId];
}
});
this.pendingAfterMsgs[peerId] = sentRequestOptions;
}
};
this.beforeMessageSending(message, {
isScheduled: !!options.scheduleDate || undefined,
@ -831,7 +831,7 @@ export class AppMessagesManager {
_: 'messageMediaDocument',
pFlags: {},
document: file
} : media;
} as MessageMedia.messageMediaDocument : media as any;
const toggleError = (on: boolean) => {
if(on) {
@ -888,6 +888,7 @@ export class AppMessagesManager {
this.log('appMessagesManager: sendFile uploaded:', inputFile);
} */
// @ts-ignore
delete message.media.preloader;
inputFile.name = apiFileName;
@ -1163,7 +1164,7 @@ export class AppMessagesManager {
const message = this.generateOutgoingMessage(peerId, options);
const replyToMsgId = options.replyToMsgId ? this.getServerMessageId(options.replyToMsgId) : undefined;
let media;
let media: MessageMedia;
switch(inputMedia._) {
case 'inputMediaPoll': {
inputMedia.poll.id = message.id;
@ -1291,7 +1292,9 @@ export class AppMessagesManager {
}, sentRequestOptions);
}
apiPromise.then((updates) => {
this.pendingAfterMsgs[peerId] = sentRequestOptions;
return apiPromise.then((updates) => {
if(updates.updates) {
updates.updates.forEach((update: any) => {
if(update._ === 'updateDraftMessage') {
@ -1308,8 +1311,7 @@ export class AppMessagesManager {
delete this.pendingAfterMsgs[peerId];
}
});
this.pendingAfterMsgs[peerId] = sentRequestOptions;
}
};
this.beforeMessageSending(message, {
isScheduled: !!options.scheduleDate || undefined,
@ -1402,7 +1404,7 @@ export class AppMessagesManager {
options.replyToMsgId = options.threadId;
}
const message: any = {
const message: Message.message = {
_: 'message',
id: this.generateTempMessageId(peerId),
from_id: this.generateFromId(peerId),
@ -5102,17 +5104,18 @@ export class AppMessagesManager {
}
private handleReleasingMessage(message: MyMessage) {
if('media' in message) {
const media = (message as Message.message).media;
if(media) {
// @ts-ignore
const c = message.media.webpage || message.media;
const c = media.webpage || media;
const smth: Photo.photo | MyDocument = c.photo || c.document;
if(smth?.file_reference) {
referenceDatabase.deleteContext(smth.file_reference, {type: 'message', peerId: message.peerId, messageId: message.mid});
}
if('webpage' in message.media) {
appWebPagesManager.deleteWebPageFromPending(message.media.webpage, message.mid);
if('webpage' in media) {
appWebPagesManager.deleteWebPageFromPending(media.webpage, message.mid);
}
}
}

View File

@ -534,7 +534,8 @@ export class Authorizer {
const newNonceHash1 = (await CryptoWorker.invokeCrypto('sha1-hash', auth.newNonce.concat([1], authKeyAux))).slice(-16);
if(!bytesCmp(newNonceHash1, response.new_nonce_hash1)) {
throw new Error('[MT] Set_client_DH_params_answer new_nonce_hash1 mismatch');
this.log.error('Set_client_DH_params_answer new_nonce_hash1 mismatch', newNonceHash1, response);
throw new Error('new_nonce_hash1 mismatch');
}
const serverSalt = bytesXor(auth.newNonce.slice(0, 8), auth.serverNonce.slice(0, 8));
@ -591,7 +592,7 @@ export class Authorizer {
this.cached[dcId] = promise;
return await promise;
} catch(err) {
if(err.originalError === -404 && auth.localTry <= 3) {
if(/* err.originalError === -404 && */auth.localTry <= 3) {
return this.sendReqPQ({
dcId: auth.dcId,
nonce: new Uint8Array(16).randomize(),

View File

@ -53,7 +53,10 @@
{"name": "is_outgoing", "type": "true"},
{"name": "rReply", "type": "string"},
{"name": "viaBotId", "type": "number"},
{"name": "clear_history", "type": "boolean"}
{"name": "clear_history", "type": "boolean"},
{"name": "pending", "type": "boolean"},
{"name": "error", "type": "any"},
{"name": "send", "type": "() => Promise<any>"}
]
}, {
"predicate": "messageService",