public class MessageFactory extends Object
Modifier and Type | Field and Description |
---|---|
private static Logger |
logger
The Logger used by the MessageFactory class and its
instances.
|
Constructor and Description |
---|
MessageFactory() |
Modifier and Type | Method and Description |
---|---|
static void |
addLongTermCredentialAttributes(Request request,
byte[] username,
byte[] realm,
byte[] nonce)
Adds the Attributes to a specific Request which support
the STUN long-term credential mechanism.
|
static Response |
create3489BindingResponse(TransportAddress mappedAddress,
TransportAddress sourceAddress,
TransportAddress changedAddress)
Creates a BindingResponse in a 3489 compliant manner, assigning the
specified values to mandatory headers.
|
static Request |
createAllocateRequest()
Create an allocate request without attribute.
|
static Request |
createAllocateRequest(byte protocol,
boolean rFlag)
Create an allocate request to allocate an even port.
|
static Response |
createAllocationErrorResponse(char errorCode)
Creates a allocation error response according to the specified error
code.
|
static Response |
createAllocationErrorResponse(char errorCode,
String reasonPhrase)
Creates a allocation error response according to the specified error
code.
|
static Response |
createAllocationResponse(Request request,
TransportAddress mappedAddress,
TransportAddress relayedAddress,
byte[] token,
int lifetime)
Creates a AllocationResponse in a 5389 compliant manner containing at most 4 attributes
XOR-RELAYED-ADDRESS attribute LIFETIME attribute RESERVATION-TOKEN attribute XOR-MAPPED-ADDRESS attribute |
static Response |
createAllocationResponse(Request request,
TransportAddress mappedAddress,
TransportAddress relayedAddress,
int lifetime)
Creates a AllocationResponse in a 5389 compliant manner containing at
most 4 attributes
XOR-RELAYED-ADDRESS attribute LIFETIME attribute XOR-MAPPED-ADDRESS attribute |
static Response |
createBindingErrorResponse(char errorCode)
Creates a binding error response according to the specified error code.
|
static Response |
createBindingErrorResponse(char errorCode,
String reasonPhrase)
Creates a binding error response with an ERROR-CODE attribute.
|
static Response |
createBindingErrorResponse(char errorCode,
String reasonPhrase,
char[] unknownAttributes)
Creates a binding error response according to the specified error code
and unknown attributes.
|
static Response |
createBindingErrorResponseUnknownAttributes(char[] unknownAttributes)
Creates a binding error response with UNKNOWN_ATTRIBUTES error code and
the specified unknown attributes.
|
static Response |
createBindingErrorResponseUnknownAttributes(String reasonPhrase,
char[] unknownAttributes)
Creates a binding error response with UNKNOWN_ATTRIBUTES error code and
the specified unknown attributes and reason phrase.
|
static Indication |
createBindingIndication()
Creates a default binding indication.
|
static Request |
createBindingRequest()
Creates a default binding request.
|
static Request |
createBindingRequest(long priority)
Creates a default binding request.
|
static Request |
createBindingRequest(long priority,
boolean controlling,
long tieBreaker)
Creates a default binding request.
|
static Response |
createBindingResponse(Request request,
TransportAddress mappedAddress)
Creates a BindingResponse in a 5389 compliant manner containing a single
XOR-MAPPED-ADDRESS attribute
|
static Response |
createChannelBindErrorResponse(char errorCode)
Creates a Channel Bind Error Response with given error code.
|
static Response |
createChannelBindErrorResponse(char errorCode,
String reasonPhrase)
Creates a Channel Bind Error Response with given error code
and reasonPhrase.
|
static Request |
createChannelBindRequest(char channelNumber,
TransportAddress peerAddress,
byte[] tranID)
Create a ChannelBind request.
|
static Response |
createChannelBindResponse()
Creates a Channel Bind Success Response.
|
static Response |
createConnectErrorResponse(char errorCode)
Creates a Connect error response according to the specified error code.
|
static Response |
createConnectErrorResponse(char errorCode,
String reasonPhrase)
Creates a Connect error response according to the specified error code.
|
static Indication |
createConnectionAttemptIndication(int connectionIdValue,
TransportAddress peerAddress)
Creates a ConnectionAttempt Indication in a 6062 compliant manner
containing only CONECTION-ID-ATTRIBUTE attribute and
XOR-PPER-ADDRESS attribute.
|
static Indication |
createConnectionAttemptIndication(int connectionIdValue,
TransportAddress peerAddress,
byte[] transactionId)
Creates a ConnectionAttempt Indication in a 6062 compliant manner
containing only CONECTION-ID-ATTRIBUTE attribute and
XOR-PPER-ADDRESS attribute.
|
static Response |
createConnectionBindErrorResponse(char errorCode)
Creates a ConnectionBind error response according to the specified error
code.
|
static Response |
createConnectionBindErrorResponse(char errorCode,
String reasonPhrase)
Creates a ConnectionBind error response according to the specified error
code.
|
static Request |
createConnectionBindRequest(int connectionIdValue)
Creates a ConnectionBindRequest in a 6062 compliant manner containing
only CONECTION-ID-ATTRIBUTE attribute.
|
static Response |
createConnectionBindResponse()
Creates a ConnectionBind Response in a 6062 compliant manner.
|
static Request |
createConnectRequest(TransportAddress peerAddress,
byte[] transactionId)
Creates a ConnectRequest in a 6062 compliant manner containing only
XOR-PEER-ADDRESS attribute.
|
static Request |
createConnectRequest(TransportAddress peerAddress,
Request request)
Creates a ConnectRequest in a 6062 compliant manner containing only
XOR-PEER-ADDRESS attribute |
static Response |
createConnectResponse(int connectionIdValue)
Creates a Connect Response in a 6062 compliant manner containing a single
CONNECTION-ID-ATTRIBUTE attribute
|
static Response |
createCreatePermissionErrorResponse(char errorCode)
Creates a create permission error response.
|
static Request |
createCreatePermissionRequest(TransportAddress peerAddress,
byte[] transactionID)
Creates a new TURN CreatePermission Request with a specific
value for its XOR-PEER-ADDRESS attribute.
|
static Response |
createCreatePermissionResponse()
Creates a create permission success response.
|
static Indication |
createDataIndication(TransportAddress peerAddress,
byte[] data,
byte[] tranID)
Create a Data Indication.
|
static Request |
createGoogleAllocateRequest(String username)
Create an allocate request for a Google TURN relay (old TURN protocol
modified).
|
static Response |
createPermissionErrorResponse(char errorCode,
String reasonPhrase)
Creates a create permission error response.
|
static Response |
createRefreshErrorResponse(char errorCode)
Creates a refresh error response
|
static Response |
createRefreshErrorResponse(char errorCode,
String reasonPhrase)
Creates a refresh error response.
|
static Request |
createRefreshRequest()
Creates a new TURN Refresh Request without any optional
attributes such as LIFETIME.
|
static Request |
createRefreshRequest(int lifetime)
Create a refresh request.
|
static Response |
createRefreshResponse(int lifetime)
Creates a refresh success response with given lifetime.
|
static Indication |
createSendIndication(TransportAddress peerAddress,
byte[] data,
byte[] tranID)
Create a Send Indication.
|
static Request |
createSendRequest(String username,
TransportAddress peerAddress,
byte[] data)
Create a old Send Request.
|
static Response |
createSharedSecretErrorResponse()
Create a shared secret error response.
|
static Request |
createSharedSecretRequest()
Create a shared secret request.
|
static Response |
createSharedSecretResponse()
Create a shared secret response.
|
private static final Logger logger
public static Request createBindingRequest()
public static Request createBindingRequest(long priority) throws StunException
priority
- the value for the priority attributeStunException
- if we have a problem creating the requestpublic static Request createBindingRequest(long priority, boolean controlling, long tieBreaker) throws StunException
priority
- the value of the ICE priority attributescontrolling
- the value of the controlling attributetieBreaker
- the value of the ICE tie breaker attributeStunException
- if we have a problem creating the requestpublic static Response create3489BindingResponse(TransportAddress mappedAddress, TransportAddress sourceAddress, TransportAddress changedAddress) throws IllegalArgumentException
mappedAddress
- the address to assign the mappedAddressAttributesourceAddress
- the address to assign the sourceAddressAttributechangedAddress
- the address to assign the changedAddressAttributeIllegalArgumentException
- if there was something wrong with the
way we are trying to create the response.public static Response createBindingResponse(Request request, TransportAddress mappedAddress) throws IllegalArgumentException
request
- the request that created the transaction that this
response will belong to.mappedAddress
- the address to assign the mappedAddressAttributeIllegalArgumentException
- if there was something wrong with the
way we are trying to create the response.public static Response createBindingErrorResponse(char errorCode, String reasonPhrase, char[] unknownAttributes) throws IllegalArgumentException
errorCode
- the error code to encapsulate in this messagereasonPhrase
- a human readable description of the errorunknownAttributes
- a char[] array containing the ids of one or more
attributes that had not been recognized.IllegalArgumentException
- INVALID_ARGUMENTS if one or more of the
given parameters had an invalid value.public static Response createBindingErrorResponseUnknownAttributes(char[] unknownAttributes) throws StunException
unknownAttributes
- a char[] array containing the ids of one or more
attributes that had not been recognized.StunException
- INVALID_ARGUMENTS if one or more of the given
parameters had an invalid value.public static Response createBindingErrorResponseUnknownAttributes(String reasonPhrase, char[] unknownAttributes) throws StunException
reasonPhrase
- a short description of the error.unknownAttributes
- a char[] array containing the ids of one or more
attributes that had not been recognized.StunException
- INVALID_ARGUMENTS if one or more of the given
parameters had an invalid value.public static Response createBindingErrorResponse(char errorCode, String reasonPhrase)
errorCode
- the error code to encapsulate in this messagereasonPhrase
- a human readable description of the error.public static Response createBindingErrorResponse(char errorCode)
errorCode
- the error code to encapsulate in this message attributes
that had not been recognized.public static Indication createBindingIndication()
public static Request createAllocateRequest()
public static Request createAllocateRequest(byte protocol, boolean rFlag)
protocol
- requested protocol numberrFlag
- R flag for the EVEN-PORTpublic static Response createAllocationResponse(Request request, TransportAddress mappedAddress, TransportAddress relayedAddress, int lifetime) throws IllegalArgumentException
request
- the request that created the transaction that this
response will belong to.mappedAddress
- the address to assign the mappedAddressAttributerelayedAddress
- the address to assign the relayedAddressAttributelifetime
- the address to assign the lifetimeAttributeIllegalArgumentException
- if there was something wrong with the
way we are trying to create the response.public static Response createAllocationResponse(Request request, TransportAddress mappedAddress, TransportAddress relayedAddress, byte[] token, int lifetime) throws IllegalArgumentException
request
- the request that created the transaction that this
response will belong to.mappedAddress
- the address to assign the mappedAddressAttributerelayedAddress
- the address to assign the relayedAddressAttributetoken
- the address to assign the reservationTokenAttributelifetime
- the address to assign the lifetimeAttributeIllegalArgumentException
- if there was something wrong with the
way we are trying to create the response.public static Response createAllocationErrorResponse(char errorCode)
errorCode
- the error code to encapsulate in this message attributes
that had not been recognised.public static Response createAllocationErrorResponse(char errorCode, String reasonPhrase)
errorCode
- the error code to encapsulate in this messagereasonPhrase
- a human readable description of the error
attributes that had not been recognised.IllegalArgumentException
- INVALID_ARGUMENTS if one or more of the
given parameters had an invalid value.public static Request createGoogleAllocateRequest(String username)
username
- short-term usernamepublic static void addLongTermCredentialAttributes(Request request, byte[] username, byte[] realm, byte[] nonce) throws StunException
Warning: The MESSAGE-INTEGRITY Attribute will also be added so Attributes added afterwards will not be taken into account for the calculation of the MESSAGE-INTEGRITY value. For example, the FINGERPRINT Attribute may still safely be added afterwards, because it is known to appear after the MESSAGE-INTEGRITY.
request
- the Request in which the Attributes of
the STUN long-term credential mechanism are to be addedusername
- the value for the USERNAME Attribute to be added
to requestrealm
- the value for the REALM Attribute to be added to
requestnonce
- the value for the NONCE Attribute to be added to
requestStunException
- if anything goes wrong while adding the
Attributes to request which support the STUN long-term
credential mechanismpublic static Request createRefreshRequest()
public static Request createRefreshRequest(int lifetime)
lifetime
- lifetime valuepublic static Response createRefreshResponse(int lifetime)
lifetime
- the lifetime value to be used.public static Response createRefreshErrorResponse(char errorCode)
errorCode
- the error code to encapsulate in this message.public static Response createRefreshErrorResponse(char errorCode, String reasonPhrase)
errorCode
- the error code to encapsulate in this message.reasonPhrase
- a human readable description of the error.public static Request createChannelBindRequest(char channelNumber, TransportAddress peerAddress, byte[] tranID)
channelNumber
- the channel numberpeerAddress
- the peer addresstranID
- the ID of the transaction that we should be usingpublic static Response createChannelBindResponse()
public static Response createChannelBindErrorResponse(char errorCode)
errorCode
- the error code to encapsulate in this message.public static Response createChannelBindErrorResponse(char errorCode, String reasonPhrase)
errorCode
- the error code to encapsulate in this message.reasonPhrase
- a human readable description of the error.public static Request createCreatePermissionRequest(TransportAddress peerAddress, byte[] transactionID)
peerAddress
- the value to assigned to the XOR-PEER-ADDRESS
attributetransactionID
- the ID of the transaction which is to be used for
the assignment of peerAddress to the XOR-PEER-ADDRESS attributepublic static Response createCreatePermissionResponse()
public static Response createCreatePermissionErrorResponse(char errorCode)
errorCode
- the error code to encapsulate in this message.public static Response createPermissionErrorResponse(char errorCode, String reasonPhrase)
errorCode
- the error code to encapsulate in this message.reasonPhrase
- a human readable description of the error.public static Indication createSendIndication(TransportAddress peerAddress, byte[] data, byte[] tranID)
peerAddress
- peer addressdata
- data (could be 0 byte)tranID
- the ID of the transaction that we should be usingpublic static Indication createDataIndication(TransportAddress peerAddress, byte[] data, byte[] tranID)
peerAddress
- peer addressdata
- data (could be 0 byte)tranID
- the ID of the transaction that we should be usingpublic static Request createSendRequest(String username, TransportAddress peerAddress, byte[] data)
username
- the usernamepeerAddress
- peer addressdata
- data (could be 0 byte)public static Request createSharedSecretRequest()
public static Response createSharedSecretResponse()
public static Response createSharedSecretErrorResponse()
public static Request createConnectRequest(TransportAddress peerAddress, Request request) throws IllegalArgumentException
request
- the request that created the transaction that this
response will belong to.peerAddress
- the address to assign the xorPeerAddressAttributeIllegalArgumentException
- if there was something wrong with the
way we are trying to create the response.public static Request createConnectRequest(TransportAddress peerAddress, byte[] transactionId) throws IllegalArgumentException
peerAddress
- the address to assign the xorPeerAddressAttributetransactionId
- the transaction id that this response will belong
to.IllegalArgumentException
- if there was something wrong with the
way we are trying to create the response.public static Response createConnectResponse(int connectionIdValue) throws IllegalArgumentException
connectionIdValue
- the address to assign the connectionIdAttributeIllegalArgumentException
- if there was something wrong with the
way we are trying to create the response.public static Response createConnectErrorResponse(char errorCode) throws IllegalArgumentException
errorCode
- the error code to encapsulate in this messageIllegalArgumentException
- INVALID_ARGUMENTS if one or more of the
given parameters had an invalid value.public static Response createConnectErrorResponse(char errorCode, String reasonPhrase) throws IllegalArgumentException
errorCode
- the error code to encapsulate in this messagereasonPhrase
- a human readable description of the errorIllegalArgumentException
- INVALID_ARGUMENTS if one or more of the
given parameters had an invalid value.public static Request createConnectionBindRequest(int connectionIdValue) throws IllegalArgumentException
connectionIdValue
- the value to assign the connectionIdAtributeIllegalArgumentException
- if there was something wrong with the
way we are trying to create the Request.public static Response createConnectionBindResponse() throws IllegalArgumentException
IllegalArgumentException
- if there was something wrong with the
way we are trying to create the response.public static Response createConnectionBindErrorResponse(char errorCode) throws IllegalArgumentException
errorCode
- the error code to encapsulate in this messageIllegalArgumentException
- INVALID_ARGUMENTS if one or more of the
given parameters had an invalid value.public static Response createConnectionBindErrorResponse(char errorCode, String reasonPhrase) throws IllegalArgumentException
errorCode
- the error code to encapsulate in this messagereasonPhrase
- a human readable description of the errorIllegalArgumentException
- INVALID_ARGUMENTS if one or more of the
given parameters had an invalid value.public static Indication createConnectionAttemptIndication(int connectionIdValue, TransportAddress peerAddress) throws IllegalArgumentException
connectionIdValue
- the value to assign the connectionidAtributepeerAddress
- the value to assign the xorPeerAddressIllegalArgumentException
- if there was something wrong with the
way we are trying to create the Request.public static Indication createConnectionAttemptIndication(int connectionIdValue, TransportAddress peerAddress, byte[] transactionId) throws IllegalArgumentException, StunException
connectionIdValue
- the value to assign the connectionidAtributepeerAddress
- the value to assign the xorPeerAddresstransactionId
- the transaction id that the response belongs to.IllegalArgumentException
- if there was something wrong with the
way we are trying to create the Request.StunException
- when the transaction id is not valid.Copyright © 2018. All rights reserved.