fix(video): recover encoder capacity, pace RTP and isolate preview sessions
This commit is contained in:
@@ -98,7 +98,8 @@ class RoverDatagramServer:
|
||||
self.channels[channel] = {
|
||||
"value": dict(value), "certificate": certificate,
|
||||
"send": DatagramCipher(channel, send), "receive": DatagramCipher(channel, receive),
|
||||
"peer": None, "probe": 0, "probe_clock": None, "last_probe": now,
|
||||
"peer": None, "probe": 0, "sent_probe": 0, "probe_clock": None,
|
||||
"last_probe": now, "probe_gap_ms": None,
|
||||
"next": now, "last_sent": -1e9, "last_command": None, "expires": now + 86400,
|
||||
}
|
||||
return 200, {"channel": channel.hex(), "send_key": receive.hex(),
|
||||
@@ -114,6 +115,7 @@ class RoverDatagramServer:
|
||||
|
||||
def run(self):
|
||||
while not self.stop.is_set():
|
||||
waiting = time.monotonic()
|
||||
try:
|
||||
packet, peer = self.socket.recvfrom(MAX_PACKET + 1)
|
||||
except (TimeoutError, BlockingIOError):
|
||||
@@ -122,6 +124,7 @@ class RoverDatagramServer:
|
||||
break
|
||||
now = time.monotonic()
|
||||
with self.lock:
|
||||
locked = time.monotonic()
|
||||
if packet is not None and len(packet) <= MAX_PACKET:
|
||||
c = self.channels.get(packet[4:20])
|
||||
if c is not None:
|
||||
@@ -131,19 +134,25 @@ class RoverDatagramServer:
|
||||
# never at a later periodic send for that same probe.
|
||||
c.update(peer=peer, probe=opened[0],
|
||||
probe_clock=self.registry.rover_control._clock(),
|
||||
probe_gap_ms=(now - c["last_probe"]) * 1000,
|
||||
last_probe=now)
|
||||
for key, c in list(self.channels.items()):
|
||||
checking = time.monotonic()
|
||||
if (now >= c["expires"] or now - c["last_probe"] >= 2
|
||||
or not self.registry.rover_channel.same_generation(c["value"])):
|
||||
self.channels.pop(key, None)
|
||||
continue
|
||||
checked = time.monotonic()
|
||||
if c["peer"] is None or now - c["last_sent"] < MIN_SEND_INTERVAL:
|
||||
continue
|
||||
# Fresh input and withdrawal must not wait for a keepalive
|
||||
# tick. This hint does not authorize a send: the original
|
||||
# Fresh probes, input and withdrawal must not wait for a
|
||||
# keepalive tick. Echo only the latest authenticated probe;
|
||||
# duplicate/replayed probes never bypass the normal cadence.
|
||||
# This hint does not authorize a send: the original
|
||||
# certificate/binding/endpoint is checked again below.
|
||||
if now < c["next"] and not self.registry.rover_control.intent_changed(
|
||||
c["value"]["node_id"], c["value"]["relay_id"], c["last_command"]):
|
||||
if (c["probe"] == c["sent_probe"] and now < c["next"]
|
||||
and not self.registry.rover_control.intent_changed(
|
||||
c["value"]["node_id"], c["value"]["relay_id"], c["last_command"])):
|
||||
continue
|
||||
periodic_lag_ms = max(0., (now - c["next"]) * 1000)
|
||||
dispatched = time.monotonic()
|
||||
@@ -160,7 +169,8 @@ class RoverDatagramServer:
|
||||
sealed = time.monotonic()
|
||||
self.socket.sendto(packet, c["peer"])
|
||||
sent = time.monotonic()
|
||||
c.update(last_sent=sent, next=sent + KEEPALIVE_INTERVAL,
|
||||
c.update(last_sent=sent, sent_probe=c["probe"],
|
||||
next=sent + KEEPALIVE_INTERVAL,
|
||||
last_command=reply.get("command"))
|
||||
trace = self.registry.rover_control.stream_trace(c["value"]["node_id"])
|
||||
if trace is not None:
|
||||
@@ -174,7 +184,13 @@ class RoverDatagramServer:
|
||||
registry_ms=(received - dispatched) * 1000,
|
||||
encrypt_ms=(sealed - received) * 1000,
|
||||
socket_ms=(sent - sealed) * 1000,
|
||||
periodic_lag_ms=periodic_lag_ms)
|
||||
periodic_lag_ms=periodic_lag_ms,
|
||||
probe_sequence=c["probe"],
|
||||
probe_receive_gap_ms=c["probe_gap_ms"],
|
||||
probe_to_send_ms=(sent - c["last_probe"]) * 1000,
|
||||
receive_wait_ms=(now - waiting) * 1000,
|
||||
channel_lock_ms=(locked - now) * 1000,
|
||||
generation_check_ms=(checked - checking) * 1000)
|
||||
if not reply.get("watch"):
|
||||
self.channels.pop(key, None)
|
||||
except (OSError, ValueError, TypeError, KeyError):
|
||||
|
||||
Reference in New Issue
Block a user