/** * Remove handlers for sasl encryption and add handlers for Crypto AES encryption */ private void setupCryptoAESHandler(ChannelPipeline p, CryptoAES cryptoAES) { p.remove(SaslWrapHandler.class); p.remove(SaslUnwrapHandler.class); String lengthDecoder = p.context(LengthFieldBasedFrameDecoder.class).name(); p.addAfter(lengthDecoder, null, new CryptoAESUnwrapHandler(cryptoAES)); p.addAfter(lengthDecoder, null, new CryptoAESWrapHandler(cryptoAES)); } }
private void established(Channel ch) throws IOException { ChannelPipeline p = ch.pipeline(); String addBeforeHandler = p.context(BufferCallBeforeInitHandler.class).name(); p.addBefore(addBeforeHandler, null, new IdleStateHandler(0, rpcClient.minIdleTimeBeforeClose, 0, TimeUnit.MILLISECONDS)); p.addBefore(addBeforeHandler, null, new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4)); p.addBefore(addBeforeHandler, null, new NettyRpcDuplexHandler(this, rpcClient.cellBlockBuilder, codec, compressor)); p.fireUserEventTriggered(BufferCallEvent.success()); }
/** * Remove handlers for sasl encryption and add handlers for Crypto AES encryption */ private void setupCryptoAESHandler(ChannelPipeline p, CryptoAES cryptoAES) { p.remove(SaslWrapHandler.class); p.remove(SaslUnwrapHandler.class); String lengthDecoder = p.context(LengthFieldBasedFrameDecoder.class).name(); p.addAfter(lengthDecoder, null, new CryptoAESUnwrapHandler(cryptoAES)); p.addAfter(lengthDecoder, null, new CryptoAESWrapHandler(cryptoAES)); } }
@Override public String name() { return ctx.name(); }
private void established(Channel ch) throws IOException { ChannelPipeline p = ch.pipeline(); String addBeforeHandler = p.context(BufferCallBeforeInitHandler.class).name(); p.addBefore(addBeforeHandler, null, new IdleStateHandler(0, rpcClient.minIdleTimeBeforeClose, 0, TimeUnit.MILLISECONDS)); p.addBefore(addBeforeHandler, null, new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4)); p.addBefore(addBeforeHandler, null, new NettyRpcDuplexHandler(this, rpcClient.cellBlockBuilder, codec, compressor)); p.fireUserEventTriggered(BufferCallEvent.success()); }
@Override protected void addCodec(ChannelHandlerContext ctx) throws Exception { ChannelPipeline p = ctx.pipeline(); String name = ctx.name(); p.addBefore(name, null, codec); }
private static void removeThisHandler(ChannelHandlerContext ctx) { ctx.pipeline().remove(ctx.name()); }
@Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { for (WebSocketServerExtension extension : validExtensions) { WebSocketExtensionDecoder decoder = extension.newExtensionDecoder(); WebSocketExtensionEncoder encoder = extension.newExtensionEncoder(); ctx.pipeline().addAfter(ctx.name(), decoder.getClass().getName(), decoder); ctx.pipeline().addAfter(ctx.name(), encoder.getClass().getName(), encoder); } } ctx.pipeline().remove(ctx.name()); } });
@Override protected void addCodec(ChannelHandlerContext ctx) throws Exception { ChannelPipeline p = ctx.pipeline(); String name = ctx.name(); Socks4ClientDecoder decoder = new Socks4ClientDecoder(); p.addBefore(name, null, decoder); decoderName = p.context(decoder).name(); encoderName = decoderName + ".encoder"; p.addBefore(name, encoderName, Socks4ClientEncoder.INSTANCE); }
@Override protected void addCodec(ChannelHandlerContext ctx) throws Exception { ChannelPipeline p = ctx.pipeline(); String name = ctx.name(); Socks5InitialResponseDecoder decoder = new Socks5InitialResponseDecoder(); p.addBefore(name, null, decoder); decoderName = p.context(decoder).name(); encoderName = decoderName + ".encoder"; p.addBefore(name, encoderName, Socks5ClientEncoder.DEFAULT); }
@Override public void upgradeTo(ChannelHandlerContext ctx, FullHttpResponse upgradeResponse) throws Exception { // Add the handler to the pipeline. ctx.pipeline().addAfter(ctx.name(), handlerName, upgradeToHandler); // Reserve local stream 1 for the response. connectionHandler.onHttpClientUpgrade(); }
@Override public void handlerAdded(ChannelHandlerContext ctx) { ChannelPipeline cp = ctx.pipeline(); if (cp.get(WebSocketServerProtocolHandshakeHandler.class) == null) { // Add the WebSocketHandshakeHandler before this one. ctx.pipeline().addBefore(ctx.name(), WebSocketServerProtocolHandshakeHandler.class.getName(), new WebSocketServerProtocolHandshakeHandler(websocketPath, subprotocols, allowExtensions, maxFramePayloadLength, allowMaskMismatch, checkStartsWith)); } if (cp.get(Utf8FrameValidator.class) == null) { // Add the UFT8 checking before this one. ctx.pipeline().addBefore(ctx.name(), Utf8FrameValidator.class.getName(), new Utf8FrameValidator()); } }
@Override public void handlerAdded(ChannelHandlerContext ctx) { ChannelPipeline cp = ctx.pipeline(); if (cp.get(WebSocketClientProtocolHandshakeHandler.class) == null) { // Add the WebSocketClientProtocolHandshakeHandler before this one. ctx.pipeline().addBefore(ctx.name(), WebSocketClientProtocolHandshakeHandler.class.getName(), new WebSocketClientProtocolHandshakeHandler(handshaker)); } if (cp.get(Utf8FrameValidator.class) == null) { // Add the UFT8 checking before this one. ctx.pipeline().addBefore(ctx.name(), Utf8FrameValidator.class.getName(), new Utf8FrameValidator()); } } }
@Override public void upgradeTo(final ChannelHandlerContext ctx, FullHttpRequest upgradeRequest) { try { // Add the HTTP/2 connection handler to the pipeline immediately following the current handler. ctx.pipeline().addAfter(ctx.name(), handlerName, connectionHandler); connectionHandler.onHttpServerUpgrade(settings); } catch (Http2Exception e) { ctx.fireExceptionCaught(e); ctx.close(); return; } if (handlers != null) { final String name = ctx.pipeline().context(connectionHandler).name(); for (int i = handlers.length - 1; i >= 0; i--) { ctx.pipeline().addAfter(name, null, handlers[i]); } } }
/** * Remove handlers for sasl encryption and add handlers for Crypto AES encryption */ private void setupCryptoAESHandler(ChannelPipeline p, CryptoAES cryptoAES) { p.remove(SaslWrapHandler.class); p.remove(SaslUnwrapHandler.class); String lengthDecoder = p.context(LengthFieldBasedFrameDecoder.class).name(); p.addAfter(lengthDecoder, null, new CryptoAESUnwrapHandler(cryptoAES)); p.addAfter(lengthDecoder, null, new CryptoAESWrapHandler(cryptoAES)); } }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { final int readerIndex = in.readerIndex(); if (in.writerIndex() == readerIndex) { return; } ChannelPipeline p = ctx.pipeline(); final byte versionVal = in.getByte(readerIndex); SocksVersion version = SocksVersion.valueOf(versionVal); switch (version) { case SOCKS4a: logKnownVersion(ctx, version); p.addAfter(ctx.name(), null, Socks4ServerEncoder.INSTANCE); p.addAfter(ctx.name(), null, new Socks4ServerDecoder()); break; case SOCKS5: logKnownVersion(ctx, version); p.addAfter(ctx.name(), null, socks5encoder); p.addAfter(ctx.name(), null, new Socks5InitialRequestDecoder()); break; default: logUnknownVersion(ctx, versionVal); in.skipBytes(in.readableBytes()); ctx.close(); return; } p.remove(this); }
@Override public void operationComplete(ChannelFuture future) { if (future.isSuccess()) { ChannelPipeline p = future.channel().pipeline(); ChannelHandlerContext ctx = p.context(HttpRequestEncoder.class); if (ctx == null) { ctx = p.context(HttpClientCodec.class); } if (ctx == null) { promise.setFailure(new IllegalStateException("ChannelPipeline does not contain " + "a HttpRequestEncoder or HttpClientCodec")); return; } p.addAfter(ctx.name(), "ws-encoder", newWebSocketEncoder()); promise.setSuccess(); } else { promise.setFailure(future.cause()); } } });
private void established(Channel ch) throws IOException { ChannelPipeline p = ch.pipeline(); String addBeforeHandler = p.context(BufferCallBeforeInitHandler.class).name(); p.addBefore(addBeforeHandler, null, new IdleStateHandler(0, rpcClient.minIdleTimeBeforeClose, 0, TimeUnit.MILLISECONDS)); p.addBefore(addBeforeHandler, null, new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4)); p.addBefore(addBeforeHandler, null, new NettyRpcDuplexHandler(this, rpcClient.cellBlockBuilder, codec, compressor)); p.fireUserEventTriggered(BufferCallEvent.success()); }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { int prefaceLength = CONNECTION_PREFACE.readableBytes(); int bytesRead = Math.min(in.readableBytes(), prefaceLength); if (!ByteBufUtil.equals(CONNECTION_PREFACE, CONNECTION_PREFACE.readerIndex(), in, in.readerIndex(), bytesRead)) { ctx.pipeline().remove(this); } else if (bytesRead == prefaceLength) { // Full h2 preface match, removed source codec, using http2 codec to handle // following network traffic ctx.pipeline() .remove(httpServerCodec) .remove(httpServerUpgradeHandler); ctx.pipeline().addAfter(ctx.name(), null, http2ServerHandler); ctx.pipeline().remove(this); ctx.fireUserEventTriggered(PriorKnowledgeUpgradeEvent.INSTANCE); } } }