io.netty.handler.codec.haproxy.HAProxyMessageDecoder Java Examples
The following examples show how to use
io.netty.handler.codec.haproxy.HAProxyMessageDecoder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServerChannelInitializer.java From Velocity with MIT License | 6 votes |
@Override protected void initChannel(final Channel ch) { ch.pipeline() .addLast(READ_TIMEOUT, new ReadTimeoutHandler(this.server.getConfiguration().getReadTimeout(), TimeUnit.MILLISECONDS)) .addLast(LEGACY_PING_DECODER, new LegacyPingDecoder()) .addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder()) .addLast(LEGACY_PING_ENCODER, LegacyPingEncoder.INSTANCE) .addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE) .addLast(MINECRAFT_DECODER, new MinecraftDecoder(ProtocolUtils.Direction.SERVERBOUND)) .addLast(MINECRAFT_ENCODER, new MinecraftEncoder(ProtocolUtils.Direction.CLIENTBOUND)); final MinecraftConnection connection = new MinecraftConnection(ch, this.server); connection.setSessionHandler(new HandshakeSessionHandler(connection, this.server)); ch.pipeline().addLast(Connections.HANDLER, connection); if (this.server.getConfiguration().isProxyProtocol()) { ch.pipeline().addFirst(new HAProxyMessageDecoder()); } }
Example #2
Source File: HAProxyMessageDetector.java From reactor-netty with Apache License 2.0 | 6 votes |
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) { ProtocolDetectionResult<HAProxyProtocolVersion> detectionResult = HAProxyMessageDecoder.detectProtocol(in); if (detectionResult.equals(ProtocolDetectionResult.needsMoreData())) { return; } else if(detectionResult.equals(ProtocolDetectionResult.invalid())) { ctx.pipeline() .remove(this); } else { ctx.pipeline() .addAfter(NettyPipeline.ProxyProtocolDecoder, NettyPipeline.ProxyProtocolReader, new HAProxyMessageReader()); ctx.pipeline() .replace(this, NettyPipeline.ProxyProtocolDecoder, new HAProxyMessageDecoder()); } }
Example #3
Source File: TestString.java From x-pipe with Apache License 2.0 | 6 votes |
private void createChannel(int port) throws InterruptedException { ServerBootstrap b = new ServerBootstrap(); EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(2); b.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast(new LoggingHandler(LogLevel.DEBUG)); p.addLast(new NettySimpleMessageHandler()); p.addLast(new NettyMasterHandler(null, new CommandHandlerManager(), 1000 * 60 * 24)); p.addLast(new HAProxyMessageDecoder()); } }); b.bind(port).sync(); }
Example #4
Source File: ElbProxyProtocolChannelHandler.java From zuul with Apache License 2.0 | 5 votes |
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (withProxyProtocol && isHAPMDetected(msg)) { ctx.pipeline().addAfter(NAME, null, new HAProxyMessageChannelHandler()) .replace(this, null, new HAProxyMessageDecoder()); } else { if (withProxyProtocol) { // This likely means initialization was requested with proxy protocol, but we failed to decode the message hapmDecodeFailure.increment(); } ctx.pipeline().remove(this); } super.channelRead(ctx, msg); }
Example #5
Source File: BungeeProxy.java From BungeeProxy with MIT License | 4 votes |
@Override public void onEnable() { try { Field remoteAddressField = AbstractChannel.class.getDeclaredField("remoteAddress"); remoteAddressField.setAccessible(true); Field serverChild = PipelineUtils.class.getField("SERVER_CHILD"); serverChild.setAccessible(true); Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(serverChild, serverChild.getModifiers() & ~Modifier.FINAL); ChannelInitializer<Channel> bungeeChannelInitializer = PipelineUtils.SERVER_CHILD; Method initChannelMethod = ChannelInitializer.class.getDeclaredMethod("initChannel", Channel.class); initChannelMethod.setAccessible(true); serverChild.set(null, new ChannelInitializer<Channel>() { @Override protected void initChannel(Channel channel) throws Exception { initChannelMethod.invoke(bungeeChannelInitializer, channel); channel.pipeline().addAfter(PipelineUtils.TIMEOUT_HANDLER, "haproxy-decoder", new HAProxyMessageDecoder()); channel.pipeline().addAfter("haproxy-decoder", "haproxy-handler", new ChannelInboundHandlerAdapter() { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof HAProxyMessage) { HAProxyMessage message = (HAProxyMessage) msg; remoteAddressField.set(channel, new InetSocketAddress(message.sourceAddress(), message.sourcePort())); } else { super.channelRead(ctx, msg); } } }); } }); } catch (Exception e) { getLogger().log(Level.SEVERE, e.getMessage(), e); getProxy().stop(); } }
Example #6
Source File: ElbProxyProtocolChannelHandler.java From zuul with Apache License 2.0 | 4 votes |
private boolean isHAPMDetected(Object msg) { return HAProxyMessageDecoder.detectProtocol((ByteBuf) msg).state() == ProtocolDetectionState.DETECTED; }