Skip to content

Commit

Permalink
[Java] Use endpoint addresses when checking against tagged endpoints …
Browse files Browse the repository at this point in the history
…instead of UdpChannel address, so it works correctly during re-resolution.
  • Loading branch information
mikeb01 committed Jan 15, 2025
1 parent aa897e9 commit a577cd2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
29 changes: 11 additions & 18 deletions aeron-driver/src/main/java/io/aeron/driver/media/UdpChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>true</code> if all the address/port pairs of this channel are set to wildcard values,
* <code>false</code> 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)
Expand Down

0 comments on commit a577cd2

Please sign in to comment.