swarmauri_transport_quic 0.1.0.dev42__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,86 @@
1
+ Metadata-Version: 2.4
2
+ Name: swarmauri_transport_quic
3
+ Version: 0.1.0.dev42
4
+ Summary: QUIC multiplex transport skeleton for Swarmauri.
5
+ License-Expression: Apache-2.0
6
+ Keywords: swarmauri,sdk,standards,transport,quic
7
+ Author: Jacob Stewart
8
+ Author-email: jacob@swarmauri.com
9
+ Requires-Python: >=3.10,<3.13
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Requires-Dist: swarmauri_base
19
+ Requires-Dist: swarmauri_core
20
+ Description-Content-Type: text/markdown
21
+
22
+ # Swarmauri QUIC Transport
23
+
24
+ ![Transport Icon](https://img.shields.io/badge/transport-quic-4B8BF4.svg)
25
+ ![Multiplex](https://img.shields.io/badge/feature-multiplexing-9B59B6.svg)
26
+ ![Lifecycle](https://img.shields.io/badge/lifecycle-async%20contexts-1E90FF.svg)
27
+
28
+ The **Swarmauri QUIC Transport** outlines a multiplexed, encrypted transport
29
+ based on QUIC. It shares the unified lifecycle helpers so that future
30
+ implementations can expose `.server(...)`, `.client(...)`, and channel-aware
31
+ APIs directly on the transport instance.
32
+
33
+ > **Note**: This package currently ships a skeleton with `NotImplementedError`
34
+ > placeholders so downstream teams can integrate their preferred QUIC stack.
35
+
36
+ ## Installation
37
+
38
+ ### Using `uv`
39
+
40
+ ```bash
41
+ uv add --directory pkgs/standards/swarmauri_transport_quic swarmauri_transport_quic
42
+ ```
43
+
44
+ ### Using `pip`
45
+
46
+ ```bash
47
+ pip install swarmauri_transport_quic
48
+ ```
49
+
50
+ ## Usage
51
+
52
+ The example below demonstrates the lifecycle of a QUIC transport once the
53
+ implementation details are filled in.
54
+
55
+ ```python
56
+ import asyncio
57
+ from swarmauri_transport_quic import QuicTransport
58
+
59
+ async def main():
60
+ server = QuicTransport(cert="srv.pem", key="srv.key")
61
+ client = QuicTransport(server_name="localhost")
62
+
63
+ async def run_server():
64
+ async with server.server(host="0.0.0.0", port=4433):
65
+ channel = await server.open_channel()
66
+ await server.send_on(channel, b"welcome")
67
+ data = await server.recv_on(channel)
68
+ await server.send_on(channel, b"ack:" + data)
69
+ await server.close_channel(channel)
70
+
71
+ async def run_client():
72
+ async with client.client(host="127.0.0.1", port=4433):
73
+ channel = await client.open_channel()
74
+ await client.send_on(channel, b"hi-quic")
75
+ response = await client.recv_on(channel)
76
+ print(response.decode())
77
+ await client.close_channel(channel)
78
+
79
+ await asyncio.gather(run_server(), run_client())
80
+
81
+ asyncio.run(main())
82
+ ```
83
+
84
+ Replace the placeholders with concrete QUIC operations once your chosen
85
+ library is integrated.
86
+
@@ -0,0 +1,64 @@
1
+ # Swarmauri QUIC Transport
2
+
3
+ ![Transport Icon](https://img.shields.io/badge/transport-quic-4B8BF4.svg)
4
+ ![Multiplex](https://img.shields.io/badge/feature-multiplexing-9B59B6.svg)
5
+ ![Lifecycle](https://img.shields.io/badge/lifecycle-async%20contexts-1E90FF.svg)
6
+
7
+ The **Swarmauri QUIC Transport** outlines a multiplexed, encrypted transport
8
+ based on QUIC. It shares the unified lifecycle helpers so that future
9
+ implementations can expose `.server(...)`, `.client(...)`, and channel-aware
10
+ APIs directly on the transport instance.
11
+
12
+ > **Note**: This package currently ships a skeleton with `NotImplementedError`
13
+ > placeholders so downstream teams can integrate their preferred QUIC stack.
14
+
15
+ ## Installation
16
+
17
+ ### Using `uv`
18
+
19
+ ```bash
20
+ uv add --directory pkgs/standards/swarmauri_transport_quic swarmauri_transport_quic
21
+ ```
22
+
23
+ ### Using `pip`
24
+
25
+ ```bash
26
+ pip install swarmauri_transport_quic
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ The example below demonstrates the lifecycle of a QUIC transport once the
32
+ implementation details are filled in.
33
+
34
+ ```python
35
+ import asyncio
36
+ from swarmauri_transport_quic import QuicTransport
37
+
38
+ async def main():
39
+ server = QuicTransport(cert="srv.pem", key="srv.key")
40
+ client = QuicTransport(server_name="localhost")
41
+
42
+ async def run_server():
43
+ async with server.server(host="0.0.0.0", port=4433):
44
+ channel = await server.open_channel()
45
+ await server.send_on(channel, b"welcome")
46
+ data = await server.recv_on(channel)
47
+ await server.send_on(channel, b"ack:" + data)
48
+ await server.close_channel(channel)
49
+
50
+ async def run_client():
51
+ async with client.client(host="127.0.0.1", port=4433):
52
+ channel = await client.open_channel()
53
+ await client.send_on(channel, b"hi-quic")
54
+ response = await client.recv_on(channel)
55
+ print(response.decode())
56
+ await client.close_channel(channel)
57
+
58
+ await asyncio.gather(run_server(), run_client())
59
+
60
+ asyncio.run(main())
61
+ ```
62
+
63
+ Replace the placeholders with concrete QUIC operations once your chosen
64
+ library is integrated.
@@ -0,0 +1,70 @@
1
+ [project]
2
+ name = "swarmauri_transport_quic"
3
+ version = "0.1.0.dev42"
4
+ authors = [
5
+ { name = "Jacob Stewart", email = "jacob@swarmauri.com" }
6
+ ]
7
+ description = "QUIC multiplex transport skeleton for Swarmauri."
8
+ readme = "README.md"
9
+ license = "Apache-2.0"
10
+ repository = "https://github.com/swarmauri/swarmauri-sdk"
11
+ requires-python = ">=3.10,<3.13"
12
+ classifiers = [
13
+ "License :: OSI Approved :: Apache Software License",
14
+ "Programming Language :: Python :: 3",
15
+ "Programming Language :: Python :: 3.10",
16
+ "Programming Language :: Python :: 3.11",
17
+ "Programming Language :: Python :: 3.12",
18
+ "Operating System :: OS Independent",
19
+ "Programming Language :: Python",
20
+ "Programming Language :: Python :: 3 :: Only",
21
+ ]
22
+ dependencies = [
23
+ "swarmauri_base",
24
+ "swarmauri_core",
25
+ ]
26
+ keywords = [
27
+ 'swarmauri',
28
+ 'sdk',
29
+ 'standards',
30
+ 'transport',
31
+ 'quic',
32
+ ]
33
+
34
+ [tool.uv.sources]
35
+ swarmauri_base = { workspace = true }
36
+ swarmauri_core = { workspace = true }
37
+
38
+ [build-system]
39
+ requires = ["poetry-core>=1.0.0"]
40
+ build-backend = "poetry.core.masonry.api"
41
+
42
+ [tool.pytest.ini_options]
43
+ markers = [
44
+ "test: standard test",
45
+ "unit: Unit tests",
46
+ "i9n: Integration tests",
47
+ "r8n: Regression tests",
48
+ "acceptance: Acceptance tests",
49
+ "perf: Performance tests",
50
+ "example: Documentation examples",
51
+ ]
52
+ timeout = 300
53
+ log_cli = true
54
+ log_cli_level = "INFO"
55
+ log_cli_format = "%(asctime)s [%(levelname)s] %(message)s"
56
+ log_cli_date_format = "%Y-%m-%d %H:%M:%S"
57
+ asyncio_default_fixture_loop_scope = "function"
58
+ addopts = "--pylicense-accept-deps=sniffio"
59
+
60
+ [dependency-groups]
61
+ dev = [
62
+ "pytest>=8.0",
63
+ "pytest-asyncio>=0.24.0",
64
+ "pytest-xdist>=3.6.1",
65
+ "pytest-json-report>=1.5.0",
66
+ "pytest-timeout>=2.3.1",
67
+ "pytest-benchmark>=4.0.0",
68
+ "ruff>=0.9.9",
69
+ "swarmauri_tests_pylicense",
70
+ ]
@@ -0,0 +1,5 @@
1
+ """QUIC transport placeholder implementation."""
2
+
3
+ from .quic_transport import QuicTransport
4
+
5
+ __all__ = ["QuicTransport"]
@@ -0,0 +1,250 @@
1
+ """QUIC-inspired transport with multiplexed channel semantics."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import asyncio
6
+ from dataclasses import dataclass
7
+ from typing import AsyncIterator, Optional, Tuple
8
+
9
+ from swarmauri_base.transports.TransportBase import TransportBase
10
+ from swarmauri_core.transports.capabilities import TransportCapabilities
11
+ from swarmauri_core.transports.enums import (
12
+ AddressScheme,
13
+ Cast,
14
+ Feature,
15
+ IOModel,
16
+ Protocol,
17
+ SecurityMode,
18
+ )
19
+ from swarmauri_core.transports.i_multiplex import ChannelHandle
20
+
21
+
22
+ @dataclass
23
+ class _QuicChannel:
24
+ """Internal structure representing a logical channel."""
25
+
26
+ identifier: int
27
+ queue: asyncio.Queue[bytes]
28
+ remote: Tuple[str, int] | None = None
29
+
30
+
31
+ class _QuicDatagramProtocol(asyncio.DatagramProtocol):
32
+ """Simple protocol forwarding datagrams to the transport instance."""
33
+
34
+ def __init__(self, handler) -> None: # type: ignore[no-untyped-def]
35
+ self._handler = handler
36
+ self.transport: asyncio.DatagramTransport | None = None
37
+
38
+ def connection_made(self, transport: asyncio.BaseTransport) -> None:
39
+ self.transport = transport # type: ignore[assignment]
40
+
41
+ def datagram_received(self, data: bytes, addr: Tuple[str, int]) -> None:
42
+ self._handler(data, addr)
43
+
44
+
45
+ class QuicTransport(TransportBase):
46
+ """QUIC-like transport built on asyncio UDP primitives."""
47
+
48
+ def __init__(self, **config: object) -> None:
49
+ super().__init__(name="QUIC")
50
+ self._config: dict[str, object] = dict(config)
51
+ self._server_transport: asyncio.DatagramTransport | None = None
52
+ self._client_transport: asyncio.DatagramTransport | None = None
53
+ self._server_protocol: _QuicDatagramProtocol | None = None
54
+ self._client_protocol: _QuicDatagramProtocol | None = None
55
+ self._default_queue: asyncio.Queue[bytes] = asyncio.Queue()
56
+ self._channels: dict[int, _QuicChannel] = {}
57
+ self._next_channel: int = 1
58
+ self._peer_addr: Tuple[str, int] | None = None
59
+ self._default_remote: Tuple[str, int] | None = None
60
+ self._peer_queue: asyncio.Queue[Tuple[str, int]] = asyncio.Queue()
61
+ self._known_peers: set[Tuple[str, int]] = set()
62
+ self._reset_state()
63
+
64
+ def _reset_state(self) -> None:
65
+ self._default_queue = asyncio.Queue()
66
+ self._channels = {}
67
+ self._next_channel = 1
68
+ self._peer_queue = asyncio.Queue()
69
+ self._known_peers = set()
70
+ self._peer_addr = None
71
+ self._default_remote = None
72
+
73
+ # ------------------------------------------------------------------
74
+ # Capability advertisement
75
+ # ------------------------------------------------------------------
76
+ def supports(self) -> TransportCapabilities:
77
+ return TransportCapabilities(
78
+ protocols=frozenset({Protocol.QUIC}),
79
+ io=IOModel.STREAM,
80
+ casts=frozenset({Cast.UNICAST}),
81
+ features=frozenset(
82
+ {
83
+ Feature.RELIABLE,
84
+ Feature.ORDERED,
85
+ Feature.ENCRYPTED,
86
+ Feature.AUTHENTICATED,
87
+ Feature.MULTIPLEX,
88
+ }
89
+ ),
90
+ security=SecurityMode.TLS,
91
+ schemes=frozenset({AddressScheme.QUIC}),
92
+ )
93
+
94
+ # ------------------------------------------------------------------
95
+ # Lifecycle management
96
+ # ------------------------------------------------------------------
97
+ async def _start_server(self, host: str = "0.0.0.0", port: int = 4433) -> None:
98
+ self._reset_state()
99
+ loop = asyncio.get_running_loop()
100
+ transport, protocol = await loop.create_datagram_endpoint(
101
+ lambda: _QuicDatagramProtocol(self._handle_datagram),
102
+ local_addr=(host, port),
103
+ )
104
+ self._server_transport = transport
105
+ self._server_protocol = protocol
106
+ self._default_remote = None
107
+ self._peer_addr = None
108
+
109
+ async def _stop_server(self) -> None:
110
+ if self._server_transport is not None:
111
+ self._server_transport.close()
112
+ self._server_transport = None
113
+ self._server_protocol = None
114
+ self._reset_state()
115
+
116
+ async def _open_client(self, host: str = "127.0.0.1", port: int = 4433) -> None:
117
+ self._reset_state()
118
+ loop = asyncio.get_running_loop()
119
+ transport, protocol = await loop.create_datagram_endpoint(
120
+ lambda: _QuicDatagramProtocol(self._handle_datagram),
121
+ remote_addr=(host, port),
122
+ )
123
+ self._client_transport = transport
124
+ self._client_protocol = protocol
125
+ self._peer_addr = (host, port)
126
+ self._default_remote = (host, port)
127
+
128
+ async def _close_client(self) -> None:
129
+ if self._client_transport is not None:
130
+ self._client_transport.close()
131
+ self._client_transport = None
132
+ self._client_protocol = None
133
+ self._reset_state()
134
+
135
+ # ------------------------------------------------------------------
136
+ # Peer handling
137
+ # ------------------------------------------------------------------
138
+ async def accept(self) -> AsyncIterator[Tuple[str, int]]: # type: ignore[override]
139
+ while True:
140
+ addr = await self._peer_queue.get()
141
+ yield addr
142
+
143
+ # ------------------------------------------------------------------
144
+ # Unicast operations
145
+ # ------------------------------------------------------------------
146
+ async def send(
147
+ self, target: str, data: bytes, *, timeout: Optional[float] = None
148
+ ) -> None:
149
+ addr = self._resolve_target(target)
150
+ await self._send_datagram((0).to_bytes(4, "big") + data, addr, timeout)
151
+
152
+ async def recv(self, *, timeout: Optional[float] = None) -> bytes:
153
+ if timeout is None:
154
+ return await self._default_queue.get()
155
+ return await asyncio.wait_for(self._default_queue.get(), timeout)
156
+
157
+ # ------------------------------------------------------------------
158
+ # Multiplexed channel management
159
+ # ------------------------------------------------------------------
160
+ async def open_channel(self) -> ChannelHandle:
161
+ handle = self._next_channel
162
+ self._next_channel += 1
163
+ remote = self._peer_addr or self._default_remote
164
+ self._channels[handle] = _QuicChannel(handle, asyncio.Queue(), remote)
165
+ return handle
166
+
167
+ async def close_channel(self, handle: ChannelHandle) -> None:
168
+ self._channels.pop(int(handle), None)
169
+
170
+ async def send_on(
171
+ self, handle: ChannelHandle, data: bytes, *, timeout: Optional[float] = None
172
+ ) -> None:
173
+ channel = self._ensure_channel(handle)
174
+ if channel.remote is None:
175
+ channel.remote = self._peer_addr or self._default_remote
176
+ if channel.remote is None:
177
+ raise RuntimeError("no remote peer associated with channel")
178
+ payload = int(channel.identifier).to_bytes(4, "big") + data
179
+ await self._send_datagram(payload, channel.remote, timeout)
180
+
181
+ async def recv_on(
182
+ self, handle: ChannelHandle, *, timeout: Optional[float] = None
183
+ ) -> bytes:
184
+ channel = self._ensure_channel(handle)
185
+ if timeout is None:
186
+ return await channel.queue.get()
187
+ return await asyncio.wait_for(channel.queue.get(), timeout)
188
+
189
+ # ------------------------------------------------------------------
190
+ # Internal helpers
191
+ # ------------------------------------------------------------------
192
+ def _ensure_channel(self, handle: ChannelHandle) -> _QuicChannel:
193
+ key = int(handle)
194
+ channel = self._channels.get(key)
195
+ if channel is None:
196
+ channel = _QuicChannel(key, asyncio.Queue())
197
+ self._channels[key] = channel
198
+ return channel
199
+
200
+ def _get_transport(self) -> asyncio.DatagramTransport:
201
+ transport = self._client_transport or self._server_transport
202
+ if transport is None:
203
+ raise RuntimeError("transport is not connected")
204
+ return transport
205
+
206
+ def _resolve_target(self, target: str) -> Tuple[str, int]:
207
+ token = target.strip().lower()
208
+ if ":" in target:
209
+ host, port_str = target.split(":", 1)
210
+ return host, int(port_str)
211
+ if token in {"peer", "server", "default"}:
212
+ if self._peer_addr is not None:
213
+ return self._peer_addr
214
+ if self._default_remote is not None:
215
+ return self._default_remote
216
+ if self._peer_addr is not None:
217
+ return self._peer_addr
218
+ if self._default_remote is not None:
219
+ return self._default_remote
220
+ raise RuntimeError("no remote peer available for send operation")
221
+
222
+ async def _send_datagram(
223
+ self, payload: bytes, addr: Tuple[str, int], timeout: Optional[float]
224
+ ) -> None:
225
+ transport = self._get_transport()
226
+ transport.sendto(payload, addr)
227
+ if timeout is not None:
228
+ await asyncio.sleep(0)
229
+
230
+ def _handle_datagram(self, data: bytes, addr: Tuple[str, int]) -> None:
231
+ if not data:
232
+ return
233
+ channel_id = int.from_bytes(data[:4], "big")
234
+ payload = data[4:]
235
+ if addr not in self._known_peers:
236
+ self._known_peers.add(addr)
237
+ self._peer_queue.put_nowait(addr)
238
+ self._default_remote = addr
239
+ if self._peer_addr is None:
240
+ self._peer_addr = addr
241
+ if channel_id == 0:
242
+ self._default_queue.put_nowait(payload)
243
+ else:
244
+ channel = self._channels.get(channel_id)
245
+ if channel is None:
246
+ channel = _QuicChannel(channel_id, asyncio.Queue(), addr)
247
+ self._channels[channel_id] = channel
248
+ elif channel.remote is None:
249
+ channel.remote = addr
250
+ channel.queue.put_nowait(payload)