Removed online broadcast message type, changed ttl logic a little, add p2p address and port to the window object when recieve message

pull/157/head
Beaudan 6 years ago
parent 07076c27ae
commit 2bae6b5eed

@ -1,5 +1,6 @@
{ {
"storageProfile": "development1", "storageProfile": "development1",
"localServerPort": "8082",
"disableAutoUpdate": true, "disableAutoUpdate": true,
"openDevTools": true "openDevTools": true
} }

@ -182,8 +182,8 @@
} }
try { try {
const swarmNodes = await window.LokiSnodeAPI.getFreshSwarmNodes(id); const swarmNodes = await window.LokiSnodeAPI.getFreshSwarmNodes(id);
conversation.set({ swarmNodes}); conversation.set({ swarmNodes });
await window.Signal.Data.saveConversation(conversation.attributes, { await window.Signal.Data.saveConversation(conversation.attributes, {
Conversation: Whisper.Conversation, Conversation: Whisper.Conversation,
}); });

@ -18,14 +18,12 @@
} }
async function sendOnlineBroadcastMessage(pubKey) { async function sendOnlineBroadcastMessage(pubKey) {
const onlineBroadcastMessage = new textsecure.protobuf.OnlineBroadcastMessage( const lokiAddressMessage = new textsecure.protobuf.LokiAddressMessage({
{ p2pAddress: 'testAddress',
p2pAddress: 'testAddress', p2pPort: parseInt(window.localServerPort, 10),
p2pPort: parseInt(window.localServerPort, 10), });
}
);
const content = new textsecure.protobuf.Content({ const content = new textsecure.protobuf.Content({
onlineBroadcastMessage, lokiAddressMessage,
}); });
// will be called once the transmission succeeded or failed // will be called once the transmission succeeded or failed

@ -712,16 +712,6 @@ MessageReceiver.prototype.extend({
.then(this.unpad) .then(this.unpad)
.then(handleSessionReset); .then(handleSessionReset);
break; break;
case textsecure.protobuf.Envelope.Type.ONLINE_BROADCAST:
window.log.info(
'Online broadcast message from',
this.getEnvelopeId(envelope)
);
promise = captureActiveSession()
.then(() => sessionCipher.decryptWhisperMessage(ciphertext))
.then(this.unpad)
.then(handleSessionReset);
break;
case textsecure.protobuf.Envelope.Type.FRIEND_REQUEST: { case textsecure.protobuf.Envelope.Type.FRIEND_REQUEST: {
window.log.info('friend-request message from ', envelope.source); window.log.info('friend-request message from ', envelope.source);
promise = fallBackSessionCipher promise = fallBackSessionCipher
@ -908,8 +898,8 @@ MessageReceiver.prototype.extend({
}) })
); );
}, },
async handleOnlineBroadcastMessage(envelope, onlineBroadcastMessage) { async handleLokiAddressMessage(envelope, lokiAddressMessage) {
const { p2pAddress, p2pPort } = onlineBroadcastMessage; const { p2pAddress, p2pPort } = lokiAddressMessage;
window.LokiP2pAPI.addContactP2pDetails( window.LokiP2pAPI.addContactP2pDetails(
envelope.source, envelope.source,
p2pAddress, p2pAddress,
@ -1031,10 +1021,10 @@ MessageReceiver.prototype.extend({
envelope.source, envelope.source,
content.preKeyBundleMessage content.preKeyBundleMessage
); );
if (content.onlineBroadcastMessage) if (content.lokiAddressMessage)
return this.handleOnlineBroadcastMessage( return this.handleLokiAddressMessage(
envelope, envelope,
content.onlineBroadcastMessage content.lokiAddressMessage
); );
if (content.syncMessage) if (content.syncMessage)
return this.handleSyncMessage(envelope, content.syncMessage); return this.handleSyncMessage(envelope, content.syncMessage);

@ -336,13 +336,19 @@ OutgoingMessage.prototype = {
dcodeIO.ByteBuffer.wrap(ciphertext.body, 'binary').toArrayBuffer() dcodeIO.ByteBuffer.wrap(ciphertext.body, 'binary').toArrayBuffer()
); );
} }
const outgoingObjectType = let ttl;
this.messageType === 'onlineBroadcast' if (this.messageType === 'friend-request') {
? textsecure.protobuf.Envelope.Type.ONLINE_BROADCAST ttl = 4 * 24 * 60 * 60; // 4 days for friend request message
: ciphertext.type; // FallBackSessionCipher sets this to FRIEND_REQUEST } else if (this.messageType === 'onlineBroadcast') {
ttl = 10 * 60; // 10 minutes for online broadcast message
} else {
const hours = window.getMessageTTL() || 24; // 1 day default for any other message
ttl = hours * 60 * 60;
}
return { return {
type: outgoingObjectType, type: ciphertext.type, // FallBackSessionCipher sets this to FRIEND_REQUEST
ttl,
ourKey, ourKey,
sourceDevice: 1, sourceDevice: 1,
destinationRegistrationId: ciphertext.registrationId, destinationRegistrationId: ciphertext.registrationId,
@ -354,21 +360,12 @@ OutgoingMessage.prototype = {
// TODO: handle multiple devices/messages per transmit // TODO: handle multiple devices/messages per transmit
const outgoingObject = outgoingObjects[0]; const outgoingObject = outgoingObjects[0];
const socketMessage = await this.wrapInWebsocketMessage(outgoingObject); const socketMessage = await this.wrapInWebsocketMessage(outgoingObject);
let ttl; await this.transmitMessage(
switch (outgoingObject.type) { number,
case textsecure.protobuf.Envelope.Type.FRIEND_REQUEST: socketMessage,
ttl = 4 * 24 * 60 * 60; // 4 days for friend request message this.timestamp,
break; outgoingObject.ttl
case textsecure.protobuf.Envelope.Type.ONLINE_BROADCAST: );
ttl = 10 * 60; // 10 minutes for online broadcast message
break;
default: {
const hours = window.getMessageTTL() || 24; // 1 day default for any other message
ttl = hours * 60 * 60;
break;
}
}
await this.transmitMessage(number, socketMessage, this.timestamp, ttl);
this.successfulNumbers[this.successfulNumbers.length] = number; this.successfulNumbers[this.successfulNumbers.length] = number;
this.numberCompleted(); this.numberCompleted();
}) })

@ -13,7 +13,6 @@ message Envelope {
RECEIPT = 5; RECEIPT = 5;
UNIDENTIFIED_SENDER = 6; UNIDENTIFIED_SENDER = 6;
FRIEND_REQUEST = 101; // contains prekeys + message and is using simple encryption FRIEND_REQUEST = 101; // contains prekeys + message and is using simple encryption
ONLINE_BROADCAST = 102; // Contains address and port information for p2p messaging
} }
optional Type type = 1; optional Type type = 1;
@ -36,10 +35,10 @@ message Content {
optional ReceiptMessage receiptMessage = 5; optional ReceiptMessage receiptMessage = 5;
optional TypingMessage typingMessage = 6; optional TypingMessage typingMessage = 6;
optional PreKeyBundleMessage preKeyBundleMessage = 101; optional PreKeyBundleMessage preKeyBundleMessage = 101;
optional OnlineBroadcastMessage onlineBroadcastMessage = 102; optional LokiAddressMessage lokiAddressMessage = 102;
} }
message OnlineBroadcastMessage { message LokiAddressMessage {
optional string p2pAddress = 1; optional string p2pAddress = 1;
optional uint32 p2pPort = 2; optional uint32 p2pPort = 2;
} }

Loading…
Cancel
Save