27 lines
963 B
Python
27 lines
963 B
Python
from __future__ import annotations
|
|
|
|
import asyncio
|
|
from .transport import DatagramServerTransport, TransportPeer
|
|
|
|
|
|
class MultiTransport(DatagramServerTransport):
|
|
"""Run both WebTransport and QUIC transports and route sends.
|
|
|
|
Inbound datagrams share the same on_datagram callback from GameServer,
|
|
so GameServer sees a unified source of datagrams.
|
|
"""
|
|
|
|
def __init__(self, wt_transport: DatagramServerTransport, quic_transport: DatagramServerTransport):
|
|
self._wt = wt_transport
|
|
self._quic = quic_transport
|
|
|
|
async def send(self, data: bytes, peer: TransportPeer) -> None:
|
|
# WebTransport peers are tuples (proto, flow_id); QUIC uses protocol instance
|
|
if isinstance(peer.addr, tuple) and len(peer.addr) == 2:
|
|
await self._wt.send(data, peer)
|
|
else:
|
|
await self._quic.send(data, peer)
|
|
|
|
async def run(self) -> None:
|
|
await asyncio.gather(self._wt.run(), self._quic.run())
|