NervesHubLink.Extensions.NetworkIdentity (nerves_hub_link v2.14.0)

Copy Markdown View Source

The Network Identity Extension.

Reports the identities this device holds on networks NervesHub does not run — an iroh endpoint id, a NetBird or Tailscale peer key, a WireGuard public key — so an operator can see them on the device page and reach the device by a route other than its NervesHub socket.

Nothing is reported unless you configure at least one provider, because NervesHubLink cannot discover these on its own. See NervesHubLink.Extensions.NetworkIdentity.Provider.

config :nerves_hub_link,
  network_identity: [providers: [MyApp.IrohIdentity]]

When identities are sent

NervesHub asks for all of them once, when the extension attaches. After that the device checks its own providers every interval_minutes and sends only what changed.

config :nerves_hub_link,
  network_identity: [
    providers: [MyApp.IrohIdentity],
    interval_minutes: 5
  ]

The polling is not about the identifier, which does not move: a key is a key. It is about everything a provider puts beside it. A device that switches relay keeps its endpoint id and changes the address anyone would reach it on, and a stale address is worse than no address when it is the only route to the device.

Nothing goes over the wire when nothing has changed, so the interval costs one local call per provider and no traffic. Set interval_minutes: 0 to switch the poll off and send only on connect.

A provider that knows the moment its identity changed need not wait for the poll — see send_identity/1.

Summary

Functions

Collect the identities the configured providers report, without sending them.

Send every configured provider's identity to NervesHub now.

Send one provider's identity to NervesHub now.

Functions

identities()

@spec identities() :: [map()]

Collect the identities the configured providers report, without sending them.

Useful from a console when working out why a device isn't showing what you expect.

send_identities()

@spec send_identities() :: :ok | :error

Send every configured provider's identity to NervesHub now.

Sends all of them whether or not they have changed, which is what the poll deliberately avoids doing. Rarely needed by hand: NervesHub asks on connect, and the poll notices anything that moves after that.

Examples

iex> NervesHubLink.Extensions.NetworkIdentity.send_identities()
:ok

send_identity(provider)

@spec send_identity(module()) :: :ok | :error

Send one provider's identity to NervesHub now.

For a provider that knows the moment its identity changed and would rather say so than wait up to interval_minutes for the poll to notice — a library that already watches its own relay assignment, say.

NervesHubLink.Extensions.NetworkIdentity.send_identity(MyApp.IrohIdentity)

What is sent updates what the poll considers current, so announcing a change this way does not make the next poll send it a second time.

Returns :error when the provider has nothing to report or the socket is detached. Neither is worth handling: the poll picks the identity up once it is available and the connection is back.