List of usage examples for io.netty.handler.codec.haproxy HAProxyMessage destinationAddress
String destinationAddress
To view the source code for io.netty.handler.codec.haproxy HAProxyMessage destinationAddress.
Click Source Link
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();// ww w .jav a 2s.c o 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;// ww w . j a va 2s . c om 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); } }
From source file:org.dcache.xrootd.plugins.ProxyAccessLogHandler.java
License:Open Source License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof HAProxyMessage) { HAProxyMessage proxyMessage = (HAProxyMessage) msg; if (proxyMessage.command() == HAProxyCommand.PROXY) { InetSocketAddress remoteAddress = (InetSocketAddress) ctx.channel().remoteAddress(); InetSocketAddress localAddress = (InetSocketAddress) ctx.channel().localAddress(); String sourceAddress = proxyMessage.sourceAddress(); String destinationAddress = proxyMessage.destinationAddress(); if (proxyMessage.proxiedProtocol() == HAProxyProxiedProtocol.UNKNOWN) { NetLoggerBuilder log = new NetLoggerBuilder(INFO, "org.dcache.xrootd.connection.start") .omitNullValues(); log.add("session", CDC.getSession()); log.add("socket.remote", remoteAddress); log.add("socket.local", localAddress); log.toLogger(logger);/*from ww w. java 2s.c om*/ replaceWith(ctx, handler); } else if (!Objects.equals(destinationAddress, localAddress.getAddress().getHostAddress())) { /* The above check is a workaround for what looks like a bug in HAProxy - health checks * should generate a LOCAL command, but it appears they do actually use PROXY. */ NetLoggerBuilder log = new NetLoggerBuilder(INFO, "org.dcache.xrootd.connection.start") .omitNullValues(); log.add("session", CDC.getSession()); log.add("socket.remote", HostAndPort.fromParts(sourceAddress, proxyMessage.sourcePort())); log.add("socket.proxy", HostAndPort.fromParts(destinationAddress, proxyMessage.destinationPort())); log.add("socket.local", localAddress); log.toLogger(logger); replaceWith(ctx, handler); } } } super.channelRead(ctx, msg); }