Meshcore.Commands.Contact (Meshcore v0.1.0)

Copy Markdown View Source

Commands for managing the device's contact list.

A contact is a map with the keys the device reports in :contacts and :next_contact events: :public_key (hex), :type, :flags, :out_path_len, :out_path_hash_mode, :out_path (hex), :adv_name, :last_advert, :adv_lat, :adv_lon, :lastmod.

Summary

Functions

Alias for update_contact/3 with no changes: adds contact to the device.

Changes a contact's flags.

Changes a contact's out path. See update_contact/3 for the path format.

Exports a contact (or, with nil, this node) as a meshcore:// URI (:contact_uri).

Reads the last known advert path of a contact (:advert_path).

Reads the auto-add configuration (:autoadd_config).

Fetches a single contact by its 32 byte public key (:next_contact), or an error if it is unknown.

Fetches the contact list and waits for the :contacts event, whose payload is a map public_key_hex => contact.

Asks for the contact list without waiting (the :contacts event follows).

Imports a contact card (raw bytes, as found after meshcore://).

Removes a contact.

Resets the stored path of a contact (it will be reached by flooding).

Sets the auto-add configuration bit field.

Shares a contact with the mesh.

Writes a contact to the device (add or update).

Types

contact()

@type contact() :: map()

mc()

@type mc() :: GenServer.server()

result()

@type result() :: {:ok, Meshcore.Event.t()} | {:error, Meshcore.Event.t()}

Functions

add_contact(mc, contact)

@spec add_contact(mc(), contact()) :: result()

Alias for update_contact/3 with no changes: adds contact to the device.

change_contact_flags(mc, contact, flags)

@spec change_contact_flags(mc(), contact(), non_neg_integer()) :: result()

Changes a contact's flags.

change_contact_path(mc, contact, path, opts \\ [])

@spec change_contact_path(mc(), contact(), String.t(), keyword()) :: result()

Changes a contact's out path. See update_contact/3 for the path format.

export_contact(mc, key \\ nil)

@spec export_contact(mc(), Meshcore.Util.destination() | nil) :: result()

Exports a contact (or, with nil, this node) as a meshcore:// URI (:contact_uri).

get_advert_path(mc, key)

@spec get_advert_path(mc(), Meshcore.Util.destination()) :: result()

Reads the last known advert path of a contact (:advert_path).

get_autoadd_config(mc)

@spec get_autoadd_config(mc()) :: result()

Reads the auto-add configuration (:autoadd_config).

get_contact_by_key(mc, pubkey)

@spec get_contact_by_key(mc(), binary()) :: result()

Fetches a single contact by its 32 byte public key (:next_contact), or an error if it is unknown.

get_contacts(mc, opts \\ [])

@spec get_contacts(mc(), keyword()) :: result()

Fetches the contact list and waits for the :contacts event, whose payload is a map public_key_hex => contact.

The timeout restarts every time another contact arrives, so large lists don't time out. Options: :lastmod (only contacts changed since, default 0), :timeout (ms of silence tolerated, default 5_000).

get_contacts_async(mc, lastmod \\ 0)

@spec get_contacts_async(mc(), non_neg_integer()) :: result()

Asks for the contact list without waiting (the :contacts event follows).

import_contact(mc, card_data)

@spec import_contact(mc(), binary()) :: result()

Imports a contact card (raw bytes, as found after meshcore://).

remove_contact(mc, key)

@spec remove_contact(mc(), Meshcore.Util.destination()) :: result()

Removes a contact.

reset_path(mc, key)

@spec reset_path(mc(), Meshcore.Util.destination()) :: result()

Resets the stored path of a contact (it will be reached by flooding).

set_autoadd_config(mc, flag)

@spec set_autoadd_config(mc(), 0..255) :: result()

Sets the auto-add configuration bit field.

share_contact(mc, key)

@spec share_contact(mc(), Meshcore.Util.destination()) :: result()

Shares a contact with the mesh.

update_contact(mc, contact, opts \\ [])

@spec update_contact(mc(), contact(), keyword()) :: result()

Writes a contact to the device (add or update).

Options:

  • :path – new out path as a hex string, optionally suffixed with ":" <> mode ("aabbcc:1"); "" makes it a zero-hop path
  • :path_hash_mode – hash mode for :path; when neither it nor a suffix is given the device's current mode is queried
  • :flags – new contact flags

The stored copy of the contact in the client is updated on success.