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 HAProxyCommandcommandprivate java.lang.StringdestinationAddressprivate intdestinationPortprivate ResourceLeakTracker<HAProxyMessage>leakprivate static ResourceLeakDetector<HAProxyMessage>leakDetectorprivate HAProxyProtocolVersionprotocolVersionprivate HAProxyProxiedProtocolproxiedProtocolprivate java.lang.StringsourceAddressprivate intsourcePortprivate 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.privateHAProxyMessage(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 voidcheckAddress(java.lang.String address, HAProxyProxiedProtocol.AddressFamily addrFamily)Validate an address (IPv4, IPv6, Unix Socket)private static voidcheckPort(int port, HAProxyProxiedProtocol.AddressFamily addrFamily)Validate the port depending on the addrFamily.HAProxyCommandcommand()Returns theHAProxyCommandof thisHAProxyMessage.protected voiddeallocate()Called onceAbstractReferenceCounted.refCnt()is equals 0.(package private) static HAProxyMessagedecodeHeader(ByteBuf header)Decodes a version 2, binary proxy protocol header.(package private) static HAProxyMessagedecodeHeader(java.lang.String header)Decodes a version 1, human-readable proxy protocol header.java.lang.StringdestinationAddress()Returns the human-readable destination address of thisHAProxyMessage.intdestinationPort()Returns the UDP/TCP destination port of thisHAProxyMessage.private static java.lang.StringipBytesToString(ByteBuf header, int addressLen)Convert ip address bytes to string representationprivate static intportStringToInt(java.lang.String value)Convert port to integerHAProxyProtocolVersionprotocolVersion()Returns theHAProxyProtocolVersionof thisHAProxyMessage.HAProxyProxiedProtocolproxiedProtocol()Returns theHAProxyProxiedProtocolof thisHAProxyMessage.private static HAProxyTLVreadNextTLV(ByteBuf header)private static java.util.List<HAProxyTLV>readTlvs(ByteBuf header)booleanrelease()Decreases the reference count by1and deallocates this object if the reference count reaches at0.booleanrelease(int decrement)Decreases the reference count by the specifieddecrementand deallocates this object if the reference count reaches at0.HAProxyMessageretain()Increases the reference count by1.HAProxyMessageretain(int increment)Increases the reference count by the specifiedincrement.java.lang.StringsourceAddress()Returns the human-readable source address of thisHAProxyMessage.intsourcePort()Returns the UDP/TCP source port of thisHAProxyMessage.(package private) inttlvNumBytes()java.util.List<HAProxyTLV>tlvs()Returns a list ofHAProxyTLVor an empty list if no TLVs are present.java.lang.StringtoString()HAProxyMessagetouch()Records the current access location of this object for debugging purposes.HAProxyMessagetouch(java.lang.Object hint)Records the current access location of this object with an additional arbitrary information for debugging purposes.private voidtryRecord()private static HAProxyMessageunknownMsg(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:
HAProxyMessageinstance- 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:
HAProxyMessageinstance- 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.AddressFamilyto 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 theHAProxyProtocolVersionof thisHAProxyMessage.
-
command
public HAProxyCommand command()
Returns theHAProxyCommandof thisHAProxyMessage.
-
proxiedProtocol
public HAProxyProxiedProtocol proxiedProtocol()
Returns theHAProxyProxiedProtocolof 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 ofHAProxyTLVor 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:ReferenceCountedRecords 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:
touchin interfaceReferenceCounted- Overrides:
touchin classAbstractReferenceCounted
-
touch
public HAProxyMessage touch(java.lang.Object hint)
Description copied from interface:ReferenceCountedRecords 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:ReferenceCountedIncreases the reference count by1.- Specified by:
retainin interfaceReferenceCounted- Overrides:
retainin classAbstractReferenceCounted
-
retain
public HAProxyMessage retain(int increment)
Description copied from interface:ReferenceCountedIncreases the reference count by the specifiedincrement.- Specified by:
retainin interfaceReferenceCounted- Overrides:
retainin classAbstractReferenceCounted
-
release
public boolean release()
Description copied from interface:ReferenceCountedDecreases the reference count by1and deallocates this object if the reference count reaches at0.- Specified by:
releasein interfaceReferenceCounted- Overrides:
releasein classAbstractReferenceCounted- Returns:
trueif and only if the reference count became0and this object has been deallocated
-
release
public boolean release(int decrement)
Description copied from interface:ReferenceCountedDecreases the reference count by the specifieddecrementand deallocates this object if the reference count reaches at0.- Specified by:
releasein interfaceReferenceCounted- Overrides:
releasein classAbstractReferenceCounted- Returns:
trueif and only if the reference count became0and this object has been deallocated
-
tryRecord
private void tryRecord()
-
deallocate
protected void deallocate()
Description copied from class:AbstractReferenceCountedCalled onceAbstractReferenceCounted.refCnt()is equals 0.- Specified by:
deallocatein classAbstractReferenceCounted
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-