dropbear-transport 0.1.1a1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,71 @@
1
+ # macOS
2
+ .DS_Store
3
+
4
+ # Python
5
+ __pycache__/
6
+ *.py[cod]
7
+ .pytest_cache/
8
+ .mypy_cache/
9
+ .ruff_cache/
10
+ .coverage
11
+ htmlcov/
12
+
13
+ # Local caches (e.g. lerobot dataset + smoke-test artifacts)
14
+ .cache/
15
+
16
+ # Virtual environments
17
+ .venv/
18
+ venv/
19
+
20
+ # Build and packaging output
21
+ build/
22
+ dist/
23
+ *.egg-info/
24
+
25
+ # Local environment files
26
+ .env
27
+ .env.*
28
+ !.env.example
29
+
30
+ # Logs
31
+ *.log
32
+
33
+ # Experiment note assets and generated analysis payloads
34
+ sandbox/experiments/*/notes/assets/
35
+
36
+ # Local scratch/checkouts
37
+ tmp/
38
+ .worktrees/
39
+ .codex/*
40
+ !.codex/skills/
41
+ !.codex/skills/**
42
+
43
+ # Root cleanup holding area for generated/non-product artifacts moved out of
44
+ # the repository root.
45
+ sandbox/.root-artifacts/
46
+
47
+ # Phase 0 traces and generated infra state (now under sandbox/)
48
+ sandbox/traces/*.jsonl
49
+ sandbox/traces/*.csv
50
+ sandbox/traces/*.parquet
51
+ sandbox/traces/mtr/
52
+ sandbox/experiments/*/runs/**/mtr-*.txt
53
+ sandbox/experiments/*/runs/**/qlog/
54
+ sandbox/infra/terraform/.terraform/
55
+ # .terraform.lock.hcl is intentionally committed so the whole team pins identical
56
+ # provider versions. State now lives in S3 (see sandbox/infra/terraform/backend.tf);
57
+ # the local tfstate files below are stale artifacts and stay ignored.
58
+ sandbox/infra/terraform/terraform.tfstate
59
+ sandbox/infra/terraform/terraform.tfstate.backup
60
+ sandbox/infra/terraform/tfplan
61
+ sandbox/infra/certs/
62
+
63
+ # Local model checkpoints
64
+ sandbox/policies/flash/molmoact2-so101/MolmoAct2-SO100_101/
65
+ .gstack/
66
+
67
+ # Cold-start benchmark run outputs (raw per-iteration meta/ssm dumps + combined.json).
68
+ # Commit a baseline report.md by hand if you want to keep it; runs/ is ephemeral.
69
+ mvp/benchmarks/runs/
70
+ mvp/e2e/runs/
71
+ sandbox/benchmarks/runs/
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the
13
+ copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other
16
+ entities that control, are controlled by, or are under common control with
17
+ that entity. For the purposes of this definition, "control" means (i) the
18
+ power, direct or indirect, to cause the direction or management of such
19
+ entity, whether by contract or otherwise, or (ii) ownership of fifty percent
20
+ (50%) or more of the outstanding shares, or (iii) beneficial ownership of
21
+ such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
24
+ permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation source, and
28
+ configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical transformation
31
+ or translation of a Source form, including but not limited to compiled object
32
+ code, generated documentation, and conversions to other media types.
33
+
34
+ "Work" shall mean the work of authorship, whether in Source or Object form,
35
+ made available under the License, as indicated by a copyright notice that is
36
+ included in or attached to the work (an example is provided in the Appendix
37
+ below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object form,
40
+ that is based on (or derived from) the Work and for which the editorial
41
+ revisions, annotations, elaborations, or other modifications represent, as a
42
+ whole, an original work of authorship. For the purposes of this License,
43
+ Derivative Works shall not include works that remain separable from, or
44
+ merely link (or bind by name) to the interfaces of, the Work and Derivative
45
+ Works thereof.
46
+
47
+ "Contribution" shall mean any work of authorship, including the original
48
+ version of the Work and any modifications or additions to that Work or
49
+ Derivative Works thereof, that is intentionally submitted to Licensor for
50
+ inclusion in the Work by the copyright owner or by an individual or Legal
51
+ Entity authorized to submit on behalf of the copyright owner. For the
52
+ purposes of this definition, "submitted" means any form of electronic,
53
+ verbal, or written communication sent to the Licensor or its representatives,
54
+ including but not limited to communication on electronic mailing lists,
55
+ source code control systems, and issue tracking systems that are managed by,
56
+ or on behalf of, the Licensor for the purpose of discussing and improving the
57
+ Work, but excluding communication that is conspicuously marked or otherwise
58
+ designated in writing by the copyright owner as "Not a Contribution."
59
+
60
+ "Contributor" shall mean Licensor and any individual or Legal Entity on
61
+ behalf of whom a Contribution has been received by Licensor and subsequently
62
+ incorporated within the Work.
63
+
64
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
65
+ License, each Contributor hereby grants to You a perpetual, worldwide,
66
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
67
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
68
+ sublicense, and distribute the Work and such Derivative Works in Source or
69
+ Object form.
70
+
71
+ 3. Grant of Patent License. Subject to the terms and conditions of this
72
+ License, each Contributor hereby grants to You a perpetual, worldwide,
73
+ non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this
74
+ section) patent license to make, have made, use, offer to sell, sell, import,
75
+ and otherwise transfer the Work, where such license applies only to those
76
+ patent claims licensable by such Contributor that are necessarily infringed
77
+ by their Contribution(s) alone or by combination of their Contribution(s)
78
+ with the Work to which such Contribution(s) was submitted. If You institute
79
+ patent litigation against any entity (including a cross-claim or counterclaim
80
+ in a lawsuit) alleging that the Work or a Contribution incorporated within
81
+ the Work constitutes direct or contributory patent infringement, then any
82
+ patent licenses granted to You under this License for that Work shall
83
+ terminate as of the date such litigation is filed.
84
+
85
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
86
+ Derivative Works thereof in any medium, with or without modifications, and in
87
+ Source or Object form, provided that You meet the following conditions:
88
+
89
+ (a) You must give any other recipients of the Work or Derivative Works a copy
90
+ of this License; and
91
+
92
+ (b) You must cause any modified files to carry prominent notices stating that
93
+ You changed the files; and
94
+
95
+ (c) You must retain, in the Source form of any Derivative Works that You
96
+ distribute, all copyright, patent, trademark, and attribution notices from the
97
+ Source form of the Work, excluding those notices that do not pertain to any
98
+ part of the Derivative Works; and
99
+
100
+ (d) If the Work includes a "NOTICE" text file as part of its distribution,
101
+ then any Derivative Works that You distribute must include a readable copy of
102
+ the attribution notices contained within such NOTICE file, excluding those
103
+ notices that do not pertain to any part of the Derivative Works, in at least
104
+ one of the following places: within a NOTICE text file distributed as part of
105
+ the Derivative Works; within the Source form or documentation, if provided
106
+ along with the Derivative Works; or, within a display generated by the
107
+ Derivative Works, if and wherever such third-party notices normally appear.
108
+ The contents of the NOTICE file are for informational purposes only and do
109
+ not modify the License. You may add Your own attribution notices within
110
+ Derivative Works that You distribute, alongside or as an addendum to the
111
+ NOTICE text from the Work, provided that such additional attribution notices
112
+ cannot be construed as modifying the License.
113
+
114
+ You may add Your own copyright statement to Your modifications and may
115
+ provide additional or different license terms and conditions for use,
116
+ reproduction, or distribution of Your modifications, or for any such
117
+ Derivative Works as a whole, provided Your use, reproduction, and distribution
118
+ of the Work otherwise complies with the conditions stated in this License.
119
+
120
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
121
+ Contribution intentionally submitted for inclusion in the Work by You to the
122
+ Licensor shall be under the terms and conditions of this License, without any
123
+ additional terms or conditions. Notwithstanding the above, nothing herein
124
+ shall supersede or modify the terms of any separate license agreement you may
125
+ have executed with Licensor regarding such Contributions.
126
+
127
+ 6. Trademarks. This License does not grant permission to use the trade names,
128
+ trademarks, service marks, or product names of the Licensor, except as
129
+ required for reasonable and customary use in describing the origin of the
130
+ Work and reproducing the content of the NOTICE file.
131
+
132
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
133
+ writing, Licensor provides the Work (and each Contributor provides its
134
+ Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
135
+ KIND, either express or implied, including, without limitation, any warranties
136
+ or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
137
+ PARTICULAR PURPOSE. You are solely responsible for determining the
138
+ appropriateness of using or redistributing the Work and assume any risks
139
+ associated with Your exercise of permissions under this License.
140
+
141
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
142
+ tort (including negligence), contract, or otherwise, unless required by
143
+ applicable law (such as deliberate and grossly negligent acts) or agreed to in
144
+ writing, shall any Contributor be liable to You for damages, including any
145
+ direct, indirect, special, incidental, or consequential damages of any
146
+ character arising as a result of this License or out of the use or inability
147
+ to use the Work (including but not limited to damages for loss of goodwill,
148
+ work stoppage, computer failure or malfunction, or any and all other
149
+ commercial damages or losses), even if such Contributor has been advised of
150
+ the possibility of such damages.
151
+
152
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work
153
+ or Derivative Works thereof, You may choose to offer, and charge a fee for,
154
+ acceptance of support, warranty, indemnity, or other liability obligations
155
+ and/or rights consistent with this License. However, in accepting such
156
+ obligations, You may act only on Your own behalf and on Your sole
157
+ responsibility, not on behalf of any other Contributor, and only if You agree
158
+ to indemnify, defend, and hold each Contributor harmless for any liability
159
+ incurred by, or claims asserted against, such Contributor by reason of your
160
+ accepting any such warranty or additional liability.
161
+
162
+ END OF TERMS AND CONDITIONS
163
+
164
+ Copyright 2026 Dreamscale Labs
165
+
166
+ Licensed under the Apache License, Version 2.0 (the "License");
167
+ you may not use this file except in compliance with the License.
168
+ You may obtain a copy of the License at
169
+
170
+ http://www.apache.org/licenses/LICENSE-2.0
171
+
172
+ Unless required by applicable law or agreed to in writing, software
173
+ distributed under the License is distributed on an "AS IS" BASIS,
174
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
175
+ See the License for the specific language governing permissions and
176
+ limitations under the License.
@@ -0,0 +1,38 @@
1
+ Metadata-Version: 2.4
2
+ Name: dropbear-transport
3
+ Version: 0.1.1a1
4
+ Summary: Dropbear QUIC data plane: pinned client, UDP preflight, multi-session worker server
5
+ Project-URL: Homepage, https://dropbear.dreamscalelabs.com
6
+ Project-URL: Documentation, https://dropbear.dreamscalelabs.com/docs
7
+ Author: Dreamscale Labs
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ Keywords: inference,quic,robotics,transport
11
+ Classifier: Development Status :: 2 - Pre-Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Requires-Python: <3.13,>=3.12
17
+ Requires-Dist: aioquic<2,>=1.2.0
18
+ Requires-Dist: cryptography>=43.0.0
19
+ Requires-Dist: numpy>=2.0.0
20
+ Requires-Dist: pillow>=11.0.0
21
+ Requires-Dist: pydantic>=2.9.0
22
+ Requires-Dist: websockets>=14.0
23
+ Description-Content-Type: text/markdown
24
+
25
+ # dropbear-transport
26
+
27
+ Shared QUIC transport primitives for Dropbear.
28
+
29
+ This package contains the pinned QUIC client, multi-session worker server,
30
+ wire-message models, JPEG/image helpers, and UDP preflight checks used by the
31
+ SDK, worker, control plane, validation, and E2E packages.
32
+
33
+ This is a pre-alpha implementation dependency of the public `dropbear`
34
+ package. Most users should install `dropbear`, which selects the compatible
35
+ transport version automatically; no independent transport API stability is
36
+ promised before 1.0.
37
+
38
+ Documentation: https://dropbear.dreamscalelabs.com/docs
@@ -0,0 +1,14 @@
1
+ # dropbear-transport
2
+
3
+ Shared QUIC transport primitives for Dropbear.
4
+
5
+ This package contains the pinned QUIC client, multi-session worker server,
6
+ wire-message models, JPEG/image helpers, and UDP preflight checks used by the
7
+ SDK, worker, control plane, validation, and E2E packages.
8
+
9
+ This is a pre-alpha implementation dependency of the public `dropbear`
10
+ package. Most users should install `dropbear`, which selects the compatible
11
+ transport version automatically; no independent transport API stability is
12
+ promised before 1.0.
13
+
14
+ Documentation: https://dropbear.dreamscalelabs.com/docs
@@ -0,0 +1,48 @@
1
+ [project]
2
+ name = "dropbear-transport"
3
+ version = "0.1.1a1"
4
+ description = "Dropbear QUIC data plane: pinned client, UDP preflight, multi-session worker server"
5
+ readme = "README.md"
6
+ requires-python = ">=3.12,<3.13"
7
+ license = "Apache-2.0"
8
+ license-files = ["LICENSE"]
9
+ authors = [
10
+ { name = "Dreamscale Labs" },
11
+ ]
12
+ classifiers = [
13
+ "Development Status :: 2 - Pre-Alpha",
14
+ "Intended Audience :: Developers",
15
+ "License :: OSI Approved :: Apache Software License",
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3.12",
18
+ ]
19
+ keywords = ["robotics", "quic", "inference", "transport"]
20
+ dependencies = [
21
+ "aioquic>=1.2.0,<2",
22
+ "cryptography>=43.0.0",
23
+ "numpy>=2.0.0",
24
+ "pillow>=11.0.0",
25
+ "pydantic>=2.9.0",
26
+ "websockets>=14.0",
27
+ ]
28
+
29
+ [project.urls]
30
+ Homepage = "https://dropbear.dreamscalelabs.com"
31
+ Documentation = "https://dropbear.dreamscalelabs.com/docs"
32
+
33
+ [build-system]
34
+ requires = ["hatchling"]
35
+ build-backend = "hatchling.build"
36
+
37
+ [tool.hatch.build.targets.wheel]
38
+ packages = ["src/dropbear_transport"]
39
+
40
+ [tool.hatch.build.targets.sdist]
41
+ only-include = [
42
+ "src/dropbear_transport",
43
+ "README.md",
44
+ "LICENSE",
45
+ ]
46
+
47
+ [tool.pytest.ini_options]
48
+ asyncio_mode = "auto"
@@ -0,0 +1,79 @@
1
+ """Dropbear QUIC data-plane transport (mvp/transport, epic C1).
2
+
3
+ Binding public API per docs/plans/2026-06-10-dropbear-mvp-00-master.md:
4
+ preflight(), QuicClient, MultiSessionQuicServer, plus the shared constants
5
+ table and wire message models every other mvp/ package re-exports.
6
+ """
7
+
8
+ from importlib.metadata import PackageNotFoundError, version
9
+
10
+ try:
11
+ __version__ = version("dropbear-transport")
12
+ except PackageNotFoundError: # Direct source import outside an installed environment.
13
+ __version__ = "0+unknown"
14
+
15
+ from dropbear_transport import constants
16
+ from dropbear_transport.certs import (
17
+ cert_file_fingerprint,
18
+ fingerprint_der_sha256,
19
+ write_self_signed_cert,
20
+ )
21
+ from dropbear_transport.client import QuicClient
22
+ from dropbear_transport.errors import (
23
+ CertFingerprintMismatchError,
24
+ QuicRequestError,
25
+ TransportError,
26
+ error_payload,
27
+ )
28
+ from dropbear_transport.messages import (
29
+ PROTOCOL_VERSION,
30
+ Action,
31
+ ActionChunk,
32
+ CameraFrame,
33
+ Observation,
34
+ ObservationFrame,
35
+ RobotState,
36
+ RtcRequestContext,
37
+ RuntimeRequestContext,
38
+ RuntimeResponseMetadata,
39
+ )
40
+ from dropbear_transport.preflight import (
41
+ PreflightResult,
42
+ UdpReachabilityReason,
43
+ UdpReachabilityReport,
44
+ diagnose_udp,
45
+ preflight,
46
+ )
47
+ from dropbear_transport.relay_client import RelayClient
48
+ from dropbear_transport.server import MultiSessionQuicServer, SessionStats
49
+
50
+ __all__ = [
51
+ "Action",
52
+ "ActionChunk",
53
+ "CameraFrame",
54
+ "CertFingerprintMismatchError",
55
+ "MultiSessionQuicServer",
56
+ "Observation",
57
+ "ObservationFrame",
58
+ "PROTOCOL_VERSION",
59
+ "PreflightResult",
60
+ "QuicClient",
61
+ "QuicRequestError",
62
+ "RelayClient",
63
+ "RobotState",
64
+ "RtcRequestContext",
65
+ "RuntimeRequestContext",
66
+ "RuntimeResponseMetadata",
67
+ "SessionStats",
68
+ "TransportError",
69
+ "UdpReachabilityReport",
70
+ "UdpReachabilityReason",
71
+ "cert_file_fingerprint",
72
+ "constants",
73
+ "diagnose_udp",
74
+ "error_payload",
75
+ "fingerprint_der_sha256",
76
+ "preflight",
77
+ "write_self_signed_cert",
78
+ "__version__",
79
+ ]
@@ -0,0 +1,158 @@
1
+ """Loopback latency micro-benchmark: ported client/server overhead, no inference.
2
+
3
+ Compares against the sandbox phase0 stack (run separately in its own venv —
4
+ e.g. `cd sandbox && uv run pytest tests/integration/test_local_quic_loop.py`,
5
+ or its benchmark CLI). The full A3 GA re-run is owned by 07-validation.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import asyncio
11
+ import socket
12
+ import tempfile
13
+ import time
14
+ from dataclasses import asdict, dataclass
15
+ from pathlib import Path
16
+
17
+ from dropbear_transport.certs import cert_file_fingerprint, write_self_signed_cert
18
+ from dropbear_transport.client import QuicClient
19
+ from dropbear_transport.messages import (
20
+ Action,
21
+ ActionChunk,
22
+ CameraFrame,
23
+ Observation,
24
+ ObservationFrame,
25
+ RobotState,
26
+ )
27
+ from dropbear_transport.server import MultiSessionQuicServer
28
+ from dropbear_transport.time import monotonic_ns
29
+
30
+ _SESSION_ID = "dropbear_sess_bench"
31
+ _TOKEN = "bench-token"
32
+
33
+
34
+ @dataclass(frozen=True)
35
+ class BenchReport:
36
+ iterations: int
37
+ payload_bytes: int
38
+ cameras: int
39
+ connect_ms: float
40
+ rtt_ms_p50: float
41
+ rtt_ms_p95: float
42
+ rtt_ms_mean: float
43
+ rtt_ms_max: float
44
+
45
+ def as_dict(self) -> dict[str, float | int]:
46
+ return asdict(self)
47
+
48
+
49
+ def _percentile(sorted_values: list[float], q: float) -> float:
50
+ index = min(len(sorted_values) - 1, max(0, round(q * (len(sorted_values) - 1))))
51
+ return sorted_values[index]
52
+
53
+
54
+ def _unused_udp_port() -> int:
55
+ with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
56
+ sock.bind(("127.0.0.1", 0))
57
+ return sock.getsockname()[1]
58
+
59
+
60
+ def _make_observation(observation_id: int, payload_bytes: int, cameras: int) -> Observation:
61
+ payload = b"\xab" * payload_bytes
62
+ camera_ids = [f"cam_{index}" for index in range(cameras)]
63
+ frame = ObservationFrame(
64
+ session_id=_SESSION_ID,
65
+ observation_id=observation_id,
66
+ capture_time_ns=monotonic_ns(),
67
+ send_time_ns=monotonic_ns(),
68
+ cameras=[
69
+ CameraFrame(
70
+ camera_id=camera_id,
71
+ width=640,
72
+ height=480,
73
+ encoding="jpeg",
74
+ payload_bytes=payload_bytes,
75
+ )
76
+ for camera_id in camera_ids
77
+ ],
78
+ robot_state=RobotState(
79
+ joint_positions=[0.0] * 6, joint_velocities=[0.0] * 6, gripper=0.5
80
+ ),
81
+ actions_remaining=0,
82
+ instruction="benchmark",
83
+ )
84
+ return Observation(
85
+ frame=frame,
86
+ camera_payloads={camera_id: payload for camera_id in camera_ids},
87
+ chunk_size=10,
88
+ )
89
+
90
+
91
+ def _echo_chunk(observation: Observation) -> ActionChunk:
92
+ now = monotonic_ns()
93
+ return ActionChunk(
94
+ session_id=_SESSION_ID,
95
+ chunk_id=observation.frame.observation_id,
96
+ generated_from_observation_id=observation.frame.observation_id,
97
+ server_receive_time_ns=now,
98
+ inference_start_time_ns=now,
99
+ inference_end_time_ns=now,
100
+ server_send_time_ns=now,
101
+ actions=[Action(action_index=index, target=[0.0] * 6) for index in range(10)],
102
+ )
103
+
104
+
105
+ async def run_loopback_bench(
106
+ iterations: int = 200,
107
+ warmup: int = 20,
108
+ payload_bytes: int = 20_000,
109
+ cameras: int = 1,
110
+ ) -> BenchReport:
111
+ with tempfile.TemporaryDirectory() as tmp:
112
+ cert_path, key_path = write_self_signed_cert(Path(tmp))
113
+ fingerprint = cert_file_fingerprint(cert_path)
114
+ port = _unused_udp_port()
115
+ server: MultiSessionQuicServer | None = None
116
+
117
+ async def on_observation(session_id: str, observation: Observation) -> None:
118
+ assert server is not None
119
+ await server.send_action_chunk(session_id, _echo_chunk(observation))
120
+
121
+ server = MultiSessionQuicServer(
122
+ port, cert_path, key_path, on_observation, host="127.0.0.1"
123
+ )
124
+ server.upsert_session(_SESSION_ID, _TOKEN, "bench-user", time.time() + 3_600)
125
+ async with server.run():
126
+ client = await QuicClient.connect(
127
+ "127.0.0.1",
128
+ port,
129
+ cert_fingerprint=fingerprint,
130
+ session_id=_SESSION_ID,
131
+ session_token=_TOKEN,
132
+ )
133
+ chunks = client.action_chunks()
134
+ rtts_ms: list[float] = []
135
+ for index in range(1, warmup + iterations + 1):
136
+ observation = _make_observation(index, payload_bytes, cameras)
137
+ start_ns = monotonic_ns()
138
+ await client.send_observation(observation)
139
+ while True:
140
+ chunk = await asyncio.wait_for(anext(chunks), timeout=10)
141
+ if chunk.generated_from_observation_id == index:
142
+ break
143
+ rtt_ms = (monotonic_ns() - start_ns) / 1_000_000.0
144
+ if index > warmup:
145
+ rtts_ms.append(rtt_ms)
146
+ connect_ms = client.connect_ms or 0.0
147
+ await client.close()
148
+ rtts_ms.sort()
149
+ return BenchReport(
150
+ iterations=iterations,
151
+ payload_bytes=payload_bytes,
152
+ cameras=cameras,
153
+ connect_ms=connect_ms,
154
+ rtt_ms_p50=_percentile(rtts_ms, 0.50),
155
+ rtt_ms_p95=_percentile(rtts_ms, 0.95),
156
+ rtt_ms_mean=sum(rtts_ms) / len(rtts_ms),
157
+ rtt_ms_max=rtts_ms[-1],
158
+ )
@@ -0,0 +1,85 @@
1
+ """Self-signed cert minting + SHA-256(DER) fingerprint helpers.
2
+
3
+ The worker mints one cert on first boot (10-year validity, persisted on EBS) and
4
+ registers its fingerprint with the control plane; the SDK pins it post-handshake.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import hashlib
10
+ import ipaddress
11
+ import os
12
+ from datetime import UTC, datetime, timedelta
13
+ from pathlib import Path
14
+
15
+ from cryptography import x509
16
+ from cryptography.hazmat.primitives import hashes, serialization
17
+ from cryptography.hazmat.primitives.asymmetric import rsa
18
+ from cryptography.x509.oid import NameOID
19
+
20
+
21
+ def write_self_signed_cert(
22
+ target_dir: Path,
23
+ *,
24
+ common_name: str = "dropbear-worker",
25
+ validity_days: int = 3650,
26
+ ) -> tuple[Path, Path]:
27
+ """Mint a self-signed cert + key as PEM files; returns (cert_path, key_path)."""
28
+ key = rsa.generate_private_key(public_exponent=65537, key_size=2048)
29
+ subject = x509.Name([x509.NameAttribute(NameOID.COMMON_NAME, common_name)])
30
+ now = datetime.now(UTC)
31
+ cert = (
32
+ x509.CertificateBuilder()
33
+ .subject_name(subject)
34
+ .issuer_name(subject)
35
+ .public_key(key.public_key())
36
+ .serial_number(x509.random_serial_number())
37
+ .not_valid_before(now - timedelta(minutes=1))
38
+ .not_valid_after(now + timedelta(days=validity_days))
39
+ .add_extension(
40
+ x509.SubjectAlternativeName(
41
+ [
42
+ x509.DNSName("localhost"),
43
+ x509.IPAddress(ipaddress.ip_address("127.0.0.1")),
44
+ x509.IPAddress(ipaddress.ip_address("::1")),
45
+ ]
46
+ ),
47
+ critical=False,
48
+ )
49
+ .sign(key, hashes.SHA256())
50
+ )
51
+
52
+ target_dir.mkdir(mode=0o700, parents=True, exist_ok=True)
53
+ target_dir.chmod(0o700)
54
+ key_path = target_dir / "quic.key"
55
+ cert_path = target_dir / "quic.crt"
56
+ _write_private_key(
57
+ key_path,
58
+ key.private_bytes(
59
+ serialization.Encoding.PEM,
60
+ serialization.PrivateFormat.TraditionalOpenSSL,
61
+ serialization.NoEncryption(),
62
+ ),
63
+ )
64
+ cert_path.write_bytes(cert.public_bytes(serialization.Encoding.PEM))
65
+ return cert_path, key_path
66
+
67
+
68
+ def fingerprint_der_sha256(der: bytes) -> str:
69
+ """Hex SHA-256 of a DER-encoded certificate (the pinning format everywhere)."""
70
+ return hashlib.sha256(der).hexdigest()
71
+
72
+
73
+ def cert_file_fingerprint(cert_path: Path) -> str:
74
+ """Fingerprint of a PEM cert file (what the worker registers over its WS)."""
75
+ cert = x509.load_pem_x509_certificate(cert_path.read_bytes())
76
+ return fingerprint_der_sha256(cert.public_bytes(serialization.Encoding.DER))
77
+
78
+
79
+ def _write_private_key(path: Path, data: bytes) -> None:
80
+ if path.exists():
81
+ path.chmod(0o600)
82
+ fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
83
+ with os.fdopen(fd, "wb") as key_file:
84
+ key_file.write(data)
85
+ path.chmod(0o600)