fix: do not double re-connect

This commit is contained in:
Vlad Stan 2023-06-21 17:12:26 +03:00
parent 322679e7c5
commit d08e91b2c7

View file

@ -22,6 +22,8 @@ class RelayManager:
def add_relay(
self, url: str, read: bool = True, write: bool = True, subscriptions={}
):
if url in self.relays:
return
policy = RelayPolicy(read, write)
relay = Relay(url, policy, self.message_pool, subscriptions.copy())
self.relays[url] = relay
@ -42,17 +44,19 @@ class RelayManager:
def open_connections(self, ssl_options: dict = None, proxy: dict = None):
for relay in self.relays.values():
if relay.url not in self.threads:
self.threads[relay.url] = threading.Thread(
target=relay.connect,
args=(ssl_options, proxy),
name=f"{relay.url}-thread",
daemon=True,
)
self.threads[relay.url].start()
if relay.url not in self.queue_threads:
self.queue_threads[relay.url] = threading.Thread(
target=relay.queue_worker,
args=(lambda: relay.shutdown,),
name=f"{relay.url}-queue",
daemon=True,
)