Search in sources :

Example 6 with HAProxyMessage

use of io.netty.handler.codec.haproxy.HAProxyMessage in project thingsboard by thingsboard.

the class ProxyIpFilter method channelRead.

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    log.trace("[{}] Received msg: {}", ctx.channel().id(), msg);
    if (msg instanceof HAProxyMessage) {
        HAProxyMessage proxyMsg = (HAProxyMessage) msg;
        if (proxyMsg.sourceAddress() != null && proxyMsg.sourcePort() > 0) {
            InetSocketAddress address = new InetSocketAddress(proxyMsg.sourceAddress(), proxyMsg.sourcePort());
            if (!context.checkAddress(address)) {
                closeChannel(ctx);
            } else {
                log.trace("[{}] Setting address: {}", ctx.channel().id(), address);
                ctx.channel().attr(MqttTransportService.ADDRESS).set(address);
                // We no longer need this channel in the pipeline. Similar to HAProxyMessageDecoder
                ctx.pipeline().remove(this);
            }
        } else {
            log.trace("Received local health-check connection message: {}", proxyMsg);
            closeChannel(ctx);
        }
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) HAProxyMessage(io.netty.handler.codec.haproxy.HAProxyMessage)

Aggregations

HAProxyMessage (io.netty.handler.codec.haproxy.HAProxyMessage)6 InetSocketAddress (java.net.InetSocketAddress)3 Channel (io.netty.channel.Channel)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 InetAddresses (com.google.common.net.InetAddresses)1 SourceAddressChannelHandler (com.netflix.netty.common.SourceAddressChannelHandler)1 Attrs (com.netflix.zuul.Attrs)1 ZuulException (com.netflix.zuul.exception.ZuulException)1 Server (com.netflix.zuul.netty.server.Server)1 Bootstrap (io.netty.bootstrap.Bootstrap)1 ByteBuf (io.netty.buffer.ByteBuf)1 ChannelFutureListener (io.netty.channel.ChannelFutureListener)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 HAProxyProtocolVersion (io.netty.handler.codec.haproxy.HAProxyProtocolVersion)1 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)1