From f36c7609a85cbc8197f8c920c4d222ddb9102e3d Mon Sep 17 00:00:00 2001 From: damencho Date: Wed, 11 Apr 2012 12:57:11 +0000 Subject: [PATCH] Moves UPnP search for WANIPConnection and WANPPPConnection when harvesting is started, to avoid block when harvester is created. --- src/org/ice4j/ice/harvest/UPNPHarvester.java | 78 ++++++++++---------- 1 file changed, 38 insertions(+), 40 deletions(-) diff --git a/src/org/ice4j/ice/harvest/UPNPHarvester.java b/src/org/ice4j/ice/harvest/UPNPHarvester.java index 62a4437..28b7865 100644 --- a/src/org/ice4j/ice/harvest/UPNPHarvester.java +++ b/src/org/ice4j/ice/harvest/UPNPHarvester.java @@ -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 Candidates that are * already present in the specified component. This method relies @@ -119,11 +80,48 @@ public class UPNPHarvester Collection candidates = new HashSet(); 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();