Search in sources :

Example 1 with GetBsqBlocksRequest

use of bisq.core.dao.node.messages.GetBsqBlocksRequest in project bisq-core by bisq-network.

the class RequestBlocksHandler method requestBlocks.

// /////////////////////////////////////////////////////////////////////////////////////////
// API
// /////////////////////////////////////////////////////////////////////////////////////////
public void requestBlocks() {
    if (!stopped) {
        GetBsqBlocksRequest getBsqBlocksRequest = new GetBsqBlocksRequest(startBlockHeight, nonce);
        log.debug("getBsqBlocksRequest " + getBsqBlocksRequest);
        if (timeoutTimer == null) {
            timeoutTimer = UserThread.runAfter(() -> {
                // setup before sending to avoid race conditions
                if (!stopped) {
                    String errorMessage = "A timeout occurred at sending getBsqBlocksRequest:" + getBsqBlocksRequest + " on peersNodeAddress:" + nodeAddress;
                    log.debug(errorMessage + " / RequestDataHandler=" + RequestBlocksHandler.this);
                    handleFault(errorMessage, nodeAddress, CloseConnectionReason.SEND_MSG_TIMEOUT);
                } else {
                    log.trace("We have stopped already. We ignore that timeoutTimer.run call. " + "Might be caused by an previous networkNode.sendMessage.onFailure.");
                }
            }, TIMEOUT);
        }
        log.debug("We send a {} to peer {}. ", getBsqBlocksRequest.getClass().getSimpleName(), nodeAddress);
        networkNode.addMessageListener(this);
        SettableFuture<Connection> future = networkNode.sendMessage(nodeAddress, getBsqBlocksRequest);
        Futures.addCallback(future, new FutureCallback<Connection>() {

            @Override
            public void onSuccess(Connection connection) {
                if (!stopped) {
                    log.trace("Send " + getBsqBlocksRequest + " to " + nodeAddress + " succeeded.");
                } else {
                    log.trace("We have stopped already. We ignore that networkNode.sendMessage.onSuccess call." + "Might be caused by an previous timeout.");
                }
            }

            @Override
            public void onFailure(@NotNull Throwable throwable) {
                if (!stopped) {
                    String errorMessage = "Sending getBsqBlocksRequest to " + nodeAddress + " failed. That is expected if the peer is offline.\n\t" + "getBsqBlocksRequest=" + getBsqBlocksRequest + "." + "\n\tException=" + throwable.getMessage();
                    log.error(errorMessage);
                    handleFault(errorMessage, nodeAddress, CloseConnectionReason.SEND_MSG_FAILURE);
                } else {
                    log.trace("We have stopped already. We ignore that networkNode.sendMessage.onFailure call. " + "Might be caused by an previous timeout.");
                }
            }
        });
    } else {
        log.warn("We have stopped already. We ignore that requestData call.");
    }
}
Also used : GetBsqBlocksRequest(bisq.core.dao.node.messages.GetBsqBlocksRequest) Connection(bisq.network.p2p.network.Connection)

Aggregations

GetBsqBlocksRequest (bisq.core.dao.node.messages.GetBsqBlocksRequest)1 Connection (bisq.network.p2p.network.Connection)1