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
public final class HAProxyMessage extends AbstractReferenceCounted
Message container for decoded HAProxy proxy protocol parameters
-
-
Field Summary
Fields Modifier and Type Field Description private HAProxyCommand
command
private java.lang.String
destinationAddress
private int
destinationPort
private ResourceLeakTracker<HAProxyMessage>
leak
private static ResourceLeakDetector<HAProxyMessage>
leakDetector
private HAProxyProtocolVersion
protocolVersion
private HAProxyProxiedProtocol
proxiedProtocol
private java.lang.String
sourceAddress
private int
sourcePort
private java.util.List<HAProxyTLV>
tlvs
-
Constructor Summary
Constructors Modifier Constructor Description 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.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.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
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static void
checkAddress(java.lang.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.HAProxyCommand
command()
Returns theHAProxyCommand
of thisHAProxyMessage
.protected void
deallocate()
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(java.lang.String header)
Decodes a version 1, human-readable proxy protocol header.java.lang.String
destinationAddress()
Returns the human-readable destination address of thisHAProxyMessage
.int
destinationPort()
Returns the UDP/TCP destination port of thisHAProxyMessage
.private static java.lang.String
ipBytesToString(ByteBuf header, int addressLen)
Convert ip address bytes to string representationprivate static int
portStringToInt(java.lang.String value)
Convert port to integerHAProxyProtocolVersion
protocolVersion()
Returns theHAProxyProtocolVersion
of thisHAProxyMessage
.HAProxyProxiedProtocol
proxiedProtocol()
Returns theHAProxyProxiedProtocol
of thisHAProxyMessage
.private static HAProxyTLV
readNextTLV(ByteBuf header)
private static java.util.List<HAProxyTLV>
readTlvs(ByteBuf header)
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
.HAProxyMessage
retain()
Increases the reference count by1
.HAProxyMessage
retain(int increment)
Increases the reference count by the specifiedincrement
.java.lang.String
sourceAddress()
Returns the human-readable source address of thisHAProxyMessage
.int
sourcePort()
Returns the UDP/TCP source port of thisHAProxyMessage
.(package private) int
tlvNumBytes()
java.util.List<HAProxyTLV>
tlvs()
Returns a list ofHAProxyTLV
or an empty list if no TLVs are present.java.lang.String
toString()
HAProxyMessage
touch()
Records the current access location of this object for debugging purposes.HAProxyMessage
touch(java.lang.Object hint)
Records the current access location of this object with an additional arbitrary information for debugging purposes.private void
tryRecord()
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 Detail
-
leakDetector
private static final ResourceLeakDetector<HAProxyMessage> leakDetector
-
leak
private final ResourceLeakTracker<HAProxyMessage> leak
-
protocolVersion
private final HAProxyProtocolVersion protocolVersion
-
command
private final HAProxyCommand command
-
proxiedProtocol
private final HAProxyProxiedProtocol proxiedProtocol
-
sourceAddress
private final java.lang.String sourceAddress
-
destinationAddress
private final java.lang.String destinationAddress
-
sourcePort
private final int sourcePort
-
destinationPort
private final int destinationPort
-
tlvs
private final java.util.List<HAProxyTLV> tlvs
-
-
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
-
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)
-
readNextTLV
private static HAProxyTLV readNextTLV(ByteBuf header)
-
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 bytesaddressLen
- 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 addressaddrFamily
- theHAProxyProxiedProtocol.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)
-
protocolVersion
public HAProxyProtocolVersion protocolVersion()
Returns theHAProxyProtocolVersion
of thisHAProxyMessage
.
-
command
public HAProxyCommand command()
Returns theHAProxyCommand
of thisHAProxyMessage
.
-
proxiedProtocol
public HAProxyProxiedProtocol proxiedProtocol()
Returns theHAProxyProxiedProtocol
of thisHAProxyMessage
.
-
sourceAddress
public java.lang.String sourceAddress()
Returns the human-readable source address of thisHAProxyMessage
.
-
destinationAddress
public java.lang.String 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
public java.util.List<HAProxyTLV> 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
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 viaResourceLeakDetector
. This method is a shortcut totouch(null)
.- Specified by:
touch
in interfaceReferenceCounted
- Overrides:
touch
in classAbstractReferenceCounted
-
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 viaResourceLeakDetector
.
-
retain
public HAProxyMessage retain()
Description copied from interface:ReferenceCounted
Increases the reference count by1
.- Specified by:
retain
in interfaceReferenceCounted
- Overrides:
retain
in classAbstractReferenceCounted
-
retain
public HAProxyMessage retain(int increment)
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
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-