/** * 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)); } }
/** * 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)); } }
/** * 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 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 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 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]); } } }
@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()); } } });
@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); } } }