diff options
Diffstat (limited to 'shard/lib/app/identity.ex')
-rw-r--r-- | shard/lib/app/identity.ex | 17 |
1 files changed, 13 insertions, 4 deletions
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 |