Skip to content

Commit

Permalink
[connection] remove protocol_version argument from connect()
Browse files Browse the repository at this point in the history
  • Loading branch information
jlaine committed Aug 11, 2019
1 parent cb553fa commit 59e9a17
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
6 changes: 4 additions & 2 deletions aioquic/asyncio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ async def connect(
*,
alpn_protocols: Optional[List[str]] = None,
idle_timeout: Optional[float] = None,
protocol_version: Optional[int] = None,
quic_logger: Optional[QuicLogger] = None,
secrets_log_file: Optional[TextIO] = None,
session_ticket: Optional[SessionTicket] = None,
session_ticket_handler: Optional[SessionTicketHandler] = None,
stream_handler: Optional[QuicStreamHandler] = None,
supported_versions: Optional[List[int]] = None,
) -> AsyncGenerator[QuicConnectionProtocol, None]:
"""
Connect to a QUIC server at the given `host` and `port`.
Expand Down Expand Up @@ -73,6 +73,8 @@ async def connect(
)
if idle_timeout is not None:
configuration.idle_timeout = idle_timeout
if supported_versions is not None:
configuration.supported_versions = supported_versions

connection = QuicConnection(
configuration=configuration, session_ticket_handler=session_ticket_handler
Expand All @@ -84,7 +86,7 @@ async def connect(
local_addr=("::", 0),
)
protocol = cast(QuicConnectionProtocol, protocol)
protocol.connect(addr, protocol_version)
protocol.connect(addr)
await protocol.wait_connected()
try:
yield protocol
Expand Down
6 changes: 2 additions & 4 deletions aioquic/asyncio/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,13 @@ def close(self) -> None:
self._quic.close()
self._send_pending()

def connect(self, addr: NetworkAddress, protocol_version: int) -> None:
def connect(self, addr: NetworkAddress) -> None:
"""
Initiate the TLS handshake.
This method can only be called for clients and a single time.
"""
self._quic.connect(
addr, now=self._loop.time(), protocol_version=protocol_version
)
self._quic.connect(addr, now=self._loop.time())
self._send_pending()

async def create_stream(
Expand Down
10 changes: 2 additions & 8 deletions aioquic/quic/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,7 @@ def close(
)
self._close_pending = True

def connect(
self, addr: NetworkAddress, now: float, protocol_version: Optional[int] = None
) -> None:
def connect(self, addr: NetworkAddress, now: float) -> None:
"""
Initiate the TLS handshake.
Expand All @@ -453,18 +451,14 @@ def connect(
:param addr: The network address of the remote peer.
:param now: The current time.
:param protocol_version: An optional QUIC protocol version.
"""
assert (
self._is_client and not self._connect_called
), "connect() can only be called for clients and a single time"
self._connect_called = True

self._network_paths = [QuicNetworkPath(addr, is_validated=True)]
if protocol_version is not None:
self._version = protocol_version
else:
self._version = max(self._configuration.supported_versions)
self._version = self._configuration.supported_versions[0]
self._connect(now=now)

def datagrams_to_send(self, now: float) -> List[Tuple[bytes, NetworkAddress]]:
Expand Down
6 changes: 5 additions & 1 deletion examples/interop.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from aioquic.asyncio import connect
from aioquic.h3.connection import H3Connection
from aioquic.quic.packet import QuicProtocolVersion


class Result(Flag):
Expand Down Expand Up @@ -111,7 +112,10 @@ async def http3_request(connection, authority, path):

async def test_version_negotiation(config, **kwargs):
async with connect(
config.host, config.port, protocol_version=0x1A2A3A4A, **kwargs
config.host,
config.port,
supported_versions=[0x1A2A3A4A, QuicProtocolVersion.DRAFT_22],
**kwargs
) as connection:
await connection.ping()
if connection._quic._version_negotiation_count == 1:
Expand Down
5 changes: 4 additions & 1 deletion tests/test_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from aioquic.asyncio.client import connect
from aioquic.asyncio.server import serve
from aioquic.quic.logger import QuicLogger
from aioquic.quic.packet import QuicProtocolVersion

from .utils import SERVER_CERTIFICATE, SERVER_PRIVATE_KEY, run

Expand Down Expand Up @@ -177,7 +178,9 @@ def test_connect_and_serve_with_version_negotiation(self):
asyncio.gather(
run_server(),
run_client(
"127.0.0.1", protocol_version=0x1A2A3A4A, quic_logger=QuicLogger()
"127.0.0.1",
quic_logger=QuicLogger(),
supported_versions=[0x1A2A3A4A, QuicProtocolVersion.DRAFT_22],
),
)
)
Expand Down

0 comments on commit 59e9a17

Please sign in to comment.