ExWapp.Session.Worker.PostAuth (ExWapp v0.1.2)

Copy Markdown View Source

Post-authentication helpers triggered after the success node is received.

Handles LID persistence, PN↔LID mapping, prekey count queries, and prekey upload logic.

Summary

Functions

Handles the response to the digest query and finalizes post-auth.

Handles the response to SetPassive(false) and finalizes post-auth by default.

Handles the prekey count response from the server and decides whether to upload.

Persists the LID value from the success node and creates own PN↔LID mapping.

Refills the server prekey pool after an encrypt inventory notification.

Starts the post-auth flow after receiving the success node.

Functions

handle_digest_response(node, iq_type, state, build_unified_session_fun)

@spec handle_digest_response(
  ExWapp.Binary.Node.t(),
  String.t(),
  map(),
  (-> ExWapp.Binary.Node.t())
) ::
  {map(), list()}

Handles the response to the digest query and finalizes post-auth.

handle_passive_response(node, iq_type, state, build_digest_query_fun, build_unified_session_fun)

@spec handle_passive_response(
  ExWapp.Binary.Node.t(),
  String.t(),
  map(),
  (-> ExWapp.Binary.Node.t()),
  (-> ExWapp.Binary.Node.t())
) :: {map(), list()}

Handles the response to SetPassive(false) and finalizes post-auth by default.

Digest validation can be re-enabled with runtime: [protocol: [post_auth_digest_enabled: true]].

handle_prekey_count_response(node, state, build_passive_iq_fun)

@spec handle_prekey_count_response(
  ExWapp.Binary.Node.t(),
  map(),
  (-> ExWapp.Binary.Node.t())
) ::
  {map(), list()}

Handles the prekey count response from the server and decides whether to upload.

Returns {state, actions}.

handle_prekey_upload_response(node, binary, state, build_passive_iq_fun)

@spec handle_prekey_upload_response(
  ExWapp.Binary.Node.t(),
  String.t(),
  map(),
  (-> ExWapp.Binary.Node.t())
) :: {map(), list()}

Handles the response to a prekey upload IQ.

persist_lid_and_mapping(state, lid)

@spec persist_lid_and_mapping(ExWapp.Session.Worker.t(), binary() | nil) ::
  ExWapp.Session.Worker.t()

Persists the LID value from the success node and creates own PN↔LID mapping.

refill_from_notification(state, server_count)

@spec refill_from_notification(ExWapp.Session.Worker.t(), non_neg_integer()) ::
  {ExWapp.Session.Worker.t(), list()}

Refills the server prekey pool after an encrypt inventory notification.

The upload restores the pool toward the configured initial size instead of adding only a tiny fixed batch. An already in-flight upload is left alone.

start(state, build_passive_iq_fun)

@spec start(ExWapp.Session.Worker.t(), (-> ExWapp.Binary.Node.t())) ::
  {ExWapp.Session.Worker.t(), list()}

Starts the post-auth flow after receiving the success node.

To preserve live inbound delivery, the activation path mirrors the older working runtime sequence:

  1. query prekey count
  2. send SetPassive(false) immediately
  3. send presence type="available" immediately
  4. upload prekeys later only if the server count requires it

Digest validation remains available as an explicit opt-in, but it is disabled by default because some fresh-pair sessions are being invalidated immediately after the digest IQ is sent.