diff options
Diffstat (limited to 'shard/lib/app')
-rw-r--r-- | shard/lib/app/chat.ex | 2 | ||||
-rw-r--r-- | shard/lib/app/file.ex | 13 | ||||
-rw-r--r-- | shard/lib/app/pagestore.ex | 7 |
3 files changed, 14 insertions, 8 deletions
diff --git a/shard/lib/app/chat.ex b/shard/lib/app/chat.ex index b046fc3..8a72d48 100644 --- a/shard/lib/app/chat.ex +++ b/shard/lib/app/chat.ex @@ -130,7 +130,7 @@ defmodule SApp.Chat do end def handle_call(:delete_shard, _from, state) do - GenServer.call(state.store, :delete_store) + SApp.PageStore.delete_store(state.store) {:stop, :normal, :ok, state} end diff --git a/shard/lib/app/file.ex b/shard/lib/app/file.ex index 0e07cc3..7f03e1f 100644 --- a/shard/lib/app/file.ex +++ b/shard/lib/app/file.ex @@ -85,7 +85,7 @@ defmodule SApp.File do infobin -> info = SData.term_unbin(infobin) Process.send_after(self(), {:calc_missing, 1}, 100) - GenServer.cast(store, {:set_roots, [info.merkle_root]}) + SApp.PageStore.set_roots(store, [info.merkle_root]) {infobin, info} end @@ -100,14 +100,14 @@ defmodule SApp.File do end def handle_call(:delete_shard, _from, state) do - GenServer.call(state.store, :delete_store) + SApp.PageStore.delete_store(state.store) File.rm(state.path) {:stop, :normal, :ok, state} end def handle_call(:get_info, _from, state) do reply = cond do - state.info != nil and GenServer.call(state.store, {:have_rec, state.info.merkle_root}) -> + state.info != nil and SApp.PageStore.have_rec?(state.store, state.info.merkle_root) -> mt = get_mt(state) nblk = MT.block_count(mt) [infohash: state.infohash, @@ -185,7 +185,7 @@ defmodule SApp.File do if state.infobin == nil and SData.bin_hash(infobin) == state.infohash do Shard.Manager.save_state(state.id, infobin) state = %{state | infobin: infobin, info: SData.term_unbin(infobin)} - GenServer.cast(state.store, {:set_roots, [state.info.merkle_root]}) + SApp.PageStore.set_roots(state.store, [state.info.merkle_root]) Process.send_after(self(), {:calc_missing, 1}, 100) state else @@ -240,7 +240,7 @@ defmodule SApp.File do def handle_info({:calc_missing, iter}, state) do if state.info != nil do Logger.info(":calc_missing for #{state.id|>Base.encode16}") - missing = case GenServer.call(state.store, {:have_rec, state.info.merkle_root}) do + missing = case SApp.PageStore.have_rec?(state.store, state.info.merkle_root) do true -> meta = get_mt(state) n_blocks = MT.block_count(meta) @@ -266,7 +266,7 @@ defmodule SApp.File do missing false -> Logger.info("Incomplete Merkle tree meta data, requesting info from peers.") - GenServer.cast(state.store, {:set_roots, [state.info.merkle_root]}) + SApp.PageStore.set_roots(state.store, [state.info.merkle_root]) Process.send_after(self(), {:calc_missing, iter + 1}, iter * 1000) nil end @@ -302,7 +302,6 @@ defmodule SApp.File do pieces = can_req |> Enum.sort() |> Enum.take(@concurrent_reqs - n_curr_req) Enum.reduce(pieces, state, fn id, state -> who = a_random_peer(state.missing[id]) - Logger.info("#{state.id|>Base.encode16} | Req #{id} to #{inspect who}") SNet.Manager.send(who, {state.id, nil, {:get, id}}) Process.send_after(self(), {:req_timeout, id}, @req_timeout_msec) put_in(state.reqs[id], who) diff --git a/shard/lib/app/pagestore.ex b/shard/lib/app/pagestore.ex index 0cbb10a..79d39b7 100644 --- a/shard/lib/app/pagestore.ex +++ b/shard/lib/app/pagestore.ex @@ -329,4 +329,11 @@ defmodule SApp.PageStore do def set_roots(pid, roots) do GenServer.cast(pid, {:set_roots, roots}) end + + @doc""" + Delete the page store. The process is stopped and the data file is deleted from disk. + """ + def delete_store(pid) do + GenServer.call(pid, :delete_store) + end end |