fix: do not double re-connect
This commit is contained in:
parent
322679e7c5
commit
d08e91b2c7
1 changed files with 18 additions and 14 deletions
|
|
@ -22,6 +22,8 @@ class RelayManager:
|
||||||
def add_relay(
|
def add_relay(
|
||||||
self, url: str, read: bool = True, write: bool = True, subscriptions={}
|
self, url: str, read: bool = True, write: bool = True, subscriptions={}
|
||||||
):
|
):
|
||||||
|
if url in self.relays:
|
||||||
|
return
|
||||||
policy = RelayPolicy(read, write)
|
policy = RelayPolicy(read, write)
|
||||||
relay = Relay(url, policy, self.message_pool, subscriptions.copy())
|
relay = Relay(url, policy, self.message_pool, subscriptions.copy())
|
||||||
self.relays[url] = relay
|
self.relays[url] = relay
|
||||||
|
|
@ -42,17 +44,19 @@ class RelayManager:
|
||||||
|
|
||||||
def open_connections(self, ssl_options: dict = None, proxy: dict = None):
|
def open_connections(self, ssl_options: dict = None, proxy: dict = None):
|
||||||
for relay in self.relays.values():
|
for relay in self.relays.values():
|
||||||
|
if relay.url not in self.threads:
|
||||||
self.threads[relay.url] = threading.Thread(
|
self.threads[relay.url] = threading.Thread(
|
||||||
target=relay.connect,
|
target=relay.connect,
|
||||||
args=(ssl_options, proxy),
|
args=(ssl_options, proxy),
|
||||||
name=f"{relay.url}-thread",
|
name=f"{relay.url}-thread",
|
||||||
daemon=True,
|
daemon=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.threads[relay.url].start()
|
self.threads[relay.url].start()
|
||||||
|
|
||||||
|
if relay.url not in self.queue_threads:
|
||||||
self.queue_threads[relay.url] = threading.Thread(
|
self.queue_threads[relay.url] = threading.Thread(
|
||||||
target=relay.queue_worker,
|
target=relay.queue_worker,
|
||||||
args=(lambda: relay.shutdown,),
|
|
||||||
name=f"{relay.url}-queue",
|
name=f"{relay.url}-queue",
|
||||||
daemon=True,
|
daemon=True,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue