improve __random_bytes function performance
This commit is contained in:
parent
bc1ceac530
commit
fb4c897ec6
@ -19,6 +19,7 @@ import math
|
|||||||
import socket
|
import socket
|
||||||
import random
|
import random
|
||||||
import typing
|
import typing
|
||||||
|
import os
|
||||||
|
|
||||||
from . import bencode
|
from . import bencode
|
||||||
|
|
||||||
@ -287,4 +288,4 @@ class DisposablePeer:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __random_bytes(n: int) -> bytes:
|
def __random_bytes(n: int) -> bytes:
|
||||||
return random.getrandbits(n * 8).to_bytes(n, "big")
|
return os.urandom(n)
|
||||||
|
@ -19,6 +19,7 @@ import logging
|
|||||||
import random
|
import random
|
||||||
import socket
|
import socket
|
||||||
import typing
|
import typing
|
||||||
|
import os
|
||||||
|
|
||||||
from . import bencode
|
from . import bencode
|
||||||
|
|
||||||
@ -244,7 +245,7 @@ class SybilNode:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __random_bytes(n: int) -> bytes:
|
def __random_bytes(n: int) -> bytes:
|
||||||
return random.getrandbits(n * 8).to_bytes(n, "big")
|
return os.urandom(n)
|
||||||
|
|
||||||
def __build_FIND_NODE_query(self, id_: bytes) -> bytes:
|
def __build_FIND_NODE_query(self, id_: bytes) -> bytes:
|
||||||
""" BENCODE IMPLEMENTATION
|
""" BENCODE IMPLEMENTATION
|
||||||
|
Loading…
Reference in New Issue
Block a user