Configurable worker ID source #4

Open
opened 2019-09-24 11:35:48 +00:00 by minibikini · 1 comment
Member

Currently, it's Random. Normal flakes use the MAC address.

We changed it to a random for safety reason in the Pleroma ecosystem and because breaking this unique safety was okay (we don't run clusters). However, some people do run huge clusters, care less about leaking some information and need guarantees which they could get with the MAC source.

Probably, the default worker ID source should be Random.

Suggested by @href.

Currently, it's Random. Normal flakes use the MAC address. We changed it to a random for safety reason in the Pleroma ecosystem and because breaking this unique safety was okay (we don't run clusters). However, some people do run huge clusters, care less about leaking some information and need guarantees which they could get with the MAC source. Probably, the default worker ID source should be `Random`. *Suggested by @href.*
Author
Member

A snippet to generate MAC-based worker ID:

  defp mac do
    {:ok, addresses} = :inet.getifaddrs()
    ifaces_with_mac = Enum.reduce(addresses, [], fn({ iface, attrs }, acc) -> if attrs[:hwaddr], do: [ iface | acc ], else: acc end)
    iface = Enum.at(ifaces_with_mac, :random.uniform(length(ifaces_with_mac))-1)
    mac(iface)
  end

  defp mac(name) do
    {:ok, addresses} = :inet.getifaddrs()
    proplist = :proplists.get_value(name, addresses)
    hwaddr = Enum.take(:proplists.get_value(:hwaddr, proplist), 6)
    <<worker::integer-size(48)>> = :binary.list_to_bin(hwaddr)
    worker
  end

(c) @href

A snippet to generate MAC-based worker ID: ```elixir defp mac do {:ok, addresses} = :inet.getifaddrs() ifaces_with_mac = Enum.reduce(addresses, [], fn({ iface, attrs }, acc) -> if attrs[:hwaddr], do: [ iface | acc ], else: acc end) iface = Enum.at(ifaces_with_mac, :random.uniform(length(ifaces_with_mac))-1) mac(iface) end defp mac(name) do {:ok, addresses} = :inet.getifaddrs() proplist = :proplists.get_value(name, addresses) hwaddr = Enum.take(:proplists.get_value(:hwaddr, proplist), 6) <<worker::integer-size(48)>> = :binary.list_to_bin(hwaddr) worker end ``` (c) @href
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
pleroma-elixir-libraries/flake_id#4
No description provided.