Makes AwsCandidateHarvester reuses the harvest logic from super.
This commit is contained in:
parent
6a97941d68
commit
9512d303a2
@ -94,51 +94,13 @@ public class AwsCandidateHarvester
|
|||||||
*/
|
*/
|
||||||
public Collection<LocalCandidate> harvest(Component component)
|
public Collection<LocalCandidate> harvest(Component component)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (mask == null || face == null)
|
if (mask == null || face == null)
|
||||||
{
|
{
|
||||||
if(!obtainEC2Addresses())
|
if(!obtainEC2Addresses())
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return super.harvest(component);
|
||||||
/*
|
|
||||||
* Report the LocalCandidates gathered by this CandidateHarvester so
|
|
||||||
* that the harvest is sure to be considered successful.
|
|
||||||
*/
|
|
||||||
Collection<LocalCandidate> candidates = new HashSet<LocalCandidate>();
|
|
||||||
|
|
||||||
for (Candidate<?> cand : component.getLocalCandidates())
|
|
||||||
{
|
|
||||||
if (!(cand instanceof HostCandidate)
|
|
||||||
|| !cand.getTransportAddress().getHostAddress()
|
|
||||||
.equals(face.getHostAddress()))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
TransportAddress mappedAddress = new TransportAddress(
|
|
||||||
mask.getHostAddress(),
|
|
||||||
cand.getHostAddress().getPort(),
|
|
||||||
cand.getHostAddress().getTransport());
|
|
||||||
|
|
||||||
ServerReflexiveCandidate mappedCandidate
|
|
||||||
= new ServerReflexiveCandidate(
|
|
||||||
mappedAddress,
|
|
||||||
(HostCandidate)cand,
|
|
||||||
cand.getStunServerAddress(),
|
|
||||||
CandidateExtendedType.STATICALLY_MAPPED_CANDIDATE);
|
|
||||||
|
|
||||||
//try to add the candidate to the component and then
|
|
||||||
//only add it to the harvest not redundant
|
|
||||||
if( !candidates.contains(mappedCandidate)
|
|
||||||
&& component.addLocalCandidate(mappedCandidate))
|
|
||||||
{
|
|
||||||
candidates.add(mappedCandidate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return candidates;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -190,7 +152,7 @@ public class AwsCandidateHarvester
|
|||||||
* Returns the discovered public (mask) address, or null.
|
* Returns the discovered public (mask) address, or null.
|
||||||
* @return the discovered public (mask) address, or null.
|
* @return the discovered public (mask) address, or null.
|
||||||
*/
|
*/
|
||||||
public static TransportAddress getMask()
|
public static TransportAddress getDiscoveredMask()
|
||||||
{
|
{
|
||||||
if (smellsLikeAnEC2())
|
if (smellsLikeAnEC2())
|
||||||
{
|
{
|
||||||
@ -204,7 +166,7 @@ public class AwsCandidateHarvester
|
|||||||
* Returns the discovered local (face) address, or null.
|
* Returns the discovered local (face) address, or null.
|
||||||
* @return the discovered local (face) address, or null.
|
* @return the discovered local (face) address, or null.
|
||||||
*/
|
*/
|
||||||
public static TransportAddress getFace()
|
public static TransportAddress getDiscoveredFace()
|
||||||
{
|
{
|
||||||
if (smellsLikeAnEC2())
|
if (smellsLikeAnEC2())
|
||||||
{
|
{
|
||||||
@ -276,4 +238,22 @@ public class AwsCandidateHarvester
|
|||||||
|
|
||||||
return retString;
|
return retString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the public (mask) address, or null.
|
||||||
|
* @return the public (mask) address, or null.
|
||||||
|
*/
|
||||||
|
public TransportAddress getMask()
|
||||||
|
{
|
||||||
|
return this.mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the local (face) address, or null.
|
||||||
|
* @return the local (face) address, or null.
|
||||||
|
*/
|
||||||
|
public TransportAddress getFace()
|
||||||
|
{
|
||||||
|
return this.face;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,12 +46,12 @@ public class MappingCandidateHarvester
|
|||||||
/**
|
/**
|
||||||
* The addresses that we will use as a mask
|
* The addresses that we will use as a mask
|
||||||
*/
|
*/
|
||||||
private TransportAddress mask;
|
private final TransportAddress mask;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The addresses that we will be masking
|
* The addresses that we will be masking
|
||||||
*/
|
*/
|
||||||
private TransportAddress face;
|
private final TransportAddress face;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a mapping harvester with the specified <tt>mask</tt>
|
* Creates a mapping harvester with the specified <tt>mask</tt>
|
||||||
@ -65,6 +65,7 @@ public class MappingCandidateHarvester
|
|||||||
this.mask = mask;
|
this.mask = mask;
|
||||||
this.face = face;
|
this.face = face;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps all candidates to this harvester's mask and adds them to
|
* Maps all candidates to this harvester's mask and adds them to
|
||||||
* <tt>component</tt>.
|
* <tt>component</tt>.
|
||||||
@ -76,8 +77,7 @@ public class MappingCandidateHarvester
|
|||||||
*/
|
*/
|
||||||
public Collection<LocalCandidate> harvest(Component component)
|
public Collection<LocalCandidate> harvest(Component component)
|
||||||
{
|
{
|
||||||
|
if (getMask() == null || getFace() == null)
|
||||||
if (mask == null || face == null)
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -90,15 +90,15 @@ public class MappingCandidateHarvester
|
|||||||
{
|
{
|
||||||
if (!(cand instanceof HostCandidate)
|
if (!(cand instanceof HostCandidate)
|
||||||
|| !cand.getTransportAddress().getHostAddress()
|
|| !cand.getTransportAddress().getHostAddress()
|
||||||
.equals(face.getHostAddress())
|
.equals(getFace().getHostAddress())
|
||||||
|| cand.getTransport() != face.getTransport())
|
|| cand.getTransport() != getFace().getTransport())
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
HostCandidate hostCandidate = (HostCandidate) cand;
|
HostCandidate hostCandidate = (HostCandidate) cand;
|
||||||
TransportAddress mappedAddress = new TransportAddress(
|
TransportAddress mappedAddress = new TransportAddress(
|
||||||
mask.getHostAddress(),
|
getMask().getHostAddress(),
|
||||||
hostCandidate.getHostAddress().getPort(),
|
hostCandidate.getHostAddress().getPort(),
|
||||||
hostCandidate.getHostAddress().getTransport());
|
hostCandidate.getHostAddress().getTransport());
|
||||||
|
|
||||||
@ -122,4 +122,22 @@ public class MappingCandidateHarvester
|
|||||||
|
|
||||||
return candidates;
|
return candidates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the public (mask) address, or null.
|
||||||
|
* @return the public (mask) address, or null.
|
||||||
|
*/
|
||||||
|
public TransportAddress getMask()
|
||||||
|
{
|
||||||
|
return this.mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the local (face) address, or null.
|
||||||
|
* @return the local (face) address, or null.
|
||||||
|
*/
|
||||||
|
public TransportAddress getFace()
|
||||||
|
{
|
||||||
|
return this.face;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -640,10 +640,10 @@ public class MultiplexingTcpHostHarvester
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Automatically add a mapping if we're on EC2
|
// Automatically add a mapping if we're on EC2
|
||||||
TransportAddress ec2Face = AwsCandidateHarvester.getFace();
|
TransportAddress ec2Face = AwsCandidateHarvester.getDiscoveredFace();
|
||||||
TransportAddress ec2Mask;
|
TransportAddress ec2Mask;
|
||||||
if (ec2Face != null &&
|
if (ec2Face != null &&
|
||||||
(ec2Mask = AwsCandidateHarvester.getMask()) != null)
|
(ec2Mask = AwsCandidateHarvester.getDiscoveredMask()) != null)
|
||||||
{
|
{
|
||||||
addMappedAddress(ec2Mask.getAddress(), ec2Face.getAddress());
|
addMappedAddress(ec2Mask.getAddress(), ec2Face.getAddress());
|
||||||
logger.info("Adding an EC2 mapping for TCP: "
|
logger.info("Adding an EC2 mapping for TCP: "
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user