Skip to content

Commit

Permalink
Remove apache (openhab#17409)
Browse files Browse the repository at this point in the history
Signed-off-by: Leo Siepel <[email protected]>
  • Loading branch information
lsiepel authored and joni1993 committed Oct 15, 2024
1 parent 10c7b7a commit 8d5c5d0
Showing 1 changed file with 8 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,15 @@
package org.openhab.binding.russound.internal.discovery;

import java.io.IOException;
import java.net.Inet6Address;
import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Collections;
import java.net.InetAddress;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import org.apache.commons.net.util.SubnetUtils;
import org.openhab.binding.russound.internal.net.SocketChannelSession;
import org.openhab.binding.russound.internal.net.SocketSession;
import org.openhab.binding.russound.internal.net.WaitingSessionListener;
Expand All @@ -37,6 +31,7 @@
import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
import org.openhab.core.config.discovery.DiscoveryService;
import org.openhab.core.net.NetUtil;
import org.openhab.core.thing.ThingUID;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
Expand Down Expand Up @@ -78,48 +73,14 @@ public RioSystemDiscovery() {
*/
@Override
protected void startScan() {
final List<NetworkInterface> interfaces;
try {
interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
} catch (SocketException e1) {
logger.debug("Exception getting network interfaces: {}", e1.getMessage(), e1);
return;
}

nbrNetworkInterfacesScanning = interfaces.size();
List<InetAddress> addressesToScan = NetUtil.getFullRangeOfAddressesToScan();
logger.debug("Performing discovery on {} ip addresses", addressesToScan.size());
executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 10);

for (final NetworkInterface networkInterface : interfaces) {
try {
if (networkInterface.isLoopback() || !networkInterface.isUp()) {
continue;
}
} catch (SocketException e) {
continue;
}

for (Iterator<InterfaceAddress> it = networkInterface.getInterfaceAddresses().iterator(); it.hasNext();) {
final InterfaceAddress interfaceAddress = it.next();

// don't bother with ipv6 addresses (russound doesn't support)
if (interfaceAddress.getAddress() instanceof Inet6Address) {
continue;
}

final String subnetRange = interfaceAddress.getAddress().getHostAddress() + "/"
+ interfaceAddress.getNetworkPrefixLength();

logger.debug("Scanning subnet: {}", subnetRange);
final SubnetUtils utils = new SubnetUtils(subnetRange);

final String[] addresses = utils.getInfo().getAllAddresses();

for (final String address : addresses) {
executorService.execute(() -> {
scanAddress(address);
});
}
}
for (final InetAddress address : addressesToScan) {
executorService.execute(() -> {
scanAddress(address.getHostAddress());
});
}

// Finishes the scan and cleans up
Expand Down

0 comments on commit 8d5c5d0

Please sign in to comment.