spoke/core/session_state

Persisted MQTT sessions (e.g. across client restarts) need to store their state. This modules contains the types required for the persistence.

Types

A QoS > 0 packet has multiple states across its lifetime, they are represented by PacketState

pub type PacketState {
  UnackedQoS1(message: packet.MessageData)
  UnreceivedQoS2(message: packet.MessageData)
  ReceivedQoS2
  UnreleasedQoS2
}

Constructors

  • UnackedQoS1(message: packet.MessageData)

    A QoS 1 message published by the client, for which we have not received a PUBACK.

  • UnreceivedQoS2(message: packet.MessageData)

    A QoS 2 message published by the client, for which we have not received a PUBREC.

  • ReceivedQoS2

    A QoS 2 message published by the client, for which we have received a PUBREC, but not PUBCOMP.

  • UnreleasedQoS2

    A QoS 2 message received by the client, for which we have not yet received a PUBREL.

The full session state, in a key-value store friendly format.

pub type SessionState {
  SessionState(
    packet_id: Int,
    packet_states: List(#(Int, PacketState)),
  )
}

Constructors

  • SessionState(
      packet_id: Int,
      packet_states: List(#(Int, PacketState)),
    )

Represents an action to update the persistent session state.

pub type StorageUpdate {
  ClearSession
  StoreNextPacketId(id: Int)
  ClearPacketState(id: Int)
  UpdatePacketState(id: Int, state: PacketState)
}

Constructors

  • ClearSession

    Clear the whole session (all packet ids).

  • StoreNextPacketId(id: Int)

    Store the next packet id to use.

  • ClearPacketState(id: Int)

    Clear the state of a single packet. There might be redundant messages of this kind.

  • UpdatePacketState(id: Int, state: PacketState)

    Update the state of a single packet (replaces previous state).

Search Document