Package 

Class MessageFactory

  • All Implemented Interfaces:

    
    public class MessageFactory
    
                        

    This class provides factory methods to allow an application to create STUN and TURN messages from a particular implementation.

    • Constructor Detail

    • Method Detail

      • createBindingRequest

         static Request createBindingRequest()

        Creates a default binding request. The request DOES NOT contains a ChangeRequest attribute with zero change ip and change port flags.

      • createBindingRequest

         static Request createBindingRequest(long priority)

        Creates a default binding request. The request contains a ChangeReqeust attribute with zero change ip and change port flags. It also contains the PRIORITY attribute used for ICE processing

        Parameters:
        priority - the value for the priority attribute
      • createBindingRequest

         static Request createBindingRequest(long priority, boolean controlling, long tieBreaker)

        Creates a default binding request. The request contains a ChangeReqeust attribute with zero change ip and change port flags. It contains the PRIORITY, ICE-CONTROLLED or ICE-CONTROLLING attributes used for ICE processing

        Parameters:
        priority - the value of the ICE priority attributes
        controlling - the value of the controlling attribute
        tieBreaker - the value of the ICE tie breaker attribute
      • create3489BindingResponse

         static Response create3489BindingResponse(TransportAddress mappedAddress, TransportAddress sourceAddress, TransportAddress changedAddress)

        Creates a BindingResponse in a 3489 compliant manner, assigning the specified values to mandatory headers.

        Parameters:
        mappedAddress - the address to assign the mappedAddressAttribute
        sourceAddress - the address to assign the sourceAddressAttribute
        changedAddress - the address to assign the changedAddressAttribute
      • createBindingResponse

         static Response createBindingResponse(Request request, TransportAddress mappedAddress)

        Creates a BindingResponse in a 5389 compliant manner containing a single XOR-MAPPED-ADDRESS attribute

        Parameters:
        request - the request that created the transaction that this response will belong to.
        mappedAddress - the address to assign the mappedAddressAttribute
      • createBindingErrorResponse

         static Response createBindingErrorResponse(char errorCode, String reasonPhrase, Array<char> unknownAttributes)

        Creates a binding error response according to the specified error code and unknown attributes.

        Parameters:
        errorCode - the error code to encapsulate in this message
        reasonPhrase - a human readable description of the error
        unknownAttributes - a char[] array containing the ids of one or more attributes that had not been recognized.
      • createBindingErrorResponseUnknownAttributes

         static Response createBindingErrorResponseUnknownAttributes(Array<char> unknownAttributes)

        Creates a binding error response with UNKNOWN_ATTRIBUTES error code and the specified unknown attributes.

        Parameters:
        unknownAttributes - a char[] array containing the ids of one or more attributes that had not been recognized.
      • createBindingErrorResponseUnknownAttributes

         static Response createBindingErrorResponseUnknownAttributes(String reasonPhrase, Array<char> unknownAttributes)

        Creates a binding error response with UNKNOWN_ATTRIBUTES error code and the specified unknown attributes and reason phrase.

        Parameters:
        reasonPhrase - a short description of the error.
        unknownAttributes - a char[] array containing the ids of one or more attributes that had not been recognized.
      • createBindingErrorResponse

         static Response createBindingErrorResponse(char errorCode, String reasonPhrase)

        Creates a binding error response with an ERROR-CODE attribute.

        Parameters:
        errorCode - the error code to encapsulate in this message
        reasonPhrase - a human readable description of the error.
      • createBindingErrorResponse

         static Response createBindingErrorResponse(char errorCode)

        Creates a binding error response according to the specified error code.

        Parameters:
        errorCode - the error code to encapsulate in this message attributes that had not been recognized.
      • createAllocateRequest

         static Request createAllocateRequest(byte protocol, boolean rFlag)

        Create an allocate request to allocate an even port. Attention this does not have attributes for long-term authentication.

        Parameters:
        protocol - requested protocol number
        rFlag - R flag for the EVEN-PORT
      • createAllocationResponse

         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

        Parameters:
        request - the request that created the transaction that this response will belong to.
        mappedAddress - the address to assign the mappedAddressAttribute
        relayedAddress - the address to assign the relayedAddressAttribute
        lifetime - the address to assign the lifetimeAttribute
      • createAllocationResponse

         static Response createAllocationResponse(Request request, TransportAddress mappedAddress, TransportAddress relayedAddress, Array<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

        Parameters:
        request - the request that created the transaction that this response will belong to.
        mappedAddress - the address to assign the mappedAddressAttribute
        relayedAddress - the address to assign the relayedAddressAttribute
        token - the address to assign the reservationTokenAttribute
        lifetime - the address to assign the lifetimeAttribute
      • createAllocationErrorResponse

         static Response createAllocationErrorResponse(char errorCode)

        Creates a allocation error response according to the specified error code.

        Parameters:
        errorCode - the error code to encapsulate in this message attributes that had not been recognised.
      • createAllocationErrorResponse

         static Response createAllocationErrorResponse(char errorCode, String reasonPhrase)

        Creates a allocation error response according to the specified error code.

        Parameters:
        errorCode - the error code to encapsulate in this message
        reasonPhrase - a human readable description of the error attributes that had not been recognised.
      • createGoogleAllocateRequest

         static Request createGoogleAllocateRequest(String username)

        Create an allocate request for a Google TURN relay (old TURN protocol modified).

        Parameters:
        username - short-term username
      • addLongTermCredentialAttributes

         static void addLongTermCredentialAttributes(Request request, Array<byte> username, Array<byte> realm, Array<byte> nonce)

        Adds the Attributes to a specific Request which support the STUN long-term credential mechanism.

        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.

        Parameters:
        request - the Request in which the Attributes of the STUN long-term credential mechanism are to be added
        username - the value for the USERNAME Attribute to be added to request
        realm - the value for the REALM Attribute to be added to request
        nonce - the value for the NONCE Attribute to be added to request
      • createRefreshRequest

         static Request createRefreshRequest()

        Creates a new TURN Refresh Request without any optional attributes such as LIFETIME.

      • createRefreshRequest

         static Request createRefreshRequest(int lifetime)

        Create a refresh request.

        Parameters:
        lifetime - lifetime value
      • createRefreshResponse

         static Response createRefreshResponse(int lifetime)

        Creates a refresh success response with given lifetime.

        Parameters:
        lifetime - the lifetime value to be used.
      • createRefreshErrorResponse

         static Response createRefreshErrorResponse(char errorCode)

        Creates a refresh error response

        Parameters:
        errorCode - the error code to encapsulate in this message.
      • createRefreshErrorResponse

         static Response createRefreshErrorResponse(char errorCode, String reasonPhrase)

        Creates a refresh error response.

        Parameters:
        errorCode - the error code to encapsulate in this message.
        reasonPhrase - a human readable description of the error.
      • createChannelBindRequest

         static Request createChannelBindRequest(char channelNumber, TransportAddress peerAddress, Array<byte> tranID)

        Create a ChannelBind request.

        Parameters:
        channelNumber - the channel number
        peerAddress - the peer address
        tranID - the ID of the transaction that we should be using
      • createChannelBindErrorResponse

         static Response createChannelBindErrorResponse(char errorCode)

        Creates a Channel Bind Error Response with given error code.

        Parameters:
        errorCode - the error code to encapsulate in this message.
      • createChannelBindErrorResponse

         static Response createChannelBindErrorResponse(char errorCode, String reasonPhrase)

        Creates a Channel Bind Error Response with given error code and reasonPhrase.

        Parameters:
        errorCode - the error code to encapsulate in this message.
        reasonPhrase - a human readable description of the error.
      • createCreatePermissionRequest

         static Request createCreatePermissionRequest(TransportAddress peerAddress, Array<byte> transactionID)

        Creates a new TURN CreatePermission Request with a specific value for its XOR-PEER-ADDRESS attribute.

        Parameters:
        peerAddress - the value to assigned to the XOR-PEER-ADDRESS attribute
        transactionID - the ID of the transaction which is to be used for the assignment of peerAddress to the XOR-PEER-ADDRESS attribute
      • createCreatePermissionErrorResponse

         static Response createCreatePermissionErrorResponse(char errorCode)

        Creates a create permission error response.

        Parameters:
        errorCode - the error code to encapsulate in this message.
      • createPermissionErrorResponse

         static Response createPermissionErrorResponse(char errorCode, String reasonPhrase)

        Creates a create permission error response.

        Parameters:
        errorCode - the error code to encapsulate in this message.
        reasonPhrase - a human readable description of the error.
      • createSendIndication

         static Indication createSendIndication(TransportAddress peerAddress, Array<byte> data, Array<byte> tranID)

        Create a Send Indication.

        Parameters:
        peerAddress - peer address
        data - data (could be 0 byte)
        tranID - the ID of the transaction that we should be using
      • createDataIndication

         static Indication createDataIndication(TransportAddress peerAddress, Array<byte> data, Array<byte> tranID)

        Create a Data Indication.

        Parameters:
        peerAddress - peer address
        data - data (could be 0 byte)
        tranID - the ID of the transaction that we should be using
      • createConnectRequest

         static Request createConnectRequest(TransportAddress peerAddress, Request request)

        Creates a ConnectRequest in a 6062 compliant manner containing only XOR-PEER-ADDRESS attribute

        Parameters:
        peerAddress - the address to assign the xorPeerAddressAttribute
        request - the request that created the transaction that this response will belong to.
      • createConnectRequest

         static Request createConnectRequest(TransportAddress peerAddress, Array<byte> transactionId)

        Creates a ConnectRequest in a 6062 compliant manner containing only XOR-PEER-ADDRESS attribute. This method is used by turnserver.

        Parameters:
        peerAddress - the address to assign the xorPeerAddressAttribute
        transactionId - the transaction id that this response will belong to.
      • createConnectResponse

         static Response createConnectResponse(int connectionIdValue)

        Creates a Connect Response in a 6062 compliant manner containing a single CONNECTION-ID-ATTRIBUTE attribute

        Parameters:
        connectionIdValue - the address to assign the connectionIdAttribute
      • createConnectErrorResponse

         static Response createConnectErrorResponse(char errorCode)

        Creates a Connect error response according to the specified error code.

        Parameters:
        errorCode - the error code to encapsulate in this message
      • createConnectErrorResponse

         static Response createConnectErrorResponse(char errorCode, String reasonPhrase)

        Creates a Connect error response according to the specified error code.

        Parameters:
        errorCode - the error code to encapsulate in this message
        reasonPhrase - a human readable description of the error
      • createConnectionBindRequest

         static Request createConnectionBindRequest(int connectionIdValue)

        Creates a ConnectionBindRequest in a 6062 compliant manner containing only CONECTION-ID-ATTRIBUTE attribute.

        Parameters:
        connectionIdValue - the value to assign the connectionIdAtribute
      • createConnectionBindErrorResponse

         static Response createConnectionBindErrorResponse(char errorCode)

        Creates a ConnectionBind error response according to the specified error code.

        Parameters:
        errorCode - the error code to encapsulate in this message
      • createConnectionBindErrorResponse

         static Response createConnectionBindErrorResponse(char errorCode, String reasonPhrase)

        Creates a ConnectionBind error response according to the specified error code.

        Parameters:
        errorCode - the error code to encapsulate in this message
        reasonPhrase - a human readable description of the error
      • createConnectionAttemptIndication

         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.

        Parameters:
        connectionIdValue - the value to assign the connectionidAtribute
        peerAddress - the value to assign the xorPeerAddress
      • createConnectionAttemptIndication

         static Indication createConnectionAttemptIndication(int connectionIdValue, TransportAddress peerAddress, Array<byte> transactionId)

        Creates a ConnectionAttempt Indication in a 6062 compliant manner containing only CONECTION-ID-ATTRIBUTE attribute and XOR-PPER-ADDRESS attribute.

        Parameters:
        connectionIdValue - the value to assign the connectionidAtribute
        peerAddress - the value to assign the xorPeerAddress
        transactionId - the transaction id that the response belongs to.