mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-16 12:12:06 +01:00
ICE Candidate now uses UDP Echo before PING
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7248 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
bd176c2515
commit
6cccdccac8
6 changed files with 80 additions and 8 deletions
|
@ -299,6 +299,7 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overides JingleNegiociator Method to add listener capabilities
|
* Overides JingleNegiociator Method to add listener capabilities
|
||||||
|
*
|
||||||
* @param newState new State
|
* @param newState new State
|
||||||
*/
|
*/
|
||||||
protected void setState(State newState) {
|
protected void setState(State newState) {
|
||||||
|
@ -1063,6 +1064,10 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
if (jingleMediaManager != null) {
|
if (jingleMediaManager != null) {
|
||||||
jingleMediaSession = jingleMediaManager.createMediaSession(pt, rc, lc);
|
jingleMediaSession = jingleMediaManager.createMediaSession(pt, rc, lc);
|
||||||
if (jingleMediaSession != null) {
|
if (jingleMediaSession != null) {
|
||||||
|
|
||||||
|
rc.removeCandidateEcho();
|
||||||
|
lc.removeCandidateEcho();
|
||||||
|
|
||||||
jingleMediaSession.startTrasmit();
|
jingleMediaSession.startTrasmit();
|
||||||
jingleMediaSession.startReceive();
|
jingleMediaSession.startReceive();
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,10 @@
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.jingle.nat;
|
package org.jivesoftware.smackx.jingle.nat;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ICE Transport candidate.
|
* ICE Transport candidate.
|
||||||
* <p/>
|
* <p/>
|
||||||
|
@ -235,6 +239,60 @@ public class ICECandidate extends TransportCandidate implements Comparable {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a transport candidate is usable. The transport resolver should
|
||||||
|
* check if the transport candidate the other endpoint has provided is
|
||||||
|
* usable.
|
||||||
|
* <p/>
|
||||||
|
* ICE Candidate can check connectivity using UDP echo Test.
|
||||||
|
*/
|
||||||
|
public void check(final List<TransportCandidate> localCandidates) {
|
||||||
|
//TODO candidate is being checked trigger
|
||||||
|
//candidatesChecking.add(cand);
|
||||||
|
|
||||||
|
Thread checkThread = new Thread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
boolean isUsable = false;
|
||||||
|
|
||||||
|
for (TransportCandidate candidate : localCandidates) {
|
||||||
|
CandidateEcho echo = candidate.getCandidateEcho();
|
||||||
|
if (echo != null) {
|
||||||
|
try {
|
||||||
|
InetAddress address = InetAddress.getByName(getIp());
|
||||||
|
if (echo.test(address, getPort())) isUsable = true;
|
||||||
|
if (isUsable) break;
|
||||||
|
}
|
||||||
|
catch (UnknownHostException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isUsable) {
|
||||||
|
System.out.println("Checked using UDP Echo:" + getLocalIp());
|
||||||
|
triggerCandidateChecked(isUsable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
InetAddress candAddress;
|
||||||
|
try {
|
||||||
|
candAddress = InetAddress.getByName(getIp());
|
||||||
|
isUsable = candAddress.isReachable(TransportResolver.CHECK_TIMEOUT);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
isUsable = false;
|
||||||
|
}
|
||||||
|
triggerCandidateChecked(isUsable);
|
||||||
|
|
||||||
|
//TODO candidate is being checked trigger
|
||||||
|
//candidatesChecking.remove(cand);
|
||||||
|
}
|
||||||
|
}, "Transport candidate check");
|
||||||
|
|
||||||
|
checkThread.setName("Transport candidate test");
|
||||||
|
checkThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
|
|
|
@ -80,6 +80,12 @@ public class ICEResolver extends TransportResolver {
|
||||||
TransportCandidate transportCandidate = new ICECandidate(candidate.getAddress().getInetAddress().getHostAddress(), 1, candidate.getNetwork(), "1", candidate.getPort(), "1", candidate.getPriority(), typeString);
|
TransportCandidate transportCandidate = new ICECandidate(candidate.getAddress().getInetAddress().getHostAddress(), 1, candidate.getNetwork(), "1", candidate.getPort(), "1", candidate.getPriority(), typeString);
|
||||||
transportCandidate.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress());
|
transportCandidate.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress());
|
||||||
transportCandidate.setPort(getFreePort());
|
transportCandidate.setPort(getFreePort());
|
||||||
|
try {
|
||||||
|
transportCandidate.addCandidateEcho();
|
||||||
|
}
|
||||||
|
catch (SocketException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
this.addCandidate(transportCandidate);
|
this.addCandidate(transportCandidate);
|
||||||
|
|
||||||
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());
|
||||||
|
|
|
@ -104,6 +104,7 @@ public abstract class TransportCandidate {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeCandidateEcho() {
|
public void removeCandidateEcho() {
|
||||||
|
if (candidateEcho != null)
|
||||||
candidateEcho.cancel();
|
candidateEcho.cancel();
|
||||||
candidateEcho = null;
|
candidateEcho = null;
|
||||||
echoThread = null;
|
echoThread = null;
|
||||||
|
@ -370,7 +371,7 @@ public abstract class TransportCandidate {
|
||||||
* <p/>
|
* <p/>
|
||||||
* Subclasses should provide better methods if they can...
|
* Subclasses should provide better methods if they can...
|
||||||
*/
|
*/
|
||||||
public void check() {
|
public void check(final List<TransportCandidate> localCandidates) {
|
||||||
//TODO candidate is being checked trigger
|
//TODO candidate is being checked trigger
|
||||||
//candidatesChecking.add(cand);
|
//candidatesChecking.add(cand);
|
||||||
|
|
||||||
|
@ -402,7 +403,7 @@ public abstract class TransportCandidate {
|
||||||
*
|
*
|
||||||
* @param result The result.
|
* @param result The result.
|
||||||
*/
|
*/
|
||||||
private void triggerCandidateChecked(boolean result) {
|
void triggerCandidateChecked(boolean result) {
|
||||||
|
|
||||||
for (TransportResolverListener.Checker trl : getListenersList()) {
|
for (TransportResolverListener.Checker trl : getListenersList()) {
|
||||||
trl.candidateChecked(this, result);
|
trl.candidateChecked(this, result);
|
||||||
|
|
|
@ -219,7 +219,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
offeredCandidate.check();
|
offeredCandidate.check(resolver.getCandidatesList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,6 +2,8 @@ package org.jivesoftware.smackx.jingle.nat;
|
||||||
|
|
||||||
import org.jivesoftware.smack.test.SmackTestCase;
|
import org.jivesoftware.smack.test.SmackTestCase;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class BasicResolverTest extends SmackTestCase {
|
public class BasicResolverTest extends SmackTestCase {
|
||||||
|
|
||||||
private int counter;
|
private int counter;
|
||||||
|
@ -54,7 +56,7 @@ public class BasicResolverTest extends SmackTestCase {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
tc.check();
|
tc.check(new ArrayList<TransportCandidate>());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(TransportResolver.CHECK_TIMEOUT);
|
Thread.sleep(TransportResolver.CHECK_TIMEOUT);
|
||||||
|
@ -83,7 +85,7 @@ public class BasicResolverTest extends SmackTestCase {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
tc.check();
|
tc.check(new ArrayList<TransportCandidate>());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(TransportResolver.CHECK_TIMEOUT);
|
Thread.sleep(TransportResolver.CHECK_TIMEOUT);
|
||||||
|
|
Loading…
Reference in a new issue