Skip to content
This repository has been archived by the owner on Aug 5, 2021. It is now read-only.

Commit

Permalink
SessionCipher: allow caller to provide fillMessageKeys limit
Browse files Browse the repository at this point in the history
If options.messageKeysLimit is provided by falsey, then we don't apply
any limit at all. This can be used to set no limit for communications
from your own devices.

Why would you want that? People leave their laptops closed for weeks at
a time and get this error, since their other devices are sending
messages to it constantly:

"Too many message keys for chain"

And it seems to be really hard to fix once you're in this state. Sync
messages no longer show up from the device that got into this state.

FREEBIE
  • Loading branch information
scottnonnenberg committed Aug 4, 2017
1 parent 66be05f commit e4144ee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
11 changes: 9 additions & 2 deletions dist/libsignal-protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -36051,7 +36051,14 @@ libsignal.SessionBuilder = function (storage, remoteAddress) {
this.processV3 = builder.processV3.bind(builder);
};

function SessionCipher(storage, remoteAddress) {
function SessionCipher(storage, remoteAddress, options) {
options = options || {};

if (typeof options.messageKeysLimit === 'undefined') {
options.messageKeysLimit = 1000;
}

this.messageKeysLimit = options.messageKeyLimit;
this.remoteAddress = remoteAddress;
this.storage = storage;
}
Expand Down Expand Up @@ -36332,7 +36339,7 @@ SessionCipher.prototype = {
});
},
fillMessageKeys: function(chain, counter) {
if (Object.keys(chain.messageKeys).length >= 1000) {
if (this.messageKeysLimit && Object.keys(chain.messageKeys).length >= this.messageKeysLimit) {
console.log("Too many message keys for chain");
return Promise.resolve(); // Stalker, much?
}
Expand Down
11 changes: 9 additions & 2 deletions src/SessionCipher.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
function SessionCipher(storage, remoteAddress) {
function SessionCipher(storage, remoteAddress, options) {
options = options || {};

if (typeof options.messageKeysLimit === 'undefined') {
options.messageKeysLimit = 1000;
}

this.messageKeysLimit = options.messageKeyLimit;
this.remoteAddress = remoteAddress;
this.storage = storage;
}
Expand Down Expand Up @@ -279,7 +286,7 @@ SessionCipher.prototype = {
});
},
fillMessageKeys: function(chain, counter) {
if (Object.keys(chain.messageKeys).length >= 1000) {
if (this.messageKeysLimit && Object.keys(chain.messageKeys).length >= this.messageKeysLimit) {
console.log("Too many message keys for chain");
return Promise.resolve(); // Stalker, much?
}
Expand Down

0 comments on commit e4144ee

Please sign in to comment.