diff options
author | Alex Auvolat <alex@adnab.me> | 2018-11-05 15:40:18 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2018-11-05 15:40:18 +0100 |
commit | 0b27af3dab56b667b50fd80590cdfd9df0feffbd (patch) | |
tree | 7c1185496166b04aa21ea66f285650d62e954f20 /shard/lib/app | |
parent | 72906c6bb473ea605235c84b6d01c318f7b6cef8 (diff) | |
download | shard-0b27af3dab56b667b50fd80590cdfd9df0feffbd.tar.gz shard-0b27af3dab56b667b50fd80590cdfd9df0feffbd.zip |
File progress
Diffstat (limited to 'shard/lib/app')
-rw-r--r-- | shard/lib/app/file.ex | 15 |
1 files changed, 11 insertions, 4 deletions
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 |