forked from I2P_Developers/i2p.i2p
more UPnP locking fixes
This commit is contained in:
@@ -134,10 +134,12 @@ class UPnP extends ControlPoint implements DeviceChangeListener, EventListener {
|
||||
} catch (InterruptedException ie) {}
|
||||
}
|
||||
super.stop();
|
||||
synchronized(lock) {
|
||||
_router = null;
|
||||
_service = null;
|
||||
_serviceLacksAPM = false;
|
||||
}
|
||||
}
|
||||
|
||||
public DetectedIP[] getAddress() {
|
||||
_log.info("UP&P.getAddress() is called \\o/");
|
||||
@@ -214,16 +216,6 @@ class UPnP extends ControlPoint implements DeviceChangeListener, EventListener {
|
||||
synchronized (lock) {
|
||||
_otherUDNs.put(udn, name);
|
||||
}
|
||||
/********** seems a little drastic
|
||||
isDisabled = true;
|
||||
|
||||
synchronized(lock) {
|
||||
_router = null;
|
||||
_service = null;
|
||||
}
|
||||
|
||||
stop();
|
||||
**************/
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -259,7 +251,7 @@ class UPnP extends ControlPoint implements DeviceChangeListener, EventListener {
|
||||
/// we should look for the next one
|
||||
if(_service == null) {
|
||||
_log.error("The IGD device we got isn't suiting our needs, let's disable the plugin");
|
||||
isDisabled = true;
|
||||
//isDisabled = true;
|
||||
_router = null;
|
||||
return;
|
||||
}
|
||||
@@ -388,18 +380,24 @@ class UPnP extends ControlPoint implements DeviceChangeListener, EventListener {
|
||||
* @return whether we are behind an UPnP-enabled NAT/router
|
||||
*/
|
||||
private boolean isNATPresent() {
|
||||
synchronized(lock) {
|
||||
return _router != null && _service != null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the external address the NAT thinks we have. Blocking.
|
||||
* null if we can't find it.
|
||||
*/
|
||||
private String getNATAddress() {
|
||||
Service service;
|
||||
synchronized(lock) {
|
||||
if(!isNATPresent())
|
||||
return null;
|
||||
service = _service;
|
||||
}
|
||||
|
||||
Action getIP = _service.getAction("GetExternalIPAddress");
|
||||
Action getIP = service.getAction("GetExternalIPAddress");
|
||||
if(getIP == null || !getIP.postControlAction())
|
||||
return null;
|
||||
|
||||
@@ -414,10 +412,14 @@ class UPnP extends ControlPoint implements DeviceChangeListener, EventListener {
|
||||
* @return the reported upstream bit rate in bits per second. -1 if it's not available. Blocking.
|
||||
*/
|
||||
private int getUpstreamMaxBitRate() {
|
||||
Service service;
|
||||
synchronized(lock) {
|
||||
if(!isNATPresent() || thinksWeAreDoubleNatted)
|
||||
return -1;
|
||||
service = _service;
|
||||
}
|
||||
|
||||
Action getIP = _service.getAction("GetLinkLayerMaxBitRates");
|
||||
Action getIP = service.getAction("GetLinkLayerMaxBitRates");
|
||||
if(getIP == null || !getIP.postControlAction())
|
||||
return -1;
|
||||
|
||||
@@ -432,10 +434,14 @@ class UPnP extends ControlPoint implements DeviceChangeListener, EventListener {
|
||||
* @return the reported downstream bit rate in bits per second. -1 if it's not available. Blocking.
|
||||
*/
|
||||
private int getDownstreamMaxBitRate() {
|
||||
Service service;
|
||||
synchronized(lock) {
|
||||
if(!isNATPresent() || thinksWeAreDoubleNatted)
|
||||
return -1;
|
||||
service = _service;
|
||||
}
|
||||
|
||||
Action getIP = _service.getAction("GetLinkLayerMaxBitRates");
|
||||
Action getIP = service.getAction("GetLinkLayerMaxBitRates");
|
||||
if(getIP == null || !getIP.postControlAction())
|
||||
return -1;
|
||||
|
||||
@@ -697,16 +703,20 @@ class UPnP extends ControlPoint implements DeviceChangeListener, EventListener {
|
||||
* Blocking!
|
||||
*/
|
||||
private boolean addMapping(String protocol, int port, String description, ForwardPort fp) {
|
||||
Service service;
|
||||
synchronized(lock) {
|
||||
if(isDisabled || !isNATPresent() || _router == null) {
|
||||
_log.error("Can't addMapping: " + isDisabled + " " + isNATPresent() + " " + _router);
|
||||
return false;
|
||||
}
|
||||
service = _service;
|
||||
}
|
||||
|
||||
// Just in case...
|
||||
// this confuses my linksys? - zzz
|
||||
//removeMapping(protocol, port, fp, true);
|
||||
|
||||
Action add = _service.getAction("AddPortMapping");
|
||||
Action add = service.getAction("AddPortMapping");
|
||||
if(add == null) {
|
||||
if (_serviceLacksAPM) {
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
@@ -839,10 +849,16 @@ class UPnP extends ControlPoint implements DeviceChangeListener, EventListener {
|
||||
|
||||
/** blocking */
|
||||
private boolean removeMapping(String protocol, int port, ForwardPort fp, boolean noLog) {
|
||||
if(isDisabled || !isNATPresent())
|
||||
Service service;
|
||||
synchronized(lock) {
|
||||
if(isDisabled || !isNATPresent()) {
|
||||
_log.error("Can't addMapping: " + isDisabled + " " + isNATPresent() + " " + _router);
|
||||
return false;
|
||||
}
|
||||
service = _service;
|
||||
}
|
||||
|
||||
Action remove = _service.getAction("DeletePortMapping");
|
||||
Action remove = service.getAction("DeletePortMapping");
|
||||
if(remove == null) {
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Couldn't find DeletePortMapping action!");
|
||||
|
Reference in New Issue
Block a user