Search in sources :

Example 1 with RpcStream

use of tech.pegasys.teku.networking.p2p.rpc.RpcStream in project teku by ConsenSys.

the class Eth2OutgoingRequestHandler method ensureReadCompleteArrivesInTime.

private void ensureReadCompleteArrivesInTime(final RpcStream stream) {
    final Duration timeout = RpcTimeouts.RESP_TIMEOUT;
    timeoutRunner.getDelayedFuture(timeout).thenAccept((__) -> {
        if (!(state.get() == READ_COMPLETE || state.get() == CLOSED)) {
            abortRequest(stream, new RpcTimeoutException("Timed out waiting for read channel close", timeout));
        }
    }).reportExceptions();
}
Also used : INITIAL(tech.pegasys.teku.networking.eth2.rpc.core.Eth2OutgoingRequestHandler.State.INITIAL) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) RpcRequest(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.RpcRequest) Bytes(org.apache.tuweni.bytes.Bytes) AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteBuf(io.netty.buffer.ByteBuf) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) SszData(tech.pegasys.teku.infrastructure.ssz.SszData) RpcStream(tech.pegasys.teku.networking.p2p.rpc.RpcStream) ABORTED(tech.pegasys.teku.networking.eth2.rpc.core.Eth2OutgoingRequestHandler.State.ABORTED) AsyncRunner(tech.pegasys.teku.infrastructure.async.AsyncRunner) Collection(java.util.Collection) DATA_COMPLETED(tech.pegasys.teku.networking.eth2.rpc.core.Eth2OutgoingRequestHandler.State.DATA_COMPLETED) RpcRequestHandler(tech.pegasys.teku.networking.p2p.rpc.RpcRequestHandler) List(java.util.List) Logger(org.apache.logging.log4j.Logger) RpcTimeoutException(tech.pegasys.teku.networking.eth2.rpc.core.RpcTimeouts.RpcTimeoutException) CLOSED(tech.pegasys.teku.networking.eth2.rpc.core.Eth2OutgoingRequestHandler.State.CLOSED) READ_COMPLETE(tech.pegasys.teku.networking.eth2.rpc.core.Eth2OutgoingRequestHandler.State.READ_COMPLETE) VisibleForTesting(com.google.common.annotations.VisibleForTesting) LogManager(org.apache.logging.log4j.LogManager) EXPECT_DATA(tech.pegasys.teku.networking.eth2.rpc.core.Eth2OutgoingRequestHandler.State.EXPECT_DATA) NodeId(tech.pegasys.teku.networking.p2p.peer.NodeId) ExtraDataAppendedException(tech.pegasys.teku.networking.eth2.rpc.core.RpcException.ExtraDataAppendedException) Duration(java.time.Duration) RpcTimeoutException(tech.pegasys.teku.networking.eth2.rpc.core.RpcTimeouts.RpcTimeoutException)

Example 2 with RpcStream

use of tech.pegasys.teku.networking.p2p.rpc.RpcStream in project teku by ConsenSys.

the class Eth2OutgoingRequestHandler method ensureNextResponseArrivesInTime.

private void ensureNextResponseArrivesInTime(final RpcStream stream, final int previousResponseCount, final AtomicInteger currentResponseCount) {
    final Duration timeout = RpcTimeouts.RESP_TIMEOUT;
    timeoutRunner.getDelayedFuture(timeout).thenAccept((__) -> {
        if (previousResponseCount == currentResponseCount.get()) {
            abortRequest(stream, new RpcTimeoutException("Timed out waiting for response chunk " + previousResponseCount, timeout));
        }
    }).reportExceptions();
}
Also used : INITIAL(tech.pegasys.teku.networking.eth2.rpc.core.Eth2OutgoingRequestHandler.State.INITIAL) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) RpcRequest(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.RpcRequest) Bytes(org.apache.tuweni.bytes.Bytes) AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteBuf(io.netty.buffer.ByteBuf) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) SszData(tech.pegasys.teku.infrastructure.ssz.SszData) RpcStream(tech.pegasys.teku.networking.p2p.rpc.RpcStream) ABORTED(tech.pegasys.teku.networking.eth2.rpc.core.Eth2OutgoingRequestHandler.State.ABORTED) AsyncRunner(tech.pegasys.teku.infrastructure.async.AsyncRunner) Collection(java.util.Collection) DATA_COMPLETED(tech.pegasys.teku.networking.eth2.rpc.core.Eth2OutgoingRequestHandler.State.DATA_COMPLETED) RpcRequestHandler(tech.pegasys.teku.networking.p2p.rpc.RpcRequestHandler) List(java.util.List) Logger(org.apache.logging.log4j.Logger) RpcTimeoutException(tech.pegasys.teku.networking.eth2.rpc.core.RpcTimeouts.RpcTimeoutException) CLOSED(tech.pegasys.teku.networking.eth2.rpc.core.Eth2OutgoingRequestHandler.State.CLOSED) READ_COMPLETE(tech.pegasys.teku.networking.eth2.rpc.core.Eth2OutgoingRequestHandler.State.READ_COMPLETE) VisibleForTesting(com.google.common.annotations.VisibleForTesting) LogManager(org.apache.logging.log4j.LogManager) EXPECT_DATA(tech.pegasys.teku.networking.eth2.rpc.core.Eth2OutgoingRequestHandler.State.EXPECT_DATA) NodeId(tech.pegasys.teku.networking.p2p.peer.NodeId) ExtraDataAppendedException(tech.pegasys.teku.networking.eth2.rpc.core.RpcException.ExtraDataAppendedException) Duration(java.time.Duration) RpcTimeoutException(tech.pegasys.teku.networking.eth2.rpc.core.RpcTimeouts.RpcTimeoutException)

Example 3 with RpcStream

use of tech.pegasys.teku.networking.p2p.rpc.RpcStream in project teku by ConsenSys.

the class Eth2IncomingRequestHandler method ensureRequestReceivedWithinTimeLimit.

private void ensureRequestReceivedWithinTimeLimit(final RpcStream stream) {
    final Duration timeout = RpcTimeouts.RESP_TIMEOUT;
    asyncRunner.getDelayedFuture(timeout).thenAccept((__) -> {
        if (!requestHandled.get()) {
            LOG.debug("Failed to receive incoming request data within {} sec for protocol {}. Close stream.", timeout.getSeconds(), protocolId);
            stream.closeAbruptly().reportExceptions();
        }
    }).reportExceptions();
}
Also used : RpcStream(tech.pegasys.teku.networking.p2p.rpc.RpcStream) PeerLookup(tech.pegasys.teku.networking.eth2.peers.PeerLookup) AsyncRunner(tech.pegasys.teku.infrastructure.async.AsyncRunner) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RpcRequest(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.RpcRequest) RpcRequestHandler(tech.pegasys.teku.networking.p2p.rpc.RpcRequestHandler) StreamClosedException(tech.pegasys.teku.networking.p2p.rpc.StreamClosedException) Logger(org.apache.logging.log4j.Logger) ByteBuf(io.netty.buffer.ByteBuf) Duration(java.time.Duration) Eth2Peer(tech.pegasys.teku.networking.eth2.peers.Eth2Peer) Optional(java.util.Optional) SszData(tech.pegasys.teku.infrastructure.ssz.SszData) VisibleForTesting(com.google.common.annotations.VisibleForTesting) LogManager(org.apache.logging.log4j.LogManager) NodeId(tech.pegasys.teku.networking.p2p.peer.NodeId) Duration(java.time.Duration)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 ByteBuf (io.netty.buffer.ByteBuf)3 Duration (java.time.Duration)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3 AsyncRunner (tech.pegasys.teku.infrastructure.async.AsyncRunner)3 SszData (tech.pegasys.teku.infrastructure.ssz.SszData)3 NodeId (tech.pegasys.teku.networking.p2p.peer.NodeId)3 RpcRequestHandler (tech.pegasys.teku.networking.p2p.rpc.RpcRequestHandler)3 RpcStream (tech.pegasys.teku.networking.p2p.rpc.RpcStream)3 RpcRequest (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.RpcRequest)3 Collection (java.util.Collection)2 List (java.util.List)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Bytes (org.apache.tuweni.bytes.Bytes)2 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)2 ABORTED (tech.pegasys.teku.networking.eth2.rpc.core.Eth2OutgoingRequestHandler.State.ABORTED)2 CLOSED (tech.pegasys.teku.networking.eth2.rpc.core.Eth2OutgoingRequestHandler.State.CLOSED)2