Skip to content

Commit

Permalink
Added matching hostname when interface has wildcards. Fixes hazelcast…
Browse files Browse the repository at this point in the history
  • Loading branch information
mdogan committed May 6, 2014
1 parent d0a5e64 commit 0ec36c8
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions hazelcast/src/main/java/com/hazelcast/impl/AddressPicker.java
Expand Up @@ -197,7 +197,8 @@ private Collection<InterfaceDefinition> getInterfaces(final NetworkConfig networ
final Collection<String> configInterfaces = networkConfig.getInterfaces().getInterfaces();
for (String configInterface : configInterfaces) {
if (AddressUtil.isIpAddress(configInterface)) {
interfaces.add(new InterfaceDefinition(addressDomainMap.get(configInterface), configInterface));
String hostname = findHostnameMatchingInterface(addressDomainMap, configInterface);
interfaces.add(new InterfaceDefinition(hostname, configInterface));
} else {
logger.log(Level.INFO, "'" + configInterface
+ "' is not an IP address! Removing from interface list.");
Expand All @@ -215,6 +216,20 @@ private Collection<InterfaceDefinition> getInterfaces(final NetworkConfig networ
return interfaces;
}

private String findHostnameMatchingInterface(Map<String, String> addressDomainMap, String configInterface) {
String hostname = addressDomainMap.get(configInterface);
if (hostname != null) {
return hostname;
}
for (Entry<String, String> entry : addressDomainMap.entrySet()) {
String address = entry.getKey();
if (AddressUtil.matchInterface(address, configInterface)) {
return entry.getValue();
}
}
return null;
}

private Collection<String> resolveDomainNames(final String domainName)
throws UnknownHostException {
final InetAddress[] inetAddresses = InetAddress.getAllByName(domainName);
Expand Down Expand Up @@ -298,7 +313,8 @@ private AddressDefinition pickMatchingAddress(final Collection<InterfaceDefiniti

private AddressDefinition match(final InetAddress address, final Collection<InterfaceDefinition> interfaces) {
for (final InterfaceDefinition inf : interfaces) {
if (AddressUtil.matchInterface(address.getHostAddress(), inf.address)) {
String interfaceMask = inf.address;
if (AddressUtil.matchInterface(address.getHostAddress(), interfaceMask)) {
return new AddressDefinition(inf.host, address);
}
}
Expand Down

0 comments on commit 0ec36c8

Please sign in to comment.