Class HAProxyMessage

java.lang.Object
io.netty.util.AbstractReferenceCounted
io.netty.handler.codec.haproxy.HAProxyMessage
All Implemented Interfaces:
ReferenceCounted

public final class HAProxyMessage extends AbstractReferenceCounted
Message container for decoded HAProxy proxy protocol parameters
  • Field Details

  • Constructor Details

    • HAProxyMessage

      private HAProxyMessage(HAProxyProtocolVersion protocolVersion, HAProxyCommand command, HAProxyProxiedProtocol proxiedProtocol, java.lang.String sourceAddress, java.lang.String destinationAddress, java.lang.String sourcePort, java.lang.String destinationPort)
      Creates a new instance
    • HAProxyMessage

      public HAProxyMessage(HAProxyProtocolVersion protocolVersion, HAProxyCommand command, HAProxyProxiedProtocol proxiedProtocol, java.lang.String sourceAddress, java.lang.String destinationAddress, int sourcePort, int destinationPort)
      Creates a new instance of HAProxyMessage.
      Parameters:
      protocolVersion - the protocol version.
      command - the command.
      proxiedProtocol - the protocol containing the address family and transport protocol.
      sourceAddress - the source address.
      destinationAddress - the destination address.
      sourcePort - the source port. This value must be 0 for unix, unspec addresses.
      destinationPort - the destination port. This value must be 0 for unix, unspec addresses.
    • HAProxyMessage

      public HAProxyMessage(HAProxyProtocolVersion protocolVersion, HAProxyCommand command, HAProxyProxiedProtocol proxiedProtocol, java.lang.String sourceAddress, java.lang.String destinationAddress, int sourcePort, int destinationPort, java.util.List<? extends HAProxyTLV> tlvs)
      Creates a new instance of HAProxyMessage.
      Parameters:
      protocolVersion - the protocol version.
      command - the command.
      proxiedProtocol - the protocol containing the address family and transport protocol.
      sourceAddress - the source address.
      destinationAddress - the destination address.
      sourcePort - the source port. This value must be 0 for unix, unspec addresses.
      destinationPort - the destination port. This value must be 0 for unix, unspec addresses.
      tlvs - the list of tlvs.
  • Method Details

    • decodeHeader

      static HAProxyMessage decodeHeader(ByteBuf header)
      Decodes a version 2, binary proxy protocol header.
      Parameters:
      header - a version 2 proxy protocol header
      Returns:
      HAProxyMessage instance
      Throws:
      HAProxyProtocolException - if any portion of the header is invalid
    • readTlvs

      private static java.util.List<HAProxyTLV> readTlvs(ByteBuf header)
    • releaseDeep

      private static void releaseDeep(java.util.List<HAProxyTLV> children)
    • releaseTlvs

      private static void releaseTlvs(java.util.List<HAProxyTLV> tlvs)
    • readNextTLV

      private static HAProxyTLV readNextTLV(ByteBuf header, int nestingLevel)
    • decodeHeader

      static HAProxyMessage decodeHeader(java.lang.String header)
      Decodes a version 1, human-readable proxy protocol header.
      Parameters:
      header - a version 1 proxy protocol header
      Returns:
      HAProxyMessage instance
      Throws:
      HAProxyProtocolException - if any portion of the header is invalid
    • unknownMsg

      private static HAProxyMessage unknownMsg(HAProxyProtocolVersion version, HAProxyCommand command)
      Proxy protocol message for 'UNKNOWN' proxied protocols. Per spec, when the proxied protocol is 'UNKNOWN' we must discard all other header values.
    • ipBytesToString

      private static java.lang.String ipBytesToString(ByteBuf header, int addressLen)
      Convert ip address bytes to string representation
      Parameters:
      header - buffer containing ip address bytes
      addressLen - number of bytes to read (4 bytes for IPv4, 16 bytes for IPv6)
      Returns:
      string representation of the ip address
    • portStringToInt

      private static int portStringToInt(java.lang.String value)
      Convert port to integer
      Parameters:
      value - the port
      Returns:
      port as an integer
      Throws:
      java.lang.IllegalArgumentException - if port is not a valid integer
    • checkAddress

      private static void checkAddress(java.lang.String address, HAProxyProxiedProtocol.AddressFamily addrFamily, HAProxyProtocolVersion version)
      Validate an address (IPv4, IPv6, Unix Socket)
      Parameters:
      address - human-readable address
      addrFamily - the HAProxyProxiedProtocol.AddressFamily to check the address against
      version - the protocol version
      Throws:
      java.lang.IllegalArgumentException - if the address is invalid
    • checkPort

      private static void checkPort(int port, HAProxyProxiedProtocol.AddressFamily addrFamily)
      Validate the port depending on the addrFamily.
      Parameters:
      port - the UDP/TCP port
      Throws:
      java.lang.IllegalArgumentException - if the port is out of range (0-65535 inclusive)
    • protocolVersion

      public HAProxyProtocolVersion protocolVersion()
    • command

      public HAProxyCommand command()
      Returns the HAProxyCommand of this HAProxyMessage.
    • proxiedProtocol

      public HAProxyProxiedProtocol proxiedProtocol()
    • sourceAddress

      public java.lang.String sourceAddress()
      Returns the human-readable source address of this HAProxyMessage or null if HAProxy performs health check with send-proxy-v2.
    • destinationAddress

      public java.lang.String destinationAddress()
      Returns the human-readable destination address of this HAProxyMessage.
    • sourcePort

      public int sourcePort()
      Returns the UDP/TCP source port of this HAProxyMessage.
    • destinationPort

      public int destinationPort()
      Returns the UDP/TCP destination port of this HAProxyMessage.
    • tlvs

      public java.util.List<HAProxyTLV> tlvs()
      Returns a list of HAProxyTLV or an empty list if no TLVs are present.

      TLVs are only available for the Proxy Protocol V2

    • tlvNumBytes

      int tlvNumBytes()
    • flattenedChildren

      static int flattenedChildren(java.util.List<HAProxyTLV> tlvs, int index)
      Returns how many entries directly following HAProxySSLTLV at index are its encapsulated TLVs.
    • touch

      public HAProxyMessage touch()
      Description copied from interface: ReferenceCounted
      Records the current access location of this object for debugging purposes. If this object is determined to be leaked, the information recorded by this operation will be provided to you via ResourceLeakDetector. This method is a shortcut to touch(null).
      Specified by:
      touch in interface ReferenceCounted
      Overrides:
      touch in class AbstractReferenceCounted
    • touch

      public HAProxyMessage touch(java.lang.Object hint)
      Description copied from interface: ReferenceCounted
      Records the current access location of this object with an additional arbitrary information for debugging purposes. If this object is determined to be leaked, the information recorded by this operation will be provided to you via ResourceLeakDetector.
    • retain

      public HAProxyMessage retain()
      Description copied from interface: ReferenceCounted
      Increases the reference count by 1.
      Specified by:
      retain in interface ReferenceCounted
      Overrides:
      retain in class AbstractReferenceCounted
    • retain

      public HAProxyMessage retain(int increment)
      Description copied from interface: ReferenceCounted
      Increases the reference count by the specified increment.
      Specified by:
      retain in interface ReferenceCounted
      Overrides:
      retain in class AbstractReferenceCounted
    • release

      public boolean release()
      Description copied from interface: ReferenceCounted
      Decreases the reference count by 1 and deallocates this object if the reference count reaches at 0.
      Specified by:
      release in interface ReferenceCounted
      Overrides:
      release in class AbstractReferenceCounted
      Returns:
      true if and only if the reference count became 0 and this object has been deallocated
    • release

      public boolean release(int decrement)
      Description copied from interface: ReferenceCounted
      Decreases the reference count by the specified decrement and deallocates this object if the reference count reaches at 0.
      Specified by:
      release in interface ReferenceCounted
      Overrides:
      release in class AbstractReferenceCounted
      Returns:
      true if and only if the reference count became 0 and this object has been deallocated
    • tryRecord

      private void tryRecord()
    • deallocate

      protected void deallocate()
      Description copied from class: AbstractReferenceCounted
      Called once AbstractReferenceCounted.refCnt() is equals 0.
      Specified by:
      deallocate in class AbstractReferenceCounted
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object