cache: store index and archive crcs, and check them for updates too

Switch archive storage to CAS as sometimes archives change content without changing revision
This commit is contained in:
Adam
2017-09-24 15:44:16 -04:00
parent 52d46c1272
commit 7ce893af7b
10 changed files with 161 additions and 58 deletions

View File

@@ -58,6 +58,7 @@ import net.runelite.cache.protocol.packets.ArchiveRequestPacket;
import net.runelite.cache.protocol.packets.HandshakePacket;
import net.runelite.cache.protocol.packets.HandshakeResponseType;
import net.runelite.cache.protocol.packets.HandshakeType;
import net.runelite.cache.util.Crc32;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -268,7 +269,9 @@ public class CacheClient implements AutoCloseable
{
Archive existing = index.getArchive(ad.getId());
if (existing != null && existing.getRevision() == ad.getRevision())
if (existing != null && existing.getRevision() == ad.getRevision()
&& existing.getCrc() == ad.getCrc()
&& existing.getNameHash() == ad.getNameHash())
{
logger.info("Archive {}/{} in index {} is up to date",
ad.getId(), indexData.getArchives().length, index.getId());
@@ -288,9 +291,12 @@ public class CacheClient implements AutoCloseable
}
else
{
logger.info("Archive {}/{} in index {} is out of date ({} != {}), downloading",
logger.info("Archive {}/{} in index {} is out of date, downloading. " +
"revision: ours: {} theirs: {}, crc: ours: {} theirs {}, name: ours {} theirs {}",
ad.getId(), indexData.getArchives().length, index.getId(),
existing.getRevision(), ad.getRevision());
existing.getRevision(), ad.getRevision(),
existing.getCrc(), ad.getCrc(),
existing.getNameHash(), ad.getNameHash());
}
final Archive archive = existing == null
@@ -313,7 +319,20 @@ public class CacheClient implements AutoCloseable
CompletableFuture<FileResult> future = requestFile(index.getId(), ad.getId(), false);
future.handle((fr, ex) ->
{
archive.setData(fr.getCompressedData());
byte[] data = fr.getCompressedData();
Crc32 crc32 = new Crc32();
crc32.update(data, 0, data.length);
int hash = crc32.getHash();
if (hash != archive.getCrc())
{
logger.warn("crc mismatch on downloaded archive {}/{}: {} != {}",
archive.getIndex().getId(), archive.getArchiveId(),
hash, archive.getCrc());
}
archive.setData(data);
if (watcher != null)
{

View File

@@ -115,6 +115,8 @@ public class ArchiveResponseDecoder extends ByteToMessageDecoder
archiveResponse.setArchive(file);
archiveResponse.setData(compressedData.array());
out.add(archiveResponse);
compressedData.release();
}
/**