iperf3: Support devices without os.urandom().

Also add a version to the manifest.

Signed-off-by: Damien George <damien@micropython.org>
pull/521/merge
Damien George 2023-03-21 16:01:01 +11:00
rodzic c8603192d1
commit ea21cb3fdc
2 zmienionych plików z 16 dodań i 4 usunięć

Wyświetl plik

@ -12,10 +12,20 @@ Usage:
iperf3.client('192.168.1.5', udp=True, reverse=True)
"""
import sys, os, struct
import sys, struct
import time, select, socket
import json
# Provide a urandom() function, supporting devices without os.urandom().
try:
from os import urandom
except ImportError:
from random import randint
def urandom(n):
return bytes(randint(0, 255) for _ in range(n))
DEBUG = False
# iperf3 cookie size, last byte is null byte
@ -177,7 +187,7 @@ def recvninto(s, buf):
def make_cookie():
cookie_chars = b"abcdefghijklmnopqrstuvwxyz234567"
cookie = bytearray(COOKIE_SIZE)
for i, x in enumerate(os.urandom(COOKIE_SIZE - 1)):
for i, x in enumerate(urandom(COOKIE_SIZE - 1)):
cookie[i] = cookie_chars[x & 31]
return cookie
@ -243,7 +253,7 @@ def server_once():
stats = Stats(param)
stats.start()
running = True
data_buf = bytearray(os.urandom(param["len"]))
data_buf = bytearray(urandom(param["len"]))
while running:
for pollable in poll.poll(stats.max_dt_ms()):
if pollable_is_sock(pollable, s_ctrl):
@ -445,7 +455,7 @@ def client(host, udp=False, reverse=False, bandwidth=10 * 1024 * 1024):
s_data = socket.socket(ai[0], socket.SOCK_STREAM)
s_data.connect(ai[-1])
s_data.sendall(cookie)
buf = bytearray(os.urandom(param["len"]))
buf = bytearray(urandom(param["len"]))
elif cmd == EXCHANGE_RESULTS:
# Close data socket now that server knows we are finished, to prevent it flooding us
poll.unregister(s_data)

Wyświetl plik

@ -1 +1,3 @@
metadata(version="0.1.3")
module("iperf3.py")