aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/app/chat.ex11
-rw-r--r--lib/data/data.ex4
2 files changed, 11 insertions, 4 deletions
diff --git a/lib/app/chat.ex b/lib/app/chat.ex
index e86f739..fe2777e 100644
--- a/lib/app/chat.ex
+++ b/lib/app/chat.ex
@@ -14,6 +14,7 @@ defmodule SApp.Chat do
- 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)
+ - partial synchronization only == data distributed over peers
"""
use GenServer
@@ -104,15 +105,17 @@ defmodule SApp.Chat do
"""
def handle_cast({:msg, peer_id, peer_pid, msg}, state) do
case msg do
+ {:get_manifest} -> send(state, peer_pid, {:manifest, state.manifest})
{:get, start} -> push_messages(peer_id, state, start, 20)
{:info, _start, list, rest} ->
if rest != nil and not GenServer.call(state.store, {:has, rest}) do
- GenServer.cast(peer_pid, {:send_msg, {state.id, {:get, rest}}})
+ send(state, peer_pid, {:get, rest})
end
spawn_link(fn ->
Process.sleep 1000
GenServer.cast(state.store, {:insert_many, list, (fn msg -> msg_callback(state.channel, msg) end)})
end)
+ _ -> nil
end
if Map.has_key?(state.peers, peer_id) do
@@ -122,11 +125,15 @@ defmodule SApp.Chat do
end
end
+ defp send(state, to, msg) do
+ GenServer.cast(to, {:send_msg, {state.id, msg}})
+ end
+
defp push_messages(state, to, start, num) do
case GenServer.call(state.store, {:read, start, num}) do
{:ok, list, rest} ->
- GenServer.cast(to, {:send_msg, {state.id, {:info, start, list, rest}}})
+ send(state, to, {:info, start, list, rest})
_ -> nil
end
end
diff --git a/lib/data/data.ex b/lib/data/data.ex
index 2c6e629..428957c 100644
--- a/lib/data/data.ex
+++ b/lib/data/data.ex
@@ -7,8 +7,8 @@ defmodule SData do
Calculate the hash of an Erlang term by first converting it to its
binary representation.
"""
- def term_hash(term) do
- :crypto.hash(:sha256, (:erlang.term_to_binary term))
+ def term_hash(term, algo \\ :sha256) do
+ :crypto.hash(algo, (:erlang.term_to_binary term))
end
end