-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[zuul-core] Remove deprecated port attrs. Use
_ADDRESS
instead.
- Loading branch information
Showing
4 changed files
with
47 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,19 +32,17 @@ | |
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Stores the source IP address as an attribute of the channel. This has the advantage of allowing | ||
* us to overwrite it if we have more info (eg. ELB sends a HAProxyMessage with info of REAL source | ||
* host + port). | ||
* | ||
* User: [email protected] | ||
* Date: 4/14/16 | ||
* Time: 4:29 PM | ||
* Stores the source IP address as an attribute of the channel. This has the advantage of allowing us to overwrite it if | ||
* we have more info (eg. ELB sends a HAProxyMessage with info of REAL source host + port). | ||
* <p> | ||
* User: [email protected] Date: 4/14/16 Time: 4:29 PM | ||
*/ | ||
@ChannelHandler.Sharable | ||
public final class SourceAddressChannelHandler extends ChannelInboundHandlerAdapter { | ||
|
||
/** | ||
* Indicates the actual source (remote) address of the channel. This can be different than the | ||
* one {@link Channel} returns if the connection is being proxied. (e.g. over HAProxy) | ||
* Indicates the actual source (remote) address of the channel. This can be different than the one {@link Channel} | ||
* returns if the connection is being proxied. (e.g. over HAProxy) | ||
*/ | ||
public static final AttributeKey<SocketAddress> ATTR_REMOTE_ADDR = AttributeKey.newInstance("_remote_addr"); | ||
|
||
|
@@ -54,30 +52,22 @@ public final class SourceAddressChannelHandler extends ChannelInboundHandlerAdap | |
public static final AttributeKey<InetSocketAddress> ATTR_PROXY_PROTOCOL_DESTINATION_ADDRESS = | ||
AttributeKey.newInstance("_proxy_protocol_destination_address"); | ||
|
||
/** Use {@link #ATTR_REMOTE_ADDR} instead. */ | ||
/** | ||
* Use {@link #ATTR_REMOTE_ADDR} instead. | ||
*/ | ||
@Deprecated | ||
public static final AttributeKey<InetSocketAddress> ATTR_SOURCE_INET_ADDR = | ||
AttributeKey.newInstance("_source_inet_addr"); | ||
|
||
/** | ||
* The host address of the source. This is derived from {@link #ATTR_REMOTE_ADDR}. If the | ||
* address is an IPv6 address, the scope identifier is absent. | ||
* The host address of the source. This is derived from {@link #ATTR_REMOTE_ADDR}. If the address is an IPv6 | ||
* address, the scope identifier is absent. | ||
*/ | ||
public static final AttributeKey<String> ATTR_SOURCE_ADDRESS = AttributeKey.newInstance("_source_address"); | ||
|
||
/** | ||
* Indicates the actual source (remote) port of the channel, if present. This can be different | ||
* than the one {@link Channel} returns if the connection is being proxies. (e.g. over | ||
* HAProxy). | ||
* @deprecated use {@link #ATTR_REMOTE_ADDR} instead, and check if it is an {@code | ||
* InetSocketAddress}. | ||
*/ | ||
@Deprecated | ||
public static final AttributeKey<Integer> ATTR_SOURCE_PORT = AttributeKey.newInstance("_source_port"); | ||
|
||
/** | ||
* Indicates the local address of the channel. This can be different than the | ||
* one {@link Channel} returns if the connection is being proxied. (e.g. over HAProxy) | ||
* Indicates the local address of the channel. This can be different than the one {@link Channel} returns if the | ||
* connection is being proxied. (e.g. over HAProxy) | ||
*/ | ||
public static final AttributeKey<SocketAddress> ATTR_LOCAL_ADDR = AttributeKey.newInstance("_local_addr"); | ||
|
||
|
@@ -89,53 +79,43 @@ public final class SourceAddressChannelHandler extends ChannelInboundHandlerAdap | |
AttributeKey.newInstance("_local_inet_addr"); | ||
|
||
/** | ||
* The local address of this channel. This is derived from {@code channel.localAddress()}, or from the | ||
* Proxy Protocol preface if provided. If the address is an IPv6 address, the scope identifier is absent. | ||
* Unlike {@link #ATTR_SERVER_LOCAL_ADDRESS}, this value is overwritten with the Proxy Protocol local address | ||
* (e.g. the LB's local address), if enabled. | ||
* The local address of this channel. This is derived from {@code channel.localAddress()}, or from the Proxy | ||
* Protocol preface if provided. If the address is an IPv6 address, the scope identifier is absent. Unlike {@link | ||
* #ATTR_SERVER_LOCAL_ADDRESS}, this value is overwritten with the Proxy Protocol local address (e.g. the LB's local | ||
* address), if enabled. | ||
*/ | ||
public static final AttributeKey<String> ATTR_LOCAL_ADDRESS = AttributeKey.newInstance("_local_address"); | ||
|
||
/** | ||
* The port number of the local socket, or {@code -1} if not appropriate. Use {@link #ATTR_LOCAL_ADDR} instead. | ||
*/ | ||
@Deprecated | ||
public static final AttributeKey<Integer> ATTR_LOCAL_PORT = AttributeKey.newInstance("_local_port"); | ||
|
||
|
||
/** | ||
* The actual local address of the channel, in string form. If the address is an IPv6 address, the scope | ||
* identifier is absent. Unlike {@link #ATTR_LOCAL_ADDRESS}, this is not overwritten by the Proxy Protocol message | ||
* if present. | ||
* The actual local address of the channel, in string form. If the address is an IPv6 address, the scope identifier | ||
* is absent. Unlike {@link #ATTR_LOCAL_ADDRESS}, this is not overwritten by the Proxy Protocol message if | ||
* present. | ||
* | ||
* @deprecated Use {@code channel.localAddress()} instead. | ||
*/ | ||
@Deprecated | ||
public static final AttributeKey<String> ATTR_SERVER_LOCAL_ADDRESS = AttributeKey.newInstance("_server_local_address"); | ||
public static final AttributeKey<String> ATTR_SERVER_LOCAL_ADDRESS = | ||
AttributeKey.newInstance("_server_local_address"); | ||
|
||
/** | ||
* The port number of the local socket, or {@code -1} if not appropriate. Unlike {@link #ATTR_LOCAL_PORT}, this | ||
* is not overwritten by the Proxy Protocol message if present. | ||
* The port number of the local socket, or {@code -1} if not appropriate. This is not overwritten by the Proxy | ||
* Protocol message if present. | ||
* | ||
* @deprecated Use {@code channel.localAddress()} instead. | ||
*/ | ||
@Deprecated | ||
public static final AttributeKey<Integer> ATTR_SERVER_LOCAL_PORT = AttributeKey.newInstance("_server_local_port"); | ||
|
||
@Override | ||
public void channelActive(ChannelHandlerContext ctx) throws Exception | ||
{ | ||
public void channelActive(ChannelHandlerContext ctx) throws Exception { | ||
ctx.channel().attr(ATTR_REMOTE_ADDR).set(ctx.channel().remoteAddress()); | ||
InetSocketAddress sourceAddress = sourceAddress(ctx.channel()); | ||
ctx.channel().attr(ATTR_SOURCE_INET_ADDR).setIfAbsent(sourceAddress); | ||
ctx.channel().attr(ATTR_SOURCE_ADDRESS).setIfAbsent(getHostAddress(sourceAddress)); | ||
ctx.channel().attr(ATTR_SOURCE_PORT).setIfAbsent(sourceAddress.getPort()); | ||
|
||
ctx.channel().attr(ATTR_LOCAL_ADDR).set(ctx.channel().localAddress()); | ||
InetSocketAddress localAddress = localAddress(ctx.channel()); | ||
ctx.channel().attr(ATTR_LOCAL_INET_ADDR).setIfAbsent(localAddress); | ||
ctx.channel().attr(ATTR_LOCAL_ADDRESS).setIfAbsent(getHostAddress(localAddress)); | ||
ctx.channel().attr(ATTR_LOCAL_PORT).setIfAbsent(localAddress.getPort()); | ||
// ATTR_LOCAL_ADDRESS and ATTR_LOCAL_PORT get overwritten with what is received in | ||
// Proxy Protocol (via the LB), so set local server's address, port explicitly | ||
ctx.channel().attr(ATTR_SERVER_LOCAL_ADDRESS).setIfAbsent(localAddress.getAddress().getHostAddress()); | ||
|
@@ -168,8 +148,7 @@ static String getHostAddress(InetSocketAddress socketAddress) { | |
} | ||
} | ||
|
||
private InetSocketAddress sourceAddress(Channel channel) | ||
{ | ||
private InetSocketAddress sourceAddress(Channel channel) { | ||
SocketAddress remoteSocketAddr = channel.remoteAddress(); | ||
if (null != remoteSocketAddr && InetSocketAddress.class.isAssignableFrom(remoteSocketAddr.getClass())) { | ||
InetSocketAddress inetSocketAddress = (InetSocketAddress) remoteSocketAddr; | ||
|
@@ -180,8 +159,7 @@ private InetSocketAddress sourceAddress(Channel channel) | |
return null; | ||
} | ||
|
||
private InetSocketAddress localAddress(Channel channel) | ||
{ | ||
private InetSocketAddress localAddress(Channel channel) { | ||
SocketAddress localSocketAddress = channel.localAddress(); | ||
if (null != localSocketAddress && InetSocketAddress.class.isAssignableFrom(localSocketAddress.getClass())) { | ||
InetSocketAddress inetSocketAddress = (InetSocketAddress) localSocketAddress; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters