Package 

Class Message

  • All Implemented Interfaces:

    
    public abstract class Message
    
                        

    This class represents a STUN message. Messages are TLV (type-length-value) encoded using big endian (network ordered) binary. All STUN messages start with a STUN header, followed by a STUN payload. The payload is a series of STUN attributes, the set of which depends on the message type. The STUN header contains a STUN message type, transaction ID, and length.

    • Constructor Detail

    • Method Detail

      • getMessageType

         char getMessageType()

        The message type of this message.

      • setMessageType

         void setMessageType(char messageType)

        Sets this message's type to be messageType. Method is package access as it should not permit changing the type of message once it has been initialized (could provoke attribute discrepancies). Called by messageFactory.

        Parameters:
        messageType - the message type.
      • setTransactionID

         void setTransactionID(Array<byte> tranID)

        Copies the specified tranID and sets it as this message's transactionID.

        Parameters:
        tranID - the transaction id to set in this message.
      • getDataLength

         char getDataLength()

        Returns the length of this message's body.

      • getDataLengthWithoutPadding

         char getDataLengthWithoutPadding()

        Returns the length of this message's body without padding. Some STUN/ICE dialect does not take into account padding (GTalk).

      • putAttribute

         void putAttribute(Attribute attribute)

        Puts the specified attribute into this message. If an attribute with that name was already added, it would be replaced.

        Parameters:
        attribute - the attribute to put into this message.
      • containsAttribute

         boolean containsAttribute(char attributeType)

        Returns true if the this Message contains an attribute with the specified type or false otherwise.

        Parameters:
        attributeType - the type whose presence we need to determine.
      • getAttribute

         Attribute getAttribute(char attributeType)

        Returns the attribute with the specified type or null if no such attribute exists.

        Parameters:
        attributeType - the type of the attribute
      • removeAttribute

         Attribute removeAttribute(char attributeType)

        Removes the specified attribute.

        Parameters:
        attributeType - the attribute to remove.
      • getAttributeCount

         int getAttributeCount()

        Returns the number of attributes, currently contained by the message.

      • getName

         String getName()

        Returns the human readable name of this message. Message names do not really matter from the protocol point of view. They are only used for debugging and readability.

      • equals

         boolean equals(Object obj)

        Compares two STUN Messages. Messages are considered equal when their type, length, and all their attributes are equal.

        Parameters:
        obj - the object to compare this message with.
      • encode

         Array<byte> encode(StunStack stunStack)

        Returns a binary representation of this message.

        Parameters:
        stunStack - the StunStack in the context of which the request to encode this Message is being made
      • decode

         static Message decode(Array<byte> binMessage, int offset, int arrayLen)

        Constructs a message from its binary representation.

        Parameters:
        binMessage - the binary array that contains the encoded message
        offset - the index where the message starts.
        arrayLen - the length of the message
      • isErrorResponseType

         static boolean isErrorResponseType(char type)

        Determines if the message type is a Error Response.

        Parameters:
        type - type to test
      • isSuccessResponseType

         static boolean isSuccessResponseType(char type)

        Determines if the message type is a Success Response.

        Parameters:
        type - type to test
      • isResponseType

         static boolean isResponseType(char type)

        Determines whether type could be the type of a STUN Response (as opposed to STUN Request).

        Parameters:
        type - the type to test.
      • isIndicationType

         static boolean isIndicationType(char type)

        Determines if the message type is Indication.

        Parameters:
        type - type to test
      • isRequestType

         static boolean isRequestType(char type)

        Determines whether type could be the type of a STUN Request (as opposed to STUN Response).

        Parameters:
        type - the type to test.
      • toString

         String toString()

        Returns a String representation of this message.