From 0b27af3dab56b667b50fd80590cdfd9df0feffbd Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Mon, 5 Nov 2018 15:40:18 +0100 Subject: File progress --- shard/lib/app/file.ex | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'shard') diff --git a/shard/lib/app/file.ex b/shard/lib/app/file.ex index b28f742..ce28beb 100644 --- a/shard/lib/app/file.ex +++ b/shard/lib/app/file.ex @@ -94,7 +94,8 @@ defmodule SApp.File do size: state.info.size, mime_type: state.info.mime_type, num_blocks: nblk, - missing_blocks: if state.missing != nil do map_size(state.missing) else nil end] + missing_blocks: if state.missing != nil do map_size(state.missing) else nil end, + path: state.path] state.info != nil -> [infohash: state.infohash, file_hash: state.info.file_hash, @@ -153,7 +154,6 @@ defmodule SApp.File do # Ignore message {:noreply, state} else - Logger.info("<- #{inspect msg}") state = case msg do {:get_info} -> if state.infobin != nil do @@ -258,7 +258,7 @@ defmodule SApp.File do end {:noreply, state} else - Logger.info(":calc_missing for #{state.infohash|>Base.encode16} -> no info") + Logger.info(":calc_missing for #{state.id|>Base.encode16} -> no info") {:noreply, state} end end @@ -281,7 +281,7 @@ 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("Req #{id} to #{inspect who}") + 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) @@ -350,4 +350,11 @@ defmodule SApp.File do GenServer.cast(pid, {:init_with, path, infobin, mt}) {:ok, manifest, pid} end + + @doc""" + Get info of a file shard including download progress + """ + def get_info(pid) do + GenServer.call(pid, :get_info) + end end -- cgit v1.2.3