mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-29 23:42: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 org.jivesoftware.smack.XMPPConnection;
|
||||||
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.net.SocketException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
@ -80,6 +81,12 @@ public class ICEResolver extends TransportResolver {
|
||||||
transportCandidate.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress());
|
transportCandidate.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress());
|
||||||
transportCandidate.setPort(getFreePort());
|
transportCandidate.setPort(getFreePort());
|
||||||
this.addCandidate(transportCandidate);
|
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());
|
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;
|
private final TransportResolver resolver;
|
||||||
|
|
||||||
// Transport candidates we have offered
|
// Transport candidates we have offered
|
||||||
private final List offeredCandidates = new ArrayList();
|
private final List<TransportCandidate> offeredCandidates = new ArrayList<TransportCandidate>();
|
||||||
|
|
||||||
// List of remote transport candidates
|
// List of remote transport candidates
|
||||||
private final List remoteCandidates = new ArrayList();
|
private final List<TransportCandidate> remoteCandidates = new ArrayList<TransportCandidate>();
|
||||||
|
|
||||||
// Valid remote candidates
|
// 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)
|
// The best local candidate we have offered (and accepted by the other part)
|
||||||
private TransportCandidate acceptedLocalCandidate;
|
private TransportCandidate acceptedLocalCandidate;
|
||||||
|
@ -103,7 +103,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
||||||
*
|
*
|
||||||
* @return true if the transport candidate is acceptable
|
* @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.
|
* Obtain the best local candidate we want to offer.
|
||||||
|
@ -167,7 +167,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
||||||
private void addRemoteCandidate(TransportCandidate rc) {
|
private void addRemoteCandidate(TransportCandidate rc) {
|
||||||
// Add the candidate to the list
|
// Add the candidate to the list
|
||||||
if (rc != null) {
|
if (rc != null) {
|
||||||
if (acceptableTransportCandidate(rc)) {
|
if (acceptableTransportCandidate(rc, offeredCandidates)) {
|
||||||
synchronized (remoteCandidates) {
|
synchronized (remoteCandidates) {
|
||||||
remoteCandidates.add(rc);
|
remoteCandidates.add(rc);
|
||||||
}
|
}
|
||||||
|
@ -773,7 +773,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
||||||
/**
|
/**
|
||||||
* Return true for fixed candidates.
|
* Return true for fixed candidates.
|
||||||
*/
|
*/
|
||||||
public boolean acceptableTransportCandidate(TransportCandidate tc) {
|
public boolean acceptableTransportCandidate(TransportCandidate tc, List<TransportCandidate> localCandidates) {
|
||||||
return tc instanceof TransportCandidate.Fixed;
|
return tc instanceof TransportCandidate.Fixed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -834,18 +834,24 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
||||||
/**
|
/**
|
||||||
* Return true for ICE candidates.
|
* Return true for ICE candidates.
|
||||||
*/
|
*/
|
||||||
public boolean acceptableTransportCandidate(TransportCandidate tc) {
|
public boolean acceptableTransportCandidate(TransportCandidate tc, List<TransportCandidate> localCandidates) {
|
||||||
try {
|
try {
|
||||||
TransportCandidate.Ice ice = (TransportCandidate.Ice) tc;
|
TransportCandidate.Ice ice = (TransportCandidate.Ice) tc;
|
||||||
if (ice.getType().equals("relay")) return true;
|
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);
|
InetAddress.getByName(tc.getIp()).isReachable(3000);
|
||||||
DatagramSocket socket = new DatagramSocket(0);
|
DatagramSocket socket = new DatagramSocket(0);
|
||||||
socket.connect(InetAddress.getByName(tc.getIp()), tc.getPort());
|
socket.connect(InetAddress.getByName(tc.getIp()), tc.getPort());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (SocketException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
catch (UnknownHostException e) {
|
catch (UnknownHostException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue