aboutsummaryrefslogtreecommitdiff
path: root/shard/lib/app/identity.ex
diff options
context:
space:
mode:
Diffstat (limited to 'shard/lib/app/identity.ex')
-rw-r--r--shard/lib/app/identity.ex45
1 files changed, 19 insertions, 26 deletions
diff --git a/shard/lib/app/identity.ex b/shard/lib/app/identity.ex
index 42d1bf8..bacfdab 100644
--- a/shard/lib/app/identity.ex
+++ b/shard/lib/app/identity.ex
@@ -24,11 +24,9 @@ defmodule SApp.Identity do
"""
defstruct [:pk]
- end
- defimpl Shard.Manifest, for: Manifest do
- def start(m) do
- DynamicSupervisor.start_child(Shard.DynamicSupervisor, {SApp.Identity, m.pk})
+ defimpl Shard.Manifest do
+ def module(_m), do: SApp.Identity
end
end
@@ -36,33 +34,28 @@ defmodule SApp.Identity do
defstruct [:info, :rev, :signed]
end
- def start_link(pk) do
- GenServer.start_link(__MODULE__, pk)
+ def start_link(manifest) do
+ GenServer.start_link(__MODULE__, manifest)
end
- def init(pk) do
- manifest = %Manifest{pk: pk}
+ def init(manifest) do
+ %Manifest{pk: pk} = manifest
id = SData.term_hash manifest
- case Shard.Manager.register(id, manifest, self()) do
- :ok ->
- Shard.Manager.dispatch_to(id, nil, self())
- state = case Shard.Manager.load_state(id) do
- nil ->
- info = %{nick: default_nick(pk)}
- SData.SignRev.new info
- st ->
- st
- end
- netgroup = %SNet.PubShardGroup{id: id}
- SNet.Group.init_lookup(netgroup, self())
- if Shard.Keys.have_sk? pk do
- GenServer.cast(self(), :update_peer_info)
- end
- {:ok, %{pk: pk, id: id, state: state, netgroup: netgroup}}
- :redundant ->
- exit(:redundant)
+ Shard.Manager.dispatch_to(id, nil, self())
+ state = case Shard.Manager.load_state(id) do
+ nil ->
+ info = %{nick: default_nick(pk)}
+ SData.SignRev.new info
+ st ->
+ st
+ end
+ netgroup = %SNet.PubShardGroup{id: id}
+ SNet.Group.init_lookup(netgroup, self())
+ if Shard.Keys.have_sk? pk do
+ GenServer.cast(self(), :update_peer_info)
end
+ {:ok, %{pk: pk, id: id, state: state, netgroup: netgroup}}
end
def handle_call(:manifest, _from, state) do