aboutsummaryrefslogtreecommitdiff
path: root/shard/lib
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2018-10-12 17:01:10 +0200
committerAlex Auvolat <alex@adnab.me>2018-10-12 17:01:10 +0200
commit7bc609a85b43ed86eccb9cd40d9db31f15aaba1d (patch)
tree80b31e39e029bb89793d95fab76bf8310031d76d /shard/lib
parent76749e8f64ce3caf7e0e5c17dfee373dcf4dfe6e (diff)
downloadshard-7bc609a85b43ed86eccb9cd40d9db31f15aaba1d.tar.gz
shard-7bc609a85b43ed86eccb9cd40d9db31f15aaba1d.zip
More notifications going around
Diffstat (limited to 'shard/lib')
-rw-r--r--shard/lib/app/chat.ex6
-rw-r--r--shard/lib/app/identity.ex6
-rw-r--r--shard/lib/cli/cli.ex2
-rw-r--r--shard/lib/net/group.ex14
4 files changed, 22 insertions, 6 deletions
diff --git a/shard/lib/app/chat.ex b/shard/lib/app/chat.ex
index 8d55cda..8c55869 100644
--- a/shard/lib/app/chat.ex
+++ b/shard/lib/app/chat.ex
@@ -228,6 +228,7 @@ defmodule SApp.Chat do
GenServer.cast(state.page_store, {:set_roots, [mst2.root]})
save_state(state)
msg_callback(state, msgitem)
+ SNet.Group.broadcast(state.netgroup, {state.id, nil, msg}, exclude_pid: [conn_pid])
state
else
Logger.warn("Invalid new root after inserting same message item!")
@@ -262,6 +263,8 @@ defmodule SApp.Chat do
end
defp init_merge(state, new_root, source_peer_pid) do
+ old_root = state.mst.root
+
if new_root == nil do
state
else
@@ -291,6 +294,9 @@ defmodule SApp.Chat do
GenServer.cast(state.page_store, {:set_roots, [mst.root]})
state = %{state | mst: mst}
save_state(state)
+ if state.mst.root != old_root do
+ SNet.Group.broadcast(state.netgroup, {state.id, nil, {:root, state.mst.root, false}}, exclude_pid: [source_peer_pid])
+ end
state
else
Logger.warn("Incorrect signatures somewhere while merging, dropping merged data")
diff --git a/shard/lib/app/identity.ex b/shard/lib/app/identity.ex
index 02e8eb9..95ffb92 100644
--- a/shard/lib/app/identity.ex
+++ b/shard/lib/app/identity.ex
@@ -112,9 +112,9 @@ defmodule SApp.Identity do
{:noreply, state}
end
- defp bcast_state(state, _exclude \\ []) do
- # TODO: effectively apply exclude list
- SNet.Group.broadcast(state.netgroup, {state.id, nil, {:update, SData.SignRev.signed(state.state), false}})
+ defp bcast_state(state, exclude \\ []) do
+ msg = {state.id, nil, {:update, SData.SignRev.signed(state.state), false}}
+ SNet.Group.broadcast(state.netgroup, msg, exclude_pid: exclude)
end
# ================
diff --git a/shard/lib/cli/cli.ex b/shard/lib/cli/cli.ex
index 3b52fa5..319f96b 100644
--- a/shard/lib/cli/cli.ex
+++ b/shard/lib/cli/cli.ex
@@ -114,6 +114,7 @@ defmodule SCLI do
defp handle_command(state, ["join", qchan]) do
pid = Shard.Manager.find_or_start %SApp.Chat.Manifest{channel: qchan}
+ GenServer.cast(pid, {:subscribe, self()})
IO.puts "Switching to ##{qchan}"
%{state | room_pid: pid}
end
@@ -144,6 +145,7 @@ defmodule SCLI do
if Enum.all?(pk_list, &(&1 != :error)) do
manifest = SApp.Chat.PrivChat.Manifest.new([state.pk | pk_list])
pid = Shard.Manager.find_or_start manifest
+ GenServer.cast(pid, {:subscribe, self()})
IO.puts "Switching to private conversation."
%{state | room_pid: pid}
else
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})))