mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-26 05:52:06 +01:00
UDP Echo added
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7030 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
e688cefd33
commit
f9203c0e00
2 changed files with 23 additions and 10 deletions
|
@ -27,6 +27,7 @@ import org.jivesoftware.smack.XMPPException;
|
|||
import org.jivesoftware.smack.XMPPConnection;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.net.SocketException;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
|
@ -80,6 +81,12 @@ public class ICEResolver extends TransportResolver {
|
|||
transportCandidate.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress());
|
||||
transportCandidate.setPort(getFreePort());
|
||||
this.addCandidate(transportCandidate);
|
||||
try {
|
||||
transportCandidate.addCandidateEcho();
|
||||
}
|
||||
catch (SocketException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("C: " + candidate.getAddress().getInetAddress() + "|" + candidate.getBase().getAddress().getInetAddress() + " p:" + candidate.getPriority());
|
||||
|
||||
}
|
||||
|
|
|
@ -41,13 +41,13 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
|||
private final TransportResolver resolver;
|
||||
|
||||
// Transport candidates we have offered
|
||||
private final List offeredCandidates = new ArrayList();
|
||||
private final List<TransportCandidate> offeredCandidates = new ArrayList<TransportCandidate>();
|
||||
|
||||
// List of remote transport candidates
|
||||
private final List remoteCandidates = new ArrayList();
|
||||
private final List<TransportCandidate> remoteCandidates = new ArrayList<TransportCandidate>();
|
||||
|
||||
// Valid remote candidates
|
||||
private final List validRemoteCandidates = new ArrayList();
|
||||
private final List<TransportCandidate> validRemoteCandidates = new ArrayList<TransportCandidate>();
|
||||
|
||||
// The best local candidate we have offered (and accepted by the other part)
|
||||
private TransportCandidate acceptedLocalCandidate;
|
||||
|
@ -103,7 +103,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
|||
*
|
||||
* @return true if the transport candidate is acceptable
|
||||
*/
|
||||
public abstract boolean acceptableTransportCandidate(TransportCandidate tc);
|
||||
public abstract boolean acceptableTransportCandidate(TransportCandidate tc, List<TransportCandidate> localCandidates);
|
||||
|
||||
/**
|
||||
* Obtain the best local candidate we want to offer.
|
||||
|
@ -167,7 +167,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
|||
private void addRemoteCandidate(TransportCandidate rc) {
|
||||
// Add the candidate to the list
|
||||
if (rc != null) {
|
||||
if (acceptableTransportCandidate(rc)) {
|
||||
if (acceptableTransportCandidate(rc, offeredCandidates)) {
|
||||
synchronized (remoteCandidates) {
|
||||
remoteCandidates.add(rc);
|
||||
}
|
||||
|
@ -773,7 +773,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
|||
/**
|
||||
* Return true for fixed candidates.
|
||||
*/
|
||||
public boolean acceptableTransportCandidate(TransportCandidate tc) {
|
||||
public boolean acceptableTransportCandidate(TransportCandidate tc, List<TransportCandidate> localCandidates) {
|
||||
return tc instanceof TransportCandidate.Fixed;
|
||||
}
|
||||
}
|
||||
|
@ -834,18 +834,24 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
|||
/**
|
||||
* Return true for ICE candidates.
|
||||
*/
|
||||
public boolean acceptableTransportCandidate(TransportCandidate tc) {
|
||||
public boolean acceptableTransportCandidate(TransportCandidate tc, List<TransportCandidate> localCandidates) {
|
||||
try {
|
||||
TransportCandidate.Ice ice = (TransportCandidate.Ice) tc;
|
||||
if (ice.getType().equals("relay")) return true;
|
||||
|
||||
for (TransportCandidate candidate : localCandidates) {
|
||||
TransportCandidate.CandidateEcho echo = candidate.getCandidateEcho();
|
||||
if (echo != null) {
|
||||
if (echo.test(InetAddress.getByName(ice.getId()), ice.getPort(), 300))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
InetAddress.getByName(tc.getIp()).isReachable(3000);
|
||||
DatagramSocket socket = new DatagramSocket(0);
|
||||
socket.connect(InetAddress.getByName(tc.getIp()), tc.getPort());
|
||||
return true;
|
||||
}
|
||||
catch (SocketException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue