/** * Wrap the incoming message in an implementation that will perform encryption lazily. This is * needed to guarantee ordering of the outgoing encrypted packets - they need to be decrypted in * the same order, and netty doesn't have an atomic ChannelHandlerContext.write() API, so it * does not guarantee any ordering. */ @Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { ctx.write(new EncryptedMessage(backend, msg, maxOutboundBlockSize), promise); }
throws IOException { Preconditions.checkArgument(position == transfered(), "Invalid position."); do { if (currentChunk == null) { nextChunk(); currentReportedBytes = 0; } while (currentChunk == null && transfered() + reportedWritten < count());
throws IOException { Preconditions.checkArgument(position == transferred(), "Invalid position."); do { if (currentChunk == null) { nextChunk(); currentReportedBytes = 0; } while (currentChunk == null && transferred() + reportedWritten < count());
throws IOException { Preconditions.checkArgument(position == transferred(), "Invalid position."); do { if (currentChunk == null) { nextChunk(); currentReportedBytes = 0; } while (currentChunk == null && transferred() + reportedWritten < count());
throws IOException { Preconditions.checkArgument(position == transfered(), "Invalid position."); do { if (currentChunk == null) { nextChunk(); currentReportedBytes = 0; } while (currentChunk == null && transfered() + reportedWritten < count());
new SaslEncryption.EncryptedMessage(backend, msg, 1024); long count = emsg.transferTo(channel, emsg.transfered()); assertTrue(count < data.length); assertTrue(count > 0); assertEquals(0, emsg.transferTo(channel, emsg.transfered())); assertEquals(1, emsg.transferTo(channel, emsg.transfered())); assertEquals(1, emsg.transferTo(channel, emsg.transfered())); count = emsg.transferTo(channel, emsg.transfered()); assertTrue("Unexpected count: " + count, count > 1 && count < data.length); assertEquals(data.length, emsg.transfered()); } finally { msg.release();
new SaslEncryption.EncryptedMessage(backend, msg, 1024); long count = emsg.transferTo(channel, emsg.transfered()); assertTrue(count < data.length); assertTrue(count > 0); assertEquals(0, emsg.transferTo(channel, emsg.transfered())); assertEquals(1, emsg.transferTo(channel, emsg.transfered())); assertEquals(1, emsg.transferTo(channel, emsg.transfered())); count = emsg.transferTo(channel, emsg.transfered()); assertTrue("Unexpected count: " + count, count > 1 && count < data.length); assertEquals(data.length, emsg.transfered()); } finally { msg.release();
@Test public void testEncryptedMessageChunking() throws Exception { File file = File.createTempFile("sasltest", ".txt"); try { TransportConf conf = new TransportConf("shuffle", MapConfigProvider.EMPTY); byte[] data = new byte[8 * 1024]; new Random().nextBytes(data); Files.write(data, file); SaslEncryptionBackend backend = mock(SaslEncryptionBackend.class); // It doesn't really matter what we return here, as long as it's not null. when(backend.wrap(any(byte[].class), anyInt(), anyInt())).thenReturn(data); FileSegmentManagedBuffer msg = new FileSegmentManagedBuffer(conf, file, 0, file.length()); SaslEncryption.EncryptedMessage emsg = new SaslEncryption.EncryptedMessage(backend, msg.convertToNetty(), data.length / 8); ByteArrayWritableChannel channel = new ByteArrayWritableChannel(data.length); while (emsg.transfered() < emsg.count()) { channel.reset(); emsg.transferTo(channel, emsg.transfered()); } verify(backend, times(8)).wrap(any(byte[].class), anyInt(), anyInt()); } finally { file.delete(); } }
@Test public void testEncryptedMessageChunking() throws Exception { File file = File.createTempFile("sasltest", ".txt"); try { TransportConf conf = new TransportConf("shuffle", MapConfigProvider.EMPTY); byte[] data = new byte[8 * 1024]; new Random().nextBytes(data); Files.write(data, file); SaslEncryptionBackend backend = mock(SaslEncryptionBackend.class); // It doesn't really matter what we return here, as long as it's not null. when(backend.wrap(any(byte[].class), anyInt(), anyInt())).thenReturn(data); FileSegmentManagedBuffer msg = new FileSegmentManagedBuffer(conf, file, 0, file.length()); SaslEncryption.EncryptedMessage emsg = new SaslEncryption.EncryptedMessage(backend, msg.convertToNetty(), data.length / 8); ByteArrayWritableChannel channel = new ByteArrayWritableChannel(data.length); while (emsg.transfered() < emsg.count()) { channel.reset(); emsg.transferTo(channel, emsg.transfered()); } verify(backend, times(8)).wrap(any(byte[].class), anyInt(), anyInt()); } finally { file.delete(); } }
/** * Wrap the incoming message in an implementation that will perform encryption lazily. This is * needed to guarantee ordering of the outgoing encrypted packets - they need to be decrypted in * the same order, and netty doesn't have an atomic ChannelHandlerContext.write() API, so it * does not guarantee any ordering. */ @Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { ctx.write(new EncryptedMessage(backend, msg, maxOutboundBlockSize), promise); }
/** * Wrap the incoming message in an implementation that will perform encryption lazily. This is * needed to guarantee ordering of the outgoing encrypted packets - they need to be decrypted in * the same order, and netty doesn't have an atomic ChannelHandlerContext.write() API, so it * does not guarantee any ordering. */ @Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { ctx.write(new EncryptedMessage(backend, msg, maxOutboundBlockSize), promise); }
/** * Wrap the incoming message in an implementation that will perform encryption lazily. This is * needed to guarantee ordering of the outgoing encrypted packets - they need to be decrypted in * the same order, and netty doesn't have an atomic ChannelHandlerContext.write() API, so it * does not guarantee any ordering. */ @Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { ctx.write(new EncryptedMessage(backend, msg, maxOutboundBlockSize), promise); }