aboutsummaryrefslogtreecommitdiff
path: root/shard/lib/app/file.ex
diff options
context:
space:
mode:
Diffstat (limited to 'shard/lib/app/file.ex')
-rw-r--r--shard/lib/app/file.ex23
1 files changed, 19 insertions, 4 deletions
diff --git a/shard/lib/app/file.ex b/shard/lib/app/file.ex
index e2a9798..0e07cc3 100644
--- a/shard/lib/app/file.ex
+++ b/shard/lib/app/file.ex
@@ -9,9 +9,12 @@ defmodule SApp.File do
file_hash: hash
size: int
mime_type: string
- }
+ }
+
+ The file is cut in blocks that are collected in a k-ary Merkle tree
+ (see SData.MerkleTree for block size and k value).
- The file is cut in blocks of 4kb that are collected in a 64-ary Merkle tree.
+ TODO I feel bad about some parts of the logic in here.
"""
use GenServer
@@ -26,7 +29,7 @@ defmodule SApp.File do
defmodule Manifest do
@moduledoc"""
Manifest for a file.
- The file is identified by the root hash of its Merkle tree and by its mime type.
+ The file is identified by its infohash, which is the hash of a `SApp.File.Info` struct.
"""
defstruct [:infohash]
@@ -46,9 +49,21 @@ defmodule SApp.File do
end
defmodule State do
+ @moduledoc"""
+ Internal state struct for file shard.
+ """
defstruct [:infohash, :id, :manifest, :netgroup, :info, :infobin, :store, :missing, :path, :reqs]
end
+ @doc """
+ Start a process that connects to a given channel. Don't call directly, use for instance:
+
+ Shard.Manager.find_or_start %SApp.File.Manifest{infohash: "some_infohash"}
+
+ or:
+
+ SApp.File.Create("/path/to/file", "mime/type")
+ """
def start_link(manifest) do
GenServer.start_link(__MODULE__, manifest)
end
@@ -229,7 +244,7 @@ defmodule SApp.File do
true ->
meta = get_mt(state)
n_blocks = MT.block_count(meta)
- expected_hashes = MT.get_range(meta, 0..(n_blocks-1))
+ expected_hashes = MT.get_all(meta)
actual_hashes = if File.exists?(state.path) do
File.stream!(state.path, [], MT.block_size())
|> Enum.map(&(:crypto.hash(:sha256, &1)))