Moves UPnP search for WANIPConnection and WANPPPConnection when harvesting is started, to avoid block when harvester is created.

This commit is contained in:
damencho 2012-04-11 12:57:11 +00:00
parent c8d9101610
commit f36c7609a8

View File

@ -64,45 +64,6 @@ public class UPNPHarvester
*/
private int finishThreads = 0;
/**
* Constructor.
*/
public UPNPHarvester()
{
try
{
logger.info("Begin UPnP harvesting");
UPNPThread wanIPThread = new UPNPThread(stIP);
UPNPThread wanPPPThread = new UPNPThread(stPPP);
wanIPThread.start();
wanPPPThread.start();
while(finishThreads != 2)
{
synchronized(rootSync)
{
rootSync.wait();
}
}
if(wanIPThread.getDevice() != null)
{
device = wanIPThread.getDevice();
}
else if(wanPPPThread.getDevice() != null)
{
device = wanPPPThread.getDevice();
}
}
catch(Exception e)
{
logger.info("UPnP discovery failed: " + e);
}
}
/**
* Gathers UPnP candidates for all host <tt>Candidate</tt>s that are
* already present in the specified <tt>component</tt>. This method relies
@ -119,11 +80,48 @@ public class UPNPHarvester
Collection<LocalCandidate> candidates = new HashSet<LocalCandidate>();
int retries = 0;
logger.info("Begin UPnP harvesting");
try
{
if(device == null)
{
return candidates;
// do it only once
if(finishThreads == 0)
{
try
{
UPNPThread wanIPThread = new UPNPThread(stIP);
UPNPThread wanPPPThread = new UPNPThread(stPPP);
wanIPThread.start();
wanPPPThread.start();
while(finishThreads != 2)
{
synchronized(rootSync)
{
rootSync.wait();
}
}
if(wanIPThread.getDevice() != null)
{
device = wanIPThread.getDevice();
}
else if(wanPPPThread.getDevice() != null)
{
device = wanPPPThread.getDevice();
}
}
catch(Throwable e)
{
logger.info("UPnP discovery failed: " + e);
}
}
if(device == null)
return candidates;
}
InetAddress localAddress = device.getLocalAddress();