Fixes a NumberFormatException in the parsing of Jingle ICE-UDP transport candidate coundations. Reported by Philipp Hancke.

cusax-fix
Lyubomir Marinov 12 years ago
parent 846a8cae6c
commit af7a2680fd

@ -694,10 +694,7 @@ private CandidatePacketExtension createCandidate(Candidate<?> candidate)
{
CandidatePacketExtension packet = new CandidatePacketExtension();
//TODO: XMPP expects int values as foundations. Luckily that's exactly
//what ice4j is using under the hood at this time. still, we'd need to
//make sure that doesn't change ... possibly by setting a property there
packet.setFoundation(Integer.parseInt( candidate.getFoundation()));
packet.setFoundation(candidate.getFoundation());
Component component = candidate.getParentComponent();
@ -918,7 +915,7 @@ public synchronized boolean startConnectivityEstablishment(
component,
org.ice4j.ice.CandidateType.parse(
candidate.getType().toString()),
Integer.toString(candidate.getFoundation()),
candidate.getFoundation(),
candidate.getPriority(),
relatedCandidate));
}
@ -1023,7 +1020,7 @@ public synchronized boolean startConnectivityEstablishment(
component,
org.ice4j.ice.CandidateType.parse(
candidate.getType().toString()),
Integer.toString(candidate.getFoundation()),
candidate.getFoundation(),
candidate.getPriority(),
relatedCandidate));
startConnectivityEstablishment = true;

@ -1,384 +1,384 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.jabber.extensions.gtalk;
import java.util.*;
import net.java.sip.communicator.impl.protocol.jabber.extensions.jingle.*;
import net.java.sip.communicator.impl.protocol.jabber.extensions.jingle.CandidateType;
import org.ice4j.*;
import org.ice4j.ice.*;
import org.jivesoftware.smack.packet.*;
/**
* A utility class containing methods for creating {@link SessionIQ}
* instances for various situations.
*
* @author Sebastien Vincent
*/
public class GTalkPacketFactory
{
/**
* Creates a {@link SessionIQ} <tt>reject</tt> packet.
*
* @param from our JID
* @param to the destination JID
* @param sid the ID of the Google Talk session that this message will be
* rejecting.
*
* @return a {@link SessionIQ} <tt>reject</tt> packet.
*/
public static SessionIQ createReject(String from, String to, String sid)
{
SessionIQ reject = new SessionIQ();
reject.setTo(to);
reject.setFrom(from);
reject.setType(IQ.Type.SET);
reject.setID(sid);
reject.setGTalkType(GTalkType.REJECT);
return reject;
}
/**
* Creates a {@link SessionIQ} <tt>terminate</tt> packet carrying a
* {@link Reason#BUSY} payload.
*
* @param from our JID
* @param to the destination JID
* @param sid the ID of the Google Talk session that this message will be
* terminating.
*
* @return a {@link SessionIQ} <tt>terminate</tt> packet.
*/
public static SessionIQ createBusy(String from, String to, String sid)
{
return createSessionTerminate(from, to, sid, Reason.BUSY, null);
}
/**
* Creates a {@link SessionIQ} <tt>session-terminate</tt> packet that is
* meant to terminate an on-going, well established session (similar to a SIP
* BYE request).
*
* @param from our JID
* @param to the destination JID
* @param sid the ID of the Google Talk session that this message will be
* terminating.
*
* @return a {@link SessionIQ} <tt>terminate</tt> packet
* .
*/
public static SessionIQ createBye(String from, String to, String sid)
{
return createSessionTerminate(from, to, sid, Reason.SUCCESS,
"Nice talking to you!");
}
/**
* Creates a {@link SessionIQ} <tt>terminate</tt> packet that is
* meant to terminate a not yet established session.
*
* @param from our JID
* @param to the destination JID
* @param sid the ID of the Google Talk session that this message will be
* terminating.
*
* @return a {@link SessionIQ} <tt>terminate</tt> packet
* .
*/
public static SessionIQ createCancel(String from, String to, String sid)
{
return createSessionTerminate(from, to, sid, Reason.CANCEL, "Oops!");
}
/**
* Creates a {@link SessionIQ} <tt>terminate</tt> packet with the
* specified src, dst, sid, and reason.
*
* @param from our JID
* @param to the destination JID
* @param sid the ID of the Google Talk session that this message will be
* terminating.
* @param reason the reason for the termination
* @param reasonText a human readable reason for the termination or
* <tt>null</tt> for none.
*
* @return the newly constructed {@link SessionIQ} <tt>terminate</tt>
* packet.
* .
*/
public static SessionIQ createSessionTerminate(String from,
String to,
String sid,
Reason reason,
String reasonText)
{
SessionIQ terminate = new SessionIQ();
terminate.setTo(to);
terminate.setFrom(from);
terminate.setType(IQ.Type.SET);
terminate.setID(sid);
terminate.setGTalkType(GTalkType.TERMINATE);
ReasonPacketExtension reasonPacketExt
= new ReasonPacketExtension(reason, reasonText, null);
terminate.setReason(reasonPacketExt);
return terminate;
}
/**
* Creates a {@link SessionIQ} <tt>accept</tt> packet with the
* specified <tt>from</tt>, <tt>to</tt>, <tt>sid</tt>, and <tt>content</tt>.
* Given our role in a conversation, we would assume that the <tt>from</tt>
* value should also be used for the value of the Google Talk <tt>responder</tt>.
*
* @param from our JID
* @param to the destination JID
* @param sid the ID of the Google Talk session that this message will be
* terminating.
* @param description description containing payload types list
* descriptions.
*
* @return the newly constructed {@link SessionIQ} <tt>accept</tt>
* packet.
* .
*/
public static SessionIQ createSessionAccept(
String from,
String to,
String sid,
RtpDescriptionPacketExtension description)
{
SessionIQ sessionAccept = new SessionIQ();
sessionAccept.setTo(to);
sessionAccept.setFrom(from);
sessionAccept.setType(IQ.Type.SET);
sessionAccept.setInitiator(to);
sessionAccept.setID(sid);
sessionAccept.setGTalkType(GTalkType.ACCEPT);
sessionAccept.addExtension(description);
return sessionAccept;
}
/**
* Creates a new {@link SessionIQ} with the <tt>initiate</tt> type.
*
* @param from our JID
* @param to the destination JID
* @param sid the ID of the Google Talk session that this message will be
* terminating.
* @param description description containing payload types list.
*
* @return the newly constructed {@link SessionIQ} <tt>terminate</tt>
* packet.
*/
public static SessionIQ createSessionInitiate(
String from,
String to,
String sid,
RtpDescriptionPacketExtension description)
{
SessionIQ sessionInitiate = new SessionIQ();
sessionInitiate.setTo(to);
sessionInitiate.setFrom(from);
sessionInitiate.setInitiator(from);
sessionInitiate.setType(IQ.Type.SET);
sessionInitiate.setID(sid);
sessionInitiate.setGTalkType(GTalkType.INITIATE);
sessionInitiate.addExtension(description);
return sessionInitiate;
}
/**
* Creates a new {@link SessionIQ} with the <tt>candidates</tt> type.
*
* @param from our JID
* @param to the destination JID
* @param sid the ID of the Google Talk session.
* @param candidate a <tt>GTalkCandidatePacketExtension</tt>.
*
* @return the newly constructed {@link SessionIQ} <tt>terminate</tt>
* packet.
*/
public static SessionIQ createSessionCandidates(
String from,
String to,
String sid,
GTalkCandidatePacketExtension candidate)
{
SessionIQ sessionInitiate = new SessionIQ();
sessionInitiate.setTo(to);
sessionInitiate.setFrom(from);
sessionInitiate.setInitiator(from);
sessionInitiate.setType(IQ.Type.SET);
sessionInitiate.setID(sid);
sessionInitiate.setGTalkType(GTalkType.CANDIDATES);
sessionInitiate.addExtension(candidate);
return sessionInitiate;
}
/**
* Converts the ICE media <tt>stream</tt> and its local candidates into a
* list of Google Talk candidates.
*
* @param name of the stream
* @param stream the {@link IceMediaStream} that we'd like to describe in
* XML.
*
* @return the list of Google Talk candidates
*/
public static List<GTalkCandidatePacketExtension> createCandidates(
String name,
IceMediaStream stream)
{
List<GTalkCandidatePacketExtension> exts = new
ArrayList<GTalkCandidatePacketExtension>();
for(Component component : stream.getComponents())
{
String mediaName = null;
if(name.equals("rtp"))
{
if(component.getComponentID() == 1)
{
mediaName = name;
}
else
{
mediaName = "rtcp";
// Audio RTCP is never used in Google Talk and it is also
// never transmitted by Gmail client
}
}
else if(name.equals("video_rtp"))
{
if(component.getComponentID() == 1)
{
mediaName = name;
}
else
{
mediaName = "video_rtcp";
}
}
List<LocalCandidate> candToRemove = new ArrayList<LocalCandidate>();
List<LocalCandidate> candidates = component.getLocalCandidates();
for(LocalCandidate candidate : component.getLocalCandidates())
{
if(candidate instanceof UPNPCandidate)
{
LocalCandidate base = candidate.getBase();
candToRemove.add(base);
}
}
for(Candidate<?> candidate : candToRemove)
{
candidates.remove(candidate);
}
for(Candidate<?> candidate : candidates)
{
GTalkCandidatePacketExtension e
= createCandidate(candidate, mediaName);
if(e != null)
exts.add(e);
}
}
return exts;
}
/**
* Creates a {@link GTalkCandidatePacketExtension} and initializes it so
* that it would describe the state of <tt>candidate</tt>
*
* @param candidate the ICE4J {@link Candidate} that we'd like to convert
* into an Google Talk packet extension.
* @param name name of the candidate extension
*
* @return a new {@link GTalkCandidatePacketExtension} corresponding to the
* state of the <tt>candidate</tt> candidate.
*/
public static GTalkCandidatePacketExtension createCandidate(
Candidate<?> candidate, String name)
{
GTalkCandidatePacketExtension packet =
new GTalkCandidatePacketExtension();
Component component = candidate.getParentComponent();
packet.setName(name);
packet.setGeneration(
component.getParentStream().getParentAgent().getGeneration());
TransportAddress transportAddress = candidate.getTransportAddress();
// different username/password for each candidate ?
packet.setUsername(((LocalCandidate)candidate).getUfrag());
if(candidate instanceof GoogleRelayedCandidate)
{
packet.setPassword(
((GoogleRelayedCandidate)
candidate).getPassword());
}
else
{
packet.setPassword("");
}
packet.setAddress(transportAddress.getHostAddress());
packet.setPort(transportAddress.getPort());
if(transportAddress.getPort() != 443)
{
packet.setProtocol(candidate.getTransport().toString());
}
else
{
packet.setProtocol("ssltcp");
}
packet.setNetwork(0);
packet.setFoundation(0);
packet.setComponent(component.getComponentID());
CandidateType candType = CandidateType.valueOf(
candidate.getType().toString());
if(candType == CandidateType.srflx)
{
candType = CandidateType.stun;
}
else if(candType == CandidateType.host)
{
candType = CandidateType.local;
}
packet.setType(candType);
double priority = candidate.getPriority();
packet.setPreference((priority / 1000));
return packet;
}
}
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.jabber.extensions.gtalk;
import java.util.*;
import net.java.sip.communicator.impl.protocol.jabber.extensions.jingle.*;
import net.java.sip.communicator.impl.protocol.jabber.extensions.jingle.CandidateType;
import org.ice4j.*;
import org.ice4j.ice.*;
import org.jivesoftware.smack.packet.*;
/**
* A utility class containing methods for creating {@link SessionIQ}
* instances for various situations.
*
* @author Sebastien Vincent
*/
public class GTalkPacketFactory
{
/**
* Creates a {@link SessionIQ} <tt>reject</tt> packet.
*
* @param from our JID
* @param to the destination JID
* @param sid the ID of the Google Talk session that this message will be
* rejecting.
*
* @return a {@link SessionIQ} <tt>reject</tt> packet.
*/
public static SessionIQ createReject(String from, String to, String sid)
{
SessionIQ reject = new SessionIQ();
reject.setTo(to);
reject.setFrom(from);
reject.setType(IQ.Type.SET);
reject.setID(sid);
reject.setGTalkType(GTalkType.REJECT);
return reject;
}
/**
* Creates a {@link SessionIQ} <tt>terminate</tt> packet carrying a
* {@link Reason#BUSY} payload.
*
* @param from our JID
* @param to the destination JID
* @param sid the ID of the Google Talk session that this message will be
* terminating.
*
* @return a {@link SessionIQ} <tt>terminate</tt> packet.
*/
public static SessionIQ createBusy(String from, String to, String sid)
{
return createSessionTerminate(from, to, sid, Reason.BUSY, null);
}
/**
* Creates a {@link SessionIQ} <tt>session-terminate</tt> packet that is
* meant to terminate an on-going, well established session (similar to a SIP
* BYE request).
*
* @param from our JID
* @param to the destination JID
* @param sid the ID of the Google Talk session that this message will be
* terminating.
*
* @return a {@link SessionIQ} <tt>terminate</tt> packet
* .
*/
public static SessionIQ createBye(String from, String to, String sid)
{
return createSessionTerminate(from, to, sid, Reason.SUCCESS,
"Nice talking to you!");
}
/**
* Creates a {@link SessionIQ} <tt>terminate</tt> packet that is
* meant to terminate a not yet established session.
*
* @param from our JID
* @param to the destination JID
* @param sid the ID of the Google Talk session that this message will be
* terminating.
*
* @return a {@link SessionIQ} <tt>terminate</tt> packet
* .
*/
public static SessionIQ createCancel(String from, String to, String sid)
{
return createSessionTerminate(from, to, sid, Reason.CANCEL, "Oops!");
}
/**
* Creates a {@link SessionIQ} <tt>terminate</tt> packet with the
* specified src, dst, sid, and reason.
*
* @param from our JID
* @param to the destination JID
* @param sid the ID of the Google Talk session that this message will be
* terminating.
* @param reason the reason for the termination
* @param reasonText a human readable reason for the termination or
* <tt>null</tt> for none.
*
* @return the newly constructed {@link SessionIQ} <tt>terminate</tt>
* packet.
* .
*/
public static SessionIQ createSessionTerminate(String from,
String to,
String sid,
Reason reason,
String reasonText)
{
SessionIQ terminate = new SessionIQ();
terminate.setTo(to);
terminate.setFrom(from);
terminate.setType(IQ.Type.SET);
terminate.setID(sid);
terminate.setGTalkType(GTalkType.TERMINATE);
ReasonPacketExtension reasonPacketExt
= new ReasonPacketExtension(reason, reasonText, null);
terminate.setReason(reasonPacketExt);
return terminate;
}
/**
* Creates a {@link SessionIQ} <tt>accept</tt> packet with the
* specified <tt>from</tt>, <tt>to</tt>, <tt>sid</tt>, and <tt>content</tt>.
* Given our role in a conversation, we would assume that the <tt>from</tt>
* value should also be used for the value of the Google Talk <tt>responder</tt>.
*
* @param from our JID
* @param to the destination JID
* @param sid the ID of the Google Talk session that this message will be
* terminating.
* @param description description containing payload types list
* descriptions.
*
* @return the newly constructed {@link SessionIQ} <tt>accept</tt>
* packet.
* .
*/
public static SessionIQ createSessionAccept(
String from,
String to,
String sid,
RtpDescriptionPacketExtension description)
{
SessionIQ sessionAccept = new SessionIQ();
sessionAccept.setTo(to);
sessionAccept.setFrom(from);
sessionAccept.setType(IQ.Type.SET);
sessionAccept.setInitiator(to);
sessionAccept.setID(sid);
sessionAccept.setGTalkType(GTalkType.ACCEPT);
sessionAccept.addExtension(description);
return sessionAccept;
}
/**
* Creates a new {@link SessionIQ} with the <tt>initiate</tt> type.
*
* @param from our JID
* @param to the destination JID
* @param sid the ID of the Google Talk session that this message will be
* terminating.
* @param description description containing payload types list.
*
* @return the newly constructed {@link SessionIQ} <tt>terminate</tt>
* packet.
*/
public static SessionIQ createSessionInitiate(
String from,
String to,
String sid,
RtpDescriptionPacketExtension description)
{
SessionIQ sessionInitiate = new SessionIQ();
sessionInitiate.setTo(to);
sessionInitiate.setFrom(from);
sessionInitiate.setInitiator(from);
sessionInitiate.setType(IQ.Type.SET);
sessionInitiate.setID(sid);
sessionInitiate.setGTalkType(GTalkType.INITIATE);
sessionInitiate.addExtension(description);
return sessionInitiate;
}
/**
* Creates a new {@link SessionIQ} with the <tt>candidates</tt> type.
*
* @param from our JID
* @param to the destination JID
* @param sid the ID of the Google Talk session.
* @param candidate a <tt>GTalkCandidatePacketExtension</tt>.
*
* @return the newly constructed {@link SessionIQ} <tt>terminate</tt>
* packet.
*/
public static SessionIQ createSessionCandidates(
String from,
String to,
String sid,
GTalkCandidatePacketExtension candidate)
{
SessionIQ sessionInitiate = new SessionIQ();
sessionInitiate.setTo(to);
sessionInitiate.setFrom(from);
sessionInitiate.setInitiator(from);
sessionInitiate.setType(IQ.Type.SET);
sessionInitiate.setID(sid);
sessionInitiate.setGTalkType(GTalkType.CANDIDATES);
sessionInitiate.addExtension(candidate);
return sessionInitiate;
}
/**
* Converts the ICE media <tt>stream</tt> and its local candidates into a
* list of Google Talk candidates.
*
* @param name of the stream
* @param stream the {@link IceMediaStream} that we'd like to describe in
* XML.
*
* @return the list of Google Talk candidates
*/
public static List<GTalkCandidatePacketExtension> createCandidates(
String name,
IceMediaStream stream)
{
List<GTalkCandidatePacketExtension> exts = new
ArrayList<GTalkCandidatePacketExtension>();
for(Component component : stream.getComponents())
{
String mediaName = null;
if(name.equals("rtp"))
{
if(component.getComponentID() == 1)
{
mediaName = name;
}
else
{
mediaName = "rtcp";
// Audio RTCP is never used in Google Talk and it is also
// never transmitted by Gmail client
}
}
else if(name.equals("video_rtp"))
{
if(component.getComponentID() == 1)
{
mediaName = name;
}
else
{
mediaName = "video_rtcp";
}
}
List<LocalCandidate> candToRemove = new ArrayList<LocalCandidate>();
List<LocalCandidate> candidates = component.getLocalCandidates();
for(LocalCandidate candidate : component.getLocalCandidates())
{
if(candidate instanceof UPNPCandidate)
{
LocalCandidate base = candidate.getBase();
candToRemove.add(base);
}
}
for(Candidate<?> candidate : candToRemove)
{
candidates.remove(candidate);
}
for(Candidate<?> candidate : candidates)
{
GTalkCandidatePacketExtension e
= createCandidate(candidate, mediaName);
if(e != null)
exts.add(e);
}
}
return exts;
}
/**
* Creates a {@link GTalkCandidatePacketExtension} and initializes it so
* that it would describe the state of <tt>candidate</tt>
*
* @param candidate the ICE4J {@link Candidate} that we'd like to convert
* into an Google Talk packet extension.
* @param name name of the candidate extension
*
* @return a new {@link GTalkCandidatePacketExtension} corresponding to the
* state of the <tt>candidate</tt> candidate.
*/
public static GTalkCandidatePacketExtension createCandidate(
Candidate<?> candidate, String name)
{
GTalkCandidatePacketExtension packet =
new GTalkCandidatePacketExtension();
Component component = candidate.getParentComponent();
packet.setName(name);
packet.setGeneration(
component.getParentStream().getParentAgent().getGeneration());
TransportAddress transportAddress = candidate.getTransportAddress();
// different username/password for each candidate ?
packet.setUsername(((LocalCandidate)candidate).getUfrag());
if(candidate instanceof GoogleRelayedCandidate)
{
packet.setPassword(
((GoogleRelayedCandidate)
candidate).getPassword());
}
else
{
packet.setPassword("");
}
packet.setAddress(transportAddress.getHostAddress());
packet.setPort(transportAddress.getPort());
if(transportAddress.getPort() != 443)
{
packet.setProtocol(candidate.getTransport().toString());
}
else
{
packet.setProtocol("ssltcp");
}
packet.setNetwork(0);
packet.setFoundation("0");
packet.setComponent(component.getComponentID());
CandidateType candType = CandidateType.valueOf(
candidate.getType().toString());
if(candType == CandidateType.srflx)
{
candType = CandidateType.stun;
}
else if(candType == CandidateType.host)
{
candType = CandidateType.local;
}
packet.setType(candType);
double priority = candidate.getPriority();
packet.setPreference((priority / 1000));
return packet;
}
}

@ -1,413 +1,413 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.jabber.extensions.jingle;
import net.java.sip.communicator.impl.protocol.jabber.extensions.*;
/**
* @author Emil Ivov
*/
public class CandidatePacketExtension extends AbstractPacketExtension
implements Comparable<CandidatePacketExtension>
{
/**
* The name of the "candidate" element.
*/
public static final String ELEMENT_NAME = "candidate";
/**
* The name of the "component" element.
*/
public static final String COMPONENT_ATTR_NAME = "component";
/**
* The "component" ID for RTP components.
*/
public static final int RTP_COMPONENT_ID = 1;
/**
* The "component" ID for RTCP components.
*/
public static final int RTCP_COMPONENT_ID = 2;
/**
* The name of the "foundation" element.
*/
public static final String FOUNDATION_ATTR_NAME = "foundation";
/**
* The name of the "generation" element.
*/
public static final String GENERATION_ATTR_NAME = "generation";
/**
* The name of the "id" element.
*/
public static final String ID_ATTR_NAME = "id";
/**
* The name of the "ip" element.
*/
public static final String IP_ATTR_NAME = "ip";
/**
* The name of the "network" element.
*/
public static final String NETWORK_ATTR_NAME = "network";
/**
* The name of the "port" element.
*/
public static final String PORT_ATTR_NAME = "port";
/**
* The name of the "priority" element.
*/
public static final String PRIORITY_ATTR_NAME = "priority";
/**
* The name of the "protocol" element.
*/
public static final String PROTOCOL_ATTR_NAME = "protocol";
/**
* The name of the "rel-addr" element.
*/
public static final String REL_ADDR_ATTR_NAME = "rel-addr";
/**
* The name of the "rel-port" element.
*/
public static final String REL_PORT_ATTR_NAME = "rel-port";
/**
* The name of the "type" element.
*/
public static final String TYPE_ATTR_NAME = "type";
/**
* Creates a new {@link CandidatePacketExtension}
*/
public CandidatePacketExtension()
{
super(null, ELEMENT_NAME);
}
/**
* Creates a new {@link CandidatePacketExtension} with the specified
* <tt>elementName</tt> so that this class would be usable as a
* <tt>RemoteCandidatePacketExtension</tt> parent.
*
* @param elementName the element name that this instance should be using.
*/
protected CandidatePacketExtension(String elementName)
{
super(null, elementName);
}
/**
* Sets a component ID as defined in ICE-CORE.
*
* @param component a component ID as defined in ICE-CORE.
*/
public void setComponent(int component)
{
super.setAttribute(COMPONENT_ATTR_NAME, component);
}
/**
* Returns a component ID as defined in ICE-CORE.
*
* @return a component ID as defined in ICE-CORE.
*/
public int getComponent()
{
return super.getAttributeAsInt(COMPONENT_ATTR_NAME);
}
/**
* Sets the candidate foundation as defined in ICE-CORE.
*
* @param foundation the candidate foundation as defined in ICE-CORE.
*/
public void setFoundation(int foundation)
{
super.setAttribute(FOUNDATION_ATTR_NAME, foundation);
}
/**
* Returns the candidate foundation as defined in ICE-CORE.
*
* @return the candidate foundation as defined in ICE-CORE.
*/
public int getFoundation()
{
return super.getAttributeAsInt(FOUNDATION_ATTR_NAME);
}
/**
* Sets this canditate's generation index. A generation is an index,
* starting at 0, that enables the parties to keep track of updates to the
* candidate throughout the life of the session. For details, see the ICE
* Restarts section of XEP-0176.
*
* @param generation this canditate's generation index.
*/
public void setGeneration(int generation)
{
super.setAttribute(GENERATION_ATTR_NAME, generation);
}
/**
* Returns this canditate's generation. A generation is an index, starting at
* 0, that enables the parties to keep track of updates to the candidate
* throughout the life of the session. For details, see the ICE Restarts
* section of XEP-0176.
*
* @return this canditate's generation index.
*/
public int getGeneration()
{
return super.getAttributeAsInt(GENERATION_ATTR_NAME);
}
/**
* Sets this candidates's unique identifier <tt>String</tt>.
*
* @param id this candidates's unique identifier <tt>String</tt>
*/
public void setID(String id)
{
super.setAttribute(ID_ATTR_NAME, id);
}
/**
* Returns this candidates's unique identifier <tt>String</tt>.
*
* @return this candidates's unique identifier <tt>String</tt>
*/
public String getID()
{
return super.getAttributeAsString(ID_ATTR_NAME);
}
/**
* Sets this candidate's Internet Protocol (IP) address; this can be either
* an IPv4 address or an IPv6 address.
*
* @param ip this candidate's IPv4 or IPv6 address.
*/
public void setIP(String ip)
{
super.setAttribute(IP_ATTR_NAME, ip);
}
/**
* Returns this candidate's Internet Protocol (IP) address; this can be
* either an IPv4 address or an IPv6 address.
*
* @return this candidate's IPv4 or IPv6 address.
*/
public String getIP()
{
return super.getAttributeAsString(IP_ATTR_NAME);
}
/**
* The network index indicating the interface that the candidate belongs to.
* The network ID is used for diagnostic purposes only in cases where the
* calling hardware has more than one Network Interface Card.
*
* @param network the network index indicating the interface that the
* candidate belongs to.
*/
public void setNetwork(int network)
{
super.setAttribute(NETWORK_ATTR_NAME, network);
}
/**
* Returns the network index indicating the interface that the candidate
* belongs to. The network ID is used for diagnostic purposes only in cases
* where the calling hardware has more than one Network Interface Card.
*
* @return the network index indicating the interface that the candidate
* belongs to.
*/
public int getNetwork()
{
return super.getAttributeAsInt(NETWORK_ATTR_NAME);
}
/**
* Sets this candidate's port number.
*
* @param port this candidate's port number.
*/
public void setPort(int port)
{
super.setAttribute(PORT_ATTR_NAME, port);
}
/**
* Returns this candidate's port number.
*
* @return this candidate's port number.
*/
public int getPort()
{
return super.getAttributeAsInt(PORT_ATTR_NAME);
}
/**
* This candidate's priority as defined in ICE's RFC 5245
*
* @param priority this candidate's priority
*/
public void setPriority(long priority)
{
super.setAttribute(PRIORITY_ATTR_NAME, priority);
}
/**
* This candidate's priority as defined in ICE's RFC 5245
*
* @return this candidate's priority
*/
public int getPriority()
{
return super.getAttributeAsInt(PRIORITY_ATTR_NAME);
}
/**
* Sets this candidate's transport protocol.
*
* @param protocol this candidate's transport protocol.
*/
public void setProtocol(String protocol)
{
super.setAttribute(PROTOCOL_ATTR_NAME, protocol);
}
/**
* Sets this candidate's transport protocol.
*
* @return this candidate's transport protocol.
*/
public String getProtocol()
{
return super.getAttributeAsString(PROTOCOL_ATTR_NAME);
}
/**
* Sets this candidate's related address as described by ICE's RFC 5245.
*
* @param relAddr this candidate's related address as described by ICE's
* RFC 5245.
*/
public void setRelAddr(String relAddr)
{
super.setAttribute(REL_ADDR_ATTR_NAME, relAddr);
}
/**
* Returns this candidate's related address as described by ICE's RFC 5245.
*
* @return this candidate's related address as described by ICE's RFC 5245.
*/
public String getRelAddr()
{
return super.getAttributeAsString(REL_ADDR_ATTR_NAME);
}
/**
* Sets this candidate's related port as described by ICE's RFC 5245.
*
* @param relPort this candidate's related port as described by ICE's
* RFC 5245.
*/
public void setRelPort(int relPort)
{
super.setAttribute(REL_PORT_ATTR_NAME, relPort);
}
/**
* Returns this candidate's related port as described by ICE's RFC 5245.
*
* @return this candidate's related port as described by ICE's RFC 5245.
*/
public int getRelPort()
{
return super.getAttributeAsInt(REL_PORT_ATTR_NAME);
}
/**
* Sets a Candidate Type as defined in ICE-CORE. The allowable values are
* "host" for host candidates, "prflx" for peer reflexive candidates,
* "relay" for relayed candidates, and "srflx" for server reflexive
* candidates. All allowable values are enumerated in the {@link
* CandidateType} enum.
*
* @param type this candidates' type as per ICE's RFC 5245.
*/
public void setType(CandidateType type)
{
super.setAttribute(TYPE_ATTR_NAME, type);
}
/**
* Returns a Candidate Type as defined in ICE-CORE. The allowable values are
* "host" for host candidates, "prflx" for peer reflexive candidates,
* "relay" for relayed candidates, and "srflx" for server reflexive
* candidates. All allowable values are enumerated in the {@link
* CandidateType} enum.
*
* @return this candidates' type as per ICE's RFC 5245.
*/
public CandidateType getType()
{
return CandidateType.valueOf(getAttributeAsString(TYPE_ATTR_NAME));
}
/**
* Compares this instance with another CandidatePacketExtension by
* preference of type: host < local < prflx < srflx < stun < relay.
*
* @return 0 if the type are equal. -1 if this instance type is preferred.
* Otherwise 1.
*/
public int compareTo(CandidatePacketExtension candidatePacketExtension)
{
// If the types are differents.
if(this.getType() != candidatePacketExtension.getType())
{
CandidateType[] types = {
CandidateType.host,
CandidateType.local,
CandidateType.prflx,
CandidateType.srflx,
CandidateType.stun,
CandidateType.relay
};
for(int i = 0; i < types.length; ++i)
{
// this object is preferred.
if(types[i] == this.getType())
{
return -1;
}
// the candidatePacketExtension is preferred.
else if(types[i] == candidatePacketExtension.getType())
{
return 1;
}
}
}
// If the types are equal.
return 0;
}
}
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.jabber.extensions.jingle;
import net.java.sip.communicator.impl.protocol.jabber.extensions.*;
/**
* @author Emil Ivov
*/
public class CandidatePacketExtension extends AbstractPacketExtension
implements Comparable<CandidatePacketExtension>
{
/**
* The name of the "candidate" element.
*/
public static final String ELEMENT_NAME = "candidate";
/**
* The name of the "component" element.
*/
public static final String COMPONENT_ATTR_NAME = "component";
/**
* The "component" ID for RTP components.
*/
public static final int RTP_COMPONENT_ID = 1;
/**
* The "component" ID for RTCP components.
*/
public static final int RTCP_COMPONENT_ID = 2;
/**
* The name of the "foundation" element.
*/
public static final String FOUNDATION_ATTR_NAME = "foundation";
/**
* The name of the "generation" element.
*/
public static final String GENERATION_ATTR_NAME = "generation";
/**
* The name of the "id" element.
*/
public static final String ID_ATTR_NAME = "id";
/**
* The name of the "ip" element.
*/
public static final String IP_ATTR_NAME = "ip";
/**
* The name of the "network" element.
*/
public static final String NETWORK_ATTR_NAME = "network";
/**
* The name of the "port" element.
*/
public static final String PORT_ATTR_NAME = "port";
/**
* The name of the "priority" element.
*/
public static final String PRIORITY_ATTR_NAME = "priority";
/**
* The name of the "protocol" element.
*/
public static final String PROTOCOL_ATTR_NAME = "protocol";
/**
* The name of the "rel-addr" element.
*/
public static final String REL_ADDR_ATTR_NAME = "rel-addr";
/**
* The name of the "rel-port" element.
*/
public static final String REL_PORT_ATTR_NAME = "rel-port";
/**
* The name of the "type" element.
*/
public static final String TYPE_ATTR_NAME = "type";
/**
* Creates a new {@link CandidatePacketExtension}
*/
public CandidatePacketExtension()
{
super(null, ELEMENT_NAME);
}
/**
* Creates a new {@link CandidatePacketExtension} with the specified
* <tt>elementName</tt> so that this class would be usable as a
* <tt>RemoteCandidatePacketExtension</tt> parent.
*
* @param elementName the element name that this instance should be using.
*/
protected CandidatePacketExtension(String elementName)
{
super(null, elementName);
}
/**
* Sets a component ID as defined in ICE-CORE.
*
* @param component a component ID as defined in ICE-CORE.
*/
public void setComponent(int component)
{
super.setAttribute(COMPONENT_ATTR_NAME, component);
}
/**
* Returns a component ID as defined in ICE-CORE.
*
* @return a component ID as defined in ICE-CORE.
*/
public int getComponent()
{
return super.getAttributeAsInt(COMPONENT_ATTR_NAME);
}
/**
* Sets the candidate foundation as defined in ICE-CORE.
*
* @param foundation the candidate foundation as defined in ICE-CORE.
*/
public void setFoundation(String foundation)
{
super.setAttribute(FOUNDATION_ATTR_NAME, foundation);
}
/**
* Returns the candidate foundation as defined in ICE-CORE.
*
* @return the candidate foundation as defined in ICE-CORE.
*/
public String getFoundation()
{
return super.getAttributeAsString(FOUNDATION_ATTR_NAME);
}
/**
* Sets this canditate's generation index. A generation is an index,
* starting at 0, that enables the parties to keep track of updates to the
* candidate throughout the life of the session. For details, see the ICE
* Restarts section of XEP-0176.
*
* @param generation this canditate's generation index.
*/
public void setGeneration(int generation)
{
super.setAttribute(GENERATION_ATTR_NAME, generation);
}
/**
* Returns this canditate's generation. A generation is an index, starting at
* 0, that enables the parties to keep track of updates to the candidate
* throughout the life of the session. For details, see the ICE Restarts
* section of XEP-0176.
*
* @return this canditate's generation index.
*/
public int getGeneration()
{
return super.getAttributeAsInt(GENERATION_ATTR_NAME);
}
/**
* Sets this candidates's unique identifier <tt>String</tt>.
*
* @param id this candidates's unique identifier <tt>String</tt>
*/
public void setID(String id)
{
super.setAttribute(ID_ATTR_NAME, id);
}
/**
* Returns this candidates's unique identifier <tt>String</tt>.
*
* @return this candidates's unique identifier <tt>String</tt>
*/
public String getID()
{
return super.getAttributeAsString(ID_ATTR_NAME);
}
/**
* Sets this candidate's Internet Protocol (IP) address; this can be either
* an IPv4 address or an IPv6 address.
*
* @param ip this candidate's IPv4 or IPv6 address.
*/
public void setIP(String ip)
{
super.setAttribute(IP_ATTR_NAME, ip);
}
/**
* Returns this candidate's Internet Protocol (IP) address; this can be
* either an IPv4 address or an IPv6 address.
*
* @return this candidate's IPv4 or IPv6 address.
*/
public String getIP()
{
return super.getAttributeAsString(IP_ATTR_NAME);
}
/**
* The network index indicating the interface that the candidate belongs to.
* The network ID is used for diagnostic purposes only in cases where the
* calling hardware has more than one Network Interface Card.
*
* @param network the network index indicating the interface that the
* candidate belongs to.
*/
public void setNetwork(int network)
{
super.setAttribute(NETWORK_ATTR_NAME, network);
}
/**
* Returns the network index indicating the interface that the candidate
* belongs to. The network ID is used for diagnostic purposes only in cases
* where the calling hardware has more than one Network Interface Card.
*
* @return the network index indicating the interface that the candidate
* belongs to.
*/
public int getNetwork()
{
return super.getAttributeAsInt(NETWORK_ATTR_NAME);
}
/**
* Sets this candidate's port number.
*
* @param port this candidate's port number.
*/
public void setPort(int port)
{
super.setAttribute(PORT_ATTR_NAME, port);
}
/**
* Returns this candidate's port number.
*
* @return this candidate's port number.
*/
public int getPort()
{
return super.getAttributeAsInt(PORT_ATTR_NAME);
}
/**
* This candidate's priority as defined in ICE's RFC 5245
*
* @param priority this candidate's priority
*/
public void setPriority(long priority)
{
super.setAttribute(PRIORITY_ATTR_NAME, priority);
}
/**
* This candidate's priority as defined in ICE's RFC 5245
*
* @return this candidate's priority
*/
public int getPriority()
{
return super.getAttributeAsInt(PRIORITY_ATTR_NAME);
}
/**
* Sets this candidate's transport protocol.
*
* @param protocol this candidate's transport protocol.
*/
public void setProtocol(String protocol)
{
super.setAttribute(PROTOCOL_ATTR_NAME, protocol);
}
/**
* Sets this candidate's transport protocol.
*
* @return this candidate's transport protocol.
*/
public String getProtocol()
{
return super.getAttributeAsString(PROTOCOL_ATTR_NAME);
}
/**
* Sets this candidate's related address as described by ICE's RFC 5245.
*
* @param relAddr this candidate's related address as described by ICE's
* RFC 5245.
*/
public void setRelAddr(String relAddr)
{
super.setAttribute(REL_ADDR_ATTR_NAME, relAddr);
}
/**
* Returns this candidate's related address as described by ICE's RFC 5245.
*
* @return this candidate's related address as described by ICE's RFC 5245.
*/
public String getRelAddr()
{
return super.getAttributeAsString(REL_ADDR_ATTR_NAME);
}
/**
* Sets this candidate's related port as described by ICE's RFC 5245.
*
* @param relPort this candidate's related port as described by ICE's
* RFC 5245.
*/
public void setRelPort(int relPort)
{
super.setAttribute(REL_PORT_ATTR_NAME, relPort);
}
/**
* Returns this candidate's related port as described by ICE's RFC 5245.
*
* @return this candidate's related port as described by ICE's RFC 5245.
*/
public int getRelPort()
{
return super.getAttributeAsInt(REL_PORT_ATTR_NAME);
}
/**
* Sets a Candidate Type as defined in ICE-CORE. The allowable values are
* "host" for host candidates, "prflx" for peer reflexive candidates,
* "relay" for relayed candidates, and "srflx" for server reflexive
* candidates. All allowable values are enumerated in the {@link
* CandidateType} enum.
*
* @param type this candidates' type as per ICE's RFC 5245.
*/
public void setType(CandidateType type)
{
super.setAttribute(TYPE_ATTR_NAME, type);
}
/**
* Returns a Candidate Type as defined in ICE-CORE. The allowable values are
* "host" for host candidates, "prflx" for peer reflexive candidates,
* "relay" for relayed candidates, and "srflx" for server reflexive
* candidates. All allowable values are enumerated in the {@link
* CandidateType} enum.
*
* @return this candidates' type as per ICE's RFC 5245.
*/
public CandidateType getType()
{
return CandidateType.valueOf(getAttributeAsString(TYPE_ATTR_NAME));
}
/**
* Compares this instance with another CandidatePacketExtension by
* preference of type: host < local < prflx < srflx < stun < relay.
*
* @return 0 if the type are equal. -1 if this instance type is preferred.
* Otherwise 1.
*/
public int compareTo(CandidatePacketExtension candidatePacketExtension)
{
// If the types are differents.
if(this.getType() != candidatePacketExtension.getType())
{
CandidateType[] types = {
CandidateType.host,
CandidateType.local,
CandidateType.prflx,
CandidateType.srflx,
CandidateType.stun,
CandidateType.relay
};
for(int i = 0; i < types.length; ++i)
{
// this object is preferred.
if(types[i] == this.getType())
{
return -1;
}
// the candidatePacketExtension is preferred.
else if(types[i] == candidatePacketExtension.getType())
{
return 1;
}
}
}
// If the types are equal.
return 0;
}
}

Loading…
Cancel
Save