}
private void processBlockHashes(BlockHashesMessage blockHashesMessage) {
List<byte[]> receivedHashes = blockHashesMessage.getBlockHashes();
BlockQueue chainQueue = blockchain.getQueue();
// result is empty, peer has no more hashes
// or peer doesn't have the best hash anymore
if (receivedHashes.isEmpty()
|| !this.peerId.equals(hashRetrievalLock)) {
startGetBlockTimer(); // start getting blocks from hash queue
return;
}
Iterator<byte[]> hashIterator = receivedHashes.iterator();
byte[] foundHash, latestHash = blockchain.getBestBlockHash();
while (hashIterator.hasNext()) {
foundHash = hashIterator.next();
if (FastByteComparisons.compareTo(foundHash, 0, 32, latestHash, 0, 32) != 0){
chainQueue.addHash(foundHash); // store unknown hashes in queue until known hash is found
}
else {
logger.trace("Catch up with the hashes until: {[]}", foundHash);
// if known hash is found, ignore the rest
startGetBlockTimer(); // start getting blocks from hash queue
return;
}
}
// no known hash has been reached
chainQueue.logHashQueueSize();
sendGetBlockHashes(); // another getBlockHashes with last received hash.
}