diff --git a/tests/test_Builder.py b/tests/test_Builder.py deleted file mode 100644 index 3aeedda..0000000 --- a/tests/test_Builder.py +++ /dev/null @@ -1,33 +0,0 @@ -import unittest -from tools.Builder import Builder - - -class BuilderTest(unittest.TestCase): - - def test_builder(self): - my_address = "191GVvAaTRxLmz3rW3nU5jAV1rF186VxQc" - my_store_path = "tmp/" - my_shard_size = 1024*1024*128 # 128 MB - my_max_size = 1024*1024*256 # 256 MB - - bucket = Builder(my_address, my_shard_size, my_max_size) - bucket.build(my_store_path, True, True) - - def test_generate(self): - my_address = "191GVvAaTRxLmz3rW3nU5jAV1rF186VxQc" - my_store_path = "tmp/" - my_shard_size = 1024*1024*1 # 1 MB - my_max_size = 1024*1024*5 # 5 MB - - bucket = Builder(my_address, my_shard_size, my_max_size) - - hash0 = 'b6f5e9dabc93c6b72b779de0dced64bf6e76a6ac0d8af98dfc05a4e2901b0573' - self.assertEqual(bucket.generate_shard(bucket.build_seed(0), my_store_path, True), hash0) - hash1 = '8f9f5f52a3e1aa2f597d81fb715f0cc912e2fe8957f402e6129339a22047d9ae' - self.assertEqual(bucket.generate_shard(bucket.build_seed(1), my_store_path, True), hash1) - hash2 = 'e964fdfe14f2ce6aa68f64e14b0180d8791ba6e6744de9662d74d574182ad8b9' - self.assertEqual(bucket.generate_shard(bucket.build_seed(2), my_store_path, True), hash2) - hash3 = '5ae47676995fe9b9ba18da77a0bc88e7560eef60e4d4b78cd62e0a9e2c421860' - self.assertEqual(bucket.generate_shard(bucket.build_seed(3), my_store_path, True), hash3) - hash4 = 'be9382d08b51246153973b03b31f4e3f5180ea025c8636966545033a1bad2cd2' - self.assertEqual(bucket.generate_shard(bucket.build_seed(4), my_store_path, True), hash4) diff --git a/tools/Builder.py b/tools/Builder.py deleted file mode 100644 index 410a340..0000000 --- a/tools/Builder.py +++ /dev/null @@ -1,53 +0,0 @@ -import os -import hashlib -import RandomIO - - -# config vars -my_address = "YOUR ADDRESS HERE" -my_store_path = "YOUR ABSOLUTE PATH HERE" -my_shard_size = 1024*1024*128 # 128 MB -my_max_size = 1024*1024*1024 # 1 GB - - -class Builder: - def __init__(self, address, shard_size, max_size): - self.address = address - self.shard_size = shard_size - self.max_size = max_size - - @staticmethod - def sha256(content): - """Finds the SHA-256 hash of the content.""" - content = content.encode('utf-8') - return hashlib.sha256(content).hexdigest() - - def build_seed(self, height): - """Deterministically build a seed.""" - seed = self.sha256(self.address) - for i in range(height): - seed = self.sha256(seed) - return seed - - def generate_shard(self, seed, store_path, cleanup=False): - """Save a shard, and return its SHA-256 hash.""" - tmp_file = RandomIO.RandomIO(seed).read(self.shard_size) # temporarily generate file - file_hash = hashlib.sha256(tmp_file).hexdigest() # get SHA-256 hash - RandomIO.RandomIO(seed).genfile(self.shard_size, store_path+seed) # save the shard - if cleanup: - os.remove(store_path+seed) - return file_hash - - def build(self, store_path, debug=False, cleanup=False): - """Fill the farmer with data up to their max.""" - for shard_num in range(int(self.max_size/self.shard_size)): - seed = self.build_seed(shard_num) - file_hash = self.generate_shard(seed, store_path, cleanup) - - if debug: - print("Saving seed {0} with SHA-256 hash {1}.".format(seed, file_hash)) - - -if __name__ == "__main__": # pragma: no cover - bucket = Builder(my_address, my_shard_size, my_max_size) - bucket.build(my_store_path, True) diff --git a/tools/__init__.py b/tools/__init__.py deleted file mode 100644 index e448a52..0000000 --- a/tools/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__author__ = 'super3'