@Override public void initialize() throws XMPPException { if (!isResolving() && !isResolved()) { LOGGER.fine("Initialized"); // Negotiation with a STUN server for a set of interfaces is quite slow, but the results // never change over then instance of a JVM. To increase connection performance considerably // we now cache established/initialized negotiators for each STUN server, so that subsequent uses // of the STUN server are much, much faster. if (negociatorsMap.get(server) == null) { // CHECKSTYLE:OFF ICENegociator iceNegociator = new ICENegociator(server, port, (short) 1); negociatorsMap.put(server, iceNegociator); // gather candidates iceNegociator.gatherCandidateAddresses(); // prioritize candidates iceNegociator.prioritizeCandidates(); // CHECKSTYLE:ON } } this.setInitialized(); }
for (Candidate candidate : iceNegociator.getSortedCandidates()) try { Candidate.CandidateType type = candidate.getCandidateType(); ICECandidate.Type iceType; if (type.equals(Candidate.CandidateType.ServerReflexive)) iceType = ICECandidate.Type.srflx; else if (type.equals(Candidate.CandidateType.PeerReflexive)) iceType = ICECandidate.Type.prflx; else if (type.equals(Candidate.CandidateType.Relayed)) iceType = ICECandidate.Type.relay; else Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces(); short i = 0; NetworkInterface nic = NetworkInterface.getByInetAddress(candidate.getAddress().getInetAddress()); while (nics.hasMoreElements()) { NetworkInterface checkNIC = nics.nextElement(); TransportCandidate transportCandidate = new ICECandidate(candidate.getAddress().getInetAddress().getHostAddress(), 1, nicNum, String.valueOf(random.nextInt(Integer.MAX_VALUE)), candidate.getPort(), "1", candidate.getPriority(), iceType); transportCandidate.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress()); transportCandidate.setPort(getFreePort()); try { LOGGER.fine("Candidate addr: " + candidate.getAddress().getInetAddress() + "|" + candidate.getBase().getAddress().getInetAddress() + " Priority:" + candidate.getPriority());
public static void main(String args[]) { ICENegotiator cc = new ICENegotiator((short) 1); // gather candidates cc.gatherCandidateAddresses(); // priorize candidates cc.prioritizeCandidates(); // get SortedCandidates List<Candidate> sortedCandidates = cc.getSortedCandidates(); // sent sorted candidate addresses to peer over SDP // received sorted candidate addresses of peer over SDP } }
while (iterCandidates.hasNext()) { Candidate cand = iterCandidates.next(); CandidateType type = cand.getCandidateType(); if (type == CandidateType.Local) numberLocal++; else if (type == CandidateType.ServerReflexive) numberServerReflexive++; int componentValue = 0; Candidate cand = iterCandidates.next(); CandidateType type = cand.getCandidateType(); if (type == CandidateType.Local) { typeValue = LOCAL_PREFERENCE; localValue = numberRelayed--; componentValue = cand.getComponentId(); int priority = ((2 ^ 24) * typeValue) + ((2 ^ 8) * localValue) + componentValue; cand.setPriority(priority);
public int compareTo(Object arg0) { Candidate cand = (Candidate) arg0; return cand.getPriority() - getPriority(); }
try { Candidate local = new Candidate(new Address(iaddress.getAddress()), componentId); candidates.add(local); DiscoveryInfo di = test.test(); if (di.getPublicIP() != null) { Candidate cand = new Candidate(new Address(di.getPublicIP().getAddress()), CandidateType.ServerReflexive, componentId, local); cand.setComponentId(componentId); candidates.add(cand);
public boolean equals(Object o) { if (o == null) return false; if ((((Candidate) o).socket.equals(socket)) && (((Candidate) o).base.equals(base))) return true; return false; } }
public Candidate(Address address, CandidateType type, short componentId, Candidate base) throws SocketException, UnknownHostException, UtilityException { this.socket = new DatagramSocket(0, address.getInetAddress()); this.type = type; setComponentId(componentId); this.priority = 0; this.base = base; this.isInUse = false; }
for (Candidate candidate : iceNegociator.getSortedCandidates()) try { Candidate.CandidateType type = candidate.getCandidateType(); ICECandidate.Type iceType = ICECandidate.Type.local; if (type.equals(Candidate.CandidateType.ServerReflexive)) iceType = ICECandidate.Type.srflx; else if (type.equals(Candidate.CandidateType.PeerReflexive)) iceType = ICECandidate.Type.prflx; else if (type.equals(Candidate.CandidateType.Relayed)) iceType = ICECandidate.Type.relay; else Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces(); short i = 0; NetworkInterface nic = NetworkInterface.getByInetAddress(candidate.getAddress().getInetAddress()); while(nics.hasMoreElements()) { NetworkInterface checkNIC = nics.nextElement(); TransportCandidate transportCandidate = new ICECandidate(candidate.getAddress().getInetAddress().getHostAddress(), 1, nicNum, String.valueOf(Math.abs(random.nextLong())), candidate.getPort(), "1", candidate.getPriority(), iceType); transportCandidate.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress()); transportCandidate.setPort(getFreePort()); try { LOGGER.debug("Candidate addr: " + candidate.getAddress().getInetAddress() + "|" + candidate.getBase().getAddress().getInetAddress() + " Priority:" + candidate.getPriority());
public void initialize() throws XMPPException { if (!isResolving() && !isResolved()) { LOGGER.fine("Initialized"); // Negotiation with a STUN server for a set of interfaces is quite slow, but the results // never change over then instance of a JVM. To increase connection performance considerably // we now cache established/initialized negotiators for each STUN server, so that subsequent uses // of the STUN server are much, much faster. if (negociatorsMap.get(server) == null) { ICENegociator iceNegociator = new ICENegociator(server, port, (short) 1); negociatorsMap.put(server, iceNegociator); // gather candidates iceNegociator.gatherCandidateAddresses(); // priorize candidates iceNegociator.prioritizeCandidates(); } } this.setInitialized(); }
while (iterCandidates.hasNext()) { Candidate cand = iterCandidates.next(); CandidateType type = cand.getCandidateType(); if (type == CandidateType.Local) numberLocal++; else if (type == CandidateType.ServerReflexive) numberServerReflexive++; int componentValue = 0; Candidate cand = iterCandidates.next(); CandidateType type = cand.getCandidateType(); if (type == CandidateType.Local) { typeValue = LOCAL_PREFERENCE; localValue = numberRelayed--; componentValue = cand.getComponentId(); int priority = ((2 ^ 24) * typeValue) + ((2 ^ 8) * localValue) + componentValue; cand.setPriority(priority);
public static void main(String args[]) { ICENegotiator cc = new ICENegotiator((short) 1); // gather candidates cc.gatherCandidateAddresses(); // priorize candidates cc.prioritizeCandidates(); // get SortedCandidates List<Candidate> sortedCandidates = cc.getSortedCandidates(); // sent sorted candidate addresses to peer over SDP // received sorted candidate addresses of peer over SDP } }
public int compareTo(Object arg0) { Candidate cand = (Candidate) arg0; return cand.getPriority() - getPriority(); }
try { Candidate local = new Candidate(new Address(iaddress.getAddress()), componentId); candidates.add(local); DiscoveryInfo di = test.test(); if (di.getPublicIP() != null) { Candidate cand = new Candidate(new Address(di.getPublicIP().getAddress()), CandidateType.ServerReflexive, componentId, local); cand.setComponentId(componentId); candidates.add(cand);
public boolean equals(Object o) { if (o == null) return false; if ((((Candidate) o).socket.equals(socket)) && (((Candidate) o).base.equals(base))) return true; return false; } }
public Candidate(Address address, CandidateType type, short componentId, Candidate base) throws SocketException, UnknownHostException, UtilityException { this.socket = new DatagramSocket(0, address.getInetAddress()); this.type = type; setComponentId(componentId); this.priority = 0; this.base = base; this.isInUse = false; }
for (Candidate candidate : iceNegociator.getSortedCandidates()) try { Candidate.CandidateType type = candidate.getCandidateType(); ICECandidate.Type iceType = ICECandidate.Type.local; if (type.equals(Candidate.CandidateType.ServerReflexive)) iceType = ICECandidate.Type.srflx; else if (type.equals(Candidate.CandidateType.PeerReflexive)) iceType = ICECandidate.Type.prflx; else if (type.equals(Candidate.CandidateType.Relayed)) iceType = ICECandidate.Type.relay; else Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces(); short i = 0; NetworkInterface nic = NetworkInterface.getByInetAddress(candidate.getAddress().getInetAddress()); while(nics.hasMoreElements()) { NetworkInterface checkNIC = nics.nextElement(); TransportCandidate transportCandidate = new ICECandidate(candidate.getAddress().getInetAddress().getHostAddress(), 1, nicNum, String.valueOf(Math.abs(random.nextLong())), candidate.getPort(), "1", candidate.getPriority(), iceType); transportCandidate.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress()); transportCandidate.setPort(getFreePort()); try { LOGGER.fine("Candidate addr: " + candidate.getAddress().getInetAddress() + "|" + candidate.getBase().getAddress().getInetAddress() + " Priority:" + candidate.getPriority());
public void initialize() throws XMPPException { if (!isResolving() && !isResolved()) { LOGGER.debug("Initialized"); // Negotiation with a STUN server for a set of interfaces is quite slow, but the results // never change over then instance of a JVM. To increase connection performance considerably // we now cache established/initialized negotiators for each STUN server, so that subsequent uses // of the STUN server are much, much faster. if (negociatorsMap.get(server) == null) { ICENegociator iceNegociator = new ICENegociator(server, port, (short) 1); negociatorsMap.put(server, iceNegociator); // gather candidates iceNegociator.gatherCandidateAddresses(); // priorize candidates iceNegociator.prioritizeCandidates(); } } this.setInitialized(); }