From a577cd2fbaa4149728dbdd525abd9c2b7c43d7e9 Mon Sep 17 00:00:00 2001 From: Michael Barker Date: Thu, 16 Jan 2025 10:00:53 +1300 Subject: [PATCH] [Java] Use endpoint addresses when checking against tagged endpoints instead of UdpChannel address, so it works correctly during re-resolution. --- .../driver/media/ReceiveChannelEndpoint.java | 13 ++++++++- .../driver/media/SendChannelEndpoint.java | 18 +++++++++++- .../io/aeron/driver/media/UdpChannel.java | 29 +++++++------------ 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/aeron-driver/src/main/java/io/aeron/driver/media/ReceiveChannelEndpoint.java b/aeron-driver/src/main/java/io/aeron/driver/media/ReceiveChannelEndpoint.java index b105646780..d4e65141b6 100644 --- a/aeron-driver/src/main/java/io/aeron/driver/media/ReceiveChannelEndpoint.java +++ b/aeron-driver/src/main/java/io/aeron/driver/media/ReceiveChannelEndpoint.java @@ -619,7 +619,18 @@ public long tag() */ public boolean matchesTag(final UdpChannel udpChannel) { - return super.udpChannel.matchesTag(udpChannel); + final boolean udpChannelMatches = super.udpChannel.matchesTag(udpChannel); + + final InetSocketAddress thisRemoteData = super.udpChannel.remoteData(); + final InetSocketAddress thatRemoteData = udpChannel.remoteData(); + final InetSocketAddress thatLocalData = udpChannel.localData(); + + final boolean addressMatches = thatRemoteData.getAddress().equals(thisRemoteData.getAddress()) && + thatRemoteData.getPort() == thisRemoteData.getPort() && + thatLocalData.getAddress().equals(currentControlAddress.getAddress()) && + thatLocalData.getPort() == currentControlAddress.getPort(); + + return udpChannelMatches && (udpChannel.isWildcard() || addressMatches); } /** diff --git a/aeron-driver/src/main/java/io/aeron/driver/media/SendChannelEndpoint.java b/aeron-driver/src/main/java/io/aeron/driver/media/SendChannelEndpoint.java index 7694bde9f7..8bea15b670 100644 --- a/aeron-driver/src/main/java/io/aeron/driver/media/SendChannelEndpoint.java +++ b/aeron-driver/src/main/java/io/aeron/driver/media/SendChannelEndpoint.java @@ -643,7 +643,23 @@ private void applyChannelSendTimestamp(final ByteBuffer buffer) */ public boolean matchesTag(final UdpChannel udpChannel) { - return super.udpChannel.matchesTag(udpChannel); + final boolean udpChannelMatches = super.udpChannel.matchesTag(udpChannel); + + final InetSocketAddress thatRemoteData = udpChannel.remoteData(); + final InetSocketAddress thisLocalData = super.udpChannel.localData(); + final InetSocketAddress thatLocalData = udpChannel.localData(); + + final boolean wildcardMatches = thatRemoteData.getAddress().isAnyLocalAddress() && + thatRemoteData.getPort() == 0 && + thatLocalData.getAddress().isAnyLocalAddress() && + thatLocalData.getPort() == 0; + + final boolean addressMatches = thatRemoteData.getAddress().equals(connectAddress.getAddress()) && + thatRemoteData.getPort() == connectAddress.getPort() && + thatLocalData.getAddress().equals(thisLocalData.getAddress()) && + thatLocalData.getPort() == thisLocalData.getPort(); + + return udpChannelMatches && (wildcardMatches || addressMatches); } } diff --git a/aeron-driver/src/main/java/io/aeron/driver/media/UdpChannel.java b/aeron-driver/src/main/java/io/aeron/driver/media/UdpChannel.java index 0be70be071..05ab1a1838 100644 --- a/aeron-driver/src/main/java/io/aeron/driver/media/UdpChannel.java +++ b/aeron-driver/src/main/java/io/aeron/driver/media/UdpChannel.java @@ -790,28 +790,21 @@ public boolean matchesTag(final UdpChannel udpChannel) "matching tag=" + tag + " has mismatched control-mode: " + uriStr + " <> " + udpChannel.uriStr); } - if (!hasMatchingAddress(udpChannel)) - { - throw new IllegalArgumentException( - "matching tag=" + tag + " has mismatched endpoint or control: " + uriStr + " <> " + udpChannel.uriStr); - } - return true; } - private boolean hasMatchingAddress(final UdpChannel udpChannel) + /** + * Is this channel a fill wildcard, i.e. no addresses specified. + * + * @return true if all the address/port pairs of this channel are set to wildcard values, + * false otherwise. + */ + public boolean isWildcard() { - final boolean otherChannelIsWildcard = udpChannel.remoteData().getAddress().isAnyLocalAddress() && - udpChannel.remoteData().getPort() == 0 && - udpChannel.localData().getAddress().isAnyLocalAddress() && - udpChannel.localData().getPort() == 0; - - final boolean otherChannelMatches = udpChannel.remoteData().getAddress().equals(remoteData.getAddress()) && - udpChannel.remoteData().getPort() == remoteData.getPort() && - udpChannel.localData().getAddress().equals(localData.getAddress()) && - udpChannel.localData().getPort() == localData.getPort(); - - return otherChannelIsWildcard || otherChannelMatches; + return remoteData.getAddress().isAnyLocalAddress() && + remoteData.getPort() == 0 && + localData.getAddress().isAnyLocalAddress() && + localData.getPort() == 0; } private boolean matchesControlMode(final UdpChannel udpChannel)