View Source ExSCTP (ex_sctp v0.1.1)

Utilities for establishing SCTP connection and sending data over it.

Summary

Types

Event obtained by calling poll/1.

SCTP Payload Protocol Identifier.

SCTP stream reliability types.

ID of the SCTP stream.

t()

Reference to mutable SCTP state.

Functions

Closes the stream with id.

Sets stream's order and reliability parameters.

Triggers connection establishment.

Handles data received from other peer.

Handles timeout.

Initializes new SCTP connection state.

Opens a new stream with specified id.

Produces event that needs to be handled by the library user.

Sends data over specified stream using provided ppi.

Types

@type event() ::
  :none
  | :connected
  | :disconnected
  | {:stream_opened, stream_id()}
  | {:stream_closed, stream_id()}
  | {:data, stream_id(), ppi(), binary()}
  | {:transmit, [binary()]}
  | {:timeout, non_neg_integer() | nil}

Event obtained by calling poll/1.

Meaning of the events:

  • :none - there's no more events to handle and no actions need to be taken
  • :connected and :disconnected - STCP connection has been established or closed
  • {:stream_opened, id} and {:stream_closed, id} - remote side either opened or closed a stream with provided id. This message is not created for locally opened or closed streams (by calling open_stream/2 or close_stream/2)
  • {:data, id, ppi, data} - data was received on stream with id and is marked with ppi PPI
  • {:transmit, [data]} - data needs to be transmited to the other peer. You need to send the packets using appropriate means, e.g. DTLS over ICE in case of WebRTC
  • {:timeout, val} - informs that handle_timeout/1 needs to be called after val milliseconds. If val is nil, handle_timeout/1 won't need to be called and awaiting timeouts can be canceled
@type ppi() :: non_neg_integer()

SCTP Payload Protocol Identifier.

@type reliability_type() :: :reliable | :rexmit | :timed

SCTP stream reliability types.

@type stream_id() :: 0..255

ID of the SCTP stream.

@opaque t()

Reference to mutable SCTP state.

Operate on it only using functions from this module.

Functions

Link to this function

close_stream(resource, id)

View Source
@spec close_stream(t(), stream_id()) :: :ok | {:error, atom()}

Closes the stream with id.

Calling this function will result in new events. See poll/1 for more information.

Link to this function

configure_stream(resource, id, ordered?, rel_param, rel_value)

View Source
@spec configure_stream(
  t(),
  stream_id(),
  boolean(),
  reliability_type(),
  non_neg_integer()
) ::
  :ok | {:error, atom()}

Sets stream's order and reliability parameters.

@spec connect(t()) :: :ok

Triggers connection establishment.

Calling this function will result in new events. See poll/1 for more information. Calling this function after :connected event was received will result in an error.

Link to this function

handle_data(resource, data)

View Source
@spec handle_data(t(), binary()) :: :ok

Handles data received from other peer.

Calling this function will result in new events. See poll/1 for more information.

Link to this function

handle_timeout(resource)

View Source
@spec handle_timeout(t()) :: :ok | {:error, atom()}

Handles timeout.

After receiving {:timeout, ms} event from poll/1, you must call this function after ms milliseconds. Calling this function will result in new events. See poll/1 for more information.

@spec new() :: t()

Initializes new SCTP connection state.

Link to this function

open_stream(resource, id)

View Source
@spec open_stream(t(), stream_id()) :: :ok | {:error, atom()}

Opens a new stream with specified id.

Calling this function will result in new events. See poll/1 for more information. Stream IDs need to be unique. Calling this function with already existing stream id will rsult in an error.

@spec poll(t()) :: event()

Produces event that needs to be handled by the library user.

New events can happen after IO is performed or timeout occurs. Related functions in this module specify explicitly that they result in new events. If such a function is called, the user needs to call poll/1 repeatedly and handle the events until the :none event is received.

See event/0 to learn how to handle events.

Link to this function

send(resource, id, ppi, data)

View Source
@spec send(t(), stream_id(), ppi(), binary()) :: :ok | {:error, atom()}

Sends data over specified stream using provided ppi.

Calling this function will result in new events. See poll/1 for more information.