mirror of
https://github.com/Qortal/qortal.git
synced 2025-02-13 02:35:50 +00:00
Further work to increase the response timeout when requesting multiple blocks.
This commit is contained in:
parent
688404011b
commit
f58a52eaa4
@ -103,6 +103,8 @@ import org.qortal.utils.Triple;
|
|||||||
|
|
||||||
import com.google.common.primitives.Longs;
|
import com.google.common.primitives.Longs;
|
||||||
|
|
||||||
|
import static org.qortal.network.Peer.FETCH_BLOCKS_TIMEOUT;
|
||||||
|
|
||||||
public class Controller extends Thread {
|
public class Controller extends Thread {
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@ -1374,7 +1376,7 @@ public class Controller extends Thread {
|
|||||||
|
|
||||||
Message blocksMessage = new BlocksMessage(blocks);
|
Message blocksMessage = new BlocksMessage(blocks);
|
||||||
blocksMessage.setId(message.getId());
|
blocksMessage.setId(message.getId());
|
||||||
if (!peer.sendMessage(blocksMessage))
|
if (!peer.sendMessageWithTimeout(blocksMessage, FETCH_BLOCKS_TIMEOUT))
|
||||||
peer.disconnect("failed to send blocks");
|
peer.disconnect("failed to send blocks");
|
||||||
|
|
||||||
} catch (DataException e) {
|
} catch (DataException e) {
|
||||||
|
@ -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
|
* @param message message to be sent
|
||||||
* @return <code>true</code> if message successfully sent; <code>false</code> otherwise
|
* @return <code>true</code> if message successfully sent; <code>false</code> otherwise
|
||||||
*/
|
*/
|
||||||
public boolean sendMessage(Message message) {
|
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()) {
|
if (!this.socketChannel.isOpen()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -563,7 +573,7 @@ public class Peer {
|
|||||||
*/
|
*/
|
||||||
Thread.sleep(1L); //NOSONAR squid:S2276
|
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
|
// We've taken too long to send this message
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -630,7 +640,7 @@ public class Peer {
|
|||||||
message.setId(id);
|
message.setId(id);
|
||||||
|
|
||||||
// Try to send message
|
// Try to send message
|
||||||
if (!this.sendMessage(message)) {
|
if (!this.sendMessageWithTimeout(message, timeout)) {
|
||||||
this.replyQueues.remove(id);
|
this.replyQueues.remove(id);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user