Class SourceAddressChannelHandler

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
com.netflix.netty.common.SourceAddressChannelHandler
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler

@Sharable public final class SourceAddressChannelHandler extends io.netty.channel.ChannelInboundHandlerAdapter
Stores the source IP address as an attribute of the channel. This has the advantage of allowing us to overwrite it if we have more info (eg. ELB sends a HAProxyMessage with info of REAL source host + port).

User: [email protected] Date: 4/14/16 Time: 4:29 PM

  • Nested Class Summary

    Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler

    io.netty.channel.ChannelHandler.Sharable
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final io.netty.util.AttributeKey<SocketAddress>
    Indicates the local address of the channel.
    static final io.netty.util.AttributeKey<String>
    The local address of this channel.
    static final io.netty.util.AttributeKey<InetSocketAddress>
    Deprecated.
    static final io.netty.util.AttributeKey<InetSocketAddress>
    Indicates the destination address received from Proxy Protocol.
    static final io.netty.util.AttributeKey<SocketAddress>
    Indicates the actual source (remote) address of the channel.
    static final io.netty.util.AttributeKey<String>
    Deprecated.
    Use channel.localAddress() instead.
    static final io.netty.util.AttributeKey<Integer>
    The port number of the local socket, or -1 if not appropriate.
    static final io.netty.util.AttributeKey<String>
    The host address of the source.
    static final io.netty.util.AttributeKey<InetSocketAddress>
    Deprecated.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    channelActive(io.netty.channel.ChannelHandlerContext ctx)
     

    Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter

    channelInactive, channelRead, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered

    Methods inherited from class io.netty.channel.ChannelHandlerAdapter

    ensureNotSharable, handlerAdded, handlerRemoved, isSharable

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.netty.channel.ChannelHandler

    handlerAdded, handlerRemoved
  • Field Details

    • ATTR_REMOTE_ADDR

      public static final io.netty.util.AttributeKey<SocketAddress> ATTR_REMOTE_ADDR
      Indicates the actual source (remote) address of the channel. This can be different than the one Channel returns if the connection is being proxied. (e.g. over HAProxy)
    • ATTR_PROXY_PROTOCOL_DESTINATION_ADDRESS

      public static final io.netty.util.AttributeKey<InetSocketAddress> ATTR_PROXY_PROTOCOL_DESTINATION_ADDRESS
      Indicates the destination address received from Proxy Protocol. Not set otherwise
    • ATTR_SOURCE_INET_ADDR

      @Deprecated public static final io.netty.util.AttributeKey<InetSocketAddress> ATTR_SOURCE_INET_ADDR
      Deprecated.
      Use ATTR_REMOTE_ADDR instead.
    • ATTR_SOURCE_ADDRESS

      public static final io.netty.util.AttributeKey<String> ATTR_SOURCE_ADDRESS
      The host address of the source. This is derived from ATTR_REMOTE_ADDR. If the address is an IPv6 address, the scope identifier is absent.
    • ATTR_LOCAL_ADDR

      public static final io.netty.util.AttributeKey<SocketAddress> ATTR_LOCAL_ADDR
      Indicates the local address of the channel. This can be different than the one Channel returns if the connection is being proxied. (e.g. over HAProxy)
    • ATTR_LOCAL_INET_ADDR

      @Deprecated public static final io.netty.util.AttributeKey<InetSocketAddress> ATTR_LOCAL_INET_ADDR
      Deprecated.
      Use ATTR_LOCAL_ADDR instead.
    • ATTR_LOCAL_ADDRESS

      public static final io.netty.util.AttributeKey<String> ATTR_LOCAL_ADDRESS
      The local address of this channel. This is derived from channel.localAddress(), or from the Proxy Protocol preface if provided. If the address is an IPv6 address, the scope identifier is absent. Unlike ATTR_SERVER_LOCAL_ADDRESS, this value is overwritten with the Proxy Protocol local address (e.g. the LB's local address), if enabled.
    • ATTR_SERVER_LOCAL_ADDRESS

      @Deprecated public static final io.netty.util.AttributeKey<String> ATTR_SERVER_LOCAL_ADDRESS
      Deprecated.
      Use channel.localAddress() instead.
      The actual local address of the channel, in string form. If the address is an IPv6 address, the scope identifier is absent. Unlike ATTR_LOCAL_ADDRESS, this is not overwritten by the Proxy Protocol message if present.
    • ATTR_SERVER_LOCAL_PORT

      public static final io.netty.util.AttributeKey<Integer> ATTR_SERVER_LOCAL_PORT
      The port number of the local socket, or -1 if not appropriate. This is not overwritten by the Proxy Protocol message if present.
  • Constructor Details

    • SourceAddressChannelHandler

      public SourceAddressChannelHandler()
  • Method Details

    • channelActive

      public void channelActive(io.netty.channel.ChannelHandlerContext ctx) throws Exception
      Specified by:
      channelActive in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelActive in class io.netty.channel.ChannelInboundHandlerAdapter
      Throws:
      Exception