Browse Source

Further work to increase the response timeout when requesting multiple blocks.

sync-multiple-blocks
CalDescent 3 years ago
parent
commit
f58a52eaa4
  1. 4
      src/main/java/org/qortal/controller/Controller.java
  2. 16
      src/main/java/org/qortal/network/Peer.java

4
src/main/java/org/qortal/controller/Controller.java

@ -103,6 +103,8 @@ import org.qortal.utils.Triple;
import com.google.common.primitives.Longs;
import static org.qortal.network.Peer.FETCH_BLOCKS_TIMEOUT;
public class Controller extends Thread {
static {
@ -1374,7 +1376,7 @@ public class Controller extends Thread {
Message blocksMessage = new BlocksMessage(blocks);
blocksMessage.setId(message.getId());
if (!peer.sendMessage(blocksMessage))
if (!peer.sendMessageWithTimeout(blocksMessage, FETCH_BLOCKS_TIMEOUT))
peer.disconnect("failed to send blocks");
} catch (DataException e) {

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

@ -524,12 +524,22 @@ public class Peer {
}
/**
* Attempt to send Message to peer.
* Attempt to send Message to peer, using default RESPONSE_TIMEOUT.
*
* @param message message to be sent
* @return <code>true</code> if message successfully sent; <code>false</code> otherwise
*/
public boolean sendMessage(Message message) {
return this.sendMessageWithTimeout(message, RESPONSE_TIMEOUT);
}
/**
* Attempt to send Message to peer, using custom timeout.
*
* @param message message to be sent
* @return <code>true</code> if message successfully sent; <code>false</code> otherwise
*/
public boolean sendMessageWithTimeout(Message message, int timeout) {
if (!this.socketChannel.isOpen()) {
return false;
}
@ -563,7 +573,7 @@ public class Peer {
*/
Thread.sleep(1L); //NOSONAR squid:S2276
if (System.currentTimeMillis() - sendStart > RESPONSE_TIMEOUT) {
if (System.currentTimeMillis() - sendStart > timeout) {
// We've taken too long to send this message
return false;
}
@ -630,7 +640,7 @@ public class Peer {
message.setId(id);
// Try to send message
if (!this.sendMessage(message)) {
if (!this.sendMessageWithTimeout(message, timeout)) {
this.replyQueues.remove(id);
return null;
}

Loading…
Cancel
Save