diff --git a/src/main/java/org/ice4j/ice/harvest/AwsCandidateHarvester.java b/src/main/java/org/ice4j/ice/harvest/AwsCandidateHarvester.java index 637ca3a..4f25851 100644 --- a/src/main/java/org/ice4j/ice/harvest/AwsCandidateHarvester.java +++ b/src/main/java/org/ice4j/ice/harvest/AwsCandidateHarvester.java @@ -18,11 +18,9 @@ package org.ice4j.ice.harvest; import org.ice4j.*; -import org.ice4j.ice.*; import java.io.*; import java.net.*; -import java.util.*; import java.util.logging.*; /** @@ -74,6 +72,11 @@ public class AwsCandidateHarvester */ private static TransportAddress face; + /** + * Whether we have already checked and found the mapping addresses. + */ + private static boolean addressChecked = false; + /** * Creates an AWS harvester. The actual addresses wil be retrieved later, * during the first harvest. @@ -83,39 +86,17 @@ public class AwsCandidateHarvester super(null, null); } - /** - * Maps all candidates to this harvester's mask and adds them to - * component. - * - * @param component the {@link Component} that we'd like to map candidates - * to. - * @return the LocalCandidates gathered by this - * CandidateHarvester or null if no mask is specified. - */ - public Collection harvest(Component component) - { - if (mask == null || face == null) - { - if(!obtainEC2Addresses()) - return null; - } - - return super.harvest(component); - } - /** * Sends HTTP GET queries to * http://169.254.169.254/latest/meta-data/local-ipv4 and * http://169.254.169.254/latest/meta-data/public-ipv4 to learn the * private (face) and public (mask) addresses of this EC2 instance. - * - * @return true if we managed to obtain addresses or someone else - * had already achieved that before us, false otherwise. */ - private static synchronized boolean obtainEC2Addresses() + private static synchronized void obtainEC2Addresses() { - if(mask != null && face != null) - return true; + if (addressChecked) + return; + addressChecked = true; String localIPStr = null; String publicIPStr = null; @@ -142,11 +123,7 @@ public class AwsCandidateHarvester + "for the following reason: ", exc); logger.info("String for local IP: " + localIPStr); logger.info("String for public IP: " + publicIPStr); - - return false; } - - return true; } /** diff --git a/src/main/java/org/ice4j/ice/harvest/StunMappingCandidateHarvester.java b/src/main/java/org/ice4j/ice/harvest/StunMappingCandidateHarvester.java index 34e1f16..62e7217 100644 --- a/src/main/java/org/ice4j/ice/harvest/StunMappingCandidateHarvester.java +++ b/src/main/java/org/ice4j/ice/harvest/StunMappingCandidateHarvester.java @@ -20,7 +20,6 @@ package org.ice4j.ice.harvest; import org.ice4j.*; import org.ice4j.ice.*; -import java.util.*; import java.util.logging.*; /** @@ -81,35 +80,12 @@ public class StunMappingCandidateHarvester super(null, null); } - /** - * Maps all candidates to this harvester's mask and adds them to - * component. - * - * @param component the {@link Component} that we'd like to map candidates - * to. - * @return the LocalCandidates gathered by this - * CandidateHarvester or null if no mask is specified. - */ - public Collection harvest(Component component) - { - if (mask == null || face == null) - { - if(!obtainAddresses()) - return null; - } - - return super.harvest(component); - } - /** * Uses the pre-configured list of stun servers to discover our public * address. Uses the first successful one and ignore the rest. * Learn the private (face) and public (mask) addresses of this instance. - * - * @return true if we managed to obtain addresses or someone else - * had already achieved that before us, false otherwise. */ - private static synchronized boolean obtainAddresses() + private static synchronized void obtainAddresses() { if (addressChecked) return; @@ -162,20 +138,7 @@ public class StunMappingCandidateHarvester //whatever happens, we just log and fail logger.log(Level.INFO, "We failed to obtain addresses " + "for the following reason: ", exc); - - return false; } - - return true; - } - - /** - * Whether we had already checked and succeeded finding address. - * @return whether we had already checked and succeeded finding address. - */ - private boolean isAddressChecked() - { - return addressChecked; } /** @@ -184,7 +147,7 @@ public class StunMappingCandidateHarvester */ public TransportAddress getMask() { - if (!isAddressChecked()) + if (mask == null) { obtainAddresses(); } @@ -197,7 +160,7 @@ public class StunMappingCandidateHarvester */ public TransportAddress getFace() { - if (!isAddressChecked()) + if (face == null) { obtainAddresses(); }