Add hint that messages must be regularly received

This commit is contained in:
AsamK 2021-05-24 12:14:44 +02:00
parent 2a0bba62be
commit cfc818872f
4 changed files with 31 additions and 1 deletions

View file

@ -57,6 +57,8 @@ Important: The USERNAME is your phone number in international format and must in
signal-cli -u USERNAME receive
**Hint**: The Signal protocol expects that incoming messages are regularly received (using `daemon` or `receive` command).
This is required for the encryption to work efficiently and for getting updates to groups, expiration timer and other features.
## Storage

View file

@ -330,6 +330,17 @@ public class Manager implements Closeable {
}
public void checkAccountState() throws IOException {
if (account.getLastReceiveTimestamp() == 0) {
logger.warn("The Signal protocol expects that incoming messages are regularly received.");
} else {
var diffInMilliseconds = new Date().getTime() - account.getLastReceiveTimestamp();
long days = TimeUnit.DAYS.convert(diffInMilliseconds, TimeUnit.MILLISECONDS);
if (days > 7) {
logger.warn(
"Messages have been last received {} days ago. The Signal protocol expects that incoming messages are regularly received.",
days);
}
}
if (accountManager.getPreKeysCount() < ServiceConfig.PREKEY_MINIMUM_COUNT) {
refreshPreKeys();
}
@ -1982,6 +1993,7 @@ public class Manager implements Closeable {
SignalServiceContent content = null;
Exception exception = null;
final CachedMessage[] cachedMessage = {null};
account.setLastReceiveTimestamp(new Date().getTime());
try {
var result = messagePipe.readOrEmpty(timeout, unit, envelope1 -> {
final var recipientId = envelope1.hasSource()

View file

@ -84,6 +84,7 @@ public class SignalAccount implements Closeable {
private ProfileKey profileKey;
private int preKeyIdOffset;
private int nextSignedPreKeyId;
private long lastReceiveTimestamp = 0;
private boolean registered = false;
@ -261,6 +262,7 @@ public class SignalAccount implements Closeable {
this.deviceId = deviceId;
this.registered = true;
this.isMultiDevice = true;
this.lastReceiveTimestamp = 0;
}
private void migrateLegacyConfigs() {
@ -368,6 +370,9 @@ public class SignalAccount implements Closeable {
if (rootNode.hasNonNull("isMultiDevice")) {
isMultiDevice = rootNode.get("isMultiDevice").asBoolean();
}
if (rootNode.hasNonNull("lastReceiveTimestamp")) {
lastReceiveTimestamp = rootNode.get("lastReceiveTimestamp").asLong();
}
int registrationId = 0;
if (rootNode.hasNonNull("registrationId")) {
registrationId = rootNode.get("registrationId").asInt();
@ -637,6 +642,7 @@ public class SignalAccount implements Closeable {
.put("deviceName", encryptedDeviceName)
.put("deviceId", deviceId)
.put("isMultiDevice", isMultiDevice)
.put("lastReceiveTimestamp", lastReceiveTimestamp)
.put("password", password)
.put("registrationId", identityKeyStore.getLocalRegistrationId())
.put("identityPrivateKey",
@ -870,6 +876,15 @@ public class SignalAccount implements Closeable {
save();
}
public long getLastReceiveTimestamp() {
return lastReceiveTimestamp;
}
public void setLastReceiveTimestamp(final long lastReceiveTimestamp) {
this.lastReceiveTimestamp = lastReceiveTimestamp;
save();
}
public boolean isUnrestrictedUnidentifiedAccess() {
// TODO make configurable
return false;
@ -893,6 +908,7 @@ public class SignalAccount implements Closeable {
this.registered = true;
this.uuid = uuid;
this.registrationLockPin = pin;
this.lastReceiveTimestamp = 0;
save();
getSessionStore().archiveAllSessions();

View file

@ -14,7 +14,7 @@ public class DateUtils {
public static String formatTimestamp(long timestamp) {
var date = new Date(timestamp);
final DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"); // Quoted "Z" to indicate UTC, no timezone offset
final DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
df.setTimeZone(tzUTC);
return timestamp + " (" + df.format(date) + ")";
}