@Override
    public synchronized void resolve(JingleSession session) throws XMPPException, SmackException, InterruptedException {
        this.setResolveInit();

        for (TransportCandidate candidate : this.getCandidatesList()) {
            if (candidate instanceof ICECandidate) {
                ICECandidate iceCandidate = (ICECandidate) candidate;
                iceCandidate.removeCandidateEcho();
            }
        }

        this.clear();

        // Create a transport candidate for each ICE negotiator candidate we have.
        ICENegociator iceNegociator = negociatorsMap.get(server);
        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
                    iceType = ICECandidate.Type.host;

               // JBW/GW - 17JUL08: Figure out the zero-based NIC number for this candidate.
                short nicNum = 0;
                try {
                    Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces();
                    short i = 0;
                    NetworkInterface nic = NetworkInterface.getByInetAddress(candidate.getAddress().getInetAddress());
                    while (nics.hasMoreElements()) {
                        NetworkInterface checkNIC = nics.nextElement();
                        if (checkNIC.equals(nic)) {
                            nicNum = i;
                            break;
                        }
                        i++;
                    }
                } catch (SocketException e1) {
                    LOGGER.log(Level.WARNING, "exeption", e1);
                }

                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 {
                    transportCandidate.addCandidateEcho(session);
                }
                catch (SocketException e) {
                    LOGGER.log(Level.WARNING, "exception", e);
                }
                this.addCandidate(transportCandidate);

                LOGGER.fine("Candidate addr: " + candidate.getAddress().getInetAddress() + "|" + candidate.getBase().getAddress().getInetAddress() + " Priority:" + candidate.getPriority());

            }
            catch (UtilityException e) {
                LOGGER.log(Level.WARNING, "exception", e);
            }
            catch (UnknownHostException e) {
                LOGGER.log(Level.WARNING, "exception", e);
            }

        // Get a Relay Candidate from XMPP Server

        if (RTPBridge.serviceAvailable(connection)) {
//            try {

                String localIp;
                int network;


                // JBW/GW - 17JUL08: ICENegotiator.getPublicCandidate() always returned null in JSTUN 1.7.0, and now the API doesn't exist in JSTUN 1.7.1
//                if (iceNegociator.getPublicCandidate() != null) {
//                    localIp = iceNegociator.getPublicCandidate().getBase().getAddress().getInetAddress().getHostAddress();
//                    network = iceNegociator.getPublicCandidate().getNetwork();
//                }
//                else {
                {
                    localIp = BridgedResolver.getLocalHost();
                    network = 0;
                }

                sid = random.nextInt(Integer.MAX_VALUE);

                RTPBridge rtpBridge = RTPBridge.getRTPBridge(connection, String.valueOf(sid));

                TransportCandidate localCandidate = new ICECandidate(
                    rtpBridge.getIp(), 1, network, String.valueOf(random.nextInt(Integer.MAX_VALUE)), rtpBridge.getPortA(), "1", 0, ICECandidate.Type.relay);
                localCandidate.setLocalIp(localIp);

                TransportCandidate remoteCandidate = new ICECandidate(
                        rtpBridge.getIp(), 1, network, String.valueOf(random.nextInt(Integer.MAX_VALUE)), rtpBridge.getPortB(), "1", 0, ICECandidate.Type.relay);
                remoteCandidate.setLocalIp(localIp);

                localCandidate.setSymmetric(remoteCandidate);
                remoteCandidate.setSymmetric(localCandidate);

                localCandidate.setPassword(rtpBridge.getPass());
                remoteCandidate.setPassword(rtpBridge.getPass());

                localCandidate.setSessionId(rtpBridge.getSid());
                remoteCandidate.setSessionId(rtpBridge.getSid());

                localCandidate.setConnection(this.connection);
                remoteCandidate.setConnection(this.connection);

                addCandidate(localCandidate);

//            }
//            catch (UtilityException e) {
//                LOGGER.log(Level.WARNING, "exception", e);
//            }
//            catch (UnknownHostException e) {
//                LOGGER.log(Level.WARNING, "exception", e);
//            }

            // Get Public Candidate From XMPP Server

 // JBW/GW - 17JUL08 - ICENegotiator.getPublicCandidate() always returned null in JSTUN 1.7.0, and now it doesn't exist in JSTUN 1.7.1
 //          if (iceNegociator.getPublicCandidate() == null) {
            if (true) {

                String publicIp = RTPBridge.getPublicIP(connection);

                if (publicIp != null && !publicIp.equals("")) {

                    Enumeration<NetworkInterface> ifaces = null;

                    try {
                        ifaces = NetworkInterface.getNetworkInterfaces();
                    }
                    catch (SocketException e) {
                        LOGGER.log(Level.WARNING, "exception", e);
                    }

                    // If detect this address in local machine, don't use it.

                    boolean found = false;

                    while (ifaces.hasMoreElements() && !false) {

                        NetworkInterface iface = ifaces.nextElement();
                        Enumeration<InetAddress> iaddresses = iface.getInetAddresses();

                        while (iaddresses.hasMoreElements()) {
                            InetAddress iaddress = iaddresses.nextElement();
                            if (iaddress.getHostAddress().indexOf(publicIp) > -1) {
                                found = true;
                                break;
                            }
                        }
                    }

                    if (!found) {
                        try {
                            TransportCandidate publicCandidate = new ICECandidate(
                                    publicIp, 1, 0, String.valueOf(random.nextInt(Integer.MAX_VALUE)), getFreePort(), "1", 0, ICECandidate.Type.srflx);
                            publicCandidate.setLocalIp(InetAddress.getLocalHost().getHostAddress());

                            try {
                                publicCandidate.addCandidateEcho(session);
                            }
                            catch (SocketException e) {
                                LOGGER.log(Level.WARNING, "exception", e);
                            }

                            addCandidate(publicCandidate);
                        }
                        catch (UnknownHostException e) {
                            LOGGER.log(Level.WARNING, "exception", e);
                        }
                    }
                }
            }

        }

        this.setResolveEnd();
    }
@ Override public synchronized void resolve ( JingleSession session ) throws XMPPException , SmackException , InterruptedException { this . setResolveInit ( ) ; for ( TransportCandidate candidate : this . getCandidatesList ( ) ) { if ( candidate instanceof ICECandidate ) { ICECandidate iceCandidate = ( ICECandidate ) candidate ; iceCandidate . removeCandidateEcho ( ) ; } } this . clear ( ) ; ICENegociator iceNegociator = negociatorsMap . get ( server ) ; 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 iceType = ICECandidate . Type . host ; short nicNum = 0 ; try { Enumeration < NetworkInterface > nics = NetworkInterface . getNetworkInterfaces ( ) ; short i = 0 ; NetworkInterface nic = NetworkInterface . getByInetAddress ( candidate . getAddress ( ) . getInetAddress ( ) ) ; while ( nics . hasMoreElements ( ) ) { NetworkInterface checkNIC = nics . nextElement ( ) ; if ( checkNIC . equals ( nic ) ) { nicNum = i ; break ; } i ++ ; } } catch ( SocketException e1 ) { LOGGER . log ( Level . WARNING , "exeption" , e1 ) ; } 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 { transportCandidate . addCandidateEcho ( session ) ; } catch ( SocketException e ) { LOGGER . log ( Level . WARNING , "exception" , e ) ; } this . addCandidate ( transportCandidate ) ; LOGGER . fine ( "Candidate addr: " + candidate . getAddress ( ) . getInetAddress ( ) + "|" + candidate . getBase ( ) . getAddress ( ) . getInetAddress ( ) + " Priority:" + candidate . getPriority ( ) ) ; } catch ( UtilityException e ) { LOGGER . log ( Level . WARNING , "exception" , e ) ; } catch ( UnknownHostException e ) { LOGGER . log ( Level . WARNING , "exception" , e ) ; } if ( RTPBridge . serviceAvailable ( connection ) ) { String localIp ; int network ; { localIp = BridgedResolver . getLocalHost ( ) ; network = 0 ; } sid = random . nextInt ( Integer . MAX_VALUE ) ; RTPBridge rtpBridge = RTPBridge . getRTPBridge ( connection , String . valueOf ( sid ) ) ; TransportCandidate localCandidate = new ICECandidate ( rtpBridge . getIp ( ) , 1 , network , String . valueOf ( random . nextInt ( Integer . MAX_VALUE ) ) , rtpBridge . getPortA ( ) , "1" , 0 , ICECandidate . Type . relay ) ; localCandidate . setLocalIp ( localIp ) ; TransportCandidate remoteCandidate = new ICECandidate ( rtpBridge . getIp ( ) , 1 , network , String . valueOf ( random . nextInt ( Integer . MAX_VALUE ) ) , rtpBridge . getPortB ( ) , "1" , 0 , ICECandidate . Type . relay ) ; remoteCandidate . setLocalIp ( localIp ) ; localCandidate . setSymmetric ( remoteCandidate ) ; remoteCandidate . setSymmetric ( localCandidate ) ; localCandidate . setPassword ( rtpBridge . getPass ( ) ) ; remoteCandidate . setPassword ( rtpBridge . getPass ( ) ) ; localCandidate . setSessionId ( rtpBridge . getSid ( ) ) ; remoteCandidate . setSessionId ( rtpBridge . getSid ( ) ) ; localCandidate . setConnection ( this . connection ) ; remoteCandidate . setConnection ( this . connection ) ; addCandidate ( localCandidate ) ; if ( true ) { String publicIp = RTPBridge . getPublicIP ( connection ) ; if ( publicIp != null && ! publicIp . equals ( "" ) ) { Enumeration < NetworkInterface > ifaces = null ; try { ifaces = NetworkInterface . getNetworkInterfaces ( ) ; } catch ( SocketException e ) { LOGGER . log ( Level . WARNING , "exception" , e ) ; } boolean found = false ; while ( ifaces . hasMoreElements ( ) && ! false ) { NetworkInterface iface = ifaces . nextElement ( ) ; Enumeration < InetAddress > iaddresses = iface . getInetAddresses ( ) ; while ( iaddresses . hasMoreElements ( ) ) { InetAddress iaddress = iaddresses . nextElement ( ) ; if ( iaddress . getHostAddress ( ) . indexOf ( publicIp ) > - 1 ) { found = true ; break ; } } } if ( ! found ) { try { TransportCandidate publicCandidate = new ICECandidate ( publicIp , 1 , 0 , String . valueOf ( random . nextInt ( Integer . MAX_VALUE ) ) , getFreePort ( ) , "1" , 0 , ICECandidate . Type . srflx ) ; publicCandidate . setLocalIp ( InetAddress . getLocalHost ( ) . getHostAddress ( ) ) ; try { publicCandidate . addCandidateEcho ( session ) ; } catch ( SocketException e ) { LOGGER . log ( Level . WARNING , "exception" , e ) ; } addCandidate ( publicCandidate ) ; } catch ( UnknownHostException e ) { LOGGER . log ( Level . WARNING , "exception" , e ) ; } } } } } this . setResolveEnd ( ) ; }
Resolve the IP and obtain a valid transport method.
@throws SmackException
@throws InterruptedException