ExWapp.Session.Outbound.Prekeys (ExWapp v0.1.2)

Copy Markdown View Source

Prekey target decisions and Signal-session bootstrap for outbound messages.

Raw network requests, response receives, and persistence remain in the outbound worker. This module owns deterministic target selection, batch and individual fallback decisions, missing-bundle retries, and the transformation of parsed prekey bundles into Signal sessions.

Summary

Functions

Expands a partial recipient prekey selection to all known recipient devices.

Fetches direct-message prekeys with batch fallback and missing-bundle retry.

Fetches group distribution prekeys with batch and individual fallback.

Returns requested device JIDs for which no prekey bundle was returned.

Types

fetch_many_fun()

@type fetch_many_fun() :: ([String.t()], ExWapp.Signal.SessionStore.t() ->
                       fetch_result())

fetch_one_fun()

@type fetch_one_fun() :: (String.t(), ExWapp.Signal.SessionStore.t() ->
                      fetch_result())

fetch_result()

@type fetch_result() ::
  {:ok, ExWapp.Signal.SessionStore.t(), map()} | {:error, term()}

fetch_state()

@type fetch_state() :: ExWapp.Signal.SessionStore.t() | {:error, term()}

Functions

create_sessions_for_bundles(signal_sessions, requested_jid, bundles, local_identity, local_reg_id, lid_mapping)

@spec create_sessions_for_bundles(
  ExWapp.Signal.SessionStore.t(),
  term(),
  [map()],
  term(),
  non_neg_integer(),
  map()
) :: {:ok, ExWapp.Signal.SessionStore.t(), map()} | {:error, term()}

Creates Signal sessions and bundle aliases from parsed prekey bundles.

devices_needing_prekeys(signal_sessions, target_jids, own_device_jids, lid_mapping, session_max_age_ms, now_ms)

@spec devices_needing_prekeys(
  ExWapp.Signal.SessionStore.t(),
  [term()],
  [term()],
  map(),
  pos_integer(),
  integer()
) :: [String.t()]

Returns outbound devices that require a prekey bootstrap.

Local-account identities are always refreshed. Other targets are selected when their PN/LID session is missing or older than the configured maximum.

expand_recipient_identity_targets(devices_needing_prekeys, recipient_devices)

@spec expand_recipient_identity_targets([term()], [term()]) :: [String.t()]

Expands a partial recipient prekey selection to all known recipient devices.

fetch_direct(devices_needing_prekeys, signal_sessions, recipient_base_jid, fetch_many_fun, fetch_one_fun)

Fetches direct-message prekeys with batch fallback and missing-bundle retry.

fetch_group(devices_needing_prekeys, signal_sessions, context, fetch_many_fun, fetch_one_fun)

@spec fetch_group(
  [String.t()],
  ExWapp.Signal.SessionStore.t(),
  term(),
  fetch_many_fun(),
  fetch_one_fun()
) :: {fetch_state(), map()}

Fetches group distribution prekeys with batch and individual fallback.

Missing bundles are retried individually after the initial result.

missing_bundle_targets(requested_device_jids, prekey_bundles)

@spec missing_bundle_targets([term()], map()) :: [String.t()]

Returns requested device JIDs for which no prekey bundle was returned.

targets_needing_prekeys(signal_sessions, target_jids, forced_identity_set, lid_mapping, session_max_age_ms, now_ms)

@spec targets_needing_prekeys(
  ExWapp.Signal.SessionStore.t(),
  [term()],
  MapSet.t({String.t(), String.t()}),
  map(),
  pos_integer(),
  integer()
) :: [String.t()]

Selects targets requiring prekeys with an explicit forced identity set.

This form is shared by group sender-key distribution.