From 2dc706a8949a68c8e2d76b11ca65e02feaa0adf9 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sat, 10 Oct 2020 00:16:24 +0000 Subject: [PATCH] fixed sneakernet, removed unused vdf --- requirements.in | 1 - requirements.txt | 4 --- src/etc/onionrvalues.py | 2 +- src/onionrproofs/vdf/__init__.py | 45 -------------------------------- src/onionrproofs/vdf/hasher.py | 0 src/onionrproofs/vdf/verify.py | 0 src/sneakernet/__init__.py | 18 +++++++------ static-data/default_config.json | 4 +-- tests/runtime-result.txt | 2 +- tests/test_block_vdf_proof.py | 36 ------------------------- tests/test_onionrvalues.py | 2 +- 11 files changed, 15 insertions(+), 99 deletions(-) delete mode 100644 src/onionrproofs/vdf/__init__.py delete mode 100644 src/onionrproofs/vdf/hasher.py delete mode 100644 src/onionrproofs/vdf/verify.py delete mode 100644 tests/test_block_vdf_proof.py diff --git a/requirements.in b/requirements.in index f2f716b4..56b4b426 100644 --- a/requirements.in +++ b/requirements.in @@ -12,6 +12,5 @@ toomanyobjs==1.1.0 niceware==0.2.1 psutil==5.7.2 filenuke==0.0.0 -mimcvdf==1.1.0 watchdog==0.10.3 ujson==4.0.0 diff --git a/requirements.txt b/requirements.txt index 1075b5bf..55bb7fe3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -137,10 +137,6 @@ markupsafe==1.1.1 \ --hash=sha256:e249096428b3ae81b08327a63a485ad0878de3fb939049038579ac0ef61e17e7 \ --hash=sha256:e8313f01ba26fbbe36c7be1966a7b7424942f670f38e666995b88d012765b9be \ # via jinja2 -mimcvdf==1.1.0 \ - --hash=sha256:97a4ccdebb58352c64c268d2e57ef8817c9fe4ac3dcc922410bfcc72033f344a \ - --hash=sha256:ae47c79bfd6b7b76077c8ce3301a48a7c10a609d8a882e7bd785e2ef851ecd28 \ - # via -r requirements.in niceware==0.2.1 \ --hash=sha256:0f8b192f2a1e800e068474f6e208be9c7e2857664b33a96f4045340de4e5c69c \ --hash=sha256:cf2dc0e1567d36d067c61b32fed0f1b9c4534ed511f9eeead4ba548d03b5c9eb \ diff --git a/src/etc/onionrvalues.py b/src/etc/onionrvalues.py index ed203078..9a7691a8 100755 --- a/src/etc/onionrvalues.py +++ b/src/etc/onionrvalues.py @@ -26,7 +26,7 @@ ONIONR_TAGLINE = 'Private P2P Communication - GPLv3 - https://Onionr.net' ONIONR_VERSION = '6.0.0' ONIONR_VERSION_CODENAME = 'Genesis' ONIONR_VERSION_TUPLE = tuple(ONIONR_VERSION.split('.')) # (MAJOR, MINOR, VERSION) -API_VERSION = '4' # increments of 1; only change when something fundamental about how the API works changes. This way other nodes know how to communicate without learning too much information about you. +API_VERSION = '2' # increments of 1; only change when something fundamental about how the API works changes. This way other nodes know how to communicate without learning too much information about you. MIN_PY_VERSION = 7 # min version of 7 so we can take advantage of non-cyclic type hints DEVELOPMENT_MODE = False IS_QUBES = False diff --git a/src/onionrproofs/vdf/__init__.py b/src/onionrproofs/vdf/__init__.py deleted file mode 100644 index f7f53dde..00000000 --- a/src/onionrproofs/vdf/__init__.py +++ /dev/null @@ -1,45 +0,0 @@ -"""Onionr - Private P2P Communication. - -verifiable delay function proof -""" -from multiprocessing import Process -from multiprocessing import Pipe - -from mimcvdf import vdf_create -from mimcvdf import vdf_verify -""" - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details.c - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -""" -ROUND_MULTIPLIER_PER_BYTE = 100 - - -def create(data: bytes) -> str: - rounds = len(data) * ROUND_MULTIPLIER_PER_BYTE - return vdf_create(data, rounds) - - -def multiproces_create(data: bytes) -> str: - parent_conn, child_conn = Pipe() - def __do_create(conn, data): - conn.send(create(data)) - conn.close() - p = Process(target=__do_create, args=(child_conn, data)) - p.start() - return parent_conn.recv() - - -def verify(data: bytes, block_id: str) -> bool: - rounds = len(data) * ROUND_MULTIPLIER_PER_BYTE - return vdf_verify(data, block_id, rounds) - diff --git a/src/onionrproofs/vdf/hasher.py b/src/onionrproofs/vdf/hasher.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/onionrproofs/vdf/verify.py b/src/onionrproofs/vdf/verify.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/sneakernet/__init__.py b/src/sneakernet/__init__.py index 123e8997..65439159 100644 --- a/src/sneakernet/__init__.py +++ b/src/sneakernet/__init__.py @@ -38,15 +38,17 @@ class _Importer(FileSystemEventHandler): if not event.src_path.endswith(BLOCK_EXPORT_FILE_EXT): return with open(event.src_path, 'rb') as block_file: + block_data = block_file.read() + os.remove(event.src_path) + try: + import_block_from_data(block_data) + except onionrexceptions.DataExists: + return + if block_data_location in event.src_path: try: - import_block_from_data(block_file.read()) - except onionrexceptions.DataExists: - return - if block_data_location in event.src_path: - try: - os.remove(event.src_path) - except FileNotFoundError: - pass + os.remove(event.src_path) + except FileNotFoundError: + pass def sneakernet_import_thread(): diff --git a/static-data/default_config.json b/static-data/default_config.json index fc8c9879..b20fe114 100755 --- a/static-data/default_config.json +++ b/static-data/default_config.json @@ -14,8 +14,8 @@ "hide_created_blocks": true, "insert_deniable_blocks": true, "max_block_age": 2678400, - "minimum_block_pow": 4, - "minimum_send_pow": 4, + "minimum_block_pow": 5, + "minimum_send_pow": 5, "public_key": "", "random_bind_ip": true, "security_level": 0, diff --git a/tests/runtime-result.txt b/tests/runtime-result.txt index b249e7d3..130450c1 100644 --- a/tests/runtime-result.txt +++ b/tests/runtime-result.txt @@ -1 +1 @@ -1599457658 \ No newline at end of file +1602268895 \ No newline at end of file diff --git a/tests/test_block_vdf_proof.py b/tests/test_block_vdf_proof.py deleted file mode 100644 index 355c5308..00000000 --- a/tests/test_block_vdf_proof.py +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env python3 -import sys, os -sys.path.append(".") -sys.path.append("src/") -import uuid -TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' -print("Test directory:", TEST_DIR) -os.environ["ONIONR_HOME"] = TEST_DIR -import unittest, json - -from utils import identifyhome, createdirs -from onionrsetup import setup_config -from onionrproofs import vdf -from time import time - -createdirs.create_dirs() -setup_config() - -class TestVdf(unittest.TestCase): - def test_vdf(self): - res = vdf.create(b'test') - int(res, 16) - if len(res) == 0: raise ValueError - self.assertEqual(vdf.multiproces_create(b'test'), res) - def test_speed(self): - t = time() - vdf.create(b'test') - self.assertTrue(time() - t <= 10) - # test 2 kb - t = time() - vdf.create(b't'*10000) - self.assertTrue(time() - t >= 10) - #timeit(lambda: vdf.create(b'test')) - - -unittest.main() diff --git a/tests/test_onionrvalues.py b/tests/test_onionrvalues.py index e59e7ebb..21f601ae 100644 --- a/tests/test_onionrvalues.py +++ b/tests/test_onionrvalues.py @@ -13,7 +13,7 @@ from etc import onionrvalues class TestOnionrValues(unittest.TestCase): def test_api_version(self): - self.assertEqual(onionrvalues.API_VERSION, '1') + self.assertEqual(onionrvalues.API_VERSION, '2') def test_default_expire(self): self.assertEqual(onionrvalues.DEFAULT_EXPIRE, 2678400)