Skip to content

Commit 46d78c8

Browse files
committed
quic protocol
1 parent 93a0d05 commit 46d78c8

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

pproxy/server.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,14 +325,24 @@ async def wait_open_connection(self, *args):
325325
if self.handshake is not None:
326326
if not self.handshake.done():
327327
await self.handshake
328-
reader, writer = await self.handshake.result().create_stream()
329328
else:
330329
self.handshake = asyncio.get_event_loop().create_future()
331-
import aioquic.asyncio
332-
self.quic_egress_acm = aioquic.asyncio.connect(self.host_name, self.port, configuration=self.quicclient)
330+
import aioquic.asyncio, aioquic.quic.events
331+
class Protocol(aioquic.asyncio.QuicConnectionProtocol):
332+
def quic_event_received(s, event):
333+
if isinstance(event, aioquic.quic.events.HandshakeCompleted):
334+
self.handshake.set_result(s)
335+
elif isinstance(event, aioquic.quic.events.ConnectionTerminated):
336+
self.handshake = None
337+
self.quic_egress_acm = None
338+
super().quic_event_received(event)
339+
self.quic_egress_acm = aioquic.asyncio.connect(self.host_name, self.port, create_protocol=Protocol, configuration=self.quicclient)
333340
conn = await self.quic_egress_acm.__aenter__()
334-
self.handshake.set_result(conn)
335-
reader, writer = await conn.create_stream()
341+
await self.handshake
342+
conn = self.handshake.result()
343+
stream_id = conn._quic.get_next_available_stream_id(False)
344+
conn._quic._get_or_create_stream_for_send(stream_id)
345+
reader, writer = conn._create_stream(stream_id)
336346
self.patch_writer(writer)
337347
return reader, writer
338348
async def start_server(self, args):

0 commit comments

Comments
 (0)