Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sending errors handling #1244

Merged
merged 3 commits into from Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion Gruntfile.js
Expand Up @@ -90,7 +90,6 @@ module.exports = grunt => {
'libtextsecure/websocket-resources.js',
'libtextsecure/http-resources.js',
'libtextsecure/message_receiver.js',
'libtextsecure/outgoing_message.js',
'libtextsecure/sendmessage.js',
'libtextsecure/sync_request.js',
'libtextsecure/contacts_parser.js',
Expand Down
16 changes: 11 additions & 5 deletions js/models/messages.js
Expand Up @@ -1087,17 +1087,25 @@
}

const { body, attachments, preview, quote } = await this.uploadData();
const ourNumber = window.storage.get('primaryDevicePubKey');
const ourConversation = window.ConversationController.get(ourNumber);

const chatMessage = new libsession.Messages.Outgoing.ChatMessage({
const chatParams = {
identifier: this.id,
body,
timestamp: this.get('sent_at'),
expireTimer: this.get('expireTimer'),
attachments,
preview,
quote,
lokiProfile: this.conversation.getOurProfile(),
});
};
if (ourConversation) {
chatParams.lokiProfile = ourConversation.getOurProfile();
}

const chatMessage = new libsession.Messages.Outgoing.ChatMessage(
chatParams
);

// Special-case the self-send case - we send only a sync message
if (recipients.length === 1) {
Expand Down Expand Up @@ -1200,7 +1208,6 @@
e =>
e.number === number &&
(e.name === 'MessageError' ||
e.name === 'OutgoingMessageError' ||
e.name === 'SendMessageNetworkError' ||
e.name === 'SignedPreKeyRotationError' ||
e.name === 'OutgoingIdentityKeyError')
Expand Down Expand Up @@ -1547,7 +1554,6 @@
this.get('errors'),
e =>
e.name === 'MessageError' ||
e.name === 'OutgoingMessageError' ||
e.name === 'SendMessageNetworkError' ||
e.name === 'SignedPreKeyRotationError'
);
Expand Down
3 changes: 2 additions & 1 deletion js/modules/loki_message_api.js
Expand Up @@ -96,8 +96,9 @@ class LokiMessageAPI {
// eslint-disable-next-line more/no-then
snode = await primitives.firstTrue(promises);
} catch (e) {
const snodeStr = snode ? `${snode.ip}:${snode.port}` : 'null';
log.warn(
`loki_message:::sendMessage - ${e.code} ${e.message} to ${pubKey} via ${snode.ip}:${snode.port}`
`loki_message:::sendMessage - ${e.code} ${e.message} to ${pubKey} via snode:${snodeStr}`
);
if (e instanceof textsecure.WrongDifficultyError) {
// Force nonce recalculation
Expand Down
1 change: 0 additions & 1 deletion js/modules/metadata/SecretSessionCipher.js
Expand Up @@ -411,7 +411,6 @@ SecretSessionCipher.prototype = {
return cipher.getRemoteRegistrationId();
},

// Used by outgoing_message.js
closeOpenSessionForDevice(remoteAddress) {
const { SessionCipher } = this;
const signalProtocolStore = this.storage;
Expand Down
5 changes: 0 additions & 5 deletions js/signal_protocol_store.js
Expand Up @@ -379,11 +379,6 @@
const sessions = allSessions.filter(session => session.number === number);
return _.pluck(sessions, 'deviceId');
},
async removeSession(encodedNumber) {
window.log.info('deleting session for ', encodedNumber);
delete this.sessions[encodedNumber];
await window.Signal.Data.removeSessionById(encodedNumber);
},
async removeAllSessions(number) {
if (number === null || number === undefined) {
throw new Error('Tried to remove sessions for undefined/null number');
Expand Down
8 changes: 0 additions & 8 deletions libloki/api.js
Expand Up @@ -9,7 +9,6 @@
GROUP_SYNC_MESSAGES: 1,
CONTACT_SYNC_MESSAGES: 2,
FALLBACK_MESSAGES: 8,
SESSION_MESSAGE_SENDING: 16,
SESSION_BACKGROUND_MESSAGE: 32,
GROUP_REQUEST_INFO: 64,
// If you add any new flag, be sure it is bitwise safe! (unique and 2 multiples)
Expand All @@ -24,12 +23,6 @@
}
};

function logSessionMessageSending(...args) {
if (debugFlags & DebugFlagsEnum.SESSION_MESSAGE_SENDING) {
debugLogFn(...args);
}
}

function logGroupSync(...args) {
if (debugFlags & DebugFlagsEnum.GROUP_SYNC_MESSAGES) {
debugLogFn(...args);
Expand Down Expand Up @@ -119,7 +112,6 @@
const debug = {
logContactSync,
logGroupSync,
logSessionMessageSending,
logBackgroundMessage,
logGroupRequestInfo,
};
Expand Down
1 change: 0 additions & 1 deletion libloki/test/index.html
Expand Up @@ -23,7 +23,6 @@
<script type="text/javascript" src="../../libtextsecure/protocol_wrapper.js" data-cover></script>
<script type="text/javascript" src="../../libtextsecure/protobufs.js" data-cover></script>
<script type="text/javascript" src="../../libtextsecure/stringview.js" data-cover></script>
<script type="text/javascript" src="../../libtextsecure/outgoing_message.js" data-cover></script>

<script type="text/javascript" src="../api.js" data-cover></script>
<script type="text/javascript" src="../crypto.js" data-cover></script>
Expand Down
33 changes: 0 additions & 33 deletions libtextsecure/errors.js
Expand Up @@ -59,22 +59,6 @@
}
inherit(ReplayableError, OutgoingIdentityKeyError);

function OutgoingMessageError(number, message, timestamp, httpError) {
// eslint-disable-next-line prefer-destructuring
this.number = number.split('.')[0];

ReplayableError.call(this, {
name: 'OutgoingMessageError',
message: httpError ? httpError.message : 'no http error',
});

if (httpError) {
this.code = httpError.code;
appendStack(this, httpError);
}
}
inherit(ReplayableError, OutgoingMessageError);

function SendMessageNetworkError(number, jsonData, httpError) {
this.number = number;
this.code = httpError.code;
Expand Down Expand Up @@ -119,21 +103,6 @@
}
inherit(ReplayableError, EmptySwarmError);

function PoWError(number, error) {
// eslint-disable-next-line prefer-destructuring
this.number = number.split('.')[0];

ReplayableError.call(this, {
name: 'PoWError',
message: 'Failed to calculate PoW',
});

if (error) {
appendStack(this, error);
}
}
inherit(ReplayableError, PoWError);

function DNSResolutionError(message) {
// eslint-disable-next-line prefer-destructuring

Expand Down Expand Up @@ -261,10 +230,8 @@
window.textsecure.IncomingIdentityKeyError = IncomingIdentityKeyError;
window.textsecure.OutgoingIdentityKeyError = OutgoingIdentityKeyError;
window.textsecure.ReplayableError = ReplayableError;
window.textsecure.OutgoingMessageError = OutgoingMessageError;
window.textsecure.MessageError = MessageError;
window.textsecure.SignedPreKeyRotationError = SignedPreKeyRotationError;
window.textsecure.PoWError = PoWError;
window.textsecure.EmptySwarmError = EmptySwarmError;
window.textsecure.SeedNodeError = SeedNodeError;
window.textsecure.DNSResolutionError = DNSResolutionError;
Expand Down
2 changes: 0 additions & 2 deletions libtextsecure/index.d.ts
Expand Up @@ -8,10 +8,8 @@ export interface LibTextsecure {
IncomingIdentityKeyError: any;
OutgoingIdentityKeyError: any;
ReplayableError: any;
OutgoingMessageError: any;
MessageError: any;
SignedPreKeyRotationError: any;
PoWError: any;
EmptySwarmError: any;
SeedNodeError: any;
DNSResolutionError: any;
Expand Down
12 changes: 0 additions & 12 deletions libtextsecure/outgoing_message.js
Expand Up @@ -580,18 +580,6 @@ OutgoingMessage.prototype = {
this.sendSessionMessage(outgoingObjects);
},

removeDeviceIdsForNumber(number, deviceIdsToRemove) {
let promise = Promise.resolve();
// eslint-disable-next-line no-restricted-syntax, guard-for-in
for (const j in deviceIdsToRemove) {
promise = promise.then(() => {
const encodedNumber = `${number}.${deviceIdsToRemove[j]}`;
return textsecure.storage.protocol.removeSession(encodedNumber);
});
}
return promise;
},

sendToNumber(number, multiDevice = true) {
return this.reloadDevicesAndSend(number, multiDevice).catch(error => {
if (error.message === 'Identity key changed') {
Expand Down
2 changes: 0 additions & 2 deletions ts/session/snode_api/serviceNodeAPI.ts
Expand Up @@ -298,8 +298,6 @@ export async function storeOnNode(
return false;
}

const res = snodeRes as any;

const json = JSON.parse(snodeRes.body);
// Make sure we aren't doing too much PoW
const currentDifficulty = window.storage.get('PoWDifficulty', null);
Expand Down
8 changes: 2 additions & 6 deletions ts/test/types/Conversation_test.ts
@@ -1,11 +1,7 @@
import { assert } from 'chai';

import * as Conversation from '../../types/Conversation';
import {
IncomingMessage,
OutgoingMessage,
VerifiedChangeMessage,
} from '../../types/Message';
import { IncomingMessage, VerifiedChangeMessage } from '../../types/Message';

describe('Conversation', () => {
describe('createLastMessageUpdate', () => {
Expand All @@ -31,7 +27,7 @@ describe('Conversation', () => {
conversationId: 'foo',
sent_at: 666,
timestamp: 666,
} as OutgoingMessage,
} as any,
lastMessageNotificationText: 'New outgoing message',
};
const expected = {
Expand Down
30 changes: 2 additions & 28 deletions ts/types/Message.ts
Expand Up @@ -3,7 +3,7 @@ import { Contact } from './Contact';
import { IndexableBoolean, IndexablePresence } from './IndexedDB';

export type Message = UserMessage | VerifiedChangeMessage;
export type UserMessage = IncomingMessage | OutgoingMessage;
export type UserMessage = IncomingMessage;

export type IncomingMessage = Readonly<
{
Expand All @@ -27,32 +27,6 @@ export type IncomingMessage = Readonly<
ExpirationTimerUpdate
>;

export type OutgoingMessage = Readonly<
{
type: 'outgoing';

// Required
attachments: Array<Attachment>;
delivered: number;
delivered_to: Array<string>;
destination: string; // PhoneNumber
expirationStartTimestamp: number;
id: string;
received_at: number;
sent: boolean;
sent_to: Array<string>; // Array<PhoneNumber>

// Optional
body?: string;
expires_at?: number;
expireTimer?: number;
recipients?: Array<string>; // Array<PhoneNumber>
synced: boolean;
} & SharedMessageProperties &
MessageSchemaVersion5 &
ExpirationTimerUpdate
>;

export type VerifiedChangeMessage = Readonly<
{
type: 'verified-change';
Expand Down Expand Up @@ -92,7 +66,7 @@ type MessageSchemaVersion6 = Partial<
>;

export const isUserMessage = (message: Message): message is UserMessage =>
message.type === 'incoming' || message.type === 'outgoing';
message.type === 'incoming';

export const hasExpiration = (message: Message): boolean => {
if (!isUserMessage(message)) {
Expand Down