remove random shuffle function for systemrandom equivalent

This commit is contained in:
Kevin Froman 2020-10-21 09:46:05 +00:00
parent fb85856f76
commit 5dddeb3f10
8 changed files with 28 additions and 40 deletions

View file

@ -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 secrets import SystemRandom
if TYPE_CHECKING:
from communicator import OnionrCommunicatorDaemon
from deadsimplekv import DeadSimpleKV
@ -82,7 +83,7 @@ def download_blocks_from_communicator(comm_inst: "OnionrCommunicatorDaemon"):
except onionrexceptions.OnlinePeerNeeded:
continue
else:
blockPeers = onionrcrypto.cryptoutils.random_shuffle(blockPeers)
SystemRandom().shuffle(blockPeers)
peerUsed = blockPeers.pop(0)
if not kv.get('shutdown') and peerUsed.strip() != '':

View file

@ -5,6 +5,7 @@ Upload blocks in the upload queue to peers from the communicator
from typing import TYPE_CHECKING
from time import sleep
from threading import Thread
from secrets import SystemRandom
from . import sessionmanager
@ -14,7 +15,6 @@ from communicatorutils import proxypicker
import onionrexceptions
from onionrblocks import onionrblockapi as block
from onionrutils import stringvalidators, basicrequests
import onionrcrypto
from communicator import onlinepeers
if TYPE_CHECKING:
from deadsimplekv import DeadSimpleKV
@ -47,8 +47,8 @@ def upload_blocks_from_communicator(comm_inst: 'OnionrCommunicatorDaemon'):
sessionmanager.BlockUploadSessionManager)
tried_peers: UserID = []
finishedUploads = []
kv.put('blocksToUpload', onionrcrypto.cryptoutils.random_shuffle(
kv.get('blocksToUpload')))
SystemRandom().shuffle(kv.get('blocksToUpload'))
def remove_from_hidden(bl):
sleep(60)

View file

@ -3,10 +3,10 @@
Upload pool
"""
from typing import List
from secrets import SystemRandom
import onionrutils
import onionrtypes
from onionrcrypto import cryptoutils
"""
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
@ -62,7 +62,8 @@ class UploadPool:
"""Get the hash pool in secure random order."""
if len(self._pool) != self._pool_size:
raise PoolNotReady
final_pool: List[onionrtypes.BlockHash] = cryptoutils.random_shuffle(
final_pool: List[onionrtypes.BlockHash] = SystemRandom().shuffle(
list(self._pool))
self._pool.clear()