From 574b572fac144135c4381581351445bf5d0de81c Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 12 Oct 2018 18:16:46 +0200 Subject: Clean up interface to shards --- shard/lib/app/identity.ex | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) (limited to 'shard/lib/app/identity.ex') diff --git a/shard/lib/app/identity.ex b/shard/lib/app/identity.ex index 95ffb92..42d1bf8 100644 --- a/shard/lib/app/identity.ex +++ b/shard/lib/app/identity.ex @@ -1,14 +1,29 @@ defmodule SApp.Identity do + @moduledoc""" + Shard application for keeping state associated with a user's identity. + + Current functionality: + + - nickname + - peer info: ip, port to connect to if we want a secure connection with this person + (used for private chat) + + Future functionnality: + + - friend list + - notifications & invites + """ + use GenServer require Logger defmodule Manifest do - defstruct [:pk] - end + @moduledoc""" + Manifest for a user identity shard, defined by the public key of the user. + """ - defmodule State do - defstruct [:info, :rev, :signed] + defstruct [:pk] end defimpl Shard.Manifest, for: Manifest do @@ -17,6 +32,10 @@ defmodule SApp.Identity do end end + defmodule State do + defstruct [:info, :rev, :signed] + end + def start_link(pk) do GenServer.start_link(__MODULE__, pk) end @@ -138,12 +157,24 @@ defmodule SApp.Identity do Shard.Manager.find_or_start %Manifest{pk: pk} end + @doc""" + Get the info dict of an identity shard. The pid of the shard must be given as an argument. + """ + def get_info(pid) do + GenServer.call(pid, :get_info) + end + + @doc""" + Set the info dict of an identity shard. + """ + def set_info(pid, new_info) do + GenServer.call(pid, {:set_info, new_info}) + end + @doc""" Get a user's nickname from his pk """ def get_nick(pk) do - pid = find_proc pk - info = GenServer.call(pid, :get_info) - info.nick + get_info(find_proc pk).nick end end -- cgit v1.2.3