UPnP: Don't bind HTTP listen sockets to all addresses at startup

The lib was binding to all addresses, and then our
UPnP.updateInterfaces() was closing most of them on first run.
Fix the lib to only bind to the non-public and non-deprecated ones,
using the same getLocalAddresses() method as in our code.
This commit is contained in:
zzz
2022-05-27 11:18:48 -04:00
parent 34789fdb30
commit 86996dde28
2 changed files with 9 additions and 11 deletions

View File

@@ -684,9 +684,9 @@ public class UPnP extends ControlPoint implements DeviceChangeListener, EventLis
/**
* Get the addresses we want to bind to
*
* @since 0.9.46
* @since 0.9.46, public since 0.9.55 for HTTPServerList
*/
static Set<String> getLocalAddresses() {
public static Set<String> getLocalAddresses() {
// older miniupnpd will send ipv6 ssdp search response to ipv4 address,
// but newer ones won't. So we need to bind to an ipv6 address
// to get his ipv6 address so we can bind to OUR ipv6 address
@@ -729,9 +729,6 @@ public class UPnP extends ControlPoint implements DeviceChangeListener, EventLis
if (pct > 0)
addr = addr.substring(0, pct);
if (!addrs.contains(addr)) {
// the first time through this will close a lot of sockets,
// because HTTPServerList binds to every address,
// including IPv6 deprecated
iter.remove();
skt.close();
skt.stop();

View File

@@ -18,11 +18,14 @@
package org.cybergarage.http;
import java.net.InetAddress;
import java.util.Set;
import java.util.Vector;
import org.cybergarage.net.HostInterface;
import org.cybergarage.upnp.Device;
import net.i2p.router.transport.UPnP;
public class HTTPServerList extends Vector<HTTPServer>
{
////////////////////////////////////////////////
@@ -80,12 +83,10 @@ public class HTTPServerList extends Vector<HTTPServer>
bindAddresses[i] = binds[i].getHostAddress();
}
}else{
int nHostAddrs = HostInterface.getNHostAddresses();
bindAddresses = new String[nHostAddrs];
for (int n=0; n<nHostAddrs; n++) {
bindAddresses[n] = HostInterface.getHostAddress(n);
}
}
// I2P non-public addresses only
Set<String> addrs = UPnP.getLocalAddresses();
bindAddresses = addrs.toArray(new String[addrs.size()]);
}
int j=0;
for (int i = 0; i < bindAddresses.length; i++) {
HTTPServer httpServer = new HTTPServer();