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.
* See terms of license at gnu.org.
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package org.ice4j.attribute;

View File

@ -9,8 +9,8 @@ package org.ice4j.attribute;
import org.ice4j.*;
/**
* This class provides factory methods to allow an application to create
* STUN / TURN / ICE Attributes from a particular implementation.
* This class provides factory methods to allow an application to create STUN /
* TURN / ICE Attributes from a particular implementation.
*
* @author Emil Ivov
* @author Sebastien Vincent
@ -22,28 +22,29 @@ public class AttributeFactory
{
}
//------------------------------------ CHANGE REQUEST --------------------------
// ------------------------------------ CHANGE REQUEST
// --------------------------
/**
* Creates a ChangeRequestAttribute with "false" values for the changeIP and
* changePort flags.
*
* @return the newly created ChangeRequestAttribute.
*/
public static ChangeRequestAttribute
createChangeRequestAttribute()
public static ChangeRequestAttribute createChangeRequestAttribute()
{
return createChangeRequestAttribute(false, false);
};
/**
* 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.
* @return the newly created ChangeRequestAttribute.
*/
public static ChangeRequestAttribute
createChangeRequestAttribute(boolean changeIP,
boolean changePort)
public static ChangeRequestAttribute createChangeRequestAttribute(
boolean changeIP, boolean changePort)
{
ChangeRequestAttribute attribute = new ChangeRequestAttribute();
@ -53,18 +54,20 @@ public class AttributeFactory
return attribute;
};
//------------------------------------ CHANGED ADDRESS -------------------------
// ------------------------------------ CHANGED ADDRESS
// -------------------------
/**
* Creates a changedAddressAttribute of the specified type and with the
* specified address and port
*
* @param address the address value of the address attribute
* @return the newly created address attribute.
*/
public static ChangedAddressAttribute
createChangedAddressAttribute(TransportAddress address)
public static ChangedAddressAttribute createChangedAddressAttribute(
TransportAddress address)
{
ChangedAddressAttribute attribute= new ChangedAddressAttribute();
ChangedAddressAttribute attribute = new ChangedAddressAttribute();
attribute.setAddress(address);
@ -72,20 +75,18 @@ public class AttributeFactory
};
//------------------------------------ ERROR CODE ------------------------------
/**
* Creates an ErrorCodeAttribute with the specified error class and number
* and a default reason phrase.
*
* @param errorClass a valid error class.
* @param errorNumber a valid error number.
* @return the newly created attribute.
* @throws StunException if the error class or number have invalid values
* according to rfc3489.
*/
public static ErrorCodeAttribute createErrorCodeAttribute(
byte errorClass,
byte errorNumber
)
public static ErrorCodeAttribute createErrorCodeAttribute(byte errorClass,
byte errorNumber)
throws StunException
{
return createErrorCodeAttribute(errorClass, errorNumber, null);
@ -94,20 +95,20 @@ public class AttributeFactory
/**
* Creates an ErrorCodeAttribute with the specified error class, number and
* reason phrase.
*
* @param errorClass a valid error class.
* @param errorNumber a valid error number.
* @param reasonPhrase a human readable reason phrase. A null reason phrase
* would be replaced (if possible) by a default one
* as defined byte the rfc3489.
* would be replaced (if possible) by a default one as defined byte the
* rfc3489.
* @return the newly created attribute.
* @throws StunException if the error class or number have invalid values
* according to rfc3489.
*/
public static ErrorCodeAttribute createErrorCodeAttribute(
byte errorClass,
byte errorNumber,
String reasonPhrase
)
byte errorClass,
byte errorNumber,
String reasonPhrase)
throws StunException
{
ErrorCodeAttribute attribute = new ErrorCodeAttribute();
@ -115,9 +116,9 @@ public class AttributeFactory
attribute.setErrorClass(errorClass);
attribute.setErrorNumber(errorNumber);
attribute.setReasonPhrase(reasonPhrase==null?
ErrorCodeAttribute.getDefaultReasonPhrase(attribute.getErrorCode())
:reasonPhrase);
attribute.setReasonPhrase(reasonPhrase == null ? ErrorCodeAttribute
.getDefaultReasonPhrase(attribute.getErrorCode())
: reasonPhrase);
return attribute;
};
@ -125,13 +126,14 @@ public class AttributeFactory
/**
* Creates an ErrorCodeAttribute with the specified error code and a default
* reason phrase.
*
* @param errorCode a valid error code.
* @return the newly created attribute.
* @throws StunException if errorCode is not a valid error code as defined
* by rfc3489
*/
public static ErrorCodeAttribute createErrorCodeAttribute(char errorCode)
throws StunException
throws StunException
{
return createErrorCodeAttribute(errorCode, null);
};
@ -139,41 +141,40 @@ public class AttributeFactory
/**
* Creates an ErrorCodeAttribute with the specified error code and reason
* phrase.
*
* @param errorCode a valid error code.
* @param reasonPhrase a human readable reason phrase. A null reason phrase
* would be replaced (if possible) by a default one
* as defined byte the rfc3489.
* would be replaced (if possible) by a default one as defined byte the
* rfc3489.
*
* @return the newly created attribute.
* @throws StunException if errorCode is not a valid error code as defined
* by rfc3489
*/
public static ErrorCodeAttribute createErrorCodeAttribute(
char errorCode,
String reasonPhrase)
char errorCode,
String reasonPhrase)
throws StunException
{
ErrorCodeAttribute attribute = new ErrorCodeAttribute();
attribute.setErrorCode(errorCode);
attribute.setReasonPhrase(reasonPhrase==null?
ErrorCodeAttribute.getDefaultReasonPhrase(attribute.getErrorCode())
:reasonPhrase);
attribute.setReasonPhrase(reasonPhrase == null ? ErrorCodeAttribute
.getDefaultReasonPhrase(attribute.getErrorCode())
: reasonPhrase);
return attribute;
};
//------------------------------------ MAPPED ADDRESS --------------------------
/**
* Creates a MappedAddressAttribute of the specified type and with the
* specified address and port
*
* @param address the address value of the address attribute
* @return the newly created address attribute.
*/
public static MappedAddressAttribute createMappedAddressAttribute(
TransportAddress address)
TransportAddress address)
{
MappedAddressAttribute attribute = new MappedAddressAttribute();
@ -183,16 +184,15 @@ public class AttributeFactory
};
//------------------------------------ REFLECTED FROM --------------------------
/**
* Creates a ReflectedFromAddressAttribute of the specified type and with
* the specified address and port
*
* @param address the address value of the address attribute
* @return the newly created address attribute.
*/
public static ReflectedFromAttribute createReflectedFromAttribute(
TransportAddress address)
TransportAddress address)
{
ReflectedFromAttribute attribute = new ReflectedFromAttribute();
@ -202,15 +202,17 @@ public class AttributeFactory
};
//------------------------------------ RESPONSE ADRESS -------------------------
// ------------------------------------ RESPONSE ADRESS
// -------------------------
/**
* Creates a ResponseFromAddressAttribute of the specified type and with
* the specified address and port
* Creates a ResponseFromAddressAttribute of the specified type and with the
* specified address and port
*
* @param address the address value of the address attribute
* @return the newly created address attribute.
*/
public static ResponseAddressAttribute createResponseAddressAttribute(
TransportAddress address)
TransportAddress address)
{
ResponseAddressAttribute attribute = new ResponseAddressAttribute();
@ -220,15 +222,17 @@ public class AttributeFactory
};
//------------------------------------ SOURCE ADDRESS --------------------------
// ------------------------------------ SOURCE ADDRESS
// --------------------------
/**
* Creates a SourceFromAddressAttribute of the specified type and with
* the specified address and port
* Creates a SourceFromAddressAttribute of the specified type and with the
* specified address and port
*
* @param address the address value of the address attribute
* @return the newly created address attribute.
*/
public static SourceAddressAttribute createSourceAddressAttribute(
TransportAddress address)
TransportAddress address)
{
SourceAddressAttribute attribute = new SourceAddressAttribute();
@ -238,9 +242,11 @@ public class AttributeFactory
};
//------------------------------------ UNKNOWN ATTRIBUTES ----------------------
// ------------------------------------ UNKNOWN ATTRIBUTES
// ----------------------
/**
* Creates an empty UnknownAttributesAttribute.
*
* @return the newly created UnknownAttributesAttribute
*/
public static UnknownAttributesAttribute createUnknownAttributesAttribute()
@ -250,10 +256,13 @@ public class AttributeFactory
return attribute;
};
/* ------------------------------------ XOR-RELAYED-ADRESS attribute ------------------------ */
/*
* ------------------------------------ XOR-RELAYED-ADRESS attribute
* ------------------------
*/
/**
* Creates a XorRelayedAddressAttribute of the specified type and with
* the specified address and port.
* Creates a XorRelayedAddressAttribute of the specified type and with the
* specified address and port.
*
* @param address the address value of the address attribute
* @param tranID the ID of the transaction that we will be using for the XOR
@ -262,20 +271,22 @@ public class AttributeFactory
* @return the newly created address attribute.
*/
public static XorRelayedAddressAttribute createXorRelayedAddressAttribute(
TransportAddress address,
byte[] tranID)
TransportAddress address, byte[] tranID)
{
XorRelayedAddressAttribute attribute = new XorRelayedAddressAttribute();
//TODO (Emil): shouldn't we be XORing the address before setting it?
// TODO (Emil): shouldn't we be XORing the address before setting it?
attribute.setAddress(address, tranID);
return attribute;
}
/* ------------------------------------ XOR-PEER-ADRESS attribute ------------------------ */
/*
* ------------------------------------ XOR-PEER-ADRESS attribute
* ------------------------
*/
/**
* Creates a XorPeerAddressAttribute of the specified type and with
* the specified address and port
* Creates a XorPeerAddressAttribute of the specified type and with the
* specified address and port
*
* @param address the address value of the address attribute
* @param tranID the ID of the transaction that we will be using for the XOR
@ -283,17 +294,17 @@ public class AttributeFactory
* @return the newly created address attribute.
*/
public static XorPeerAddressAttribute createXorPeerAddressAttribute(
TransportAddress address,
byte[] tranID)
TransportAddress address, byte[] tranID)
{
XorPeerAddressAttribute attribute = new XorPeerAddressAttribute();
//TODO (Emil): shouldn't we be XORing the address before setting it?
// TODO (Emil): shouldn't we be XORing the address before setting it?
attribute.setAddress(address, tranID);
return attribute;
}
//------------------------------------ XOR MAPPED ADDRESS --------------------------
// ------------------------------------ XOR MAPPED ADDRESS
// --------------------------
/**
* Creates a XorMappedAddressAttribute for the specified <tt>address</tt>.
*
@ -304,8 +315,7 @@ public class AttributeFactory
* @return the newly created xor address attribute.
*/
public static XorMappedAddressAttribute createXorMappedAddressAttribute(
TransportAddress address,
byte[] tranID)
TransportAddress address, byte[] tranID)
{
XorMappedAddressAttribute attribute = new XorMappedAddressAttribute();
@ -315,235 +325,278 @@ public class AttributeFactory
};
/* --------------------------------- USERNAME attribute ----------------------------- */
/*
* --------------------------------- USERNAME attribute
* -----------------------------
*/
/**
* Create a UsernameAttribute.
*
* @param username username value
* @return newly created UsernameAttribute
*/
public static UsernameAttribute createUsernameAttribute(byte username[])
{
UsernameAttribute attribute = new UsernameAttribute();
UsernameAttribute attribute = new UsernameAttribute();
attribute.setUsername(username);
return attribute;
attribute.setUsername(username);
return attribute;
}
/* --------------------------------- CHANNEL-NUMBER attribute ----------------------------- */
/*
* --------------------------------- CHANNEL-NUMBER attribute
* -----------------------------
*/
/**
* Create a ChannelNumberAttribute.
*
* @param channelNumber channel number
* @return newly created ChannelNumberAttribute
*/
public static ChannelNumberAttribute createChannelNumberAttribute(char channelNumber)
public static ChannelNumberAttribute createChannelNumberAttribute(
char channelNumber)
{
ChannelNumberAttribute attribute = new ChannelNumberAttribute();
ChannelNumberAttribute attribute = new ChannelNumberAttribute();
attribute.setChannelNumber(channelNumber);
return attribute;
attribute.setChannelNumber(channelNumber);
return attribute;
}
/* --------------------------------- REALM attribute ----------------------------- */
/*
* --------------------------------- REALM attribute
* -----------------------------
*/
/**
* Create a RealmAttribute.
*
* @param realm realm value
* @return newly created RealmAttribute
*/
public static RealmAttribute createRealmAttribute(byte realm[])
{
RealmAttribute attribute = new RealmAttribute();
RealmAttribute attribute = new RealmAttribute();
attribute.setRealm(realm);
return attribute;
attribute.setRealm(realm);
return attribute;
}
/* --------------------------------- NONCE attribute ----------------------------- */
/*
* --------------------------------- NONCE attribute
* -----------------------------
*/
/**
* Create a NonceAttribute.
*
* @param nonce nonce value
* @return newly created NonceAttribute
*/
public static NonceAttribute createNonceAttribute(byte nonce[])
{
NonceAttribute attribute = new NonceAttribute();
NonceAttribute attribute = new NonceAttribute();
attribute.setNonce(nonce);
return attribute;
attribute.setNonce(nonce);
return attribute;
}
/* --------------------------------- SOFTWARE attribute ----------------------------- */
/*
* --------------------------------- SOFTWARE attribute
* -----------------------------
*/
/**
* Create a SoftwareAttribute.
*
* @param software software value
* @return newly created SoftwareAttribute
*/
public static SoftwareAttribute createSoftwareAttribute(byte software[])
{
SoftwareAttribute attribute = new SoftwareAttribute();
SoftwareAttribute attribute = new SoftwareAttribute();
attribute.setSoftware(software);
return attribute;
attribute.setSoftware(software);
return attribute;
}
/* --------------------------------- EVEN-PORT attribute ---------------- */
/* --------------------------------- EVEN-PORT attribute ---------------- */
/**
* Create a EventAttribute.
*
* @param rFlag R flag
* @return the newly created EventPortAttribute
*/
public static EvenPortAttribute createEvenPortAttribute(boolean rFlag)
{
EvenPortAttribute attribute = new EvenPortAttribute();
EvenPortAttribute attribute = new EvenPortAttribute();
attribute.setRFlag(rFlag);
return attribute;
attribute.setRFlag(rFlag);
return attribute;
}
/* --------------------------------- LIFETIME attribute --------------------------- */
/*
* --------------------------------- LIFETIME attribute
* ---------------------------
*/
/**
* Create a LifetimeAttribute.
*
* @param lifetime lifetime value
* @return newly created LifetimeAttribute
*/
public static LifetimeAttribute createLifetimeAttribute(int lifetime)
{
LifetimeAttribute attribute = new LifetimeAttribute();
LifetimeAttribute attribute = new LifetimeAttribute();
attribute.setLifetime(lifetime);
return attribute;
attribute.setLifetime(lifetime);
return attribute;
}
/* --------------------------------- REQUESTED-TRANSPORT attribute ---------------- */
/*
* --------------------------------- REQUESTED-TRANSPORT attribute
* ----------------
*/
/**
* Create a RequestedTransportAttribute.
*
* @param protocol transport protocol requested
* @return newly created RequestedTransportAttribute
*/
public static RequestedTransportAttribute createRequestedTransportAttribute(byte protocol)
public static RequestedTransportAttribute createRequestedTransportAttribute(
byte protocol)
{
RequestedTransportAttribute attribute = new RequestedTransportAttribute();
RequestedTransportAttribute attribute = new RequestedTransportAttribute();
attribute.setRequestedTransport(protocol);
return attribute;
attribute.setRequestedTransport(protocol);
return attribute;
}
/* -------------------------------- RESERVATION-TOKEN attribute -------------------- */
/*
* -------------------------------- RESERVATION-TOKEN attribute
* --------------------
*/
/**
* Create a ReservationTokenAttribute.
*
* @param token the token
* @return newly created RequestedTransportAttribute
*/
public static ReservationTokenAttribute createReservationTokenAttribute(byte token[])
public static ReservationTokenAttribute createReservationTokenAttribute(
byte token[])
{
ReservationTokenAttribute attribute = new ReservationTokenAttribute();
ReservationTokenAttribute attribute = new ReservationTokenAttribute();
attribute.setReservationToken(token);
return attribute;
attribute.setReservationToken(token);
return attribute;
}
/* -------------------------------- DATA attribute --------------------------------- */
/*
* -------------------------------- DATA attribute
* ---------------------------------
*/
/**
* Create a DataAtttribute.
*
* @param data the data
* @return newly created DataAttribute
*/
public static DataAttribute createDataAttribute(byte data[])
{
DataAttribute attribute = new DataAttribute();
DataAttribute attribute = new DataAttribute();
attribute.setData(data);
return attribute;
attribute.setData(data);
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
* @return the created IceControlledAttribute
* @throws StunException if the value in tie-breaker is not valid
* @param tieBreaker the tie-breaker value to be used
* @return the created IceControlledAttribute
* @throws IllegalArgumentException if the value in tie-breaker is not valid
*/
public static IceControlledAttribute createIceControlledAttribute(long tieBreaker)
throws StunException
public static IceControlledAttribute createIceControlledAttribute(
long tieBreaker)
throws IllegalArgumentException
{
// generating the network ordered byte stream of the tieBreaker long variable
byte[] tieBreakerBytes = new byte[8];
tieBreakerBytes[0] = (byte)(tieBreaker>>56);
tieBreakerBytes[1] = (byte)((tieBreaker & 0x00FF000000000000L) >> 48);
tieBreakerBytes[2] = (byte)((tieBreaker & 0x0000FF0000000000L) >> 40);
tieBreakerBytes[3] = (byte)((tieBreaker & 0x000000FF00000000L) >> 32);
tieBreakerBytes[4] = (byte)((tieBreaker & 0x00000000FF000000L) >> 24);
tieBreakerBytes[5] = (byte)((tieBreaker & 0x0000000000FF0000L) >> 16);
tieBreakerBytes[6] = (byte)((tieBreaker & 0x000000000000FF00L) >> 8);
tieBreakerBytes[7] = (byte)((tieBreaker & 0x00000000000000FFL));
// generating the network ordered byte stream of the tieBreaker long
// variable
byte[] tieBreakerBytes = new byte[8];
tieBreakerBytes[0] = (byte) (tieBreaker >> 56);
tieBreakerBytes[1] = (byte) ((tieBreaker & 0x00FF000000000000L) >> 48);
tieBreakerBytes[2] = (byte) ((tieBreaker & 0x0000FF0000000000L) >> 40);
tieBreakerBytes[3] = (byte) ((tieBreaker & 0x000000FF00000000L) >> 32);
tieBreakerBytes[4] = (byte) ((tieBreaker & 0x00000000FF000000L) >> 24);
tieBreakerBytes[5] = (byte) ((tieBreaker & 0x0000000000FF0000L) >> 16);
tieBreakerBytes[6] = (byte) ((tieBreaker & 0x000000000000FF00L) >> 8);
tieBreakerBytes[7] = (byte) ((tieBreaker & 0x00000000000000FFL));
IceControlledAttribute attribute = new IceControlledAttribute();
attribute.setTieBreaker(tieBreakerBytes);
IceControlledAttribute attribute = new IceControlledAttribute();
attribute.setTieBreaker(tieBreakerBytes);
return attribute;
return attribute;
}
//---------------------------------- PRIORITY ATTRIBUTE -----------------------
// ---------------------------------- PRIORITY ATTRIBUTE
// -----------------------
/**
* Creates a Priority attribute with the specified priority value
*
* @param priority the priority value
* @return the created PriorityAttribute
* @throws StunException if priority < 0 or priority > (2^31 - 1)
* @param priority the priority value
* @return the created PriorityAttribute
* @throws IllegalArgumentException if priority < 0 or priority > (2^31 - 1)
*/
public static PriorityAttribute createPriorityAttribute(long priority)
throws StunException
throws IllegalArgumentException
{
PriorityAttribute attribute = new PriorityAttribute();
PriorityAttribute attribute = new PriorityAttribute();
attribute.setPriority(priority);
attribute.setPriority(priority);
return attribute;
return attribute;
}
//--------------------------------- USE-CANDIDATE ATTRIBUTE ---------------------
/**
* Creates a UseCandidateAttribute
*
* @return the created UseCandidateAttribute
* @return the created UseCandidateAttribute
*/
public static UseCandidateAttribute createUseCandidateAttribute()
{
UseCandidateAttribute attribute = new UseCandidateAttribute();
UseCandidateAttribute attribute = new UseCandidateAttribute();
return attribute;
return attribute;
}
/**
* Creates an IceControllingAttribute 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 IceControllingAttribute
* @throws StunException of tie-breaker value is not valid
* @return the created IceControllingAttribute
* @throws IllegalArgumentException of tie-breaker value is not valid
*/
public static IceControllingAttribute createIceControllingAttribute(long tieBreaker)
throws StunException
public static IceControllingAttribute createIceControllingAttribute(
long tieBreaker)
throws IllegalArgumentException
{
// generating the network ordered byte stream of the tieBreaker long variable
byte[] tieBreakerBytes = new byte[8];
tieBreakerBytes[0] = (byte)(tieBreaker>>56);
tieBreakerBytes[1] = (byte)((tieBreaker & 0x00FF000000000000L) >> 48);
tieBreakerBytes[2] = (byte)((tieBreaker & 0x0000FF0000000000L) >> 40);
tieBreakerBytes[3] = (byte)((tieBreaker & 0x000000FF00000000L) >> 32);
tieBreakerBytes[4] = (byte)((tieBreaker & 0x00000000FF000000L) >> 24);
tieBreakerBytes[5] = (byte)((tieBreaker & 0x0000000000FF0000L) >> 16);
tieBreakerBytes[6] = (byte)((tieBreaker & 0x000000000000FF00L) >> 8);
tieBreakerBytes[7] = (byte)((tieBreaker & 0x00000000000000FFL));
// generating the network ordered byte stream of the tieBreaker long
// variable
byte[] tieBreakerBytes = new byte[8];
tieBreakerBytes[0] = (byte) (tieBreaker >> 56);
tieBreakerBytes[1] = (byte) ((tieBreaker & 0x00FF000000000000L) >> 48);
tieBreakerBytes[2] = (byte) ((tieBreaker & 0x0000FF0000000000L) >> 40);
tieBreakerBytes[3] = (byte) ((tieBreaker & 0x000000FF00000000L) >> 32);
tieBreakerBytes[4] = (byte) ((tieBreaker & 0x00000000FF000000L) >> 24);
tieBreakerBytes[5] = (byte) ((tieBreaker & 0x0000000000FF0000L) >> 16);
tieBreakerBytes[6] = (byte) ((tieBreaker & 0x000000000000FF00L) >> 8);
tieBreakerBytes[7] = (byte) ((tieBreaker & 0x00000000000000FFL));
IceControllingAttribute attribute = new IceControllingAttribute();
attribute.setTieBreaker(tieBreakerBytes);
IceControllingAttribute attribute = new IceControllingAttribute();
attribute.setTieBreaker(tieBreakerBytes);
return attribute;
return attribute;
}
}

View File

@ -122,27 +122,25 @@ public class IceControlledAttribute
}
/**
* Sets the Tie Breaker byte array to the specified byte array
* An exact copy of the specified byte array is made
* Sets the <tt>tieBreaker</tt> byte array.
*
* @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)
throws StunException
throws IllegalArgumentException
{
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"
+" of bytes");
}
else
{
//FIXME - uncomment.
//this.tieBreaker = Arrays.copyOf(tieBreaker, tieBreaker.length);
this.tieBreaker = tieBreaker;
}
}
@ -153,16 +151,7 @@ public class IceControlledAttribute
*/
public byte[] getTieBreaker()
{
if(tieBreaker == null)
{
return null;
}
else
{
//FIXME uncomment
//return Arrays.copyOf(tieBreaker, tieBreaker.length);
return null;
}
return tieBreaker;
}
}

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;
import java.util.Arrays;
@ -120,24 +126,21 @@ public class IceControllingAttribute
* Sets the Tie Breaker byte array to the specified byte array
* An exact copy of the specified byte array is made
*
* @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)
throws StunException
throws IllegalArgumentException
{
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 "
+"of bytes");
}
else
{
//FIXME - uncomment
//this.tieBreaker = Arrays.copyOf(tieBreaker, tieBreaker.length);
}
this.tieBreaker = tieBreaker;
}
/**
@ -149,12 +152,8 @@ public class IceControllingAttribute
{
if(tieBreaker == null)
return null;
else
{
//FIXME -- uncomment
//return Arrays.copyOf(tieBreaker, tieBreaker.length);
return null;
}
return tieBreaker;
}
}

View File

@ -154,17 +154,19 @@ public class PriorityAttribute
/**
* Sets the priority of the PRIORITY Attribute with the specified value
*
* @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)
throws StunException
throws IllegalArgumentException
{
/* Priority must be between 1 and (2^31 - 1) */
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)");
}
else
this.priority = priority;
}

View File

@ -87,6 +87,16 @@ public class Agent
*/
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
* repair the case where both agents believe to have the controlling or the
@ -236,12 +246,13 @@ public class Agent
List<IceMediaStream> streams = getStreams();
ConnectivityCheckDispatcher client
= new ConnectivityCheckDispatcher(this);
for(IceMediaStream stream : streams)
{
CheckList list = stream.getCheckList();
ConnectivityCheckDispatcher client = new ConnectivityCheckDispatcher(list);
client.startChecks();
client.startChecks(list);
}
}
@ -324,6 +335,59 @@ public class Agent
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
* <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..
*/
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:
//priority = (2^24)*(type preference) +
// (2^8)*(local preference) +
// (2^0)*(256 - component ID)
this.priority = (long)( getTypePreference() << 24 )+
(long)( getLocalPreference() << 8 )+
(long) (256 - getParentComponent().getComponentID());
return (long)( getTypePreference(candidateType) << 24 )+
(long)( getLocalPreference() << 8 )+
(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>
* inclusive, and represents the preference for the type of the candidate
* (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
* 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
* procedures in the ICE specification.
*/
private int getTypePreference()
private static int getTypePreference(CandidateType candidateType)
{
int typePreference;
CandidateType candidateType = getType();
if(candidateType == CandidateType.HOST_CANDIDATE)
{
typePreference = MAX_TYPE_PREFERENCE; // 126

View File

@ -10,6 +10,7 @@ import java.util.*;
import org.ice4j.*;
import org.ice4j.attribute.*;
import org.ice4j.stack.*;
/**
* 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())
+")[attrib.count=" + getAttributeCount()
+" len=" + (int) this.getDataLength()
+" tranID=" + this.getTransactionID() + "]";
+" tranID=" + TransactionID.toString(getTransactionID()) + "]";
}
}

View File

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

View File

@ -143,24 +143,36 @@ public class TransactionID
/**
* Returns a string representation of the ID
*
* @return a hex string representing the id
*/
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();
idStr.append("0x");
for(int i = 0; i < transactionID.length; i++)
{
idStr.append("0x");
if((transactionID[i]&0xFF) <= 15)
{
idStr.append("0");
}
idStr.append(Integer.toHexString(transactionID[i]&0xff).toUpperCase());
if(i < transactionID.length)
idStr.append(" ");
idStr.append(Integer.toHexString(transactionID[i]&0xff)
.toUpperCase());
}
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.
* See terms of license at gnu.org.
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package org.ice4j.attribute;
@ -15,7 +15,7 @@ import org.ice4j.attribute.*;
/**
* Tests the nonce attribute class.
* <p>Organization Network Research Team, Louis Pasteur University</p>
*
* @author Emil Ivov
* @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.
* See terms of license at gnu.org.
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package org.ice4j.attribute;
@ -15,7 +15,7 @@ import org.ice4j.attribute.*;
/**
* Tests the realm attribute class.
* <p>Organization Network Research Team, Louis Pasteur University</p>
*
* @author Emil Ivov
* @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.
* See terms of license at gnu.org.
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package org.ice4j.attribute;
@ -11,11 +11,10 @@ import junit.framework.*;
import java.util.*;
import org.ice4j.*;
import org.ice4j.attribute.*;
/**
* Tests the username attribute class.
* <p>Organization Network Research Team, Louis Pasteur University</p>
*
* @author Emil Ivov
* @author Sebastien Vincent
*/

View File

@ -41,6 +41,11 @@ public class Ice
long endTime = System.currentTimeMillis();
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: "
+ (endTime - startTime) + "ms");