From 63aac5e6f92565ab5779a303741981e1f494abd8 Mon Sep 17 00:00:00 2001 From: emcho Date: Sat, 8 May 2010 21:34:35 +0000 Subject: [PATCH] Refactors the implementation of the ICE-CONTROLLING and ICE-CONRTOLLED attributes to avoir the 95% duplication between the two --- src/org/ice4j/attribute/AttributeDecoder.java | 4 + src/org/ice4j/attribute/AttributeFactory.java | 32 +-- .../ice4j/attribute/IceControlAttribute.java | 175 +++++++++++++++++ .../attribute/IceControlledAttribute.java | 180 +++-------------- .../attribute/IceControllingAttribute.java | 182 +++--------------- .../ice/checks/ConnectivityCheckServer.java | 124 +++++++++--- src/org/ice4j/message/Message.java | 14 ++ src/org/ice4j/stack/StunStack.java | 2 + 8 files changed, 344 insertions(+), 369 deletions(-) create mode 100644 src/org/ice4j/attribute/IceControlAttribute.java diff --git a/src/org/ice4j/attribute/AttributeDecoder.java b/src/org/ice4j/attribute/AttributeDecoder.java index 8f3b400..3cf84c8 100644 --- a/src/org/ice4j/attribute/AttributeDecoder.java +++ b/src/org/ice4j/attribute/AttributeDecoder.java @@ -109,6 +109,10 @@ public class AttributeDecoder decodedAttribute = new ReservationTokenAttribute(); break; case Attribute.PRIORITY: decodedAttribute = new PriorityAttribute(); break; + case Attribute.ICE_CONTROLLING: + decodedAttribute = new IceControllingAttribute(); break; + case Attribute.ICE_CONTROLLED: + decodedAttribute = new IceControlledAttribute(); break; //According to rfc3489 we should silently ignore unknown attributes. default: decodedAttribute diff --git a/src/org/ice4j/attribute/AttributeFactory.java b/src/org/ice4j/attribute/AttributeFactory.java index c1ed10a..39b145f 100644 --- a/src/org/ice4j/attribute/AttributeFactory.java +++ b/src/org/ice4j/attribute/AttributeFactory.java @@ -499,26 +499,12 @@ public class AttributeFactory * * @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 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); + attribute.setTieBreaker(tieBreaker); return attribute; } @@ -558,26 +544,12 @@ public class AttributeFactory * @param tieBreaker the tie-breaker value to be used * * @return the created IceControllingAttribute - * @throws IllegalArgumentException of tie-breaker value is not valid */ 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); + attribute.setTieBreaker(tieBreaker); return attribute; } diff --git a/src/org/ice4j/attribute/IceControlAttribute.java b/src/org/ice4j/attribute/IceControlAttribute.java new file mode 100644 index 0000000..d6ccc01 --- /dev/null +++ b/src/org/ice4j/attribute/IceControlAttribute.java @@ -0,0 +1,175 @@ +/* + * 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 org.ice4j.*; + +/** + * + * @author Emil Ivov + */ +public abstract class IceControlAttribute + extends Attribute +{ + /** + * The length of the data contained in this attribute + */ + static final char DATA_LENGTH_ICE_CONTROL = 8; + + /** + * The tie-breaker value stored in this attribute + */ + long tieBreaker; + + /** + * Indicates whether this is an ICE-CONTROLLING or an + * ICE-CONTROLLED attribute. + */ + boolean isControlling; + + /** + * Constructs an ICE-CONTROLLING or an ICE-CONTROLLED attribute depending + * on the value of isControlling. + * + * @param isControlling indicates the kind of attribute we are trying to + * create + */ + IceControlAttribute(boolean isControlling) + { + super(isControlling ? ICE_CONTROLLING : ICE_CONTROLLED); + this.isControlling = isControlling; + } + + /** + * Sets this attribute's fields according to attributeValue array. + * + * @param attributeValue a binary array containing this attribute's field + * values and NOT containing the attribute header. + * @param offset the position where attribute values begin (most often + * offset is equal to the index of the first byte after + * length) + * @param length the length of the attribute data. + * + * @throws StunException if attrubteValue contains invalid data. + */ + void decodeAttributeBody(byte[] attributeValue, char offset, char length) + throws StunException + { + // array used to hold the intermediate long values reconstructed from the + // attributeValue array + + // Reading in the network byte order (Big-Endian) + tieBreaker= ((attributeValue[offset++] & 0xffl) << 56) + | ((attributeValue[offset++] & 0xffl) << 48) + | ((attributeValue[offset++] & 0xffl) << 40) + | ((attributeValue[offset++] & 0xffl) << 32) + | ((attributeValue[offset++] & 0xffl) << 24) + | ((attributeValue[offset++] & 0xffl) << 16) + | ((attributeValue[offset++] & 0xffl) << 8) + | (attributeValue[offset++] & 0xffl); + } + + /** + * Returns a binary representation of this attribute. + * + * @return a binary representation of this attribute. + */ + public byte[] encode() + { + char type = getAttributeType(); + byte[] binValue = new byte[HEADER_LENGTH + getDataLength()]; + + //Type + binValue[0] = (byte)(type>>8); + binValue[1] = (byte)(type&0x00FF); + + //Length + binValue[2] = (byte)(getDataLength()>>8); + binValue[3] = (byte)(getDataLength()&0x00FF); + + //Tie-Breaker + binValue[4] = (byte)((tieBreaker & 0xFF00000000000000L) >> 56); + binValue[5] = (byte)((tieBreaker & 0x00FF000000000000L) >> 48); + binValue[6] = (byte)((tieBreaker & 0x0000FF0000000000L) >> 40); + binValue[7] = (byte)((tieBreaker & 0x000000FF00000000L) >> 32); + binValue[8] = (byte)((tieBreaker & 0x00000000FF000000L) >> 24); + binValue[9] = (byte)((tieBreaker & 0x0000000000FF0000L) >> 16); + binValue[10] = (byte)((tieBreaker & 0x000000000000FF00L) >> 8); + binValue[11] = (byte)( tieBreaker & 0x00000000000000FFL); + + return binValue; + } + + /** + * Compares two STUN Attributes. Attributes are considered equal when their + * type, length, and all data are the same. + * + * @param obj the object to compare this attribute with. + * + * @return true if the attributes are equal and false otherwise. + */ + public boolean equals(Object obj) + { + if(!(obj instanceof IceControlAttribute) + || obj == null) + return false; + + if(obj == this) + return true; + + IceControlAttribute iceControlAtt = (IceControlAttribute)obj; + if(iceControlAtt.getAttributeType() != getAttributeType() + || iceControlAtt.isControlling != isControlling + || iceControlAtt.getDataLength() != DATA_LENGTH_ICE_CONTROL + || getTieBreaker() != iceControlAtt.getTieBreaker()) + { + return false; + } + + return true; + } + + /** + * Returns the data length of this attribute + * + * @return the data length of this attribute + */ + public char getDataLength() + { + return DATA_LENGTH_ICE_CONTROL; + } + + /** + * Returns the human readable name of this attribute. + * + * @return this attribute's name. + */ + public String getName() + { + return isControlling ? "ICE-CONTROLLING" : "ICE-CONTROLLED"; + } + + /** + * Sets the tie-breaker value. + * + * @param tieBreaker the the tie-breaker value + */ + public void setTieBreaker(long tieBreaker) + { + this.tieBreaker = tieBreaker; + } + + /** + * Returns the value of the tie-breaker. + * + * @return the value of the tie-breaker. + */ + public long getTieBreaker() + { + return tieBreaker; + } +} diff --git a/src/org/ice4j/attribute/IceControlledAttribute.java b/src/org/ice4j/attribute/IceControlledAttribute.java index 861b073..66058d1 100644 --- a/src/org/ice4j/attribute/IceControlledAttribute.java +++ b/src/org/ice4j/attribute/IceControlledAttribute.java @@ -1,157 +1,23 @@ -package org.ice4j.attribute; - -import java.util.Arrays; - -import org.ice4j.*; - - -public class IceControlledAttribute - extends Attribute -{ - - /** - * The length of the data contained in this attribute - */ - private static final char DATA_LENGTH_ICE_CONTROLLED = 8; - - /** - * The tie-breaker value represented in this attribute - */ - byte[] tieBreaker = null; - - /** - * Constructs an ICE-CONTROLLED attribute - */ - protected IceControlledAttribute() - { - super(ICE_CONTROLLED); - } - - /** - * Sets this attribute's fields according to attributeValue array. - * - * @param attributeValue a binary array containing this attribute's field - * values and NOT containing the attribute header. - * @param offset the position where attribute values begin (most often - * offset is equal to the index of the first byte after - * length) - * @param length the length of the attribute data. - * - * @throws StunException if attributeValue contains invalid data. - */ - void decodeAttributeBody(byte[] attributeValue, char offset, char length) - throws StunException - { - // initializing the byte arrays which holds the 64 bit value - // after decoding - tieBreaker = new byte[length]; - - System.arraycopy(attributeValue, offset, tieBreaker, 0, length); - } - - /** - * Returns a binary representation of this attribute. - * - * @return a binary representation of this attribute. - */ - public byte[] encode() { - - char type = getAttributeType(); - byte[] binValue = new byte[HEADER_LENGTH + DATA_LENGTH_ICE_CONTROLLED]; - - // Type - binValue[0] = (byte)(type>>8); - binValue[1] = (byte)(type&0x00FF); - - // Length - binValue[2] = (byte)(DATA_LENGTH_ICE_CONTROLLED>>8); - binValue[3] = (byte)(DATA_LENGTH_ICE_CONTROLLED&0x00FF); - - // Tie-Breaker, 64 bits stored in network byte order - System.arraycopy(tieBreaker, 0, binValue, 4, tieBreaker.length); - - return binValue; - } - - /** - * Compares two STUN Attributes. Attributes are considered equal when their - * type, length, and all data are the same. - * - * @param obj the object to compare this attribute with. - * - * @return true if the attributes are equal and false otherwise. - */ - public boolean equals(Object obj) - { - if(!(obj instanceof IceControlledAttribute) - || obj == null) - return false; - - if(obj == this) - return true; - - IceControlledAttribute iceControlledAtt = (IceControlledAttribute)obj; - if(iceControlledAtt.getAttributeType() != getAttributeType() - || iceControlledAtt.getDataLength() != DATA_LENGTH_ICE_CONTROLLED - || (tieBreaker != null - && !Arrays.equals(tieBreaker, iceControlledAtt.tieBreaker)) - ) - return false; - - return true; - } - - /** - * Returns the data length of this attribute - * - * @return the data length of this attribute - */ - public char getDataLength() - { - return DATA_LENGTH_ICE_CONTROLLED; - } - - /** - * Returns the human readable name of this attribute. - * - * @return this attribute's name. - */ - public String getName() - { - return "ICE-CONTROLLED"; - } - - /** - * Sets the tieBreaker byte array. - * - * @param tieBreaker the byte array containing the 64 bit tie-breaker - * value - * - * @throws IllegalArgumentException if tieBreaker contains invalid data - */ - public void setTieBreaker(byte[] tieBreaker) - throws IllegalArgumentException - { - if(tieBreaker.length != DATA_LENGTH_ICE_CONTROLLED) - { - throw new IllegalArgumentException( - "The supplied byte array does not contain the correct number" - +" of bytes"); - } - else - { - this.tieBreaker = tieBreaker; - } - } - - /** - * Returns a copy of the Tie Breaker byte array - * - * @return an exact copy of the Tie Breaker byte array - */ - public byte[] getTieBreaker() - { - return tieBreaker; - } - -} +/* + * 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; + +/** + * An {@link IceControlAttribute} implementation representing the + * ICE-CONTROLLED ICE {@link Attribute}s. + */ +public final class IceControlledAttribute + extends IceControlAttribute +{ + /** + * Constructs an ICE-CONTROLLING attribute. + */ + public IceControlledAttribute() + { + super(false); + } +} diff --git a/src/org/ice4j/attribute/IceControllingAttribute.java b/src/org/ice4j/attribute/IceControllingAttribute.java index c6b674d..2f2dc97 100644 --- a/src/org/ice4j/attribute/IceControllingAttribute.java +++ b/src/org/ice4j/attribute/IceControllingAttribute.java @@ -1,159 +1,23 @@ -/* - * 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; - -import org.ice4j.*; - - -public class IceControllingAttribute - extends Attribute -{ - /** - * The length of the data contained in this attribute - */ - private static final char DATA_LENGTH_ICE_CONTROLLING = 8; - - /** - * The tie-breaker value stored in this attribute - */ - byte[] tieBreaker = null; - - /** - * Constructs an ICE-CONTROLLING attribute - */ - protected IceControllingAttribute() - { - super(ICE_CONTROLLING); - } - - /** - * Sets this attribute's fields according to attributeValue array. - * - * @param attributeValue a binary array containing this attribute's field - * values and NOT containing the attribute header. - * @param offset the position where attribute values begin (most often - * offset is equal to the index of the first byte after - * length) - * @param length the length of the attribute data. - * - * @throws StunException if attrubteValue contains invalid data. - */ - void decodeAttributeBody(byte[] attributeValue, char offset, char length) - throws StunException { - // initializing the byte arrays which holds the 64 bit value after decoding - tieBreaker = new byte[length]; - - System.arraycopy(attributeValue, offset, tieBreaker, 0, length); - } - - /** - * Returns a binary representation of this attribute. - * - * @return a binary representation of this attribute. - */ - public byte[] encode() { - char type = getAttributeType(); - byte[] binValue = new byte[HEADER_LENGTH + DATA_LENGTH_ICE_CONTROLLING]; - - // Type - binValue[0] = (byte)(type>>8); - binValue[1] = (byte)(type&0x00FF); - - // Length - binValue[2] = (byte)(DATA_LENGTH_ICE_CONTROLLING>>8); - binValue[3] = (byte)(DATA_LENGTH_ICE_CONTROLLING&0x00FF); - - // Tie-Breaker, 64 bits stored in network byte order - System.arraycopy(tieBreaker, 0, binValue, 4, tieBreaker.length); - - return binValue; - } - - /** - * Compares two STUN Attributes. Attributes are considered equal when their - * type, length, and all data are the same. - * - * @param obj the object to compare this attribute with. - * - * @return true if the attributes are equal and false otherwise. - */ - public boolean equals(Object obj) - { - if(!(obj instanceof IceControllingAttribute) - || obj == null) - return false; - - if(obj == this) - return true; - - IceControllingAttribute iceControllingAtt = (IceControllingAttribute)obj; - if(iceControllingAtt.getAttributeType() != getAttributeType() - || iceControllingAtt.getDataLength() != DATA_LENGTH_ICE_CONTROLLING - || !(Arrays.equals(getTieBreaker(), - iceControllingAtt.getTieBreaker()))) - return false; - - return true; - } - - /** - * Returns the data length of this attribute - * - * @return the data length of this attribute - */ - public char getDataLength() - { - return DATA_LENGTH_ICE_CONTROLLING; - } - - /** - * Returns the human readable name of this attribute. - * - * @return this attribute's name. - */ - public String getName() - { - return "ICE-CONTROLLING"; - } - - /** - * 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 - * - * @throws IllegalArgumentException if tieBreaker contains invalid data - */ - public void setTieBreaker(byte[] tieBreaker) - throws IllegalArgumentException - { - if(tieBreaker.length != DATA_LENGTH_ICE_CONTROLLING) - { - throw new IllegalArgumentException( - "The supplied byte array does not contain the correct number " - +"of bytes"); - } - - this.tieBreaker = tieBreaker; - } - - /** - * Returns a copy of the Tie Breaker byte array - * - * @return an exact copy of the Tie Breaker byte array - */ - public byte[] getTieBreaker() - { - if(tieBreaker == null) - return null; - - return tieBreaker; - } - -} +/* + * 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; + +/** + * An {@link IceControlAttribute} implementation representing the + * ICE-CONTROLLING ICE {@link Attribute}s. + */ +public final class IceControllingAttribute + extends IceControlAttribute +{ + /** + * Constructs an ICE-CONTROLLING attribute. + */ + public IceControllingAttribute() + { + super(true); + } +} diff --git a/src/org/ice4j/ice/checks/ConnectivityCheckServer.java b/src/org/ice4j/ice/checks/ConnectivityCheckServer.java index 952dedd..5151d4e 100644 --- a/src/org/ice4j/ice/checks/ConnectivityCheckServer.java +++ b/src/org/ice4j/ice/checks/ConnectivityCheckServer.java @@ -45,15 +45,6 @@ public class ConnectivityCheckServer */ private StunStack stunStack = StunStack.getInstance(); - /** - * The triggeredCheckQueue is a FIFO queue containing candidate - * pairs for which checks are to be sent at the next available opportunity. - * A pair would get into a triggered check queue as soon as we receive - * a check on its local candidate. - */ - private final List triggeredCheckQueue - = new Vector(); - /** * Creates a new ConnectivityCheckServer setting * parentAgent as the agent that will be used for retrieving @@ -106,23 +97,19 @@ public class ConnectivityCheckServer //caller gave us the entire username. String remoteUfrag = username.substring(0, colon); - //make sure we have a priority attribute and ignore otherwise. - PriorityAttribute priorityAttr - = (PriorityAttribute)request.getAttribute(Attribute.PRIORITY); - - //extract priority - if(priorityAttr == null) + //detect role conflicts +/* if( ( parentAgent.isControlling() + && request.contains(Attribute.ICE_CONTROLLING)) + || ( ! parentAgent.isControlling() + && request.contains(Attribute.ICE_CONTROLLED)))*/ { - if(logger.isLoggable(Level.FINE)) - { - logger.log(Level.FINE, "Received a connectivity ckeck with" - +"no PRIORITY attribute. Discarting."); - } - - throw new IllegalArgumentException("Missing PRIORITY attribtue!"); + System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!tb="+ + ((IceControllingAttribute)request.getAttribute(Attribute.ICE_CONTROLLING)).getTieBreaker()); + repairRoleConflict(evt); + //return; } - long priority = priorityAttr.getPriority(); + long priority = extractPriority(request); //tell our address handler we saw a new remote address; addressHandler.incomingCheckReceived(evt.getRemoteAddress(), @@ -144,6 +131,97 @@ public class ConnectivityCheckServer } } + /** + * Returns the value of the {@link PriorityAttribute} in request if + * there is one or throws an IllegalArgumentException with the + * corresponding message. + * + * @param request the {@link Request} whose priority we'd like to obtain. + * + * @return the value of the {@link PriorityAttribute} in request if + * there is one + * + * @throws IllegalArgumentException if the request does not contain a + * PRIORITY attribute and the stack needs to respond with a 400 Bad Request + * {@link Response}. + */ + private long extractPriority(Request request) + throws IllegalArgumentException + { + //make sure we have a priority attribute and ignore otherwise. + PriorityAttribute priorityAttr + = (PriorityAttribute)request.getAttribute(Attribute.PRIORITY); + + //apply tie-breaking + + //extract priority + if(priorityAttr == null) + { + if(logger.isLoggable(Level.FINE)) + { + logger.log(Level.FINE, "Received a connectivity ckeck with" + +"no PRIORITY attribute. Discarting."); + } + + throw new IllegalArgumentException("Missing PRIORITY attribtue!"); + } + + return priorityAttr.getPriority(); + } + + private void repairRoleConflict(StunMessageEvent evt) + { + Message req = evt.getMessage(); + long ourTieBreaker = parentAgent.getTieBreaker(); + + // If the agent is in the controlling role, and the + // ICE-CONTROLLING attribute is present in the request: + if(parentAgent.isControlling() + && req.contains(Attribute.ICE_CONTROLLING)) + { + IceControllingAttribute controlling = (IceControllingAttribute) + req.getAttribute(Attribute.ICE_CONTROLLING); + + long theirTieBreaker = controlling.getTieBreaker(); +System.out.println("############################################ TB=" + theirTieBreaker); + // If the agent's tie-breaker is larger than or equal to the + // contents of the ICE-CONTROLLING attribute, the agent generates + // a Binding error response and includes an ERROR-CODE attribute + // with a value of 487 (Role Conflict) but retains its role. + //if() + + //If the agent's tie-breaker is less than the contents of the + //ICE-CONTROLLING attribute, the agent switches to the controlled role. + } + + else if(!parentAgent.isControlling() + && req.contains(Attribute.ICE_CONTROLLED)) + { + IceControllingAttribute controlled = (IceControllingAttribute) + req.getAttribute(Attribute.ICE_CONTROLLED); + + long theirTieBreaker = controlled.getTieBreaker(); +System.out.println("############################################ TB=" + theirTieBreaker); + } +/* + + + o If the agent is in the controlled role, and the ICE-CONTROLLED + attribute is present in the request: + + * If the agent's tie-breaker is larger than or equal to the + contents of the ICE-CONTROLLED attribute, the agent switches to + the controlling role. + + * If the agent's tie-breaker is less than the contents of the + ICE-CONTROLLED attribute, the agent generates a Binding error + response and includes an ERROR-CODE attribute with a value of + 487 (Role Conflict) but retains its role. + + + * */ + } + /** * Verifies whether username is currently known to this server * and returns true if so. Returns false otherwise. diff --git a/src/org/ice4j/message/Message.java b/src/org/ice4j/message/Message.java index 575dcc4..f816eae 100644 --- a/src/org/ice4j/message/Message.java +++ b/src/org/ice4j/message/Message.java @@ -300,6 +300,20 @@ public abstract class Message attributes.put(attributeType, attribute); } + /** + * Returns true if the this Message contains an attribute + * with the specified type or false otherwise. + * + * @param attributeType the type whose presence we need to determine. + * + * @return true if the this Message contains an attribute + * with the specified type or false otherwise. + */ + public boolean contains(char attributeType) + { + return attributes.containsKey(new Character(attributeType)); + } + /** * Returns the attribute with the specified type or null if no such * attribute exists. diff --git a/src/org/ice4j/stack/StunStack.java b/src/org/ice4j/stack/StunStack.java index aabb77c..7d393bf 100644 --- a/src/org/ice4j/stack/StunStack.java +++ b/src/org/ice4j/stack/StunStack.java @@ -543,6 +543,8 @@ public class StunStack catch (Throwable t) { Response error; +t.printStackTrace(); + logger.log(Level.FINER, "Received an invalid request.", t); if(t instanceof IllegalArgumentException) {