# `NoNoncense.MachineId.Strategy.HostIdentifiers`
[🔗](https://github.com/juulSme/NoNoncense/blob/v2.0.0/lib/no_noncense/machine_id/strategy/host_identifiers.ex#L1)

Strategy to assign machine IDs based on the current node's network identifiers (hostname,
FQDN, IP addresses, or OTP node name), matched against a fixed list of all possible nodes.

Each entry in `node_list` receives a stable zero-based index as its machine ID. No external
coordinator is required — IDs are determined locally — but every node must be configured with
the same list. The list is treated as a set: insertion order does not affect which ID is
assigned.

Configure the strategy when starting `NoNoncense.MachineId`:

    children = [
      {NoNoncense.MachineId,
       strategy: NoNoncense.MachineId.Strategy.HostIdentifiers,
       strategy_opts: [node_list: [:"myapp@10.0.0.1", :"myapp@10.0.0.2"]],
       instances: [[base_key: System.fetch_env!("BASE_KEY")]]}
    ]

The default `ConflictGuard` detects duplicate IDs among connected Erlang nodes.

## Options

  * `:node_list` (required) - identifiers (IP addresses, OTP node names, hostnames, or FQDNs)
    for every node in the cluster; must be identical on every node and must not contain
    identifiers shared across nodes (e.g. do not include `:"nonode@nohost"`)

> #### Use the same node list everywhere {: .warning}
>
> Your `node_list` must be the same for every node or the generated machine IDs will not be unique.

# `host_identifiers`

```elixir
@type host_identifiers() :: [binary() | atom()]
```

# `opt`

```elixir
@type opt() :: {:node_list, host_identifiers()}
```

# `host_identifiers`

```elixir
@spec host_identifiers() :: host_identifiers()
```

Get a list of all identifiers of the current node. You can use one or more of these values to populate your node list.

## Examples / doctests

    iex> host_identifiers()
    [:nonode@nohost, "host.mydomain.com", "10.11.12.13", "myhost", "fe80::1234::abcd"]

# `id!`

```elixir
@spec id!([opt()]) :: non_neg_integer()
```

Determine the current node's machine ID.

## Examples / doctests

    # provide a list of possible node identifiers
    iex> node_list = [:a, :b, :nonode@nohost, "1.1.1.1"]
    iex> id!(node_list: node_list)
    2

    # raises when the machine ID could not be determined from the node list
    iex> node_list = ["1.1.1.1"]
    iex> id!(node_list: node_list)
    ** (RuntimeError) machine ID could not be determined

---

*Consult [api-reference.md](api-reference.md) for complete listing*
