Browse Source

Rework of onNetworkGetArbitraryDataFileListMessage() to support custom hashes to be optionally supplied.

Also simplified the existing logic, to make the code more readable.
block-minter-updates
CalDescent 3 years ago
parent
commit
7994fc6407
  1. 38
      src/main/java/org/qortal/controller/arbitrary/ArbitraryDataFileListManager.java

38
src/main/java/org/qortal/controller/arbitrary/ArbitraryDataFileListManager.java

@ -484,6 +484,7 @@ public class ArbitraryDataFileListManager {
GetArbitraryDataFileListMessage getArbitraryDataFileListMessage = (GetArbitraryDataFileListMessage) message; GetArbitraryDataFileListMessage getArbitraryDataFileListMessage = (GetArbitraryDataFileListMessage) message;
byte[] signature = getArbitraryDataFileListMessage.getSignature(); byte[] signature = getArbitraryDataFileListMessage.getSignature();
String signature58 = Base58.encode(signature); String signature58 = Base58.encode(signature);
List<byte[]> requestedHashes = getArbitraryDataFileListMessage.getHashes();
Long now = NTP.getTime(); Long now = NTP.getTime();
Triple<String, Peer, Long> newEntry = new Triple<>(signature58, peer, now); Triple<String, Peer, Long> newEntry = new Triple<>(signature58, peer, now);
@ -513,21 +514,32 @@ public class ArbitraryDataFileListManager {
// Load file(s) and add any that exist to the list of hashes // Load file(s) and add any that exist to the list of hashes
ArbitraryDataFile arbitraryDataFile = ArbitraryDataFile.fromHash(hash, signature); ArbitraryDataFile arbitraryDataFile = ArbitraryDataFile.fromHash(hash, signature);
if (metadataHash != null) {
arbitraryDataFile.setMetadataHash(metadataHash); arbitraryDataFile.setMetadataHash(metadataHash);
// Assume all chunks exists, unless one can't be found below // If the peer didn't supply a hash list, we need to return all hashes for this transaction
allChunksExist = true; if (requestedHashes == null || requestedHashes.isEmpty()) {
requestedHashes = new ArrayList<>();
// Add the metadata file
if (arbitraryDataFile.getMetadataHash() != null) {
requestedHashes.add(arbitraryDataFile.getMetadataHash());
}
// If we have the metadata file, add its hash // Add the chunk hashes
if (arbitraryDataFile.getMetadataFile().exists()) { if (arbitraryDataFile.getChunkHashes().size() > 0) {
hashes.add(arbitraryDataFile.getMetadataHash()); requestedHashes.addAll(arbitraryDataFile.getChunkHashes());
} }
// Add complete file if there are no hashes
else { else {
allChunksExist = false; requestedHashes.add(arbitraryDataFile.getHash());
}
} }
for (ArbitraryDataFileChunk chunk : arbitraryDataFile.getChunks()) { // Assume all chunks exists, unless one can't be found below
allChunksExist = true;
for (byte[] requestedHash : requestedHashes) {
ArbitraryDataFileChunk chunk = ArbitraryDataFileChunk.fromHash(requestedHash, signature);
if (chunk.exists()) { if (chunk.exists()) {
hashes.add(chunk.getHash()); hashes.add(chunk.getHash());
//LOGGER.trace("Added hash {}", chunk.getHash58()); //LOGGER.trace("Added hash {}", chunk.getHash58());
@ -536,16 +548,6 @@ public class ArbitraryDataFileListManager {
allChunksExist = false; allChunksExist = false;
} }
} }
} else {
// This transaction has no chunks, so include the complete file if we have it
if (arbitraryDataFile.exists()) {
hashes.add(arbitraryDataFile.getHash());
allChunksExist = true;
}
else {
allChunksExist = false;
}
}
} }
} }

Loading…
Cancel
Save