remove random shuffle function for systemrandom equivalent
This commit is contained in:
parent
fb85856f76
commit
5dddeb3f10
@ -1,9 +1,10 @@
|
|||||||
"""
|
"""Onionr - Private P2P Communication.
|
||||||
Onionr - Private P2P Communication
|
|
||||||
|
|
||||||
Download blocks using the communicator instance
|
Download blocks using the communicator instance.
|
||||||
"""
|
"""
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
from secrets import SystemRandom
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from communicator import OnionrCommunicatorDaemon
|
from communicator import OnionrCommunicatorDaemon
|
||||||
from deadsimplekv import DeadSimpleKV
|
from deadsimplekv import DeadSimpleKV
|
||||||
@ -82,7 +83,7 @@ def download_blocks_from_communicator(comm_inst: "OnionrCommunicatorDaemon"):
|
|||||||
except onionrexceptions.OnlinePeerNeeded:
|
except onionrexceptions.OnlinePeerNeeded:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
blockPeers = onionrcrypto.cryptoutils.random_shuffle(blockPeers)
|
SystemRandom().shuffle(blockPeers)
|
||||||
peerUsed = blockPeers.pop(0)
|
peerUsed = blockPeers.pop(0)
|
||||||
|
|
||||||
if not kv.get('shutdown') and peerUsed.strip() != '':
|
if not kv.get('shutdown') and peerUsed.strip() != '':
|
||||||
|
@ -5,6 +5,7 @@ Upload blocks in the upload queue to peers from the communicator
|
|||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
from secrets import SystemRandom
|
||||||
|
|
||||||
from . import sessionmanager
|
from . import sessionmanager
|
||||||
|
|
||||||
@ -14,7 +15,6 @@ from communicatorutils import proxypicker
|
|||||||
import onionrexceptions
|
import onionrexceptions
|
||||||
from onionrblocks import onionrblockapi as block
|
from onionrblocks import onionrblockapi as block
|
||||||
from onionrutils import stringvalidators, basicrequests
|
from onionrutils import stringvalidators, basicrequests
|
||||||
import onionrcrypto
|
|
||||||
from communicator import onlinepeers
|
from communicator import onlinepeers
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from deadsimplekv import DeadSimpleKV
|
from deadsimplekv import DeadSimpleKV
|
||||||
@ -47,8 +47,8 @@ def upload_blocks_from_communicator(comm_inst: 'OnionrCommunicatorDaemon'):
|
|||||||
sessionmanager.BlockUploadSessionManager)
|
sessionmanager.BlockUploadSessionManager)
|
||||||
tried_peers: UserID = []
|
tried_peers: UserID = []
|
||||||
finishedUploads = []
|
finishedUploads = []
|
||||||
kv.put('blocksToUpload', onionrcrypto.cryptoutils.random_shuffle(
|
|
||||||
kv.get('blocksToUpload')))
|
SystemRandom().shuffle(kv.get('blocksToUpload'))
|
||||||
|
|
||||||
def remove_from_hidden(bl):
|
def remove_from_hidden(bl):
|
||||||
sleep(60)
|
sleep(60)
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
Upload pool
|
Upload pool
|
||||||
"""
|
"""
|
||||||
from typing import List
|
from typing import List
|
||||||
|
from secrets import SystemRandom
|
||||||
|
|
||||||
import onionrutils
|
import onionrutils
|
||||||
import onionrtypes
|
import onionrtypes
|
||||||
from onionrcrypto import cryptoutils
|
|
||||||
"""
|
"""
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
@ -62,7 +62,8 @@ class UploadPool:
|
|||||||
"""Get the hash pool in secure random order."""
|
"""Get the hash pool in secure random order."""
|
||||||
if len(self._pool) != self._pool_size:
|
if len(self._pool) != self._pool_size:
|
||||||
raise PoolNotReady
|
raise PoolNotReady
|
||||||
final_pool: List[onionrtypes.BlockHash] = cryptoutils.random_shuffle(
|
|
||||||
|
final_pool: List[onionrtypes.BlockHash] = SystemRandom().shuffle(
|
||||||
list(self._pool))
|
list(self._pool))
|
||||||
|
|
||||||
self._pool.clear()
|
self._pool.clear()
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
from . import safecompare, replayvalidation, randomshuffle, verifypow
|
from . import safecompare, replayvalidation, verifypow
|
||||||
from . import getpubfrompriv
|
from . import getpubfrompriv
|
||||||
|
|
||||||
replay_validator = replayvalidation.replay_timestamp_validation
|
replay_validator = replayvalidation.replay_timestamp_validation
|
||||||
random_shuffle = randomshuffle.random_shuffle
|
|
||||||
safe_compare = safecompare.safe_compare
|
safe_compare = safecompare.safe_compare
|
||||||
verify_POW = verifypow.verify_POW
|
verify_POW = verifypow.verify_POW
|
||||||
get_pub_key_from_priv = getpubfrompriv.get_pub_key_from_priv
|
get_pub_key_from_priv = getpubfrompriv.get_pub_key_from_priv
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
from random import SystemRandom
|
|
||||||
|
|
||||||
def random_shuffle(theList):
|
|
||||||
myList = list(theList)
|
|
||||||
SystemRandom().shuffle(myList)
|
|
||||||
return myList
|
|
@ -3,10 +3,10 @@
|
|||||||
Test Onionr as it is running
|
Test Onionr as it is running
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
|
from secrets import SystemRandom
|
||||||
|
|
||||||
import logger
|
import logger
|
||||||
from onionrutils import epoch
|
from onionrutils import epoch
|
||||||
from onionrcrypto.cryptoutils.randomshuffle import random_shuffle
|
|
||||||
|
|
||||||
from . import uicheck, inserttest, stresstest
|
from . import uicheck, inserttest, stresstest
|
||||||
from . import ownnode
|
from . import ownnode
|
||||||
@ -55,7 +55,7 @@ class OnionrRunTestManager:
|
|||||||
self.run_date: int = 0
|
self.run_date: int = 0
|
||||||
|
|
||||||
def run_tests(self):
|
def run_tests(self):
|
||||||
tests = random_shuffle(RUN_TESTS)
|
tests = SystemRandom.shuffle(list(RUN_TESTS))
|
||||||
cur_time = epoch.get_epoch()
|
cur_time = epoch.get_epoch()
|
||||||
logger.info(f"Doing runtime tests at {cur_time}")
|
logger.info(f"Doing runtime tests at {cur_time}")
|
||||||
|
|
||||||
|
@ -2,9 +2,10 @@
|
|||||||
|
|
||||||
NetUtils offers various useful functions to Onionr networking.
|
NetUtils offers various useful functions to Onionr networking.
|
||||||
"""
|
"""
|
||||||
|
from random import SystemRandom
|
||||||
|
|
||||||
from onionrutils import basicrequests
|
from onionrutils import basicrequests
|
||||||
from .readstatic import read_static
|
from .readstatic import read_static
|
||||||
from onionrcrypto.cryptoutils import random_shuffle
|
|
||||||
"""
|
"""
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
@ -26,8 +27,7 @@ def check_network(torPort=0) -> bool:
|
|||||||
success = False
|
success = False
|
||||||
connect_urls = []
|
connect_urls = []
|
||||||
try:
|
try:
|
||||||
connect_urls = random_shuffle(
|
connect_urls = SystemRandom().shuffle(read_static('connect-check.txt').split(','))
|
||||||
read_static('connect-check.txt').split(','))
|
|
||||||
|
|
||||||
for url in connect_urls:
|
for url in connect_urls:
|
||||||
if basicrequests.do_get_request(
|
if basicrequests.do_get_request(
|
||||||
|
@ -64,13 +64,6 @@ class OnionrCryptoTests(unittest.TestCase):
|
|||||||
else:
|
else:
|
||||||
self.assertTrue(False)
|
self.assertTrue(False)
|
||||||
|
|
||||||
def test_random_shuffle(self):
|
|
||||||
# Small chance that the randomized list will be same. Rerun test a couple times if it fails
|
|
||||||
startList = ['cat', 'dog', 'moose', 'rabbit', 'monkey', 'crab', 'human', 'dolphin', 'whale', 'etc'] * 10
|
|
||||||
|
|
||||||
self.assertNotEqual(startList, list(crypto.cryptoutils.random_shuffle(startList)))
|
|
||||||
self.assertTrue(len(list(crypto.cryptoutils.random_shuffle(startList))) == len(startList))
|
|
||||||
|
|
||||||
def test_asymmetric(self):
|
def test_asymmetric(self):
|
||||||
keyPair = crypto.generate()
|
keyPair = crypto.generate()
|
||||||
keyPair2 = crypto.generate()
|
keyPair2 = crypto.generate()
|
||||||
|
Loading…
Reference in New Issue
Block a user