Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass along ssl_context #1

Open
wants to merge 1 commit into
base: electrum
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions aionostr/relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Relay:
"""
Interact with a relay
"""
def __init__(self, url, verbose=False, origin:str = '', private_key:str='', connect_timeout: float=1.0, log=None):
def __init__(self, url, verbose=False, origin:str = '', private_key:str='', connect_timeout: float=1.0, log=None, ssl_context=None):
self.log = log or logging.getLogger(__name__)
self.url = url
self.ws = None
Expand All @@ -32,11 +32,12 @@ def __init__(self, url, verbose=False, origin:str = '', private_key:str='', conn
self.origin = origin or url
self.connected = False
self.connect_timeout = connect_timeout
self.ssl_context = ssl_context

async def connect(self, taskgroup, retries=2):
for i in range(retries):
try:
self.ws = await asyncio.wait_for(connect(self.url, origin=self.origin), self.connect_timeout)
self.ws = await asyncio.wait_for(connect(self.url, origin=self.origin, ssl=self.ssl_context), self.connect_timeout)
except:
await asyncio.sleep(0.2 * i)
else:
Expand Down Expand Up @@ -151,9 +152,9 @@ class Manager:
"""
Manage a collection of relays
"""
def __init__(self, relays=None, verbose=False, origin='aionostr', private_key=None, log=None):
def __init__(self, relays=None, verbose=False, origin='aionostr', private_key=None, log=None, ssl_context=None):
self.log = log or logging.getLogger(__name__)
self.relays = [Relay(r, origin=origin, private_key=private_key, log=log) for r in (relays or [])]
self.relays = [Relay(r, origin=origin, private_key=private_key, log=log, ssl_context=ssl_context) for r in (relays or [])]
self.subscriptions = {}
self.connected = False
self._connectlock = asyncio.Lock()
Expand Down