diff options
Diffstat (limited to 'shard/lib/net/group.ex')
-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}))) |