Add additional logging for reading message cache

This commit is contained in:
AsamK 2022-10-19 11:02:10 +02:00
parent 9da42e27f1
commit 316c35b258
2 changed files with 11 additions and 3 deletions

View file

@ -27,7 +27,7 @@ public final class CachedMessage {
try {
return MessageCacheUtils.loadEnvelope(file);
} catch (Exception e) {
logger.error("Failed to load cached message envelope “{}”: {}", file, e.getMessage());
logger.error("Failed to load cached message envelope “{}”: {}", file, e.getMessage(), e);
return null;
}
}

View file

@ -1,5 +1,7 @@
package org.asamk.signal.manager.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
@ -15,11 +17,17 @@ import java.util.Optional;
public class MessageCacheUtils {
private final static Logger logger = LoggerFactory.getLogger(MessageCacheUtils.class);
final static int CURRENT_VERSION = 8;
public static SignalServiceEnvelope loadEnvelope(File file) throws IOException {
try (var f = new FileInputStream(file)) {
var in = new DataInputStream(f);
var version = in.readInt();
if (version > 8) {
logger.trace("Reading cached envelope file with version {} (current: {})", version, CURRENT_VERSION);
if (version > CURRENT_VERSION) {
logger.warn("Unsupported envelope version {} (current: {})", version, CURRENT_VERSION);
// Unsupported envelope version
return null;
}
@ -96,7 +104,7 @@ public class MessageCacheUtils {
public static void storeEnvelope(SignalServiceEnvelope envelope, File file) throws IOException {
try (var f = new FileOutputStream(file)) {
try (var out = new DataOutputStream(f)) {
out.writeInt(8); // version
out.writeInt(CURRENT_VERSION); // version
out.writeInt(envelope.getType());
out.writeUTF(""); // legacy number
out.writeUTF(envelope.getSourceUuid().isPresent() ? envelope.getSourceUuid().get() : "");