blob: 21596630d84632847ff5dca26868dc77ead2e858 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
"""
The node's ICE sockets ask for a receive buffer that holds an upload's window.
Measured on a node in service: during a 200 MB upload from a browser 22 ms
away the node's machine dropped 2460 of 264000 datagrams at the socket
(`Udp6RcvbufErrors`), with a buffer of 512 KB, and the upload ran at 6.4 MB/s.
The browser keeps 32 chunks of 48 KB in flight, 1.5 MB, and the kernel counts
about twice the bytes it holds.
"""
import socket
import aioice
import pytest
from meshbay_node.transport.webrtc import udp_buffer
def test_the_request_covers_what_an_upload_keeps_in_flight():
in_flight = 32 * 48 * 1024
assert udp_buffer.WANTED >= 2 * in_flight
assert aioice.turn.UDP_SOCKET_BUFFER_SIZE == udp_buffer.WANTED
@pytest.mark.asyncio
async def test_a_gathered_socket_gets_what_the_kernel_allows():
"""aioice reads the constant when it gathers, not when it is imported: the
socket of a real candidate has the buffer, up to the machine's ceiling."""
conn = aioice.Connection(ice_controlling=True)
try:
await conn.gather_candidates()
sizes = [p.transport.get_extra_info("socket").getsockopt(
socket.SOL_SOCKET, socket.SO_RCVBUF)
for p in conn._protocols]
assert sizes, "no candidate was gathered"
assert min(sizes) == udp_buffer.granted()
assert min(sizes) > 262144, "the machine grants no more than aioice asked before"
finally:
await conn.close()
|