From 923809ab43d7ab4a335b42cb72b0b59156abf022 Mon Sep 17 00:00:00 2001 From: jesopo Date: Sat, 11 Apr 2020 11:33:53 +0100 Subject: [PATCH] add async_stagger reference for backported happy eyeballs open_connection --- ircrobots/transport.py | 17 ++++++++++++----- requirements.txt | 1 + 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/ircrobots/transport.py b/ircrobots/transport.py index 9e20e7d..ff51e15 100644 --- a/ircrobots/transport.py +++ b/ircrobots/transport.py @@ -1,6 +1,7 @@ -from ssl import SSLContext -from typing import Optional, Tuple -from asyncio import open_connection, StreamReader, StreamWriter +from ssl import SSLContext +from typing import Optional, Tuple +from asyncio import StreamReader, StreamWriter +from async_stagger import open_connection from .interface import ITCPTransport, ITCPReader, ITCPWriter from .security import tls_context @@ -34,9 +35,15 @@ class TCPTransport(ITCPTransport): if tls: cur_ssl = tls_context(tls_verify) + local_addr: Optional[Tuple[str, int]] = None + if not bindhost is None: + local_addr = (bindhost, 53567) + reader, writer = await open_connection( hostname, port, - ssl=cur_ssl, - local_addr=(bindhost, 0)) + server_hostname=hostname, + ssl =cur_ssl, + local_addr =local_addr) return (TCPReader(reader), TCPWriter(writer)) + diff --git a/requirements.txt b/requirements.txt index 4961e9c..6744b01 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ anyio ==1.3.0 asyncio-throttle ==1.0.1 dataclasses ==0.6 ircstates ==0.8.7 +async_stagger ==0.3.0