diff options
author | Alex Auvolat <alex@adnab.me> | 2018-10-12 17:01:10 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2018-10-12 17:01:10 +0200 |
commit | 7bc609a85b43ed86eccb9cd40d9db31f15aaba1d (patch) | |
tree | 80b31e39e029bb89793d95fab76bf8310031d76d /shard/lib/net | |
parent | 76749e8f64ce3caf7e0e5c17dfee373dcf4dfe6e (diff) | |
download | shard-7bc609a85b43ed86eccb9cd40d9db31f15aaba1d.tar.gz shard-7bc609a85b43ed86eccb9cd40d9db31f15aaba1d.zip |
More notifications going around
Diffstat (limited to 'shard/lib/net')
-rw-r--r-- | shard/lib/net/group.ex | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/shard/lib/net/group.ex b/shard/lib/net/group.ex index 7086c2d..3cce22a 100644 --- a/shard/lib/net/group.ex +++ b/shard/lib/net/group.ex @@ -21,7 +21,7 @@ defprotocol SNet.Group do Broadcast a message to peers of the group. Will send to at most nmax peers, so this is a good primitive for gossip. """ - def broadcast(group, msg, nmax \\ 10) + def broadcast(group, msg, opts \\ []) @doc""" Check if a peer is allowed to participate in this group. @@ -58,9 +58,13 @@ defmodule SNet.PubShardGroup do |> Enum.map(fn [{pid, _auth}|_] -> pid end) end - def broadcast(group, msg, nmax) do + def broadcast(group, msg, opts) do + nmax = opts[:nmax] || 10 + exclude_pid = opts[:exclude_pid] || [] + %SNet.PubShardGroup{id: id} = group nsent = get_connections(group) + |> Enum.filter(&(&1 not in exclude_pid)) |> Enum.shuffle |> Enum.take(nmax) |> Enum.map(&(GenServer.cast(&1, {:send_msg, msg}))) @@ -116,9 +120,13 @@ defmodule SNet.PrivGroup do do: pid end - def broadcast(group, msg, nmax) do + def broadcast(group, msg, opts) do + nmax = opts[:nmax] || 10 + exclude_pid = opts[:exclude_pid] || [] + %SNet.PrivGroup{pk_list: pk_list} = group nsent = get_connections(group) + |> Enum.filter(&(&1 not in exclude_pid)) |> Enum.shuffle |> Enum.take(nmax) |> Enum.map(&(GenServer.cast(&1, {:send_msg, msg}))) |