diff options
Diffstat (limited to 'shard/lib/app/chat.ex')
-rw-r--r-- | shard/lib/app/chat.ex | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/shard/lib/app/chat.ex b/shard/lib/app/chat.ex index 051fab6..471d8f7 100644 --- a/shard/lib/app/chat.ex +++ b/shard/lib/app/chat.ex @@ -10,7 +10,6 @@ defmodule SApp.Chat do Future improvements: - message signing - storage of the chatroom messages to disk - - storage of the known peers that have this channel to disk - use a DHT to find peers that are interested in this channel - epidemic broadcast (carefull not to be too costly, maybe by limiting the number of peers we talk to) @@ -22,6 +21,18 @@ defmodule SApp.Chat do require Logger alias SData.MerkleSearchTree, as: MST + + defmodule Manifest do + defstruct [:channel] + end + + defimpl Shard.Manifest, for: Manifest do + def start(m) do + SApp.Chat.start_link(m.channel) + end + end + + @doc """ Start a process that connects to a given channel """ @@ -33,7 +44,7 @@ defmodule SApp.Chat do Initialize channel process. """ def init(channel) do - manifest = {:chat, channel} + manifest = %Manifest{channel: channel} id = SData.term_hash manifest case Shard.Manager.register(id, manifest, self()) do @@ -75,7 +86,7 @@ defmodule SApp.Chat do send data for this channel if they have some. """ def handle_cast(:init_pull, state) do - for {_, pid, _, _} <- :ets.tab2list(:peer_db) do + for {_, pid, _, _} <- Shard.Manager.list_peers do GenServer.cast(pid, {:send_msg, {:interested, [state.id]}}) end {:noreply, state} @@ -101,7 +112,7 @@ defmodule SApp.Chat do end notif = {:append, prev_root, msgitem, mst.root} - for {_, peer_id} <- :ets.lookup(:shard_peer_db, state.id) do + for peer_id <- Shard.Manager.get_shard_peers(state.id) do Shard.Manager.send(peer_id, {state.id, nil, notif}) end |