-
- All Implemented Interfaces:
public abstract class MessageThis 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.
-
-
Field Summary
Fields Modifier and Type Field Description public final static charSTUN_REQUESTpublic final static charSTUN_INDICATIONpublic final static charSTUN_SUCCESS_RESPpublic final static charSTUN_ERROR_RESPpublic final static charSTUN_METHOD_BINDINGpublic final static charBINDING_REQUESTpublic final static charBINDING_SUCCESS_RESPONSEpublic final static charBINDING_ERROR_RESPONSEpublic final static charBINDING_INDICATIONpublic final static charSHARED_SECRET_REQUESTpublic final static charSHARED_SECRET_RESPONSEpublic final static charSHARED_SECRET_ERROR_RESPONSEpublic final static charTURN_METHOD_ALLOCATEpublic final static charTURN_METHOD_REFRESHpublic final static charTURN_METHOD_SENDpublic final static charTURN_METHOD_DATApublic final static charTURN_METHOD_CREATEPERMISSIONpublic final static charTURN_METHOD_CHANNELBINDpublic final static charTURN_METHOD_CONNECTpublic final static charTURN_METHOD_CONNECTION_BINDpublic final static charTURN_METHOD_CONNECTION_ATTEMPTpublic final static charALLOCATE_REQUESTpublic final static charALLOCATE_RESPONSEpublic final static charALLOCATE_ERROR_RESPONSEpublic final static charREFRESH_REQUESTpublic final static charALLOCATE_REFRESH_REQUESTpublic final static charREFRESH_RESPONSEpublic final static charREFRESH_ERROR_RESPONSEpublic final static charCHANNELBIND_REQUESTpublic final static charCHANNELBIND_RESPONSEpublic final static charCHANNELBIND_ERROR_RESPONSEpublic final static charCREATEPERMISSION_REQUESTpublic final static charCREATEPERMISSION_RESPONSEpublic final static charCREATEPERMISSION_ERROR_RESPONSEpublic final static charSEND_INDICATIONpublic final static charDATA_INDICATIONpublic final static charCONNECT_REQUESTpublic final static charCONNECT_RESPONSEpublic final static charCONNECT_ERROR_RESPONSEpublic final static charCONNECTION_BIND_REQUESTpublic final static charCONNECTION_BIND_SUCCESS_RESPONSEpublic final static charCONNECTION_BIND_ERROR_RESPONSEpublic final static charCONNECTION_ATTEMPT_INDICATIONpublic final static charSEND_REQUESTpublic final static charOLD_DATA_INDICATIONpublic final static byteHEADER_LENGTHprotected charmessageTypeprotected Array<byte>transactionIDpublic final static Array<byte>MAGIC_COOKIEpublic final static byteTRANSACTION_ID_LENGTHpublic final static byteRFC3489_TRANSACTION_ID_LENGTHpublic final static byteOpublic final static byteM
-
Method Summary
Modifier and Type Method Description chargetMessageType()The message type of this message. voidsetMessageType(char messageType)Sets this message's type to be messageType. Array<byte>getTransactionID()Returns a reference to this message's transaction id. voidsetTransactionID(Array<byte> tranID)Copies the specified tranID and sets it as this message's transactionID. chargetDataLength()Returns the length of this message's body. chargetDataLengthWithoutPadding()Returns the length of this message's body without padding. voidputAttribute(Attribute attribute)Puts the specified attribute into this message. booleancontainsAttribute(char attributeType)Returns true if the this Message contains an attribute with the specified type or false otherwise. AttributegetAttribute(char attributeType)Returns the attribute with the specified type or null if no such attribute exists. AttributeremoveAttribute(char attributeType)Removes the specified attribute. intgetAttributeCount()Returns the number of attributes, currently contained by the message. StringgetName()Returns the human readable name of this message. booleanequals(Object obj)Compares two STUN Messages. Array<byte>encode(StunStack stunStack)Returns a binary representation of this message. static Messagedecode(Array<byte> binMessage, int offset, int arrayLen)Constructs a message from its binary representation. static booleanisErrorResponseType(char type)Determines if the message type is a Error Response. static booleanisSuccessResponseType(char type)Determines if the message type is a Success Response. static booleanisResponseType(char type)Determines whether type could be the type of a STUN Response (as opposed to STUN Request). static booleanisIndicationType(char type)Determines if the message type is Indication. static booleanisRequestType(char type)Determines whether type could be the type of a STUN Request (as opposed to STUN Response). StringtoString()Returns a String representation of this message. -
-
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.
-
getTransactionID
Array<byte> getTransactionID()
Returns a reference to this message's transaction id.
-
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 messageoffset- 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.
-
-
-
-