- Fix up port handling, add some logging on bind fails
      - Force IPv4 only for binds
This commit is contained in:
zzz
2009-05-20 15:01:43 +00:00
parent 3ba43a77f4
commit 31cd726b7b
4 changed files with 21 additions and 7 deletions

View File

@ -48,6 +48,9 @@ public class UPnPManager {
_context = context;
_manager = manager;
_log = _context.logManager().getLog(UPnPManager.class);
// UPnP wants to bind to IPv6 link local interfaces by default, but what UPnP router
// is going to want to talk IPv6 anyway? Just make it easy and force IPv4 only
org.cybergarage.upnp.UPnP.setEnable(org.cybergarage.upnp.UPnP.USE_ONLY_IPV4_ADDR);
_upnp = new UPnP(context);
_upnp.setHTTPPort(_context.getProperty(PROP_HTTP_PORT, DEFAULT_HTTP_PORT));
_upnp.setSSDPPort(_context.getProperty(PROP_SSDP_PORT, DEFAULT_SSDP_PORT));
@ -150,7 +153,7 @@ public class UPnPManager {
public String renderStatusHTML() {
if (!_isRunning)
return "<a name=\"upnp\"><<b>UPnP is not enabled</b>\n";
return "<a name=\"upnp\"><b>UPnP is not enabled</b>\n";
return _upnp.renderStatusHTML();
}
}

View File

@ -91,6 +91,7 @@ public class HTTPServer implements Runnable
serverSock.setSoTimeout(10*1000);
}
catch (IOException e) {
Debug.warning("HTTP server open failed " + addr + " " + port, e);
return false;
}
return true;

View File

@ -786,9 +786,13 @@ public class ControlPoint implements HTTPRequestListener
HTTPServerList httpServerList = getHTTPServerList();
while (httpServerList.open(bindPort) == false) {
retryCnt++;
if (UPnP.SERVER_RETRY_COUNT < retryCnt)
if (UPnP.SERVER_RETRY_COUNT < retryCnt) {
Debug.warning("Failed to open HTTP event listener port " + bindPort);
// I2P do we really need this, or can we just break ?
return false;
setHTTPPort(bindPort + 1);
}
// I2P go down not up so we don't run into other I2P things
setHTTPPort(bindPort - 1);
bindPort = getHTTPPort();
}
httpServerList.addRequestListener(this);
@ -799,8 +803,10 @@ public class ControlPoint implements HTTPRequestListener
////////////////////////////////////////
SSDPNotifySocketList ssdpNotifySocketList = getSSDPNotifySocketList();
if (ssdpNotifySocketList.open() == false)
if (ssdpNotifySocketList.open() == false) {
Debug.warning("Failed to open SSDP notify port 1900");
return false;
}
ssdpNotifySocketList.setControlPoint(this);
ssdpNotifySocketList.start();
@ -813,9 +819,12 @@ public class ControlPoint implements HTTPRequestListener
SSDPSearchResponseSocketList ssdpSearchResponseSocketList = getSSDPSearchResponseSocketList();
while (ssdpSearchResponseSocketList.open(ssdpPort) == false) {
retryCnt++;
if (UPnP.SERVER_RETRY_COUNT < retryCnt)
if (UPnP.SERVER_RETRY_COUNT < retryCnt) {
Debug.warning("Failed to open SSDP search response port " + ssdpPort);
return false;
setSSDPPort(ssdpPort + 1);
}
// I2P go down not up so we don't run into other I2P things
setSSDPPort(ssdpPort - 1);
ssdpPort = getSSDPPort();
}
ssdpSearchResponseSocketList.setControlPoint(this);

View File

@ -37,7 +37,8 @@ public class UPnP
public final static String NAME = "CyberLink";
public final static String VERSION = "1.7";
public final static int SERVER_RETRY_COUNT = 100;
// I2P was 100
public final static int SERVER_RETRY_COUNT = 4;
public final static int DEFAULT_EXPIRED_DEVICE_EXTRA_TIME = 60;
public final static String getServerName()