From: href Date: Sun, 27 Jan 2019 15:04:36 +0000 (+0100) Subject: Flake: random worker id X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=e0e0cc5ab044b64b83abf6382780ff1342025a43;p=akkoma Flake: random worker id --- diff --git a/lib/pleroma/flake_id.ex b/lib/pleroma/flake_id.ex index 26399ae05..3623ac597 100644 --- a/lib/pleroma/flake_id.ex +++ b/lib/pleroma/flake_id.ex @@ -90,7 +90,7 @@ defmodule Pleroma.FlakeId do @impl GenServer def init([]) do - {:ok, %FlakeId{node: mac(), time: time()}} + {:ok, %FlakeId{node: worker_id(), time: time()}} end @impl GenServer @@ -161,23 +161,8 @@ defmodule Pleroma.FlakeId do 1_000_000_000 * mega_seconds + seconds * 1000 + :erlang.trunc(micro_seconds / 1000) end - def mac do - {:ok, addresses} = :inet.getifaddrs() - - macids = - Enum.reduce(addresses, [], fn {_iface, attrs}, acc -> - case attrs[:hwaddr] do - [0, 0, 0 | _] -> acc - mac when is_list(mac) -> [mac_to_worker_id(mac) | acc] - _ -> acc - end - end) - - List.first(macids) - end - - def mac_to_worker_id(mac) do - <> = :binary.list_to_bin(mac) + defp worker_id() do + <> = :crypto.strong_rand_bytes(6) worker end end