Ongoing work on connectivity checks. Support for user names in connectivity checks

This commit is contained in:
emcho 2010-04-25 14:42:10 +00:00
parent 883237239d
commit 7e0b166d93
15 changed files with 410 additions and 237 deletions

View File

@ -1,8 +1,8 @@
/* /*
* Ice4j, the OpenSource Java Solution for NAT and Firewall Traversal. * ice4j, the OpenSource Java Solution for NAT and Firewall Traversal.
* Maintained by the SIP Communicator community (http://sip-communicator.org).
* *
* Distributable under LGPL license. * Distributable under LGPL license. See terms of license at gnu.org.
* See terms of license at gnu.org.
*/ */
package org.ice4j.attribute; package org.ice4j.attribute;

View File

@ -9,8 +9,8 @@ package org.ice4j.attribute;
import org.ice4j.*; import org.ice4j.*;
/** /**
* This class provides factory methods to allow an application to create * This class provides factory methods to allow an application to create STUN /
* STUN / TURN / ICE Attributes from a particular implementation. * TURN / ICE Attributes from a particular implementation.
* *
* @author Emil Ivov * @author Emil Ivov
* @author Sebastien Vincent * @author Sebastien Vincent
@ -22,28 +22,29 @@ public class AttributeFactory
{ {
} }
//------------------------------------ CHANGE REQUEST -------------------------- // ------------------------------------ CHANGE REQUEST
// --------------------------
/** /**
* Creates a ChangeRequestAttribute with "false" values for the changeIP and * Creates a ChangeRequestAttribute with "false" values for the changeIP and
* changePort flags. * changePort flags.
*
* @return the newly created ChangeRequestAttribute. * @return the newly created ChangeRequestAttribute.
*/ */
public static ChangeRequestAttribute public static ChangeRequestAttribute createChangeRequestAttribute()
createChangeRequestAttribute()
{ {
return createChangeRequestAttribute(false, false); return createChangeRequestAttribute(false, false);
}; };
/** /**
* Creates a ChangeRequestAttribute with the specified flag values. * Creates a ChangeRequestAttribute with the specified flag values.
*
* @param changeIP the value of the changeIP flag. * @param changeIP the value of the changeIP flag.
* @param changePort the value of the changePort flag. * @param changePort the value of the changePort flag.
* @return the newly created ChangeRequestAttribute. * @return the newly created ChangeRequestAttribute.
*/ */
public static ChangeRequestAttribute public static ChangeRequestAttribute createChangeRequestAttribute(
createChangeRequestAttribute(boolean changeIP, boolean changeIP, boolean changePort)
boolean changePort)
{ {
ChangeRequestAttribute attribute = new ChangeRequestAttribute(); ChangeRequestAttribute attribute = new ChangeRequestAttribute();
@ -53,16 +54,18 @@ public class AttributeFactory
return attribute; return attribute;
}; };
//------------------------------------ CHANGED ADDRESS ------------------------- // ------------------------------------ CHANGED ADDRESS
// -------------------------
/** /**
* Creates a changedAddressAttribute of the specified type and with the * Creates a changedAddressAttribute of the specified type and with the
* specified address and port * specified address and port
*
* @param address the address value of the address attribute * @param address the address value of the address attribute
* @return the newly created address attribute. * @return the newly created address attribute.
*/ */
public static ChangedAddressAttribute public static ChangedAddressAttribute createChangedAddressAttribute(
createChangedAddressAttribute(TransportAddress address) TransportAddress address)
{ {
ChangedAddressAttribute attribute = new ChangedAddressAttribute(); ChangedAddressAttribute attribute = new ChangedAddressAttribute();
@ -72,20 +75,18 @@ public class AttributeFactory
}; };
//------------------------------------ ERROR CODE ------------------------------
/** /**
* Creates an ErrorCodeAttribute with the specified error class and number * Creates an ErrorCodeAttribute with the specified error class and number
* and a default reason phrase. * and a default reason phrase.
*
* @param errorClass a valid error class. * @param errorClass a valid error class.
* @param errorNumber a valid error number. * @param errorNumber a valid error number.
* @return the newly created attribute. * @return the newly created attribute.
* @throws StunException if the error class or number have invalid values * @throws StunException if the error class or number have invalid values
* according to rfc3489. * according to rfc3489.
*/ */
public static ErrorCodeAttribute createErrorCodeAttribute( public static ErrorCodeAttribute createErrorCodeAttribute(byte errorClass,
byte errorClass, byte errorNumber)
byte errorNumber
)
throws StunException throws StunException
{ {
return createErrorCodeAttribute(errorClass, errorNumber, null); return createErrorCodeAttribute(errorClass, errorNumber, null);
@ -94,11 +95,12 @@ public class AttributeFactory
/** /**
* Creates an ErrorCodeAttribute with the specified error class, number and * Creates an ErrorCodeAttribute with the specified error class, number and
* reason phrase. * reason phrase.
*
* @param errorClass a valid error class. * @param errorClass a valid error class.
* @param errorNumber a valid error number. * @param errorNumber a valid error number.
* @param reasonPhrase a human readable reason phrase. A null reason phrase * @param reasonPhrase a human readable reason phrase. A null reason phrase
* would be replaced (if possible) by a default one * would be replaced (if possible) by a default one as defined byte the
* as defined byte the rfc3489. * rfc3489.
* @return the newly created attribute. * @return the newly created attribute.
* @throws StunException if the error class or number have invalid values * @throws StunException if the error class or number have invalid values
* according to rfc3489. * according to rfc3489.
@ -106,8 +108,7 @@ public class AttributeFactory
public static ErrorCodeAttribute createErrorCodeAttribute( public static ErrorCodeAttribute createErrorCodeAttribute(
byte errorClass, byte errorClass,
byte errorNumber, byte errorNumber,
String reasonPhrase String reasonPhrase)
)
throws StunException throws StunException
{ {
ErrorCodeAttribute attribute = new ErrorCodeAttribute(); ErrorCodeAttribute attribute = new ErrorCodeAttribute();
@ -115,8 +116,8 @@ public class AttributeFactory
attribute.setErrorClass(errorClass); attribute.setErrorClass(errorClass);
attribute.setErrorNumber(errorNumber); attribute.setErrorNumber(errorNumber);
attribute.setReasonPhrase(reasonPhrase==null? attribute.setReasonPhrase(reasonPhrase == null ? ErrorCodeAttribute
ErrorCodeAttribute.getDefaultReasonPhrase(attribute.getErrorCode()) .getDefaultReasonPhrase(attribute.getErrorCode())
: reasonPhrase); : reasonPhrase);
return attribute; return attribute;
@ -125,6 +126,7 @@ public class AttributeFactory
/** /**
* Creates an ErrorCodeAttribute with the specified error code and a default * Creates an ErrorCodeAttribute with the specified error code and a default
* reason phrase. * reason phrase.
*
* @param errorCode a valid error code. * @param errorCode a valid error code.
* @return the newly created attribute. * @return the newly created attribute.
* @throws StunException if errorCode is not a valid error code as defined * @throws StunException if errorCode is not a valid error code as defined
@ -139,11 +141,12 @@ public class AttributeFactory
/** /**
* Creates an ErrorCodeAttribute with the specified error code and reason * Creates an ErrorCodeAttribute with the specified error code and reason
* phrase. * phrase.
*
* @param errorCode a valid error code. * @param errorCode a valid error code.
* @param reasonPhrase a human readable reason phrase. A null reason phrase * @param reasonPhrase a human readable reason phrase. A null reason phrase
* would be replaced (if possible) by a default one * would be replaced (if possible) by a default one as defined byte the
* as defined byte the rfc3489. * rfc3489.
*
* @return the newly created attribute. * @return the newly created attribute.
* @throws StunException if errorCode is not a valid error code as defined * @throws StunException if errorCode is not a valid error code as defined
* by rfc3489 * by rfc3489
@ -156,19 +159,17 @@ public class AttributeFactory
ErrorCodeAttribute attribute = new ErrorCodeAttribute(); ErrorCodeAttribute attribute = new ErrorCodeAttribute();
attribute.setErrorCode(errorCode); attribute.setErrorCode(errorCode);
attribute.setReasonPhrase(reasonPhrase==null? attribute.setReasonPhrase(reasonPhrase == null ? ErrorCodeAttribute
ErrorCodeAttribute.getDefaultReasonPhrase(attribute.getErrorCode()) .getDefaultReasonPhrase(attribute.getErrorCode())
: reasonPhrase); : reasonPhrase);
return attribute; return attribute;
}; };
//------------------------------------ MAPPED ADDRESS --------------------------
/** /**
* Creates a MappedAddressAttribute of the specified type and with the * Creates a MappedAddressAttribute of the specified type and with the
* specified address and port * specified address and port
*
* @param address the address value of the address attribute * @param address the address value of the address attribute
* @return the newly created address attribute. * @return the newly created address attribute.
*/ */
@ -183,11 +184,10 @@ public class AttributeFactory
}; };
//------------------------------------ REFLECTED FROM --------------------------
/** /**
* Creates a ReflectedFromAddressAttribute of the specified type and with * Creates a ReflectedFromAddressAttribute of the specified type and with
* the specified address and port * the specified address and port
*
* @param address the address value of the address attribute * @param address the address value of the address attribute
* @return the newly created address attribute. * @return the newly created address attribute.
*/ */
@ -202,10 +202,12 @@ public class AttributeFactory
}; };
//------------------------------------ RESPONSE ADRESS ------------------------- // ------------------------------------ RESPONSE ADRESS
// -------------------------
/** /**
* Creates a ResponseFromAddressAttribute of the specified type and with * Creates a ResponseFromAddressAttribute of the specified type and with the
* the specified address and port * specified address and port
*
* @param address the address value of the address attribute * @param address the address value of the address attribute
* @return the newly created address attribute. * @return the newly created address attribute.
*/ */
@ -220,10 +222,12 @@ public class AttributeFactory
}; };
//------------------------------------ SOURCE ADDRESS -------------------------- // ------------------------------------ SOURCE ADDRESS
// --------------------------
/** /**
* Creates a SourceFromAddressAttribute of the specified type and with * Creates a SourceFromAddressAttribute of the specified type and with the
* the specified address and port * specified address and port
*
* @param address the address value of the address attribute * @param address the address value of the address attribute
* @return the newly created address attribute. * @return the newly created address attribute.
*/ */
@ -238,9 +242,11 @@ public class AttributeFactory
}; };
//------------------------------------ UNKNOWN ATTRIBUTES ---------------------- // ------------------------------------ UNKNOWN ATTRIBUTES
// ----------------------
/** /**
* Creates an empty UnknownAttributesAttribute. * Creates an empty UnknownAttributesAttribute.
*
* @return the newly created UnknownAttributesAttribute * @return the newly created UnknownAttributesAttribute
*/ */
public static UnknownAttributesAttribute createUnknownAttributesAttribute() public static UnknownAttributesAttribute createUnknownAttributesAttribute()
@ -250,10 +256,13 @@ public class AttributeFactory
return attribute; return attribute;
}; };
/* ------------------------------------ XOR-RELAYED-ADRESS attribute ------------------------ */ /*
* ------------------------------------ XOR-RELAYED-ADRESS attribute
* ------------------------
*/
/** /**
* Creates a XorRelayedAddressAttribute of the specified type and with * Creates a XorRelayedAddressAttribute of the specified type and with the
* the specified address and port. * specified address and port.
* *
* @param address the address value of the address attribute * @param address the address value of the address attribute
* @param tranID the ID of the transaction that we will be using for the XOR * @param tranID the ID of the transaction that we will be using for the XOR
@ -262,8 +271,7 @@ public class AttributeFactory
* @return the newly created address attribute. * @return the newly created address attribute.
*/ */
public static XorRelayedAddressAttribute createXorRelayedAddressAttribute( public static XorRelayedAddressAttribute createXorRelayedAddressAttribute(
TransportAddress address, TransportAddress address, byte[] tranID)
byte[] tranID)
{ {
XorRelayedAddressAttribute attribute = new XorRelayedAddressAttribute(); XorRelayedAddressAttribute attribute = new XorRelayedAddressAttribute();
@ -272,10 +280,13 @@ public class AttributeFactory
return attribute; return attribute;
} }
/* ------------------------------------ XOR-PEER-ADRESS attribute ------------------------ */ /*
* ------------------------------------ XOR-PEER-ADRESS attribute
* ------------------------
*/
/** /**
* Creates a XorPeerAddressAttribute of the specified type and with * Creates a XorPeerAddressAttribute of the specified type and with the
* the specified address and port * specified address and port
* *
* @param address the address value of the address attribute * @param address the address value of the address attribute
* @param tranID the ID of the transaction that we will be using for the XOR * @param tranID the ID of the transaction that we will be using for the XOR
@ -283,8 +294,7 @@ public class AttributeFactory
* @return the newly created address attribute. * @return the newly created address attribute.
*/ */
public static XorPeerAddressAttribute createXorPeerAddressAttribute( public static XorPeerAddressAttribute createXorPeerAddressAttribute(
TransportAddress address, TransportAddress address, byte[] tranID)
byte[] tranID)
{ {
XorPeerAddressAttribute attribute = new XorPeerAddressAttribute(); XorPeerAddressAttribute attribute = new XorPeerAddressAttribute();
@ -293,7 +303,8 @@ public class AttributeFactory
return attribute; return attribute;
} }
//------------------------------------ XOR MAPPED ADDRESS -------------------------- // ------------------------------------ XOR MAPPED ADDRESS
// --------------------------
/** /**
* Creates a XorMappedAddressAttribute for the specified <tt>address</tt>. * Creates a XorMappedAddressAttribute for the specified <tt>address</tt>.
* *
@ -304,8 +315,7 @@ public class AttributeFactory
* @return the newly created xor address attribute. * @return the newly created xor address attribute.
*/ */
public static XorMappedAddressAttribute createXorMappedAddressAttribute( public static XorMappedAddressAttribute createXorMappedAddressAttribute(
TransportAddress address, TransportAddress address, byte[] tranID)
byte[] tranID)
{ {
XorMappedAddressAttribute attribute = new XorMappedAddressAttribute(); XorMappedAddressAttribute attribute = new XorMappedAddressAttribute();
@ -315,9 +325,13 @@ public class AttributeFactory
}; };
/* --------------------------------- USERNAME attribute ----------------------------- */ /*
* --------------------------------- USERNAME attribute
* -----------------------------
*/
/** /**
* Create a UsernameAttribute. * Create a UsernameAttribute.
*
* @param username username value * @param username username value
* @return newly created UsernameAttribute * @return newly created UsernameAttribute
*/ */
@ -329,13 +343,18 @@ public class AttributeFactory
return attribute; return attribute;
} }
/* --------------------------------- CHANNEL-NUMBER attribute ----------------------------- */ /*
* --------------------------------- CHANNEL-NUMBER attribute
* -----------------------------
*/
/** /**
* Create a ChannelNumberAttribute. * Create a ChannelNumberAttribute.
*
* @param channelNumber channel number * @param channelNumber channel number
* @return newly created ChannelNumberAttribute * @return newly created ChannelNumberAttribute
*/ */
public static ChannelNumberAttribute createChannelNumberAttribute(char channelNumber) public static ChannelNumberAttribute createChannelNumberAttribute(
char channelNumber)
{ {
ChannelNumberAttribute attribute = new ChannelNumberAttribute(); ChannelNumberAttribute attribute = new ChannelNumberAttribute();
@ -343,9 +362,13 @@ public class AttributeFactory
return attribute; return attribute;
} }
/* --------------------------------- REALM attribute ----------------------------- */ /*
* --------------------------------- REALM attribute
* -----------------------------
*/
/** /**
* Create a RealmAttribute. * Create a RealmAttribute.
*
* @param realm realm value * @param realm realm value
* @return newly created RealmAttribute * @return newly created RealmAttribute
*/ */
@ -357,9 +380,13 @@ public class AttributeFactory
return attribute; return attribute;
} }
/* --------------------------------- NONCE attribute ----------------------------- */ /*
* --------------------------------- NONCE attribute
* -----------------------------
*/
/** /**
* Create a NonceAttribute. * Create a NonceAttribute.
*
* @param nonce nonce value * @param nonce nonce value
* @return newly created NonceAttribute * @return newly created NonceAttribute
*/ */
@ -371,9 +398,13 @@ public class AttributeFactory
return attribute; return attribute;
} }
/* --------------------------------- SOFTWARE attribute ----------------------------- */ /*
* --------------------------------- SOFTWARE attribute
* -----------------------------
*/
/** /**
* Create a SoftwareAttribute. * Create a SoftwareAttribute.
*
* @param software software value * @param software software value
* @return newly created SoftwareAttribute * @return newly created SoftwareAttribute
*/ */
@ -385,10 +416,10 @@ public class AttributeFactory
return attribute; return attribute;
} }
/* --------------------------------- EVEN-PORT attribute ---------------- */ /* --------------------------------- EVEN-PORT attribute ---------------- */
/** /**
* Create a EventAttribute. * Create a EventAttribute.
*
* @param rFlag R flag * @param rFlag R flag
* @return the newly created EventPortAttribute * @return the newly created EventPortAttribute
*/ */
@ -400,9 +431,13 @@ public class AttributeFactory
return attribute; return attribute;
} }
/* --------------------------------- LIFETIME attribute --------------------------- */ /*
* --------------------------------- LIFETIME attribute
* ---------------------------
*/
/** /**
* Create a LifetimeAttribute. * Create a LifetimeAttribute.
*
* @param lifetime lifetime value * @param lifetime lifetime value
* @return newly created LifetimeAttribute * @return newly created LifetimeAttribute
*/ */
@ -414,14 +449,19 @@ public class AttributeFactory
return attribute; return attribute;
} }
/* --------------------------------- REQUESTED-TRANSPORT attribute ---------------- */ /*
* --------------------------------- REQUESTED-TRANSPORT attribute
* ----------------
*/
/** /**
* Create a RequestedTransportAttribute. * Create a RequestedTransportAttribute.
*
* @param protocol transport protocol requested * @param protocol transport protocol requested
* @return newly created RequestedTransportAttribute * @return newly created RequestedTransportAttribute
*/ */
public static RequestedTransportAttribute createRequestedTransportAttribute(byte protocol) public static RequestedTransportAttribute createRequestedTransportAttribute(
byte protocol)
{ {
RequestedTransportAttribute attribute = new RequestedTransportAttribute(); RequestedTransportAttribute attribute = new RequestedTransportAttribute();
@ -429,13 +469,18 @@ public class AttributeFactory
return attribute; return attribute;
} }
/* -------------------------------- RESERVATION-TOKEN attribute -------------------- */ /*
* -------------------------------- RESERVATION-TOKEN attribute
* --------------------
*/
/** /**
* Create a ReservationTokenAttribute. * Create a ReservationTokenAttribute.
*
* @param token the token * @param token the token
* @return newly created RequestedTransportAttribute * @return newly created RequestedTransportAttribute
*/ */
public static ReservationTokenAttribute createReservationTokenAttribute(byte token[]) public static ReservationTokenAttribute createReservationTokenAttribute(
byte token[])
{ {
ReservationTokenAttribute attribute = new ReservationTokenAttribute(); ReservationTokenAttribute attribute = new ReservationTokenAttribute();
@ -443,9 +488,13 @@ public class AttributeFactory
return attribute; return attribute;
} }
/* -------------------------------- DATA attribute --------------------------------- */ /*
* -------------------------------- DATA attribute
* ---------------------------------
*/
/** /**
* Create a DataAtttribute. * Create a DataAtttribute.
*
* @param data the data * @param data the data
* @return newly created DataAttribute * @return newly created DataAttribute
*/ */
@ -457,18 +506,22 @@ public class AttributeFactory
return attribute; return attribute;
} }
//-------------------------------- ICE-CONTROLLED ATTRIBUTE ----------------------- // -------------------------------- ICE-CONTROLLED ATTRIBUTE
// -----------------------
/** /**
* Creates an IceControlledAttribute object with the specified tie-breaker value * Creates an IceControlledAttribute object with the specified tie-breaker
* value
* *
* @param tieBreaker the tie-breaker value to be used * @param tieBreaker the tie-breaker value to be used
* @return the created IceControlledAttribute * @return the created IceControlledAttribute
* @throws StunException if the value in tie-breaker is not valid * @throws IllegalArgumentException if the value in tie-breaker is not valid
*/ */
public static IceControlledAttribute createIceControlledAttribute(long tieBreaker) public static IceControlledAttribute createIceControlledAttribute(
throws StunException long tieBreaker)
throws IllegalArgumentException
{ {
// generating the network ordered byte stream of the tieBreaker long variable // generating the network ordered byte stream of the tieBreaker long
// variable
byte[] tieBreakerBytes = new byte[8]; byte[] tieBreakerBytes = new byte[8];
tieBreakerBytes[0] = (byte) (tieBreaker >> 56); tieBreakerBytes[0] = (byte) (tieBreaker >> 56);
tieBreakerBytes[1] = (byte) ((tieBreaker & 0x00FF000000000000L) >> 48); tieBreakerBytes[1] = (byte) ((tieBreaker & 0x00FF000000000000L) >> 48);
@ -485,17 +538,18 @@ public class AttributeFactory
return attribute; return attribute;
} }
//---------------------------------- PRIORITY ATTRIBUTE ----------------------- // ---------------------------------- PRIORITY ATTRIBUTE
// -----------------------
/** /**
* Creates a Priority attribute with the specified priority value * Creates a Priority attribute with the specified priority value
* *
* @param priority the priority value * @param priority the priority value
* @return the created PriorityAttribute * @return the created PriorityAttribute
* @throws StunException if priority < 0 or priority > (2^31 - 1) * @throws IllegalArgumentException if priority < 0 or priority > (2^31 - 1)
*/ */
public static PriorityAttribute createPriorityAttribute(long priority) public static PriorityAttribute createPriorityAttribute(long priority)
throws StunException throws IllegalArgumentException
{ {
PriorityAttribute attribute = new PriorityAttribute(); PriorityAttribute attribute = new PriorityAttribute();
@ -504,8 +558,6 @@ public class AttributeFactory
return attribute; return attribute;
} }
//--------------------------------- USE-CANDIDATE ATTRIBUTE ---------------------
/** /**
* Creates a UseCandidateAttribute * Creates a UseCandidateAttribute
* *
@ -524,12 +576,14 @@ public class AttributeFactory
* @param tieBreaker the tie-breaker value to be used * @param tieBreaker the tie-breaker value to be used
* *
* @return the created IceControllingAttribute * @return the created IceControllingAttribute
* @throws StunException of tie-breaker value is not valid * @throws IllegalArgumentException of tie-breaker value is not valid
*/ */
public static IceControllingAttribute createIceControllingAttribute(long tieBreaker) public static IceControllingAttribute createIceControllingAttribute(
throws StunException long tieBreaker)
throws IllegalArgumentException
{ {
// generating the network ordered byte stream of the tieBreaker long variable // generating the network ordered byte stream of the tieBreaker long
// variable
byte[] tieBreakerBytes = new byte[8]; byte[] tieBreakerBytes = new byte[8];
tieBreakerBytes[0] = (byte) (tieBreaker >> 56); tieBreakerBytes[0] = (byte) (tieBreaker >> 56);
tieBreakerBytes[1] = (byte) ((tieBreaker & 0x00FF000000000000L) >> 48); tieBreakerBytes[1] = (byte) ((tieBreaker & 0x00FF000000000000L) >> 48);
@ -546,4 +600,3 @@ public class AttributeFactory
return attribute; return attribute;
} }
} }

View File

@ -122,27 +122,25 @@ public class IceControlledAttribute
} }
/** /**
* Sets the Tie Breaker byte array to the specified byte array * Sets the <tt>tieBreaker</tt> byte array.
* An exact copy of the specified byte array is made
* *
* @param tieBreaker the byte array containing the 64 bit tie-breaker * @param tieBreaker the byte array containing the 64 bit tie-breaker
* value * value
* *
* @throws StunException if tieBreaker contains invalid data * @throws IllegalArgumentException if tieBreaker contains invalid data
*/ */
public void setTieBreaker(byte[] tieBreaker) public void setTieBreaker(byte[] tieBreaker)
throws StunException throws IllegalArgumentException
{ {
if(tieBreaker.length != DATA_LENGTH_ICE_CONTROLLED) if(tieBreaker.length != DATA_LENGTH_ICE_CONTROLLED)
{ {
throw new StunException(StunException.ILLEGAL_ARGUMENT, throw new IllegalArgumentException(
"The supplied byte array does not contain the correct number" "The supplied byte array does not contain the correct number"
+" of bytes"); +" of bytes");
} }
else else
{ {
//FIXME - uncomment. this.tieBreaker = tieBreaker;
//this.tieBreaker = Arrays.copyOf(tieBreaker, tieBreaker.length);
} }
} }
@ -153,16 +151,7 @@ public class IceControlledAttribute
*/ */
public byte[] getTieBreaker() public byte[] getTieBreaker()
{ {
if(tieBreaker == null) return tieBreaker;
{
return null;
}
else
{
//FIXME uncomment
//return Arrays.copyOf(tieBreaker, tieBreaker.length);
return null;
}
} }
} }

View File

@ -1,3 +1,9 @@
/*
* ice4j, the OpenSource Java Solution for NAT and Firewall Traversal.
* Maintained by the SIP Communicator community (http://sip-communicator.org).
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package org.ice4j.attribute; package org.ice4j.attribute;
import java.util.Arrays; import java.util.Arrays;
@ -122,22 +128,19 @@ public class IceControllingAttribute
* *
* @param tieBreaker the byte array containing the 64 bit tie-breaker value * @param tieBreaker the byte array containing the 64 bit tie-breaker value
* *
* @throws StunException if tieBreaker contains invalid data * @throws IllegalArgumentException if tieBreaker contains invalid data
*/ */
public void setTieBreaker(byte[] tieBreaker) public void setTieBreaker(byte[] tieBreaker)
throws StunException throws IllegalArgumentException
{ {
if(tieBreaker.length != DATA_LENGTH_ICE_CONTROLLING) if(tieBreaker.length != DATA_LENGTH_ICE_CONTROLLING)
{ {
throw new StunException(StunException.ILLEGAL_ARGUMENT, throw new IllegalArgumentException(
"The supplied byte array does not contain the correct number " "The supplied byte array does not contain the correct number "
+"of bytes"); +"of bytes");
} }
else
{ this.tieBreaker = tieBreaker;
//FIXME - uncomment
//this.tieBreaker = Arrays.copyOf(tieBreaker, tieBreaker.length);
}
} }
/** /**
@ -149,12 +152,8 @@ public class IceControllingAttribute
{ {
if(tieBreaker == null) if(tieBreaker == null)
return null; return null;
else
{ return tieBreaker;
//FIXME -- uncomment
//return Arrays.copyOf(tieBreaker, tieBreaker.length);
return null;
}
} }
} }

View File

@ -156,15 +156,17 @@ public class PriorityAttribute
* *
* @param priority the long variable specifying the priority value * @param priority the long variable specifying the priority value
* *
* @throws StunException throws StunException if indicated priority value is illegal * @throws IllegalArgumentException if indicated priority value is illegal.
*/ */
public void setPriority(long priority) public void setPriority(long priority)
throws StunException throws IllegalArgumentException
{ {
/* Priority must be between 1 and (2^31 - 1) */ /* Priority must be between 1 and (2^31 - 1) */
if(priority <= 0 || priority > 0x7FFFFFFFL) if(priority <= 0 || priority > 0x7FFFFFFFL)
throw new StunException(StunException.ILLEGAL_ARGUMENT, "Priority must be " + {
throw new IllegalArgumentException("Priority must be " +
"between 0 and (2**31 - 1)"); "between 0 and (2**31 - 1)");
}
else else
this.priority = priority; this.priority = priority;
} }

View File

@ -87,6 +87,16 @@ public class Agent
*/ */
private final String password; private final String password;
/**
* The user fragment that we received from the remote party.
*/
private String remoteUfrag;
/**
* The password that we received from the remote party.
*/
private String remotePassword;
/** /**
* The tie-breaker number is used in connectivity checks to detect and * The tie-breaker number is used in connectivity checks to detect and
* repair the case where both agents believe to have the controlling or the * repair the case where both agents believe to have the controlling or the
@ -236,12 +246,13 @@ public class Agent
List<IceMediaStream> streams = getStreams(); List<IceMediaStream> streams = getStreams();
ConnectivityCheckDispatcher client
= new ConnectivityCheckDispatcher(this);
for(IceMediaStream stream : streams) for(IceMediaStream stream : streams)
{ {
CheckList list = stream.getCheckList(); CheckList list = stream.getCheckList();
ConnectivityCheckDispatcher client = new ConnectivityCheckDispatcher(list); client.startChecks(list);
client.startChecks();
} }
} }
@ -324,6 +335,59 @@ public class Agent
return password; return password;
} }
/**
* Returns the user name that we received from the remote peer or
* <tt>null</tt> if we haven't received a user name from them yet.
*
* @return the user name that we received from the remote peer or
* <tt>null</tt> if we haven't received a user name from them yet.
*/
public String getRemoteUserName()
{
return remoteUfrag;
}
/**
* Returns the password that we received from the remote peer or
* <tt>null</tt> if we haven't received a password from them yet.
*
* @return the password that we received from the remote peer or
* <tt>null</tt> if we haven't received a password from them yet.
*/
public String getRemotePassword()
{
return remotePassword;
}
/**
* Specifies the user name that we received from the remote peer.
*
* @param remoteUfrag the user name that we received from the remote peer.
*/
public void setRemoteUserName(String remoteUfrag)
{
this.remoteUfrag = remoteUfrag;
}
/**
* Returns the
*/
public String generateUserName()
{
return getUserName();
}
/**
* Specifies the password that we received from the remote peer.
*
* @param remotePassword the user name that we received from the remote
* peer.
*/
public void setRemotePassword(String remotePassword)
{
this.remotePassword = remotePassword;
}
/** /**
* Returns the <tt>IceMediaStream</tt> with the specified <tt>name</tt> or * Returns the <tt>IceMediaStream</tt> with the specified <tt>name</tt> or
* <tt>null</tt> if no such stream has been registered with this * <tt>null</tt> if no such stream has been registered with this

View File

@ -314,21 +314,42 @@ public abstract class Candidate
* defined in the ICE specification.. * defined in the ICE specification..
*/ */
public long computePriority() public long computePriority()
{
this.priority = computePriorityForType(getType());
return this.priority;
}
/**
* Computes the priority this <tt>Candidate</tt> would have if it were of
* the specified <tt>candidateType</tt> and based on the procedures
* defined in the ICE specification. The reason we need this method in
* addition to the {@link #computePriority()} one is the need to be able
* to compute the priority of a peer reflexive <tt>candidate</tt> that we
* might learn during connectivity checks through this <tt>Candidate</tt>.
*
* @param candidateType the hypothetical type that we'd like to use when
* computing the priority for this <tt>Candidate</tt>.
*
* @return the priority this <tt>Candidate</tt> would have had if it were
* of the specified <tt>candidateType</tt>.
*/
public long computePriorityForType(CandidateType candidateType)
{ {
//According to the ICE speck we compute priority this way: //According to the ICE speck we compute priority this way:
//priority = (2^24)*(type preference) + //priority = (2^24)*(type preference) +
// (2^8)*(local preference) + // (2^8)*(local preference) +
// (2^0)*(256 - component ID) // (2^0)*(256 - component ID)
this.priority = (long)( getTypePreference() << 24 )+ return (long)( getTypePreference(candidateType) << 24 )+
(long)( getLocalPreference() << 8 )+ (long)( getLocalPreference() << 8 )+
(long) (256 - getParentComponent().getComponentID()); (long) (256 - getParentComponent().getComponentID());
return priority;
} }
/** /**
* Returns the type preference for this candidate according to its type. * Returns the type preference that should be used when computing priority
* for <tt>Candidate</tt>s of the specified <tt>candidateType</tt>.
* The type preference MUST be an integer from <tt>0</tt> to <tt>126</tt> * The type preference MUST be an integer from <tt>0</tt> to <tt>126</tt>
* inclusive, and represents the preference for the type of the candidate * inclusive, and represents the preference for the type of the candidate
* (where the types are local, server reflexive, peer reflexive and * (where the types are local, server reflexive, peer reflexive and
@ -340,13 +361,16 @@ public abstract class Candidate
* reflexive candidates MUST be higher than that of server reflexive * reflexive candidates MUST be higher than that of server reflexive
* candidates. * candidates.
* *
* @param candidateType the <tt>CandidateType</tt> that we'd like to obtain
* a preference for.
*
* @return the type preference for this <tt>Candidate</tt> as per the * @return the type preference for this <tt>Candidate</tt> as per the
* procedures in the ICE specification. * procedures in the ICE specification.
*/ */
private int getTypePreference() private static int getTypePreference(CandidateType candidateType)
{ {
int typePreference; int typePreference;
CandidateType candidateType = getType();
if(candidateType == CandidateType.HOST_CANDIDATE) if(candidateType == CandidateType.HOST_CANDIDATE)
{ {
typePreference = MAX_TYPE_PREFERENCE; // 126 typePreference = MAX_TYPE_PREFERENCE; // 126

View File

@ -10,6 +10,7 @@ import java.util.*;
import org.ice4j.*; import org.ice4j.*;
import org.ice4j.attribute.*; import org.ice4j.attribute.*;
import org.ice4j.stack.*;
/** /**
* This class represents a STUN message. STUN messages are TLV (type-length-value) * This class represents a STUN message. STUN messages are TLV (type-length-value)
@ -689,7 +690,7 @@ public abstract class Message
return getName()+"(0x"+Integer.toHexString(getMessageType()) return getName()+"(0x"+Integer.toHexString(getMessageType())
+")[attrib.count=" + getAttributeCount() +")[attrib.count=" + getAttributeCount()
+" len=" + (int) this.getDataLength() +" len=" + (int) this.getDataLength()
+" tranID=" + this.getTransactionID() + "]"; +" tranID=" + TransactionID.toString(getTransactionID()) + "]";
} }
} }

View File

@ -324,4 +324,18 @@ class StunServerTransaction
{ {
return requestSource; return requestSource;
} }
/**
* Returns the <tt>Response</tt> that the <tt>StunStack</tt> has sent
* through this transaction or <tt>null</tt> if no <tt>Response</tt> has
* been sent yet.
*
* @return the <tt>Response</tt> that the <tt>StunStack</tt> has sent
* through this transaction or <tt>null</tt> if no <tt>Response</tt> has
* been sent yet.
*/
protected Response getResponse()
{
return response;
}
} }

View File

@ -47,14 +47,16 @@ public class StunStack
/** /**
* Stores active client transactions mapped against TransactionID-s. * Stores active client transactions mapped against TransactionID-s.
*/ */
private final Hashtable<TransactionID, StunClientTransaction> clientTransactions private final Hashtable<TransactionID, StunClientTransaction>
clientTransactions
= new Hashtable<TransactionID, StunClientTransaction>(); = new Hashtable<TransactionID, StunClientTransaction>();
/** /**
* Currently open server transactions. The vector contains transaction ids * Currently open server transactions. The vector contains transaction ids
* for transactions corresponding to all non-answered received requests. * for transactions corresponding to all non-answered received requests.
*/ */
private final Hashtable<TransactionID, StunServerTransaction> serverTransactions private final Hashtable<TransactionID, StunServerTransaction>
serverTransactions
= new Hashtable<TransactionID, StunServerTransaction>(); = new Hashtable<TransactionID, StunServerTransaction>();
/** /**
@ -279,12 +281,21 @@ public class StunStack
StunServerTransaction sTran = StunServerTransaction sTran =
serverTransactions.get(tid); serverTransactions.get(tid);
if(sTran == null || sTran.isReransmitting()) if(sTran == null)
{ {
throw new StunException(StunException.TRANSACTION_DOES_NOT_EXIST, throw new StunException(StunException.TRANSACTION_DOES_NOT_EXIST,
"The transaction specified in the response " "The transaction specified in the response "
+ "object does not exist or has already " + "(tid="+ tid.toString() +") "
+ "transmitted a response."); + "object does not exist.");
}
else if( sTran.isReransmitting())
{
throw new StunException(StunException.TRANSACTION_DOES_NOT_EXIST,
"The transaction specified in the response "
+ "(tid="+ tid.toString() +") "
+ "has already seen a previous response. "
+ "Response was:\n"
+ sTran.getResponse());
} }
else else
{ {

View File

@ -143,24 +143,36 @@ public class TransactionID
/** /**
* Returns a string representation of the ID * Returns a string representation of the ID
*
* @return a hex string representing the id * @return a hex string representing the id
*/ */
public String toString() public String toString()
{
return TransactionID.toString(transactionID);
}
/**
* Returns a string representation of the ID
*
* @param transactionID the transaction ID to convert into <tt>String</tt>.
*
* @return a hex string representing the id
*/
public static String toString(byte[] transactionID)
{ {
StringBuffer idStr = new StringBuffer(); StringBuffer idStr = new StringBuffer();
idStr.append("0x");
for(int i = 0; i < transactionID.length; i++) for(int i = 0; i < transactionID.length; i++)
{ {
idStr.append("0x");
if((transactionID[i]&0xFF) <= 15) if((transactionID[i]&0xFF) <= 15)
{ {
idStr.append("0"); idStr.append("0");
} }
idStr.append(Integer.toHexString(transactionID[i]&0xff).toUpperCase()); idStr.append(Integer.toHexString(transactionID[i]&0xff)
.toUpperCase());
if(i < transactionID.length)
idStr.append(" ");
} }
return idStr.toString(); return idStr.toString();

View File

@ -1,8 +1,8 @@
/* /*
* Ice4j, the OpenSource Java Solution for NAT and Firewall Traversal. * ice4j, the OpenSource Java Solution for NAT and Firewall Traversal.
* Maintained by the SIP Communicator community (http://sip-communicator.org).
* *
* Distributable under LGPL license. * Distributable under LGPL license. See terms of license at gnu.org.
* See terms of license at gnu.org.
*/ */
package org.ice4j.attribute; package org.ice4j.attribute;
@ -15,7 +15,7 @@ import org.ice4j.attribute.*;
/** /**
* Tests the nonce attribute class. * Tests the nonce attribute class.
* <p>Organization Network Research Team, Louis Pasteur University</p> *
* @author Emil Ivov * @author Emil Ivov
* @author Sebastien Vincent * @author Sebastien Vincent
*/ */

View File

@ -1,8 +1,8 @@
/* /*
* Ice4j, the OpenSource Java Solution for NAT and Firewall Traversal. * ice4j, the OpenSource Java Solution for NAT and Firewall Traversal.
* Maintained by the SIP Communicator community (http://sip-communicator.org).
* *
* Distributable under LGPL license. * Distributable under LGPL license. See terms of license at gnu.org.
* See terms of license at gnu.org.
*/ */
package org.ice4j.attribute; package org.ice4j.attribute;
@ -15,7 +15,7 @@ import org.ice4j.attribute.*;
/** /**
* Tests the realm attribute class. * Tests the realm attribute class.
* <p>Organization Network Research Team, Louis Pasteur University</p> *
* @author Emil Ivov * @author Emil Ivov
* @author Sebastien Vincent * @author Sebastien Vincent
*/ */

View File

@ -1,8 +1,8 @@
/* /*
* Ice4j, the OpenSource Java Solution for NAT and Firewall Traversal. * ice4j, the OpenSource Java Solution for NAT and Firewall Traversal.
* Maintained by the SIP Communicator community (http://sip-communicator.org).
* *
* Distributable under LGPL license. * Distributable under LGPL license. See terms of license at gnu.org.
* See terms of license at gnu.org.
*/ */
package org.ice4j.attribute; package org.ice4j.attribute;
@ -11,11 +11,10 @@ import junit.framework.*;
import java.util.*; import java.util.*;
import org.ice4j.*; import org.ice4j.*;
import org.ice4j.attribute.*;
/** /**
* Tests the username attribute class. * Tests the username attribute class.
* <p>Organization Network Research Team, Louis Pasteur University</p> *
* @author Emil Ivov * @author Emil Ivov
* @author Sebastien Vincent * @author Sebastien Vincent
*/ */

View File

@ -41,6 +41,11 @@ public class Ice
long endTime = System.currentTimeMillis(); long endTime = System.currentTimeMillis();
transferRemoteCandidates(localAgent, remotePeer); transferRemoteCandidates(localAgent, remotePeer);
localAgent.setRemoteUserName(remotePeer.getUserName());
localAgent.setRemotePassword(remotePeer.getPassword());
remotePeer.setRemoteUserName(localAgent.getUserName());
remotePeer.setRemotePassword(localAgent.getPassword());
System.out.println("Total candidate gathering time: " System.out.println("Total candidate gathering time: "
+ (endTime - startTime) + "ms"); + (endTime - startTime) + "ms");