aboutsummaryrefslogtreecommitdiff
path: root/shard/lib/app
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2018-10-11 17:52:25 +0200
committerAlex Auvolat <alex@adnab.me>2018-10-11 17:52:25 +0200
commit28c9cac2e92011e2f7e6f23e93e8a5d9480a0922 (patch)
treead81473619ba5b9c18e925323264f58982311662 /shard/lib/app
parente5a7330d0526efb592e200ab96c3f33585ae8d02 (diff)
downloadshard-28c9cac2e92011e2f7e6f23e93e8a5d9480a0922.tar.gz
shard-28c9cac2e92011e2f7e6f23e93e8a5d9480a0922.zip
Fix initiation issues
Diffstat (limited to 'shard/lib/app')
-rw-r--r--shard/lib/app/chat.ex13
-rw-r--r--shard/lib/app/identity.ex17
2 files changed, 21 insertions, 9 deletions
diff --git a/shard/lib/app/chat.ex b/shard/lib/app/chat.ex
index 61403b8..f874e86 100644
--- a/shard/lib/app/chat.ex
+++ b/shard/lib/app/chat.ex
@@ -154,8 +154,7 @@ defmodule SApp.Chat do
end
def handle_cast({:peer_connected, conn_pid}, state) do
- # this is called by the SNet.Group thing so it is already authenticated
- SNet.Manager.send_pid(conn_pid, {state.id, nil, {:root, state.mst.root}})
+ GenServer.cast(conn_pid, {:send_msg, {:interested, [state.id]}})
{:noreply, state}
end
@@ -165,7 +164,7 @@ defmodule SApp.Chat do
"""
def handle_cast({:interested, conn_pid, auth}, state) do
if SNet.Group.in_group?(state.netgroup, conn_pid, auth) do
- SNet.Manager.send_pid(conn_pid, {state.id, nil, {:root, state.mst.root}})
+ SNet.Manager.send_pid(conn_pid, {state.id, nil, {:root, state.mst.root, true}})
end
{:noreply, state}
end
@@ -225,13 +224,17 @@ defmodule SApp.Chat do
state
end
end
- {:root, new_root} ->
- if new_root == state.mst.root do
+ {:root, new_root, ask_reply} ->
+ state = if new_root == state.mst.root do
# already up to date, ignore
state
else
init_merge(state, new_root, conn_pid)
end
+ if ask_reply do
+ SNet.Manager.send_pid(conn_pid, {state.id, nil, {:root, state.mst.root, false}})
+ end
+ state
x ->
Logger.info("Unhandled message: #{inspect x}")
state
diff --git a/shard/lib/app/identity.ex b/shard/lib/app/identity.ex
index 255bebb..390ef6d 100644
--- a/shard/lib/app/identity.ex
+++ b/shard/lib/app/identity.ex
@@ -88,15 +88,20 @@ defmodule SApp.Identity do
end
end
+ def handle_cast({:peer_connected, peer_pid}, state) do
+ GenServer.cast(peer_pid, {:send_msg, {:interested, [state.id]}})
+ {:noreply, state}
+ end
+
def handle_cast({:interested, peer_pid, _auth}, state) do
- SNet.Manager.send_pid(peer_pid, {state.id, nil, {:update, SData.SignRev.signed(state.state)}})
+ SNet.Manager.send_pid(peer_pid, {state.id, nil, {:update, SData.SignRev.signed(state.state), true}})
{:noreply, state}
end
def handle_cast({:msg, conn_pid, _auth, _shard_id, nil, msg}, state) do
state = case msg do
- {:update, signed} when signed != nil ->
- case SData.SignRev.merge(state.state, signed, state.pk) do
+ {:update, signed, ask_reply} when signed != nil ->
+ state = case SData.SignRev.merge(state.state, signed, state.pk) do
{true, st2} ->
Shard.Manager.save_state(state.id, st2)
state = put_in(state.state, st2)
@@ -105,6 +110,10 @@ defmodule SApp.Identity do
{false, _} ->
state
end
+ if ask_reply do
+ SNet.Manager.send_pid(conn_pid, {state.id, nil, {:update, SData.SignRev.signed(state.state), false}})
+ end
+ state
_ -> state
end
{:noreply, state}
@@ -127,6 +136,6 @@ defmodule SApp.Identity do
def bcast_state(state, _exclude \\ []) do
# TODO: effectively apply exclude list
- SNet.Group.broadcast(state.netgroup, {state.id, nil, {:update, SData.SignRev.signed(state.state)}})
+ SNet.Group.broadcast(state.netgroup, {state.id, nil, {:update, SData.SignRev.signed(state.state), false}})
end
end