mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-29 15:32:06 +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:
parent
b47038b82f
commit
574cdab26f
8 changed files with 54 additions and 36 deletions
|
@ -71,6 +71,13 @@ public class BridgedResolver extends TransportResolver{
|
||||||
String localIp="127.0.0.1";
|
String localIp="127.0.0.1";
|
||||||
try {
|
try {
|
||||||
localIp = InetAddress.getLocalHost().getHostAddress();
|
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) {
|
catch (UnknownHostException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -51,6 +51,8 @@
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.jingle.nat;
|
package org.jivesoftware.smackx.jingle.nat;
|
||||||
|
|
||||||
|
import de.javawi.jstun.test.demo.ice.Candidate;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -77,7 +79,11 @@ public class ICECandidate extends TransportCandidate implements Comparable {
|
||||||
|
|
||||||
private int network;
|
private int network;
|
||||||
|
|
||||||
private String type;
|
private Type type;
|
||||||
|
|
||||||
|
public enum Type {
|
||||||
|
relay, srflx, prflx, local, host
|
||||||
|
}
|
||||||
|
|
||||||
public ICECandidate() {
|
public ICECandidate() {
|
||||||
super();
|
super();
|
||||||
|
@ -99,7 +105,7 @@ public class ICECandidate extends TransportCandidate implements Comparable {
|
||||||
*/
|
*/
|
||||||
public ICECandidate(String ip, int generation, int network,
|
public ICECandidate(String ip, int generation, int network,
|
||||||
String password, int port, String username,
|
String password, int port, String username,
|
||||||
int preference, String type) {
|
int preference, Type type) {
|
||||||
super(ip, port, generation);
|
super(ip, port, generation);
|
||||||
|
|
||||||
proto = Protocol.UDP;
|
proto = Protocol.UDP;
|
||||||
|
@ -226,7 +232,7 @@ public class ICECandidate extends TransportCandidate implements Comparable {
|
||||||
*
|
*
|
||||||
* @return candidate Type
|
* @return candidate Type
|
||||||
*/
|
*/
|
||||||
public String getType() {
|
public Type getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,7 +241,7 @@ public class ICECandidate extends TransportCandidate implements Comparable {
|
||||||
*
|
*
|
||||||
* @param type candidate type.
|
* @param type candidate type.
|
||||||
*/
|
*/
|
||||||
public void setType(String type) {
|
public void setType(Type type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,17 +94,17 @@ public class ICEResolver extends TransportResolver {
|
||||||
for (Candidate candidate : iceNegociator.getSortedCandidates())
|
for (Candidate candidate : iceNegociator.getSortedCandidates())
|
||||||
try {
|
try {
|
||||||
Candidate.CandidateType type = candidate.getCandidateType();
|
Candidate.CandidateType type = candidate.getCandidateType();
|
||||||
String typeString = "local";
|
ICECandidate.Type iceType = ICECandidate.Type.local;
|
||||||
if (type.equals(Candidate.CandidateType.ServerReflexive))
|
if (type.equals(Candidate.CandidateType.ServerReflexive))
|
||||||
typeString = "srflx";
|
iceType = ICECandidate.Type.srflx;
|
||||||
else if (type.equals(Candidate.CandidateType.PeerReflexive))
|
else if (type.equals(Candidate.CandidateType.PeerReflexive))
|
||||||
typeString = "prflx";
|
iceType = ICECandidate.Type.prflx;
|
||||||
else if (type.equals(Candidate.CandidateType.Relayed))
|
else if (type.equals(Candidate.CandidateType.Relayed))
|
||||||
typeString = "relay";
|
iceType = ICECandidate.Type.relay;
|
||||||
else
|
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.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress());
|
||||||
transportCandidate.setPort(getFreePort());
|
transportCandidate.setPort(getFreePort());
|
||||||
try {
|
try {
|
||||||
|
@ -147,11 +147,11 @@ public class ICEResolver extends TransportResolver {
|
||||||
RTPBridge rtpBridge = RTPBridge.getRTPBridge(connection, String.valueOf(sid));
|
RTPBridge rtpBridge = RTPBridge.getRTPBridge(connection, String.valueOf(sid));
|
||||||
|
|
||||||
TransportCandidate localCandidate = new ICECandidate(
|
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);
|
localCandidate.setLocalIp(localIp);
|
||||||
|
|
||||||
TransportCandidate remoteCandidate = new ICECandidate(
|
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);
|
remoteCandidate.setLocalIp(localIp);
|
||||||
|
|
||||||
localCandidate.setSymmetric(remoteCandidate);
|
localCandidate.setSymmetric(remoteCandidate);
|
||||||
|
@ -214,7 +214,7 @@ public class ICEResolver extends TransportResolver {
|
||||||
if (!found) {
|
if (!found) {
|
||||||
try {
|
try {
|
||||||
TransportCandidate publicCandidate = new ICECandidate(
|
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());
|
publicCandidate.setLocalIp(InetAddress.getLocalHost().getHostAddress());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -350,7 +350,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
||||||
for (TransportCandidate candidate : remoteCandidates) {
|
for (TransportCandidate candidate : remoteCandidates) {
|
||||||
if (candidate instanceof ICECandidate) {
|
if (candidate instanceof ICECandidate) {
|
||||||
ICECandidate iceCandidate = (ICECandidate) candidate;
|
ICECandidate iceCandidate = (ICECandidate) candidate;
|
||||||
if (iceCandidate.getType().equals("srflx")) {
|
if (iceCandidate.getType().equals(ICECandidate.Type.srflx)) {
|
||||||
addValidRemoteCandidate(iceCandidate);
|
addValidRemoteCandidate(iceCandidate);
|
||||||
foundRemotePublic = true;
|
foundRemotePublic = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,7 +191,7 @@ public abstract class JingleTransportProvider implements PacketExtensionProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
mt.setType(type);
|
mt.setType(ICECandidate.Type.valueOf(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new JingleTransport.Ice.Candidate(mt);
|
return new JingleTransport.Ice.Candidate(mt);
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.jivesoftware.smackx.jingle.media.JingleMediaManager;
|
||||||
import org.jivesoftware.smackx.jingle.nat.BridgedTransportManager;
|
import org.jivesoftware.smackx.jingle.nat.BridgedTransportManager;
|
||||||
import org.jivesoftware.smackx.jingle.nat.ICETransportManager;
|
import org.jivesoftware.smackx.jingle.nat.ICETransportManager;
|
||||||
import org.jivesoftware.smackx.jingle.nat.STUNTransportManager;
|
import org.jivesoftware.smackx.jingle.nat.STUNTransportManager;
|
||||||
|
import org.jivesoftware.smackx.packet.JingleError;
|
||||||
|
|
||||||
import javax.media.MediaLocator;
|
import javax.media.MediaLocator;
|
||||||
import javax.media.format.AudioFormat;
|
import javax.media.format.AudioFormat;
|
||||||
|
@ -316,7 +317,11 @@ public class JingleMediaTest extends SmackTestCase {
|
||||||
|
|
||||||
js0.start();
|
js0.start();
|
||||||
|
|
||||||
Thread.sleep(55000);
|
Thread.sleep(20000);
|
||||||
|
|
||||||
|
js0.sendFormattedError(JingleError.UNSUPPORTED_TRANSPORTS);
|
||||||
|
|
||||||
|
Thread.sleep(20000);
|
||||||
|
|
||||||
js0.terminate();
|
js0.terminate();
|
||||||
|
|
||||||
|
|
|
@ -61,15 +61,15 @@ public class STUNResolverTest extends SmackTestCase {
|
||||||
int highestPref = 100;
|
int highestPref = 100;
|
||||||
|
|
||||||
TransportCandidate cand1 = new ICECandidate("192.168.2.1", 3, 2,
|
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,
|
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,
|
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,
|
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,
|
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() {
|
STUNResolver stunResolver = new STUNResolver() {
|
||||||
};
|
};
|
||||||
|
@ -91,15 +91,15 @@ public class STUNResolverTest extends SmackTestCase {
|
||||||
int highestPref = 100;
|
int highestPref = 100;
|
||||||
|
|
||||||
TransportCandidate cand1 = new ICECandidate("192.168.2.1", 3, 2,
|
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,
|
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,
|
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,
|
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,
|
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) {
|
ICEResolver iceResolver = new ICEResolver(getConnection(0), "stun.xten.net", 3478) {
|
||||||
};
|
};
|
||||||
|
@ -132,7 +132,7 @@ public class STUNResolverTest extends SmackTestCase {
|
||||||
|
|
||||||
for (Candidate candidate : cc.getSortedCandidates())
|
for (Candidate candidate : cc.getSortedCandidates())
|
||||||
try {
|
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());
|
transportCandidate.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress());
|
||||||
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());
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,11 @@ public class TransportCandidateTest extends SmackTestCase {
|
||||||
*/
|
*/
|
||||||
public void testEqualsObject() {
|
public void testEqualsObject() {
|
||||||
TransportCandidate cand1 = new ICECandidate("192.168.2.1", 1, 2,
|
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,
|
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,
|
TransportCandidate cand3 = new ICECandidate("192.168.2.1", 1, 2,
|
||||||
"password", 3469, "username", 25, "");
|
"password", 3469, "username", 25, ICECandidate.Type.prflx);
|
||||||
|
|
||||||
assertEquals(cand1, cand2);
|
assertEquals(cand1, cand2);
|
||||||
assertFalse(cand1.equals(cand3));
|
assertFalse(cand1.equals(cand3));
|
||||||
|
@ -36,15 +36,15 @@ public class TransportCandidateTest extends SmackTestCase {
|
||||||
int highestPref = 100;
|
int highestPref = 100;
|
||||||
|
|
||||||
TransportCandidate cand1 = new ICECandidate("192.168.2.1", 3, 2,
|
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,
|
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,
|
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,
|
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,
|
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();
|
ArrayList candList = new ArrayList();
|
||||||
candList.add(cand1);
|
candList.add(cand1);
|
||||||
|
|
Loading…
Reference in a new issue