LibclusterMesh.Peer (libcluster_mesh v0.1.0)

Copy Markdown View Source

A peer on the mesh network, as reported by the local mesh daemon.

Note that node_name/2 creates atoms at runtime (Erlang node names are atoms). This is safe under the library's trust model — the local mesh daemon is trusted input and a mesh has a bounded set of peer IPs — but it is one more reason not to point the strategies at untrusted data sources.

Summary

Functions

Returns true when the peer's hostname starts with any of the given prefixes.

Builds a node name from a basename and the peer's mesh IP.

Types

t()

@type t() :: %LibclusterMesh.Peer{
  hostname: String.t(),
  ip: String.t(),
  online?: boolean()
}
  • ip — mesh IPv4 address as a string (e.g. "100.64.0.7")
  • hostname — bare host name (first DNS label, e.g. "myapp-2"), or the mesh IP on meshes that have no hostnames
  • online? — whether the daemon reports the peer as online

Functions

matches?(peer, prefixes)

@spec matches?(t(), [String.t()]) :: boolean()

Returns true when the peer's hostname starts with any of the given prefixes.

iex> peer = %LibclusterMesh.Peer{ip: "100.64.0.7", hostname: "myapp-2"}
iex> LibclusterMesh.Peer.matches?(peer, ["myapp-"])
true
iex> LibclusterMesh.Peer.matches?(peer, ["other"])
false

node_name(peer, basename)

@spec node_name(t(), String.t()) :: node()

Builds a node name from a basename and the peer's mesh IP.

iex> peer = %LibclusterMesh.Peer{ip: "100.64.0.7", hostname: "myapp-2"}
iex> LibclusterMesh.Peer.node_name(peer, "myapp")
:"myapp@100.64.0.7"