mirror of
https://github.com/aljazceru/python-nostr.git
synced 2025-12-19 07:14:23 +01:00
udpate client
This commit is contained in:
@@ -8,18 +8,18 @@ from .message_type import ClientMessageType
|
||||
from .relay import Relay, RelayPolicy
|
||||
|
||||
|
||||
|
||||
class RelayException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class RelayManager:
|
||||
def __init__(self) -> None:
|
||||
self.relays: dict[str, Relay] = {}
|
||||
self.message_pool = MessagePool()
|
||||
|
||||
def add_relay(self, url: str, read: bool=True, write: bool=True, subscriptions={}):
|
||||
def add_relay(
|
||||
self, url: str, read: bool = True, write: bool = True, subscriptions={}
|
||||
):
|
||||
policy = RelayPolicy(read, write)
|
||||
relay = Relay(url, policy, self.message_pool, subscriptions)
|
||||
self.relays[url] = relay
|
||||
@@ -35,12 +35,12 @@ class RelayManager:
|
||||
for relay in self.relays.values():
|
||||
relay.close_subscription(id)
|
||||
|
||||
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():
|
||||
threading.Thread(
|
||||
target=relay.connect,
|
||||
args=(ssl_options, proxy),
|
||||
name=f"{relay.url}-thread"
|
||||
name=f"{relay.url}-thread",
|
||||
).start()
|
||||
|
||||
def close_connections(self):
|
||||
@@ -53,11 +53,12 @@ class RelayManager:
|
||||
relay.publish(message)
|
||||
|
||||
def publish_event(self, event: Event):
|
||||
""" Verifies that the Event is publishable before submitting it to relays """
|
||||
"""Verifies that the Event is publishable before submitting it to relays"""
|
||||
if event.signature is None:
|
||||
raise RelayException(f"Could not publish {event.id}: must be signed")
|
||||
|
||||
if not event.verify():
|
||||
raise RelayException(f"Could not publish {event.id}: failed to verify signature {event.signature}")
|
||||
|
||||
raise RelayException(
|
||||
f"Could not publish {event.id}: failed to verify signature {event.signature}"
|
||||
)
|
||||
self.publish_message(event.to_message())
|
||||
|
||||
Reference in New Issue
Block a user