[ice4j] r131 committed - Ongoing work on connectivity checks. Support for user names in connect...

ice4j at googlecode.com ice4j at googlecode.com
Sun Apr 25 17:04:55 CEST 2010


Revision: 131
Author: emcho at sip-communicator.org
Date: Sun Apr 25 07:42:10 2010
Log: Ongoing work on connectivity checks. Support for user names in  
connectivity checks
http://code.google.com/p/ice4j/source/detail?r=131

Modified:
  /trunk/src/org/ice4j/attribute/AlternateServerAttribute.java
  /trunk/src/org/ice4j/attribute/AttributeFactory.java
  /trunk/src/org/ice4j/attribute/IceControlledAttribute.java
  /trunk/src/org/ice4j/attribute/IceControllingAttribute.java
  /trunk/src/org/ice4j/attribute/PriorityAttribute.java
  /trunk/src/org/ice4j/ice/Agent.java
  /trunk/src/org/ice4j/ice/Candidate.java
  /trunk/src/org/ice4j/message/Message.java
  /trunk/src/org/ice4j/stack/StunServerTransaction.java
  /trunk/src/org/ice4j/stack/StunStack.java
  /trunk/src/org/ice4j/stack/TransactionID.java
  /trunk/test/org/ice4j/attribute/NonceAttributeTest.java
  /trunk/test/org/ice4j/attribute/RealmAttributeTest.java
  /trunk/test/org/ice4j/attribute/UsernameAttributeTest.java
  /trunk/test/test/Ice.java

=======================================
--- /trunk/src/org/ice4j/attribute/AlternateServerAttribute.java	Sun Apr 25  
07:40:58 2010
+++ /trunk/src/org/ice4j/attribute/AlternateServerAttribute.java	Sun Apr 25  
07:42:10 2010
@@ -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;

=======================================
--- /trunk/src/org/ice4j/attribute/AttributeFactory.java	Sun Apr 25  
07:40:58 2010
+++ /trunk/src/org/ice4j/attribute/AttributeFactory.java	Sun Apr 25  
07:42:10 2010
@@ -9,8 +9,8 @@
  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 @@
      {
      }

-//------------------------------------ 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 @@
          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)
-    {
-        ChangedAddressAttribute attribute= new ChangedAddressAttribute();
+    public static ChangedAddressAttribute createChangedAddressAttribute(
+                    TransportAddress address)
+    {
+        ChangedAddressAttribute attribute = new ChangedAddressAttribute();

          attribute.setAddress(address);

@@ -72,20 +75,18 @@

      };

-//------------------------------------ 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 @@
      /**
       * 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 @@
          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 @@
      /**
       * 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 @@
      /**
       * 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 @@

      };

-//------------------------------------ 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 @@

      };

-//------------------------------------ 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 @@

      };

-//------------------------------------ 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 @@

      };

-//------------------------------------ UNKNOWN ATTRIBUTES  
----------------------
+    // ------------------------------------ UNKNOWN ATTRIBUTES
+    // ----------------------
      /**
       * Creates an empty UnknownAttributesAttribute.
+     *
       * @return the newly created UnknownAttributesAttribute
       */
      public static UnknownAttributesAttribute  
createUnknownAttributesAttribute()
@@ -250,10 +256,13 @@
          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 @@
       * @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 @@
       * @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 @@
       * @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 @@

      };

-/* --------------------------------- 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();
-
-      attribute.setUsername(username);
-      return attribute;
+        UsernameAttribute attribute = new UsernameAttribute();
+
+        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)
-    {
-      ChannelNumberAttribute attribute = new ChannelNumberAttribute();
-
-      attribute.setChannelNumber(channelNumber);
-      return attribute;
+    public static ChannelNumberAttribute createChannelNumberAttribute(
+                    char channelNumber)
+    {
+        ChannelNumberAttribute attribute = new ChannelNumberAttribute();
+
+        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();
-
-      attribute.setRealm(realm);
-      return attribute;
+        RealmAttribute attribute = new RealmAttribute();
+
+        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();
-
-      attribute.setNonce(nonce);
-      return attribute;
+        NonceAttribute attribute = new NonceAttribute();
+
+        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();
-
-      attribute.setSoftware(software);
-      return attribute;
+        SoftwareAttribute attribute = new SoftwareAttribute();
+
+        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();
-
-      attribute.setRFlag(rFlag);
-      return attribute;
+        EvenPortAttribute attribute = new EvenPortAttribute();
+
+        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();
-
-      attribute.setLifetime(lifetime);
-      return attribute;
+        LifetimeAttribute attribute = new LifetimeAttribute();
+
+        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)
-    {
-      RequestedTransportAttribute attribute = new  
RequestedTransportAttribute();
-
-      attribute.setRequestedTransport(protocol);
-      return attribute;
+    public static RequestedTransportAttribute  
createRequestedTransportAttribute(
+                    byte protocol)
+    {
+        RequestedTransportAttribute attribute = new  
RequestedTransportAttribute();
+
+        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[])
-    {
-      ReservationTokenAttribute attribute = new  
ReservationTokenAttribute();
-
-      attribute.setReservationToken(token);
-      return attribute;
+    public static ReservationTokenAttribute  
createReservationTokenAttribute(
+                    byte token[])
+    {
+        ReservationTokenAttribute attribute = new  
ReservationTokenAttribute();
+
+        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();
-
-      attribute.setData(data);
-      return attribute;
+        DataAttribute attribute = new DataAttribute();
+
+        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
-    {
-      // 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);
-
-      return attribute;
+    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));
+
+        IceControlledAttribute attribute = new IceControlledAttribute();
+        attribute.setTieBreaker(tieBreakerBytes);
+
+        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
-    {
-      PriorityAttribute attribute = new PriorityAttribute();
-
-      attribute.setPriority(priority);
-
-      return attribute;
-    }
-
-//--------------------------------- USE-CANDIDATE ATTRIBUTE  
---------------------
+                    throws IllegalArgumentException
+    {
+        PriorityAttribute attribute = new PriorityAttribute();
+
+        attribute.setPriority(priority);
+
+        return attribute;
+    }

      /**
       * Creates a UseCandidateAttribute
       *
-     * @return  the created UseCandidateAttribute
+     * @return the created UseCandidateAttribute
       */
      public static UseCandidateAttribute createUseCandidateAttribute()
      {
-      UseCandidateAttribute attribute = new UseCandidateAttribute();
-
-      return attribute;
+        UseCandidateAttribute attribute = new UseCandidateAttribute();
+
+        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
-    {
-      // 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);
-
-      return attribute;
+    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));
+
+        IceControllingAttribute attribute = new IceControllingAttribute();
+        attribute.setTieBreaker(tieBreakerBytes);
+
+        return attribute;
      }
  }
-
=======================================
--- /trunk/src/org/ice4j/attribute/IceControlledAttribute.java	Wed Jan 20  
07:34:29 2010
+++ /trunk/src/org/ice4j/attribute/IceControlledAttribute.java	Sun Apr 25  
07:42:10 2010
@@ -122,27 +122,25 @@
      }

      /**
-     * 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 byte[] getTieBreaker()
      {
-        if(tieBreaker == null)
-        {
-            return null;
-        }
-        else
-        {
-            //FIXME uncomment
-            //return Arrays.copyOf(tieBreaker, tieBreaker.length);
-            return null;
-        }
+        return tieBreaker;
      }

  }
=======================================
--- /trunk/src/org/ice4j/attribute/IceControllingAttribute.java	Wed Jan 20  
07:34:29 2010
+++ /trunk/src/org/ice4j/attribute/IceControllingAttribute.java	Sun Apr 25  
07:42:10 2010
@@ -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 @@
       * 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 @@
      {
          if(tieBreaker == null)
              return null;
-        else
-        {
-            //FIXME -- uncomment
-            //return Arrays.copyOf(tieBreaker, tieBreaker.length);
-            return null;
-        }
+
+        return tieBreaker;
      }

  }
=======================================
--- /trunk/src/org/ice4j/attribute/PriorityAttribute.java	Sun Apr 25  
07:40:58 2010
+++ /trunk/src/org/ice4j/attribute/PriorityAttribute.java	Sun Apr 25  
07:42:10 2010
@@ -154,17 +154,19 @@
      /**
       * 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;
      }
=======================================
--- /trunk/src/org/ice4j/ice/Agent.java	Sun Apr 25 07:40:11 2010
+++ /trunk/src/org/ice4j/ice/Agent.java	Sun Apr 25 07:42:10 2010
@@ -87,6 +87,16 @@
       */
      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 @@

          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);
          }
      }

@@ -323,6 +334,59 @@
      {
          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
=======================================
--- /trunk/src/org/ice4j/ice/Candidate.java	Sat Mar  6 08:05:44 2010
+++ /trunk/src/org/ice4j/ice/Candidate.java	Sun Apr 25 07:42:10 2010
@@ -314,21 +314,42 @@
       * 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 priority;
+        return (long)( getTypePreference(candidateType)  << 24 )+
+               (long)( getLocalPreference()              << 8  )+
+               (long) (256 - getParentComponent().getComponentID());
+
      }

      /**
-     * 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 @@
       * 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
=======================================
--- /trunk/src/org/ice4j/message/Message.java	Sun Apr 25 07:40:11 2010
+++ /trunk/src/org/ice4j/message/Message.java	Sun Apr 25 07:42:10 2010
@@ -10,6 +10,7 @@

  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 @@
          return getName()+"(0x"+Integer.toHexString(getMessageType())
              +")[attrib.count=" + getAttributeCount()
              +" len=" + (int) this.getDataLength()
-            +" tranID=" + this.getTransactionID() + "]";
+            +" tranID=" + TransactionID.toString(getTransactionID()) + "]";
      }

  }
=======================================
--- /trunk/src/org/ice4j/stack/StunServerTransaction.java	Mon Feb 15  
11:34:29 2010
+++ /trunk/src/org/ice4j/stack/StunServerTransaction.java	Sun Apr 25  
07:42:10 2010
@@ -324,4 +324,18 @@
      {
          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;
+    }
+}
=======================================
--- /trunk/src/org/ice4j/stack/StunStack.java	Tue Mar  2 01:12:33 2010
+++ /trunk/src/org/ice4j/stack/StunStack.java	Sun Apr 25 07:42:10 2010
@@ -47,15 +47,17 @@
      /**
       * 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 @@
          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
          {
=======================================
--- /trunk/src/org/ice4j/stack/TransactionID.java	Thu Feb 25 00:38:27 2010
+++ /trunk/src/org/ice4j/stack/TransactionID.java	Sun Apr 25 07:42:10 2010
@@ -143,24 +143,36 @@

      /**
       * 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();
=======================================
--- /trunk/test/org/ice4j/attribute/NonceAttributeTest.java	Wed Jan 20  
07:34:29 2010
+++ /trunk/test/org/ice4j/attribute/NonceAttributeTest.java	Sun Apr 25  
07:42:10 2010
@@ -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 @@

  /**
   * Tests the nonce attribute class.
- * <p>Organization Network Research Team, Louis Pasteur University</p>
+ *
   * @author Emil Ivov
   * @author Sebastien Vincent
   */
=======================================
--- /trunk/test/org/ice4j/attribute/RealmAttributeTest.java	Wed Jan 20  
07:34:29 2010
+++ /trunk/test/org/ice4j/attribute/RealmAttributeTest.java	Sun Apr 25  
07:42:10 2010
@@ -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 @@

  /**
   * Tests the realm attribute class.
- * <p>Organization Network Research Team, Louis Pasteur University</p>
+ *
   * @author Emil Ivov
   * @author Sebastien Vincent
   */
=======================================
--- /trunk/test/org/ice4j/attribute/UsernameAttributeTest.java	Wed Jan 20  
07:34:29 2010
+++ /trunk/test/org/ice4j/attribute/UsernameAttributeTest.java	Sun Apr 25  
07:42:10 2010
@@ -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 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
   */
=======================================
--- /trunk/test/test/Ice.java	Sun Apr 25 07:40:38 2010
+++ /trunk/test/test/Ice.java	Sun Apr 25 07:42:10 2010
@@ -41,6 +41,11 @@
          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");

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe at sip-communicator.dev.java.net
For additional commands, e-mail: commits-help at sip-communicator.dev.java.net





More information about the commits mailing list