aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorhref <href@random.sh>2019-01-24 13:08:27 +0100
committerhref <href@random.sh>2019-01-24 13:08:27 +0100
commitbe43aa2875e08cd48b10fc0157d71239f098d1e4 (patch)
treeade000a41b1c851b8804c12c2fc326bad8ca6513 /lib
parent9ba6e1fabed3a583ba09c730efb144939a3a15a8 (diff)
downloadpleroma-be43aa2875e08cd48b10fc0157d71239f098d1e4.tar.gz
FlakeId: ignore null mac for workerid, use first mac
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/flake_id.ex22
1 files changed, 11 insertions, 11 deletions
diff --git a/lib/pleroma/flake_id.ex b/lib/pleroma/flake_id.ex
index 6b83ee890..26399ae05 100644
--- a/lib/pleroma/flake_id.ex
+++ b/lib/pleroma/flake_id.ex
@@ -161,23 +161,23 @@ defmodule Pleroma.FlakeId do
1_000_000_000 * mega_seconds + seconds * 1000 + :erlang.trunc(micro_seconds / 1000)
end
- defp mac do
+ def mac do
{:ok, addresses} = :inet.getifaddrs()
- ifaces_with_mac =
- Enum.reduce(addresses, [], fn {iface, attrs}, acc ->
- if attrs[:hwaddr], do: [iface | acc], else: acc
+ 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)
- iface = Enum.at(ifaces_with_mac, :rand.uniform(length(ifaces_with_mac)) - 1)
- mac(iface)
+ List.first(macids)
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)
+ def mac_to_worker_id(mac) do
+ <<worker::integer-size(48)>> = :binary.list_to_bin(mac)
worker
end
end