public abstract class Message extends Object
Modifier and Type | Field and Description |
---|---|
static char |
ALLOCATE_ERROR_RESPONSE
TURN allocate error response code.
|
static char |
ALLOCATE_REFRESH_REQUEST
TURN allocate refresh request code.
|
static char |
ALLOCATE_REQUEST
TURN allocate request code.
|
protected static byte |
ALLOCATE_REQUEST_PRESENTITY_INDEX |
static char |
ALLOCATE_RESPONSE
TURN allocate response code.
|
protected static byte |
ALLOCATE_RESPONSE_PRESENTITY_INDEX |
protected static byte |
ALTERNATE_SERVER_PRESENTITY_INDEX |
protected static byte[][] |
attributePresentities |
protected LinkedHashMap<Character,Attribute> |
attributes
The list of attributes contained by the message.
|
static char |
BINDING_ERROR_RESPONSE
STUN binding error response code.
|
protected static byte |
BINDING_ERROR_RESPONSE_PRESENTITY_INDEX |
static char |
BINDING_INDICATION
STUN binding request code.
|
static char |
BINDING_REQUEST
STUN binding request code.
|
protected static byte |
BINDING_REQUEST_PRESENTITY_INDEX |
protected static byte |
BINDING_RESPONSE_PRESENTITY_INDEX |
static char |
BINDING_SUCCESS_RESPONSE
STUN binding success response code.
|
private static byte |
C
C means it's conditional based on some other aspect of the message.
|
protected static byte |
CHANGE_REQUEST_PRESENTITY_INDEX |
protected static byte |
CHANGED_ADDRESS_PRESENTITY_INDEX |
protected static byte |
CHANNEL_NUMBER_PRESENTITY_INDEX |
static char |
CHANNELBIND_ERROR_RESPONSE
TURN ChannelBind error response code.
|
static char |
CHANNELBIND_REQUEST
TURN ChannelBind request code.
|
protected static byte |
CHANNELBIND_REQUEST_PRESENTITY_INDEX |
static char |
CHANNELBIND_RESPONSE
TURN ChannelBind response code.
|
protected static byte |
CHANNELBIND_RESPONSE_PRESENTITY_INDEX |
static char |
CONNECT_ERROR_RESPONSE
TURN Connect Error Response code.
|
static char |
CONNECT_REQUEST
TURN Connect Request code.
|
static char |
CONNECT_RESPONSE
TURN Connect Success Response code.
|
static char |
CONNECTION_ATTEMPT_INDICATION
TURN Connection Attempt Indication code.
|
static char |
CONNECTION_BIND_ERROR_RESPONSE
TURN Connection Bind error code.
|
static char |
CONNECTION_BIND_REQUEST
TURN Connection Bind Request code.
|
static char |
CONNECTION_BIND_SUCCESS_RESPONSE
TURN Connection Bind Success Response code.
|
static char |
CREATEPERMISSION_ERROR_RESPONSE
TURN CreatePermission error response code.
|
static char |
CREATEPERMISSION_REQUEST
TURN CreatePermission request code.
|
static char |
CREATEPERMISSION_RESPONSE
TURN CreatePermission response code.
|
static char |
DATA_INDICATION
TURN data indication code.
|
protected static byte |
DATA_INDICATION_PRESENTITY_INDEX |
protected static byte |
DATA_PRESENTITY_INDEX |
protected static byte |
DESTINATION_ADDRESS_PRESENTITY_INDEX |
protected static byte |
DONT_FRAGMENT_PRESENTITY_INDEX |
protected static byte |
ERROR_CODE_PRESENTITY_INDEX |
protected static byte |
EVEN_PORT_PRESENTITY_INDEX |
protected static byte |
FINGERPRINT_PRESENTITY_INDEX |
static byte |
HEADER_LENGTH
The length of Stun Message Headers in bytes
= len(Type) + len(DataLength) + len(Transaction ID).
|
protected static byte |
ICE_CONTROLLED_PRESENTITY_INDEX |
protected static byte |
ICE_CONTROLLING_PRESENTITY_INDEX |
protected static byte |
LIFETIME_PRESENTITY_INDEX |
private static Logger |
logger
The Logger used by the Message class and its instances
for logging output.
|
static byte |
M
M indicates that inclusion of the attribute in the message is
mandatory.
|
static byte[] |
MAGIC_COOKIE
The magic cookie (0x2112A442).
|
protected static byte |
MAPPED_ADDRESS_PRESENTITY_INDEX |
private static char |
MESSAGE_CLASS_MASK
The mask of the two bits from the message type structure, which indicate
the message class.
|
protected static byte |
MESSAGE_INTEGRITY_PRESENTITY_INDEX |
protected char |
messageType
Indicates the type of the message.
|
private static byte |
N_A
Describes which attributes are present in which messages.
|
protected static byte |
NONCE_PRESENTITY_INDEX |
static byte |
O
O means the parameter is optional.
|
static char |
OLD_DATA_INDICATION
TURN Send request.
|
protected static byte |
PASSWORD_PRESENTITY_INDEX |
protected static byte |
PRIORITY_PRESENTITY_INDEX |
protected static byte |
REALM_PRESENTITY_INDEX |
protected static byte |
REFLECTED_FROM_PRESENTITY_INDEX |
static char |
REFRESH_ERROR_RESPONSE
TURN refresh error response code.
|
static char |
REFRESH_REQUEST
TURN refresh request code.
|
protected static byte |
REFRESH_REQUEST_PRESENTITY_INDEX |
static char |
REFRESH_RESPONSE
TURN refresh response code.
|
protected static byte |
REFRESH_RESPONSE_PRESENTITY_INDEX |
protected static byte |
REQUESTED_TRANSPORT_PRESENTITY_INDEX |
protected static byte |
RESERVATION_TOKEN_PRESENTITY_INDEX |
protected static byte |
RESPONSE_ADDRESS_PRESENTITY_INDEX |
static byte |
RFC3489_TRANSACTION_ID_LENGTH
The length of the RFC3489 transaction id (in bytes).
|
private static boolean |
rfc3489CompatibilityMode
Attribute presentity is a thing of RFC 3489 and no longer exists in
5389.
|
static char |
SEND_INDICATION
TURN send indication code.
|
protected static byte |
SEND_INDICATION_PRESENTITY_INDEX |
static char |
SEND_REQUEST
TURN Send request.
|
static char |
SHARED_SECRET_ERROR_RESPONSE
STUN shared secret error response.
|
protected static byte |
SHARED_SECRET_ERROR_RESPONSE_PRESENTITY_INDEX |
static char |
SHARED_SECRET_REQUEST
STUN shared secret request.
|
protected static byte |
SHARED_SECRET_REQUEST_PRESENTITY_INDEX |
static char |
SHARED_SECRET_RESPONSE
STUN shared secret response.
|
protected static byte |
SHARED_SECRET_RESPONSE_PRESENTITY_INDEX |
protected static byte |
SOFTWARE_PRESENTITY_INDEX |
protected static byte |
SOURCE_ADDRESS_PRESENTITY_INDEX |
static char |
STUN_ERROR_RESP
STUN error response code.
|
static char |
STUN_INDICATION
STUN indication code.
|
static char |
STUN_METHOD_BINDING
STUN binding method.
|
static char |
STUN_REQUEST
STUN request code.
|
static char |
STUN_SUCCESS_RESP
STUN success response code.
|
static byte |
TRANSACTION_ID_LENGTH
The length of the transaction id (in bytes).
|
protected byte[] |
transactionID
The transaction ID is used to correlate requests and responses.
|
static char |
TURN_METHOD_ALLOCATE
TURN allocate method code.
|
static char |
TURN_METHOD_CHANNELBIND
TURN ChannelBind method code.
|
static char |
TURN_METHOD_CONNECT
TURN Connect method code.
|
static char |
TURN_METHOD_CONNECTION_ATTEMPT
TURN ConnectionAttempt method code.
|
static char |
TURN_METHOD_CONNECTION_BIND
TURN ConnectionBind method code.
|
static char |
TURN_METHOD_CREATEPERMISSION
TURN CreatePermission method code.
|
static char |
TURN_METHOD_DATA
TURN data method code.
|
static char |
TURN_METHOD_REFRESH
TURN refresh method code.
|
static char |
TURN_METHOD_SEND
TURN send method code.
|
protected static byte |
UNKNOWN_ATTRIBUTES_PRESENTITY_INDEX |
protected static byte |
UNKNOWN_OPTIONAL_ATTRIBUTES_PRESENTITY_INDEX |
protected static byte |
USE_CANDIDATE_PRESENTITY_INDEX |
protected static byte |
USERNAME_PRESENTITY_INDEX |
protected static byte |
XOR_MAPPED_ADDRESS_PRESENTITY_INDEX |
protected static byte |
XOR_ONLY_PRESENTITY_INDEX |
protected static byte |
XOR_PEER_ADDRESS_PRESENTITY_INDEX |
protected static byte |
XOR_RELAYED_ADDRESS_PRESENTITY_INDEX |
Modifier | Constructor and Description |
---|---|
protected |
Message()
Creates an empty STUN Message.
|
Modifier and Type | Method and Description |
---|---|
boolean |
containsAttribute(char attributeType)
Returns true if the this Message contains an attribute
with the specified type or false otherwise.
|
static Message |
decode(byte[] binMessage,
char offset,
char arrayLen)
Constructs a message from its binary representation.
|
byte[] |
encode(StunStack stunStack)
Returns a binary representation of this message.
|
boolean |
equals(Object obj)
Compares two STUN Messages.
|
Attribute |
getAttribute(char attributeType)
Returns the attribute with the specified type or null if no such
attribute exists.
|
int |
getAttributeCount()
Returns the number of attributes, currently contained by the message.
|
protected byte |
getAttributePresentity(char attributeType)
Returns whether an attribute could be present in this message.
|
List<Attribute> |
getAttributes()
|
char |
getDataLength()
Returns the length of this message's body.
|
char |
getDataLengthWithoutPadding()
Returns the length of this message's body without padding.
|
char |
getMessageType()
The message type of this message.
|
String |
getName()
Returns the human readable name of this message.
|
byte[] |
getTransactionID()
Returns a reference to this message's transaction id.
|
static boolean |
isErrorResponseType(char type)
Determines if the message type is a Error Response.
|
static boolean |
isIndicationType(char type)
Determines if the message type is Indication.
|
static boolean |
isRequestType(char type)
Determines whether type could be the type of a STUN Request (as opposed
to STUN Response).
|
static boolean |
isResponseType(char type)
Determines whether type could be the type of a STUN Response (as opposed
to STUN Request).
|
static boolean |
isSuccessResponseType(char type)
Determines if the message type is a Success Response.
|
private static void |
performAttributeSpecificActions(Attribute attribute,
byte[] binMessage,
int offset,
int msgLen)
Executes actions related specific attributes like asserting proper
fingerprint checksum.
|
private void |
prepareForEncoding()
Adds attributes that have been requested vis configuration properties.
|
void |
putAttribute(Attribute attribute)
Puts the specified attribute into this message.
|
Attribute |
removeAttribute(char attributeType)
Removes the specified attribute.
|
protected void |
setMessageType(char messageType)
Sets this message's type to be messageType.
|
void |
setTransactionID(byte[] tranID)
Copies the specified tranID and sets it as this message's transactionID.
|
String |
toString()
Returns a String representation of this message.
|
protected void |
validateAttributePresentity()
Verify that the message has all obligatory attributes and throw an
exception if this is not the case.
|
private static boolean |
validateFingerprint(FingerprintAttribute fingerprint,
byte[] message,
int offset,
int length)
Recalculates the FINGERPRINT CRC32 checksum of the message
array so that we could compare it with the value brought by the
FingerprintAttribute . |
private static final Logger logger
private static final char MESSAGE_CLASS_MASK
public static final char STUN_REQUEST
public static final char STUN_INDICATION
public static final char STUN_SUCCESS_RESP
public static final char STUN_ERROR_RESP
public static final char STUN_METHOD_BINDING
public static final char BINDING_REQUEST
public static final char BINDING_SUCCESS_RESPONSE
public static final char BINDING_ERROR_RESPONSE
public static final char BINDING_INDICATION
public static final char SHARED_SECRET_REQUEST
public static final char SHARED_SECRET_RESPONSE
public static final char SHARED_SECRET_ERROR_RESPONSE
public static final char TURN_METHOD_ALLOCATE
public static final char TURN_METHOD_REFRESH
public static final char TURN_METHOD_SEND
public static final char TURN_METHOD_DATA
public static final char TURN_METHOD_CREATEPERMISSION
public static final char TURN_METHOD_CHANNELBIND
public static final char TURN_METHOD_CONNECT
public static final char TURN_METHOD_CONNECTION_BIND
public static final char TURN_METHOD_CONNECTION_ATTEMPT
public static final char ALLOCATE_REQUEST
public static final char ALLOCATE_RESPONSE
public static final char ALLOCATE_ERROR_RESPONSE
public static final char REFRESH_REQUEST
public static final char ALLOCATE_REFRESH_REQUEST
public static final char REFRESH_RESPONSE
public static final char REFRESH_ERROR_RESPONSE
public static final char CHANNELBIND_REQUEST
public static final char CHANNELBIND_RESPONSE
public static final char CHANNELBIND_ERROR_RESPONSE
public static final char CREATEPERMISSION_REQUEST
public static final char CREATEPERMISSION_RESPONSE
public static final char CREATEPERMISSION_ERROR_RESPONSE
public static final char SEND_INDICATION
public static final char DATA_INDICATION
public static final char CONNECT_REQUEST
public static final char CONNECT_RESPONSE
public static final char CONNECT_ERROR_RESPONSE
public static final char CONNECTION_BIND_REQUEST
public static final char CONNECTION_BIND_SUCCESS_RESPONSE
public static final char CONNECTION_BIND_ERROR_RESPONSE
public static final char CONNECTION_ATTEMPT_INDICATION
public static final char SEND_REQUEST
public static final char OLD_DATA_INDICATION
public static final byte HEADER_LENGTH
protected char messageType
protected byte[] transactionID
public static final byte[] MAGIC_COOKIE
public static final byte TRANSACTION_ID_LENGTH
public static final byte RFC3489_TRANSACTION_ID_LENGTH
protected final LinkedHashMap<Character,Attribute> attributes
private static boolean rfc3489CompatibilityMode
private static final byte N_A
Binding Shared Shared Shared Binding Binding Error Secret Secret Secret Att. Req. Resp. Resp. Req. Resp. Error Resp. _____________________________________________________________________ MAPPED-ADDRESS N/A M N/A N/A N/A N/A RESPONSE-ADDRESS O N/A N/A N/A N/A N/A CHANGE-REQUEST O N/A N/A N/A N/A N/A SOURCE-ADDRESS N/A M N/A N/A N/A N/A CHANGED-ADDRESS N/A M N/A N/A N/A N/A USERNAME O N/A N/A N/A M N/A PASSWORD N/A N/A N/A N/A M N/A MESSAGE-INTEGRITY O O N/A N/A N/A N/A ERROR-CODE N/A N/A M N/A N/A M UNKNOWN-ATTRIBUTES N/A N/A C N/A N/A C REFLECTED-FROM N/A C N/A N/A N/A N/A XOR-MAPPED-ADDRESS N/A M N/A N/A N/A N/A XOR-ONLY O N/A N/A N/A N/A N/A SOFTWARE N/A O O N/A O O
private static final byte C
public static final byte O
N_A
,
Constant Field Valuespublic static final byte M
N_A
,
Constant Field Valuesprotected static final byte BINDING_REQUEST_PRESENTITY_INDEX
protected static final byte BINDING_RESPONSE_PRESENTITY_INDEX
protected static final byte BINDING_ERROR_RESPONSE_PRESENTITY_INDEX
protected static final byte SHARED_SECRET_REQUEST_PRESENTITY_INDEX
protected static final byte SHARED_SECRET_RESPONSE_PRESENTITY_INDEX
protected static final byte SHARED_SECRET_ERROR_RESPONSE_PRESENTITY_INDEX
protected static final byte ALLOCATE_REQUEST_PRESENTITY_INDEX
protected static final byte ALLOCATE_RESPONSE_PRESENTITY_INDEX
protected static final byte REFRESH_REQUEST_PRESENTITY_INDEX
protected static final byte REFRESH_RESPONSE_PRESENTITY_INDEX
protected static final byte CHANNELBIND_REQUEST_PRESENTITY_INDEX
protected static final byte CHANNELBIND_RESPONSE_PRESENTITY_INDEX
protected static final byte SEND_INDICATION_PRESENTITY_INDEX
protected static final byte DATA_INDICATION_PRESENTITY_INDEX
protected static final byte MAPPED_ADDRESS_PRESENTITY_INDEX
protected static final byte RESPONSE_ADDRESS_PRESENTITY_INDEX
protected static final byte CHANGE_REQUEST_PRESENTITY_INDEX
protected static final byte SOURCE_ADDRESS_PRESENTITY_INDEX
protected static final byte CHANGED_ADDRESS_PRESENTITY_INDEX
protected static final byte USERNAME_PRESENTITY_INDEX
protected static final byte PASSWORD_PRESENTITY_INDEX
protected static final byte MESSAGE_INTEGRITY_PRESENTITY_INDEX
protected static final byte ERROR_CODE_PRESENTITY_INDEX
protected static final byte UNKNOWN_ATTRIBUTES_PRESENTITY_INDEX
protected static final byte REFLECTED_FROM_PRESENTITY_INDEX
protected static final byte XOR_MAPPED_ADDRESS_PRESENTITY_INDEX
protected static final byte XOR_ONLY_PRESENTITY_INDEX
protected static final byte SOFTWARE_PRESENTITY_INDEX
protected static final byte UNKNOWN_OPTIONAL_ATTRIBUTES_PRESENTITY_INDEX
protected static final byte ALTERNATE_SERVER_PRESENTITY_INDEX
protected static final byte REALM_PRESENTITY_INDEX
protected static final byte NONCE_PRESENTITY_INDEX
protected static final byte FINGERPRINT_PRESENTITY_INDEX
protected static final byte CHANNEL_NUMBER_PRESENTITY_INDEX
protected static final byte LIFETIME_PRESENTITY_INDEX
protected static final byte XOR_PEER_ADDRESS_PRESENTITY_INDEX
protected static final byte DATA_PRESENTITY_INDEX
protected static final byte XOR_RELAYED_ADDRESS_PRESENTITY_INDEX
protected static final byte EVEN_PORT_PRESENTITY_INDEX
protected static final byte REQUESTED_TRANSPORT_PRESENTITY_INDEX
protected static final byte DONT_FRAGMENT_PRESENTITY_INDEX
protected static final byte RESERVATION_TOKEN_PRESENTITY_INDEX
protected static final byte PRIORITY_PRESENTITY_INDEX
protected static final byte ICE_CONTROLLING_PRESENTITY_INDEX
protected static final byte ICE_CONTROLLED_PRESENTITY_INDEX
protected static final byte USE_CANDIDATE_PRESENTITY_INDEX
protected static final byte DESTINATION_ADDRESS_PRESENTITY_INDEX
protected static final byte[][] attributePresentities
public char getDataLength()
public char getDataLengthWithoutPadding()
public void putAttribute(Attribute attribute) throws IllegalArgumentException
attribute
- the attribute to put into this message.IllegalArgumentException
- if the message cannot contain
such an attribute.public boolean containsAttribute(char attributeType)
attributeType
- the type whose presence we need to determine.public Attribute getAttribute(char attributeType)
attributeType
- the type of the attributepublic Attribute removeAttribute(char attributeType)
attributeType
- the attribute to remove.public int getAttributeCount()
protected void setMessageType(char messageType)
messageType
- the message type.public char getMessageType()
public void setTransactionID(byte[] tranID) throws StunException
tranID
- the transaction id to set in this message.StunException
- ILLEGAL_ARGUMENT if the transaction id is not
valid.public byte[] getTransactionID()
protected byte getAttributePresentity(char attributeType)
attributeType
- the id of the attribute to check .public String getName()
public boolean equals(Object obj)
public byte[] encode(StunStack stunStack) throws IllegalStateException
stunStack
- the StunStack in the context of which the
request to encode this Message is being madeIllegalStateException
- if the message does not have all
required attributes.private void prepareForEncoding()
public static Message decode(byte[] binMessage, char offset, char arrayLen) throws StunException
binMessage
- the binary array that contains the encoded messageoffset
- the index where the message starts.arrayLen
- the length of the messageStunException
- ILLEGAL_ARGUMENT if one or more of the
arguments have invalid values.private static void performAttributeSpecificActions(Attribute attribute, byte[] binMessage, int offset, int msgLen) throws StunException
attribute
- the Attribute we'd like to process.binMessage
- the byte array that the message arrived with.offset
- the index where data starts in binMessage.msgLen
- the number of message bytes in binMessage.StunException
- if there's something in the attribute that
caused us to discard the whole message (e.g. an invalid checksum or
username)private static boolean validateFingerprint(FingerprintAttribute fingerprint, byte[] message, int offset, int length)
FingerprintAttribute
.fingerprint
- the attribute that we need to validate.message
- the message whose CRC32 checksum we'd need to recalculate.offset
- the index in message where data starts.length
- the number of bytes in message that the CRC32
would need to be calculated over.protected void validateAttributePresentity() throws IllegalStateException
IllegalStateException
- if the message does not have all
required attributes.public static boolean isErrorResponseType(char type)
type
- type to testpublic static boolean isSuccessResponseType(char type)
type
- type to testpublic static boolean isResponseType(char type)
type
- the type to test.public static boolean isIndicationType(char type)
type
- type to testpublic static boolean isRequestType(char type)
type
- the type to test.Copyright © 2018. All rights reserved.