use of tech.pegasys.teku.networking.eth2.rpc.core.RpcException.ExtraDataAppendedException in project teku by ConsenSys.
the class Eth2OutgoingRequestHandlerTest method sendTooManyChunks.
@Test
public void sendTooManyChunks() throws Exception {
sendInitialPayload();
verify(rpcStream).closeWriteStream();
for (int i = 0; i < maxChunks; i++) {
if (i == maxChunks - 1) {
// Send 2 chunks in the last batch of data which should only contain 1 chunk
final Bytes lastChunk = chunks.get(i);
final Bytes lastChunkWithExtraChunk = Bytes.concatenate(lastChunk, lastChunk);
deliverBytes(lastChunkWithExtraChunk);
} else {
deliverChunk(i);
}
}
complete();
close();
asyncRequestRunner.waitForExactly(maxChunks - 1);
timeoutRunner.executeUntilDone();
Waiter.waitFor(() -> assertThat(finishedProcessingFuture).isDone());
verify(rpcStream).closeAbruptly();
assertThat(blocks.size()).isEqualTo(2);
assertThat(finishedProcessingFuture).isCompletedExceptionally();
assertThatThrownBy(finishedProcessingFuture::get).hasRootCause(new ExtraDataAppendedException());
}
use of tech.pegasys.teku.networking.eth2.rpc.core.RpcException.ExtraDataAppendedException in project teku by ConsenSys.
the class LengthPrefixedPayloadDecoder method decodeOneMessage.
@Override
public Optional<T> decodeOneMessage(final ByteBuf in) throws RpcException {
if (disposed) {
throw new IllegalStateException("Trying to reuse disposed LengthPrefixedPayloadDecoder");
}
if (!in.isReadable()) {
return Optional.empty();
}
if (decoded) {
throw new RpcException.ExtraDataAppendedException();
}
if (decompressor.isEmpty()) {
final Optional<Integer> maybeLength = readLengthPrefixHeader(in);
if (maybeLength.isPresent()) {
final int length = maybeLength.get();
if (!payloadEncoder.isLengthWithinBounds(length)) {
throw new LengthOutOfBoundsException();
}
decompressor = Optional.of(compressor.createDecompressor(length));
}
}
if (decompressor.isPresent()) {
final Optional<ByteBuf> ret;
try {
ret = decompressor.get().decodeOneMessage(in);
} catch (PayloadSmallerThanExpectedException e) {
throw new PayloadTruncatedException();
} catch (PayloadLargerThanExpectedException e) {
throw new ExtraDataAppendedException();
} catch (CompressionException e) {
throw new DecompressFailedException();
}
if (ret.isPresent()) {
decompressor = Optional.empty();
try {
// making a copy here since the Bytes.wrapByteBuf(buf).slice(...)
// would be broken after [in] buffer is released
byte[] arr = new byte[ret.get().readableBytes()];
ret.get().readBytes(arr);
Bytes bytes = Bytes.wrap(arr);
decoded = true;
return Optional.of(payloadEncoder.decode(bytes));
} finally {
ret.get().release();
}
} else {
return Optional.empty();
}
} else {
return Optional.empty();
}
}
Aggregations