Simplify.
This commit is contained in:
parent
7a8b7ec2c3
commit
bd55b3645b
@ -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
|
||||
* <tt>component</tt>.
|
||||
*
|
||||
* @param component the {@link Component} that we'd like to map candidates
|
||||
* to.
|
||||
* @return the <tt>LocalCandidate</tt>s gathered by this
|
||||
* <tt>CandidateHarvester</tt> or <tt>null</tt> if no mask is specified.
|
||||
*/
|
||||
public Collection<LocalCandidate> harvest(Component component)
|
||||
{
|
||||
if (mask == null || face == null)
|
||||
{
|
||||
if(!obtainEC2Addresses())
|
||||
return null;
|
||||
}
|
||||
|
||||
return super.harvest(component);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends HTTP GET queries to
|
||||
* <tt>http://169.254.169.254/latest/meta-data/local-ipv4</tt> and
|
||||
* <tt>http://169.254.169.254/latest/meta-data/public-ipv4</tt> to learn the
|
||||
* private (face) and public (mask) addresses of this EC2 instance.
|
||||
*
|
||||
* @return <tt>true</tt> if we managed to obtain addresses or someone else
|
||||
* had already achieved that before us, <tt>false</tt> 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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
|
||||
* <tt>component</tt>.
|
||||
*
|
||||
* @param component the {@link Component} that we'd like to map candidates
|
||||
* to.
|
||||
* @return the <tt>LocalCandidate</tt>s gathered by this
|
||||
* <tt>CandidateHarvester</tt> or <tt>null</tt> if no mask is specified.
|
||||
*/
|
||||
public Collection<LocalCandidate> 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 <tt>true</tt> if we managed to obtain addresses or someone else
|
||||
* had already achieved that before us, <tt>false</tt> 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();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user