Example usage for io.netty.handler.codec.haproxy HAProxyProxiedProtocol TCP6

List of usage examples for io.netty.handler.codec.haproxy HAProxyProxiedProtocol TCP6

Introduction

In this page you can find the example usage for io.netty.handler.codec.haproxy HAProxyProxiedProtocol TCP6.

Prototype

HAProxyProxiedProtocol TCP6

To view the source code for io.netty.handler.codec.haproxy HAProxyProxiedProtocol TCP6.

Click Source Link

Document

The TCP6 represents a connection which was forwarded for an IPv6 client over TCP.

Usage

From source file:diskCacheV111.doors.NettyLineBasedDoor.java

License:Open Source License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (msg instanceof HAProxyMessage) {
        HAProxyMessage proxyMessage = (HAProxyMessage) msg;
        switch (proxyMessage.command()) {
        case LOCAL:
            ctx.close();/* w  w  w.ja v a2s .  co  m*/
            return;
        case PROXY:
            String sourceAddress = proxyMessage.sourceAddress();
            String destinationAddress = proxyMessage.destinationAddress();
            InetSocketAddress localAddress = (InetSocketAddress) ctx.channel().localAddress();
            if (proxyMessage.proxiedProtocol() == HAProxyProxiedProtocol.TCP4
                    || proxyMessage.proxiedProtocol() == HAProxyProxiedProtocol.TCP6) {
                if (Objects.equals(destinationAddress, localAddress.getAddress().getHostAddress())) {
                    /* Workaround for what looks like a bug in HAProxy - health checks should
                     * generate a LOCAL command, but it appears they do actually use PROXY.
                     */
                    ctx.close();
                    return;
                } else {
                    this.proxyAddress = new InetSocketAddress(InetAddresses.forString(destinationAddress),
                            proxyMessage.destinationPort());
                    this.remoteAddress = new InetSocketAddress(InetAddresses.forString(sourceAddress),
                            proxyMessage.sourcePort());
                }
            }
            break;
        }
        start(ctx);
    } else if (msg instanceof String) {
        if (interpreter == null) {
            throw new IOException("Unexpected input: " + msg);
        }
        commandExecutor.execute(new Command((String) msg));
    }
}

From source file:org.dcache.xrootd.core.XrootdRequestHandler.java

License:Open Source License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (msg instanceof XrootdRequest) {
        requestReceived(ctx, (XrootdRequest) msg);
    } else if (msg instanceof HAProxyMessage) {
        HAProxyMessage proxyMessage = (HAProxyMessage) msg;
        switch (proxyMessage.command()) {
        case LOCAL:
            _isHealthCheck = true;//w ww.j a  v a  2s. c  o m
            break;
        case PROXY:
            String sourceAddress = proxyMessage.sourceAddress();
            String destinationAddress = proxyMessage.destinationAddress();
            InetSocketAddress localAddress = (InetSocketAddress) ctx.channel().localAddress();
            if (proxyMessage.proxiedProtocol() == HAProxyProxiedProtocol.TCP4
                    || proxyMessage.proxiedProtocol() == HAProxyProxiedProtocol.TCP6) {
                if (Objects.equals(destinationAddress, localAddress.getAddress().getHostAddress())) {
                    /* Workaround for what looks like a bug in HAProxy - health checks should
                     * generate a LOCAL command, but it appears they do actually use PROXY.
                     */
                    _isHealthCheck = true;
                } else {
                    _destinationAddress = new InetSocketAddress(InetAddresses.forString(destinationAddress),
                            proxyMessage.destinationPort());
                    _sourceAddress = new InetSocketAddress(InetAddresses.forString(sourceAddress),
                            proxyMessage.sourcePort());
                }
            }
            break;
        }
        ctx.fireChannelRead(msg);
    } else {
        ctx.fireChannelRead(msg);
    }
}