forked from Qortal/qortal
Rework of onNetworkGetArbitraryDataFileListMessage() to support custom hashes to be optionally supplied.
Also simplified the existing logic, to make the code more readable.
This commit is contained in:
parent
d98df3e47d
commit
7994fc6407
@ -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,36 +514,37 @@ 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<>();
|
||||||
|
|
||||||
// If we have the metadata file, add its hash
|
// Add the metadata file
|
||||||
if (arbitraryDataFile.getMetadataFile().exists()) {
|
if (arbitraryDataFile.getMetadataHash() != null) {
|
||||||
hashes.add(arbitraryDataFile.getMetadataHash());
|
requestedHashes.add(arbitraryDataFile.getMetadataHash());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add the chunk hashes
|
||||||
|
if (arbitraryDataFile.getChunkHashes().size() > 0) {
|
||||||
|
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
|
||||||
if (chunk.exists()) {
|
allChunksExist = true;
|
||||||
hashes.add(chunk.getHash());
|
|
||||||
//LOGGER.trace("Added hash {}", chunk.getHash58());
|
for (byte[] requestedHash : requestedHashes) {
|
||||||
} else {
|
ArbitraryDataFileChunk chunk = ArbitraryDataFileChunk.fromHash(requestedHash, signature);
|
||||||
LOGGER.trace("Couldn't add hash {} because it doesn't exist", chunk.getHash58());
|
if (chunk.exists()) {
|
||||||
allChunksExist = false;
|
hashes.add(chunk.getHash());
|
||||||
}
|
//LOGGER.trace("Added hash {}", chunk.getHash58());
|
||||||
}
|
} else {
|
||||||
} else {
|
LOGGER.trace("Couldn't add hash {} because it doesn't exist", chunk.getHash58());
|
||||||
// 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;
|
allChunksExist = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user