Browse Source

Increased timeout when syncing multiple blocks from 4s to 10s.

sync-multiple-blocks
CalDescent 3 years ago
parent
commit
3aa9b5f0b6
  1. 5
      src/main/java/org/qortal/controller/Synchronizer.java
  2. 23
      src/main/java/org/qortal/network/Peer.java

5
src/main/java/org/qortal/controller/Synchronizer.java

@ -63,6 +63,9 @@ public class Synchronizer {
/* Minimum peer version that supports syncing multiple blocks at once via GetBlocksMessage */
private static final long PEER_VERSION_160 = 0x0100060000L;
/** Maximum time to wait for a peer to respond with blocks (ms) */
private static final int FETCH_BLOCKS_TIMEOUT = 10000;
private static Synchronizer instance;
@ -1189,7 +1192,7 @@ public class Synchronizer {
private List<Block> fetchBlocks(Repository repository, Peer peer, byte[] parentSignature, int numberRequested) throws InterruptedException {
Message getBlocksMessage = new GetBlocksMessage(parentSignature, numberRequested);
Message message = peer.getResponse(getBlocksMessage);
Message message = peer.getResponseWithTimeout(getBlocksMessage, FETCH_BLOCKS_TIMEOUT);
if (message == null || message.getType() != MessageType.BLOCKS) {
return null;
}

23
src/main/java/org/qortal/network/Peer.java

@ -538,18 +538,35 @@ public class Peer {
}
/**
* Send message to peer and await response.
* Send message to peer and await response, using default RESPONSE_TIMEOUT.
* <p>
* Message is assigned a random ID and sent. If a response with matching ID is received then it is returned to caller.
* <p>
* If no response with matching ID within timeout, or some other error/exception occurs, then return <code>null</code>.<br>
* (Assume peer will be rapidly disconnected after this).
*
*
* @param message
* @return <code>Message</code> if valid response received; <code>null</code> if not or error/exception occurs
* @throws InterruptedException
*/
public Message getResponse(Message message) throws InterruptedException {
return getResponseWithTimeout(message, RESPONSE_TIMEOUT);
}
/**
* Send message to peer and await response, using custom timeout.
* <p>
* Message is assigned a random ID and sent. If a response with matching ID is received then it is returned to caller.
* <p>
* If no response with matching ID within timeout, or some other error/exception occurs, then return <code>null</code>.<br>
* (Assume peer will be rapidly disconnected after this).
*
* @param message
* @param timeout
* @return <code>Message</code> if valid response received; <code>null</code> if not or error/exception occurs
* @throws InterruptedException
*/
public Message getResponseWithTimeout(Message message, int timeout) throws InterruptedException {
BlockingQueue<Message> blockingQueue = new ArrayBlockingQueue<>(1);
// Assign random ID to this message
@ -570,7 +587,7 @@ public class Peer {
}
try {
return blockingQueue.poll(RESPONSE_TIMEOUT, TimeUnit.MILLISECONDS);
return blockingQueue.poll(timeout, TimeUnit.MILLISECONDS);
} finally {
this.replyQueues.remove(id);
}

Loading…
Cancel
Save