1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-12-23 13:07:59 +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:
Thiago Camargo 2007-02-23 16:07:23 +00:00 committed by thiago
parent bd176c2515
commit 6cccdccac8
6 changed files with 80 additions and 8 deletions

View file

@ -299,6 +299,7 @@ public abstract class JingleSession extends JingleNegotiator {
/**
* Overides JingleNegiociator Method to add listener capabilities
*
* @param newState new State
*/
protected void setState(State newState) {
@ -880,7 +881,7 @@ public abstract class JingleSession extends JingleNegotiator {
protected void removePacketListener() {
if (packetListener != null) {
getConnection().removePacketListener(packetListener);
System.out.println("REMOVE PACKET LISTENER");
}
}
@ -1063,6 +1064,10 @@ public abstract class JingleSession extends JingleNegotiator {
if (jingleMediaManager != null) {
jingleMediaSession = jingleMediaManager.createMediaSession(pt, rc, lc);
if (jingleMediaSession != null) {
rc.removeCandidateEcho();
lc.removeCandidateEcho();
jingleMediaSession.startTrasmit();
jingleMediaSession.startReceive();
}

View file

@ -51,6 +51,10 @@
*/
package org.jivesoftware.smackx.jingle.nat;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
/**
* ICE Transport candidate.
* <p/>
@ -235,6 +239,60 @@ public class ICECandidate extends TransportCandidate implements Comparable {
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)
*

View file

@ -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.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress());
transportCandidate.setPort(getFreePort());
try {
transportCandidate.addCandidateEcho();
}
catch (SocketException e) {
e.printStackTrace();
}
this.addCandidate(transportCandidate);
System.out.println("C: " + candidate.getAddress().getInetAddress() + "|" + candidate.getBase().getAddress().getInetAddress() + " p:" + candidate.getPriority());

View file

@ -104,7 +104,8 @@ public abstract class TransportCandidate {
}
public void removeCandidateEcho() {
candidateEcho.cancel();
if (candidateEcho != null)
candidateEcho.cancel();
candidateEcho = null;
echoThread = null;
}
@ -370,7 +371,7 @@ public abstract class TransportCandidate {
* <p/>
* Subclasses should provide better methods if they can...
*/
public void check() {
public void check(final List<TransportCandidate> localCandidates) {
//TODO candidate is being checked trigger
//candidatesChecking.add(cand);
@ -402,7 +403,7 @@ public abstract class TransportCandidate {
*
* @param result The result.
*/
private void triggerCandidateChecked(boolean result) {
void triggerCandidateChecked(boolean result) {
for (TransportResolverListener.Checker trl : getListenersList()) {
trl.candidateChecked(this, result);
@ -461,7 +462,7 @@ public abstract class TransportCandidate {
super(ip, port, generation);
}
}
/**
* Type-safe enum for the transportElement protocol
*/

View file

@ -219,7 +219,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
}
});
offeredCandidate.check();
offeredCandidate.check(resolver.getCandidatesList());
}
/**

View file

@ -2,6 +2,8 @@ package org.jivesoftware.smackx.jingle.nat;
import org.jivesoftware.smack.test.SmackTestCase;
import java.util.ArrayList;
public class BasicResolverTest extends SmackTestCase {
private int counter;
@ -54,7 +56,7 @@ public class BasicResolverTest extends SmackTestCase {
}
});
tc.check();
tc.check(new ArrayList<TransportCandidate>());
try {
Thread.sleep(TransportResolver.CHECK_TIMEOUT);
@ -83,7 +85,7 @@ public class BasicResolverTest extends SmackTestCase {
}
});
tc.check();
tc.check(new ArrayList<TransportCandidate>());
try {
Thread.sleep(TransportResolver.CHECK_TIMEOUT);