Current section
Files
Jump to
Current section
Files
lib/ex_reticulum/link.ex
defmodule ExReticulum.Link do
@moduledoc """
A bidirectional encrypted communication channel between two Reticulum nodes.
"""
alias ExReticulum.Native
@type t :: %__MODULE__{
ref: reference(),
id: binary(),
status: :pending | :handshake | :active | :stale | :closed
}
@enforce_keys [:ref, :id]
defstruct [:ref, :id, status: :pending]
defimpl Jason.Encoder do
def encode(link, opts) do
link
|> Map.take([:id, :status])
|> Map.update!(:id, &Base.encode16(&1, case: :lower))
|> Jason.Encode.map(opts)
end
end
@spec status(t()) :: {:ok, atom()} | {:error, atom()}
def status(%__MODULE__{ref: ref}) do
Native.link_status(ref)
end
@spec rtt(t()) :: {:ok, non_neg_integer()} | {:error, atom()}
def rtt(%__MODULE__{ref: ref}) do
Native.link_rtt(ref)
end
end