forked from Qortal/qortal
Increased timeout when syncing multiple blocks from 4s to 10s.
This commit is contained in:
parent
6c5dbf7bd0
commit
3aa9b5f0b6
@ -63,6 +63,9 @@ public class Synchronizer {
|
|||||||
/* Minimum peer version that supports syncing multiple blocks at once via GetBlocksMessage */
|
/* Minimum peer version that supports syncing multiple blocks at once via GetBlocksMessage */
|
||||||
private static final long PEER_VERSION_160 = 0x0100060000L;
|
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;
|
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 {
|
private List<Block> fetchBlocks(Repository repository, Peer peer, byte[] parentSignature, int numberRequested) throws InterruptedException {
|
||||||
Message getBlocksMessage = new GetBlocksMessage(parentSignature, numberRequested);
|
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) {
|
if (message == null || message.getType() != MessageType.BLOCKS) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -538,7 +538,7 @@ public class Peer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send message to peer and await response.
|
* Send message to peer and await response, using default RESPONSE_TIMEOUT.
|
||||||
* <p>
|
* <p>
|
||||||
* Message is assigned a random ID and sent. If a response with matching ID is received then it is returned to caller.
|
* Message is assigned a random ID and sent. If a response with matching ID is received then it is returned to caller.
|
||||||
* <p>
|
* <p>
|
||||||
@ -550,6 +550,23 @@ public class Peer {
|
|||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
*/
|
*/
|
||||||
public Message getResponse(Message message) 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);
|
BlockingQueue<Message> blockingQueue = new ArrayBlockingQueue<>(1);
|
||||||
|
|
||||||
// Assign random ID to this message
|
// Assign random ID to this message
|
||||||
@ -570,7 +587,7 @@ public class Peer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return blockingQueue.poll(RESPONSE_TIMEOUT, TimeUnit.MILLISECONDS);
|
return blockingQueue.poll(timeout, TimeUnit.MILLISECONDS);
|
||||||
} finally {
|
} finally {
|
||||||
this.replyQueues.remove(id);
|
this.replyQueues.remove(id);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user