diff --git a/src/main/java/org/ice4j/ice/harvest/AwsCandidateHarvester.java b/src/main/java/org/ice4j/ice/harvest/AwsCandidateHarvester.java index e9f4560..73bf410 100644 --- a/src/main/java/org/ice4j/ice/harvest/AwsCandidateHarvester.java +++ b/src/main/java/org/ice4j/ice/harvest/AwsCandidateHarvester.java @@ -94,51 +94,13 @@ public class AwsCandidateHarvester */ public Collection harvest(Component component) { - if (mask == null || face == null) { if(!obtainEC2Addresses()) return null; } - - /* - * Report the LocalCandidates gathered by this CandidateHarvester so - * that the harvest is sure to be considered successful. - */ - Collection candidates = new HashSet(); - - 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; + return super.harvest(component); } /** @@ -190,7 +152,7 @@ public class AwsCandidateHarvester * Returns 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()) { @@ -204,7 +166,7 @@ public class AwsCandidateHarvester * Returns 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()) { @@ -276,4 +238,22 @@ public class AwsCandidateHarvester 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; + } } diff --git a/src/main/java/org/ice4j/ice/harvest/MappingCandidateHarvester.java b/src/main/java/org/ice4j/ice/harvest/MappingCandidateHarvester.java index 6d8eee3..ed4b623 100644 --- a/src/main/java/org/ice4j/ice/harvest/MappingCandidateHarvester.java +++ b/src/main/java/org/ice4j/ice/harvest/MappingCandidateHarvester.java @@ -46,12 +46,12 @@ public class MappingCandidateHarvester /** * The addresses that we will use as a mask */ - private TransportAddress mask; + private final TransportAddress mask; /** * The addresses that we will be masking */ - private TransportAddress face; + private final TransportAddress face; /** * Creates a mapping harvester with the specified mask @@ -65,6 +65,7 @@ public class MappingCandidateHarvester this.mask = mask; this.face = face; } + /** * Maps all candidates to this harvester's mask and adds them to * component. @@ -76,8 +77,7 @@ public class MappingCandidateHarvester */ public Collection harvest(Component component) { - - if (mask == null || face == null) + if (getMask() == null || getFace() == null) return null; /* @@ -90,15 +90,15 @@ public class MappingCandidateHarvester { if (!(cand instanceof HostCandidate) || !cand.getTransportAddress().getHostAddress() - .equals(face.getHostAddress()) - || cand.getTransport() != face.getTransport()) + .equals(getFace().getHostAddress()) + || cand.getTransport() != getFace().getTransport()) { continue; } HostCandidate hostCandidate = (HostCandidate) cand; TransportAddress mappedAddress = new TransportAddress( - mask.getHostAddress(), + getMask().getHostAddress(), hostCandidate.getHostAddress().getPort(), hostCandidate.getHostAddress().getTransport()); @@ -122,4 +122,22 @@ public class MappingCandidateHarvester 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; + } } diff --git a/src/main/java/org/ice4j/ice/harvest/MultiplexingTcpHostHarvester.java b/src/main/java/org/ice4j/ice/harvest/MultiplexingTcpHostHarvester.java index 6c8a51f..10a4c05 100644 --- a/src/main/java/org/ice4j/ice/harvest/MultiplexingTcpHostHarvester.java +++ b/src/main/java/org/ice4j/ice/harvest/MultiplexingTcpHostHarvester.java @@ -640,10 +640,10 @@ public class MultiplexingTcpHostHarvester } // Automatically add a mapping if we're on EC2 - TransportAddress ec2Face = AwsCandidateHarvester.getFace(); + TransportAddress ec2Face = AwsCandidateHarvester.getDiscoveredFace(); TransportAddress ec2Mask; if (ec2Face != null && - (ec2Mask = AwsCandidateHarvester.getMask()) != null) + (ec2Mask = AwsCandidateHarvester.getDiscoveredMask()) != null) { addMappedAddress(ec2Mask.getAddress(), ec2Face.getAddress()); logger.info("Adding an EC2 mapping for TCP: "