Skip to content

Commit

Permalink
also reuse proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Feb 2, 2023
1 parent 3aee210 commit 88d4367
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions nostr/relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__(
self.error_counter: int = 0
self.error_threshold: int = 0
self.ssl_options: dict = {}
self.proxy: dict = {}
self.lock = Lock()
self.ws = WebSocketApp(
url,
Expand All @@ -44,13 +45,14 @@ def __init__(
on_close=self._on_close,
)

def connect(self, ssl_options: dict=None, proxy: dict=None):
def connect(self, ssl_options: dict = None, proxy: dict = None):
self.ssl_options = ssl_options
self.proxy = proxy
self.ws.run_forever(
sslopt=ssl_options,
http_proxy_host=None if proxy is None else proxy.get('host'),
http_proxy_port=None if proxy is None else proxy.get('port'),
proxy_type=None if proxy is None else proxy.get('type')
http_proxy_host=None if proxy is None else proxy.get("host"),
http_proxy_port=None if proxy is None else proxy.get("port"),
proxy_type=None if proxy is None else proxy.get("type"),
)

def close(self):
Expand All @@ -64,7 +66,7 @@ def check_reconnect(self):
self.connected = False
if self.reconnect:
time.sleep(1)
self.connect(self.ssl_options)
self.connect(self.ssl_options, self.proxy)

def publish(self, message: str):
if self.connected:
Expand Down

0 comments on commit 88d4367

Please sign in to comment.