1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-12-26 12:37:58 +01:00

[SMACK-215] - Added ICE Types as Enum

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@8038 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Thiago Camargo 2007-04-16 15:44:55 +00:00 committed by thiago
parent b47038b82f
commit 574cdab26f
8 changed files with 54 additions and 36 deletions

View file

@ -71,6 +71,13 @@ public class BridgedResolver extends TransportResolver{
String localIp="127.0.0.1";
try {
localIp = InetAddress.getLocalHost().getHostAddress();
InetAddress iaddress = InetAddress.getLocalHost();
System.out.println(iaddress.isLoopbackAddress());
System.out.println(iaddress.isLinkLocalAddress());
System.out.println(iaddress.isSiteLocalAddress());
}
catch (UnknownHostException e) {
e.printStackTrace();

View file

@ -51,6 +51,8 @@
*/
package org.jivesoftware.smackx.jingle.nat;
import de.javawi.jstun.test.demo.ice.Candidate;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
@ -77,7 +79,11 @@ public class ICECandidate extends TransportCandidate implements Comparable {
private int network;
private String type;
private Type type;
public enum Type {
relay, srflx, prflx, local, host
}
public ICECandidate() {
super();
@ -99,7 +105,7 @@ public class ICECandidate extends TransportCandidate implements Comparable {
*/
public ICECandidate(String ip, int generation, int network,
String password, int port, String username,
int preference, String type) {
int preference, Type type) {
super(ip, port, generation);
proto = Protocol.UDP;
@ -226,7 +232,7 @@ public class ICECandidate extends TransportCandidate implements Comparable {
*
* @return candidate Type
*/
public String getType() {
public Type getType() {
return type;
}
@ -235,7 +241,7 @@ public class ICECandidate extends TransportCandidate implements Comparable {
*
* @param type candidate type.
*/
public void setType(String type) {
public void setType(Type type) {
this.type = type;
}

View file

@ -94,17 +94,17 @@ public class ICEResolver extends TransportResolver {
for (Candidate candidate : iceNegociator.getSortedCandidates())
try {
Candidate.CandidateType type = candidate.getCandidateType();
String typeString = "local";
ICECandidate.Type iceType = ICECandidate.Type.local;
if (type.equals(Candidate.CandidateType.ServerReflexive))
typeString = "srflx";
iceType = ICECandidate.Type.srflx;
else if (type.equals(Candidate.CandidateType.PeerReflexive))
typeString = "prflx";
iceType = ICECandidate.Type.prflx;
else if (type.equals(Candidate.CandidateType.Relayed))
typeString = "relay";
iceType = ICECandidate.Type.relay;
else
typeString = "host";
iceType = ICECandidate.Type.host;
TransportCandidate transportCandidate = new ICECandidate(candidate.getAddress().getInetAddress().getHostAddress(), 1, candidate.getNetwork(), String.valueOf(Math.abs(random.nextLong())), candidate.getPort(), "1", candidate.getPriority(), typeString);
TransportCandidate transportCandidate = new ICECandidate(candidate.getAddress().getInetAddress().getHostAddress(), 1, candidate.getNetwork(), String.valueOf(Math.abs(random.nextLong())), candidate.getPort(), "1", candidate.getPriority(), iceType);
transportCandidate.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress());
transportCandidate.setPort(getFreePort());
try {
@ -147,11 +147,11 @@ public class ICEResolver extends TransportResolver {
RTPBridge rtpBridge = RTPBridge.getRTPBridge(connection, String.valueOf(sid));
TransportCandidate localCandidate = new ICECandidate(
rtpBridge.getIp(), 1, network, String.valueOf(Math.abs(random.nextLong())), rtpBridge.getPortA(), "1", 0, "relay");
rtpBridge.getIp(), 1, network, String.valueOf(Math.abs(random.nextLong())), rtpBridge.getPortA(), "1", 0, ICECandidate.Type.relay);
localCandidate.setLocalIp(localIp);
TransportCandidate remoteCandidate = new ICECandidate(
rtpBridge.getIp(), 1, network, String.valueOf(Math.abs(random.nextLong())), rtpBridge.getPortB(), "1", 0, "relay");
rtpBridge.getIp(), 1, network, String.valueOf(Math.abs(random.nextLong())), rtpBridge.getPortB(), "1", 0, ICECandidate.Type.relay);
remoteCandidate.setLocalIp(localIp);
localCandidate.setSymmetric(remoteCandidate);
@ -214,7 +214,7 @@ public class ICEResolver extends TransportResolver {
if (!found) {
try {
TransportCandidate publicCandidate = new ICECandidate(
publicIp, 1, 0, String.valueOf(Math.abs(random.nextLong())), getFreePort(), "1", 0, "srflx");
publicIp, 1, 0, String.valueOf(Math.abs(random.nextLong())), getFreePort(), "1", 0, ICECandidate.Type.srflx);
publicCandidate.setLocalIp(InetAddress.getLocalHost().getHostAddress());
try {

View file

@ -350,7 +350,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
for (TransportCandidate candidate : remoteCandidates) {
if (candidate instanceof ICECandidate) {
ICECandidate iceCandidate = (ICECandidate) candidate;
if (iceCandidate.getType().equals("srflx")) {
if (iceCandidate.getType().equals(ICECandidate.Type.srflx)) {
addValidRemoteCandidate(iceCandidate);
foundRemotePublic = true;
}

View file

@ -191,7 +191,7 @@ public abstract class JingleTransportProvider implements PacketExtensionProvider
}
if (type != null) {
mt.setType(type);
mt.setType(ICECandidate.Type.valueOf(type));
}
return new JingleTransport.Ice.Candidate(mt);

View file

@ -32,6 +32,7 @@ import org.jivesoftware.smackx.jingle.media.JingleMediaManager;
import org.jivesoftware.smackx.jingle.nat.BridgedTransportManager;
import org.jivesoftware.smackx.jingle.nat.ICETransportManager;
import org.jivesoftware.smackx.jingle.nat.STUNTransportManager;
import org.jivesoftware.smackx.packet.JingleError;
import javax.media.MediaLocator;
import javax.media.format.AudioFormat;
@ -316,7 +317,11 @@ public class JingleMediaTest extends SmackTestCase {
js0.start();
Thread.sleep(55000);
Thread.sleep(20000);
js0.sendFormattedError(JingleError.UNSUPPORTED_TRANSPORTS);
Thread.sleep(20000);
js0.terminate();
@ -371,7 +376,7 @@ public class JingleMediaTest extends SmackTestCase {
try {
IncomingJingleSession session = request.accept(jm1.getMediaManager().getPayloads());
session.start(request);
}
catch (XMPPException e) {

View file

@ -61,15 +61,15 @@ public class STUNResolverTest extends SmackTestCase {
int highestPref = 100;
TransportCandidate cand1 = new ICECandidate("192.168.2.1", 3, 2,
"password", 3468, "username1", 1, "");
"password", 3468, "username1", 1, ICECandidate.Type.prflx);
TransportCandidate cand2 = new ICECandidate("192.168.5.1", 2, 10,
"password", 3469, "username2", 15, "");
"password", 3469, "username2", 15, ICECandidate.Type.prflx);
TransportCandidate candH = new ICECandidate("192.168.2.11", 1, 2,
"password", 3468, "usernameH", highestPref, "");
"password", 3468, "usernameH", highestPref, ICECandidate.Type.prflx);
TransportCandidate cand3 = new ICECandidate("192.168.2.10", 2, 10,
"password", 3469, "username3", 2, "");
"password", 3469, "username3", 2, ICECandidate.Type.prflx);
TransportCandidate cand4 = new ICECandidate("192.168.4.1", 3, 2,
"password", 3468, "username4", 78, "");
"password", 3468, "username4", 78, ICECandidate.Type.prflx);
STUNResolver stunResolver = new STUNResolver() {
};
@ -91,15 +91,15 @@ public class STUNResolverTest extends SmackTestCase {
int highestPref = 100;
TransportCandidate cand1 = new ICECandidate("192.168.2.1", 3, 2,
"password", 3468, "username1", 1, "");
"password", 3468, "username1", 1, ICECandidate.Type.prflx);
TransportCandidate cand2 = new ICECandidate("192.168.5.1", 2, 10,
"password", 3469, "username2", 15, "");
"password", 3469, "username2", 15, ICECandidate.Type.prflx);
TransportCandidate candH = new ICECandidate("192.168.2.11", 1, 2,
"password", 3468, "usernameH", highestPref, "");
"password", 3468, "usernameH", highestPref, ICECandidate.Type.prflx);
TransportCandidate cand3 = new ICECandidate("192.168.2.10", 2, 10,
"password", 3469, "username3", 2, "");
"password", 3469, "username3", 2, ICECandidate.Type.prflx);
TransportCandidate cand4 = new ICECandidate("192.168.4.1", 3, 2,
"password", 3468, "username4", 78, "");
"password", 3468, "username4", 78, ICECandidate.Type.prflx);
ICEResolver iceResolver = new ICEResolver(getConnection(0), "stun.xten.net", 3478) {
};
@ -132,7 +132,7 @@ public class STUNResolverTest extends SmackTestCase {
for (Candidate candidate : cc.getSortedCandidates())
try {
TransportCandidate transportCandidate = new ICECandidate(candidate.getAddress().getInetAddress().getHostAddress(), 1, candidate.getNetwork(), "1", candidate.getPort(), "1", candidate.getPriority(), "");
TransportCandidate transportCandidate = new ICECandidate(candidate.getAddress().getInetAddress().getHostAddress(), 1, candidate.getNetwork(), "1", candidate.getPort(), "1", candidate.getPriority(), ICECandidate.Type.prflx);
transportCandidate.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress());
System.out.println("C: " + candidate.getAddress().getInetAddress() + "|" + candidate.getBase().getAddress().getInetAddress() + " p:" + candidate.getPriority());
}

View file

@ -19,11 +19,11 @@ public class TransportCandidateTest extends SmackTestCase {
*/
public void testEqualsObject() {
TransportCandidate cand1 = new ICECandidate("192.168.2.1", 1, 2,
"password", 3468, "username", 25, "");
"password", 3468, "username", 25, ICECandidate.Type.prflx);
TransportCandidate cand2 = new ICECandidate("192.168.2.1", 1, 2,
"password", 3468, "username", 25, "");
"password", 3468, "username", 25, ICECandidate.Type.prflx);
TransportCandidate cand3 = new ICECandidate("192.168.2.1", 1, 2,
"password", 3469, "username", 25, "");
"password", 3469, "username", 25, ICECandidate.Type.prflx);
assertEquals(cand1, cand2);
assertFalse(cand1.equals(cand3));
@ -36,15 +36,15 @@ public class TransportCandidateTest extends SmackTestCase {
int highestPref = 100;
TransportCandidate cand1 = new ICECandidate("192.168.2.1", 3, 2,
"password", 3468, "username", 1, "");
"password", 3468, "username", 1, ICECandidate.Type.prflx);
TransportCandidate cand2 = new ICECandidate("192.168.5.1", 2, 10,
"password", 3469, "username", 15, "");
"password", 3469, "username", 15,ICECandidate.Type.prflx);
TransportCandidate candH = new ICECandidate("192.168.2.1", 1, 2,
"password", 3468, "username", highestPref, "");
"password", 3468, "username", highestPref, ICECandidate.Type.prflx);
TransportCandidate cand3 = new ICECandidate("192.168.2.10", 2, 10,
"password", 3469, "username", 2, "");
"password", 3469, "username", 2, ICECandidate.Type.prflx);
TransportCandidate cand4 = new ICECandidate("192.168.4.1", 3, 2,
"password", 3468, "username", 78, "");
"password", 3468, "username", 78, ICECandidate.Type.prflx);
ArrayList candList = new ArrayList();
candList.add(cand1);