Package io.netty.handler.codec.haproxy
Class HAProxyMessage
java.lang.Object
io.netty.util.AbstractReferenceCounted
io.netty.handler.codec.haproxy.HAProxyMessage
- All Implemented Interfaces:
ReferenceCounted
Message container for decoded HAProxy proxy protocol parameters
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final HAProxyCommand
private final String
private final int
private final ResourceLeakTracker
<HAProxyMessage> private static final ResourceLeakDetector
<HAProxyMessage> private static final int
private final HAProxyProtocolVersion
private final HAProxyProxiedProtocol
private final String
private final int
private final List
<HAProxyTLV> -
Constructor Summary
ConstructorsModifierConstructorDescriptionHAProxyMessage
(HAProxyProtocolVersion protocolVersion, HAProxyCommand command, HAProxyProxiedProtocol proxiedProtocol, String sourceAddress, String destinationAddress, int sourcePort, int destinationPort) Creates a new instance of HAProxyMessage.HAProxyMessage
(HAProxyProtocolVersion protocolVersion, HAProxyCommand command, HAProxyProxiedProtocol proxiedProtocol, String sourceAddress, String destinationAddress, int sourcePort, int destinationPort, List<? extends HAProxyTLV> tlvs) Creates a new instance of HAProxyMessage.private
HAProxyMessage
(HAProxyProtocolVersion protocolVersion, HAProxyCommand command, HAProxyProxiedProtocol proxiedProtocol, String sourceAddress, String destinationAddress, String sourcePort, String destinationPort) Creates a new instance -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
checkAddress
(String address, HAProxyProxiedProtocol.AddressFamily addrFamily) Validate an address (IPv4, IPv6, Unix Socket)private static void
checkPort
(int port, HAProxyProxiedProtocol.AddressFamily addrFamily) Validate the port depending on the addrFamily.command()
Returns theHAProxyCommand
of thisHAProxyMessage
.protected void
Called onceAbstractReferenceCounted.refCnt()
is equals 0.(package private) static HAProxyMessage
decodeHeader
(ByteBuf header) Decodes a version 2, binary proxy protocol header.(package private) static HAProxyMessage
decodeHeader
(String header) Decodes a version 1, human-readable proxy protocol header.Returns the human-readable destination address of thisHAProxyMessage
.int
Returns the UDP/TCP destination port of thisHAProxyMessage
.private static String
ipBytesToString
(ByteBuf header, int addressLen) Convert ip address bytes to string representationprivate static int
portStringToInt
(String value) Convert port to integerReturns theHAProxyProtocolVersion
of thisHAProxyMessage
.Returns theHAProxyProxiedProtocol
of thisHAProxyMessage
.private static HAProxyTLV
readNextTLV
(ByteBuf header, int nestingLevel) private static List
<HAProxyTLV> boolean
release()
Decreases the reference count by1
and deallocates this object if the reference count reaches at0
.boolean
release
(int decrement) Decreases the reference count by the specifieddecrement
and deallocates this object if the reference count reaches at0
.retain()
Increases the reference count by1
.retain
(int increment) Increases the reference count by the specifiedincrement
.Returns the human-readable source address of thisHAProxyMessage
ornull
if HAProxy performs health check withsend-proxy-v2
.int
Returns the UDP/TCP source port of thisHAProxyMessage
.(package private) int
tlvs()
Returns a list ofHAProxyTLV
or an empty list if no TLVs are present.toString()
touch()
Records the current access location of this object for debugging purposes.Records the current access location of this object with an additional arbitrary information for debugging purposes.private void
private static HAProxyMessage
unknownMsg
(HAProxyProtocolVersion version, HAProxyCommand command) Proxy protocol message for 'UNKNOWN' proxied protocols.Methods inherited from class io.netty.util.AbstractReferenceCounted
refCnt, setRefCnt
-
Field Details
-
MAX_NESTING_LEVEL
private static final int MAX_NESTING_LEVEL- See Also:
-
leakDetector
-
leak
-
protocolVersion
-
command
-
proxiedProtocol
-
sourceAddress
-
destinationAddress
-
sourcePort
private final int sourcePort -
destinationPort
private final int destinationPort -
tlvs
-
-
Constructor Details
-
HAProxyMessage
private HAProxyMessage(HAProxyProtocolVersion protocolVersion, HAProxyCommand command, HAProxyProxiedProtocol proxiedProtocol, String sourceAddress, String destinationAddress, String sourcePort, String destinationPort) Creates a new instance -
HAProxyMessage
public HAProxyMessage(HAProxyProtocolVersion protocolVersion, HAProxyCommand command, HAProxyProxiedProtocol proxiedProtocol, String sourceAddress, 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, String sourceAddress, String destinationAddress, int sourcePort, int destinationPort, 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
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
-
readNextTLV
-
decodeHeader
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
Proxy protocol message for 'UNKNOWN' proxied protocols. Per spec, when the proxied protocol is 'UNKNOWN' we must discard all other header values. -
ipBytesToString
Convert ip address bytes to string representation- Parameters:
header
- buffer containing ip address bytesaddressLen
- number of bytes to read (4 bytes for IPv4, 16 bytes for IPv6)- Returns:
- string representation of the ip address
-
portStringToInt
Convert port to integer- Parameters:
value
- the port- Returns:
- port as an integer
- Throws:
IllegalArgumentException
- if port is not a valid integer
-
checkAddress
Validate an address (IPv4, IPv6, Unix Socket)- Parameters:
address
- human-readable addressaddrFamily
- theHAProxyProxiedProtocol.AddressFamily
to check the address against- Throws:
IllegalArgumentException
- if the address is invalid
-
checkPort
Validate the port depending on the addrFamily.- Parameters:
port
- the UDP/TCP port- Throws:
IllegalArgumentException
- if the port is out of range (0-65535 inclusive)
-
protocolVersion
Returns theHAProxyProtocolVersion
of thisHAProxyMessage
. -
command
Returns theHAProxyCommand
of thisHAProxyMessage
. -
proxiedProtocol
Returns theHAProxyProxiedProtocol
of thisHAProxyMessage
. -
sourceAddress
Returns the human-readable source address of thisHAProxyMessage
ornull
if HAProxy performs health check withsend-proxy-v2
. -
destinationAddress
Returns the human-readable destination address of thisHAProxyMessage
. -
sourcePort
public int sourcePort()Returns the UDP/TCP source port of thisHAProxyMessage
. -
destinationPort
public int destinationPort()Returns the UDP/TCP destination port of thisHAProxyMessage
. -
tlvs
Returns a list ofHAProxyTLV
or an empty list if no TLVs are present.TLVs are only available for the Proxy Protocol V2
-
tlvNumBytes
int tlvNumBytes() -
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 viaResourceLeakDetector
. This method is a shortcut totouch(null)
.- Specified by:
touch
in interfaceReferenceCounted
- Overrides:
touch
in classAbstractReferenceCounted
-
touch
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 viaResourceLeakDetector
. -
retain
Description copied from interface:ReferenceCounted
Increases the reference count by1
.- Specified by:
retain
in interfaceReferenceCounted
- Overrides:
retain
in classAbstractReferenceCounted
-
retain
Description copied from interface:ReferenceCounted
Increases the reference count by the specifiedincrement
.- Specified by:
retain
in interfaceReferenceCounted
- Overrides:
retain
in classAbstractReferenceCounted
-
release
public boolean release()Description copied from interface:ReferenceCounted
Decreases the reference count by1
and deallocates this object if the reference count reaches at0
.- Specified by:
release
in interfaceReferenceCounted
- Overrides:
release
in classAbstractReferenceCounted
- Returns:
true
if and only if the reference count became0
and this object has been deallocated
-
release
public boolean release(int decrement) Description copied from interface:ReferenceCounted
Decreases the reference count by the specifieddecrement
and deallocates this object if the reference count reaches at0
.- Specified by:
release
in interfaceReferenceCounted
- Overrides:
release
in classAbstractReferenceCounted
- Returns:
true
if and only if the reference count became0
and this object has been deallocated
-
tryRecord
private void tryRecord() -
deallocate
protected void deallocate()Description copied from class:AbstractReferenceCounted
Called onceAbstractReferenceCounted.refCnt()
is equals 0.- Specified by:
deallocate
in classAbstractReferenceCounted
-
toString
-