Class HAProxyMessage

    • Constructor Detail

      • 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 Detail

      • 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)
        Validate an address (IPv4, IPv6, Unix Socket)
        Parameters:
        address - human-readable address
        addrFamily - the HAProxyProxiedProtocol.AddressFamily to check the address against
        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)
      • 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()
      • 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.
      • 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()
      • toString

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