Transport: add MultiTransport to run WT and QUIC concurrently and route sends
This commit is contained in:
26
server/multi_transport.py
Normal file
26
server/multi_transport.py
Normal file
@@ -0,0 +1,26 @@
|
||||
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())
|
||||
Reference in New Issue
Block a user