Added vdf create wrapper

Removed some dead code
This commit is contained in:
Kevin F 2021-12-31 15:46:56 -06:00
parent 8f784f208b
commit 6a8ab46815
7 changed files with 15 additions and 104 deletions

15
src/onionrproofs/vdf.py Normal file
View File

@ -0,0 +1,15 @@
import multiprocessing
import mimcvdf
def _wrap_vdf_create(queue, block_data_bytes, rounds):
queue.put(mimcvdf.vdf_create(block_data_bytes, rounds))
def do_vdf(block_data_bytes):
queue = multiprocessing.Queue()
vdf_proc = multiprocessing.Process(target=_wrap_vdf_create, args=(queue, block_data_bytes, 1000))
vdf_proc.start()
vdf_proc.join()
return queue.get()

View File

@ -1,2 +0,0 @@
from .extracted25519 import extract_ed25519_from_onion_address
from .neighbors import identify_neighbors

View File

@ -1,14 +0,0 @@
from base64 import b32decode
from typing import TYPE_CHECKING
from onionrutils.bytesconverter import str_to_bytes
if TYPE_CHECKING:
from onionrtypes import Ed25519PublicKeyBytes, OnionAddressString
def extract_ed25519_from_onion_address(
address: 'OnionAddressString') -> 'Ed25519PublicKeyBytes':
address = str_to_bytes(address).replace(b'.onion', b'').upper()
ed25519 = b32decode(address)[:-3]
return ed25519

View File

@ -1,40 +0,0 @@
from onionrtypes import OnionAddressString
from typing import Iterable
from collections import OrderedDict
from .extracted25519 import extract_ed25519_from_onion_address
def identify_neighbors(
address: OnionAddressString,
peers: Iterable[OnionAddressString],
closest_n: int) -> OnionAddressString:
"""Identify node addresses that are closest
in value to a given node address"""
peers_to_test = list(peers)
try:
peers_to_test.remove(address)
except ValueError:
pass
address = extract_ed25519_from_onion_address(address)
address_int = int.from_bytes(address, "big")
closeness_values = []
end_result = []
def _calc_closeness(y):
ret = abs(
address_int -
int.from_bytes(extract_ed25519_from_onion_address(y), "big"))
return ret
for peer in peers_to_test:
closeness_values.append((peer, _calc_closeness(peer)))
closeness_values.sort(key=lambda p: p[1])
for i, result in enumerate(closeness_values):
end_result.append(result[0])
if i > closest_n:
break
return end_result

View File

@ -1,10 +0,0 @@
from typing import List
from onionrutils.localcommand import local_command
from .neighbors import identify_neighbors
def stream_pool():
peers = lioc

View File

@ -1,38 +0,0 @@
from secrets import token_bytes
from typing import TYPE_CHECKING
import socket
if TYPE_CHECKING:
from stem.control import Controller
from onionrtypes import OnionAddressString
import yam
def peer_tunnel(tor_controller: Controller, peer):
socks_port = tor_controller.get_conf('SocksPort')
class Connected:
connected = False
send_buffer = []
rec_buffer = []
rec_address = None
yam.client(1, peer, socks_port, send_buffer, rec_buffer, Connected)
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
ip = '127.0.0.1'
s.bind((ip, 0))
s.listen(1)
port = s.getsockname()[1]
serv = tor_controller.create_ephemeral_hidden_service(
{1337: '127.0.0.1:' + str(port)},
key_content='ED25519-V3',
await_publication=True,
)
rec_address = serv.service_id
conn, addr = s.accept()
yam.server(1, tor_controller, conn, send_buffer, rec_buffer, Connected)