chore: code clean-up

This commit is contained in:
Vlad Stan 2023-06-22 13:19:22 +03:00
parent 414ae16cb0
commit 4238be498f
5 changed files with 2 additions and 15 deletions

View file

@ -47,7 +47,6 @@ class Relay:
self.queue = Queue() self.queue = Queue()
def connect(self, ssl_options: dict = None, proxy: dict = None): def connect(self, ssl_options: dict = None, proxy: dict = None):
print("### relay.connect", self.url)
self.ws = WebSocketApp( self.ws = WebSocketApp(
self.url, self.url,
on_open=self._on_open, on_open=self._on_open,
@ -84,7 +83,6 @@ class Relay:
@property @property
def ping(self): def ping(self):
print("### ping: ", self.url)
ping_ms = int((self.ws.last_pong_tm - self.ws.last_ping_tm) * 1000) ping_ms = int((self.ws.last_pong_tm - self.ws.last_ping_tm) * 1000)
return ping_ms if self.connected and ping_ms > 0 else 0 return ping_ms if self.connected and ping_ms > 0 else 0
@ -98,21 +96,17 @@ class Relay:
self.publish(json_str) self.publish(json_str)
def queue_worker(self): def queue_worker(self):
print("#### IN !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", self.url)
while True: while True:
if self.connected: if self.connected:
try: try:
message = self.queue.get(timeout=1) message = self.queue.get(timeout=1)
print("#### queue_worker", message)
self.num_sent_events += 1 self.num_sent_events += 1
self.ws.send(message) self.ws.send(message)
except Exception as e: except Exception as e:
if self.shutdown: if self.shutdown:
print("#### !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! e [", e, self.url, self.shutdown," ]###")
break break
else: else:
time.sleep(0.1) time.sleep(0.1)
print("#### OUT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", self.url)
def add_subscription(self, id, filters: Filters): def add_subscription(self, id, filters: Filters):
with self.lock: with self.lock:

View file

@ -2,7 +2,6 @@
import ssl import ssl
import threading import threading
from .event import Event
from .filter import Filters from .filter import Filters
from .message_pool import MessagePool from .message_pool import MessagePool
from .relay import Relay, RelayPolicy from .relay import Relay, RelayPolicy

View file

@ -81,12 +81,10 @@ class NostrRouter:
async def _handle_received_subscription_eosenotices(self, s): async def _handle_received_subscription_eosenotices(self, s):
my_event = received_subscription_eosenotices[s]
s_original = self.original_subscription_ids[s] s_original = self.original_subscription_ids[s]
event_to_forward = ["EOSE", s_original] event_to_forward = ["EOSE", s_original]
del received_subscription_eosenotices[s] del received_subscription_eosenotices[s]
# send data back to client
# print("Sending EOSE", event_to_forward)
await self.websocket.send_text(json.dumps(event_to_forward)) await self.websocket.send_text(json.dumps(event_to_forward))
async def _handle_received_subscription_events(self, s): async def _handle_received_subscription_events(self, s):
@ -114,7 +112,7 @@ class NostrRouter:
my_event = received_subscription_notices.pop(0) my_event = received_subscription_notices.pop(0)
event_to_forward = ["NOTICE", my_event.content] event_to_forward = ["NOTICE", my_event.content]
# note: we don't send it to the user because we don't know who should receive it # note: we don't send it to the user because we don't know who should receive it
logger.debug("Nostrclient: Received notice", event_to_forward[1]) logger.debug("Nostrclient: Received notice: ", event_to_forward[1])

View file

@ -4,10 +4,7 @@ import ssl
import threading import threading
from .crud import get_relays from .crud import get_relays
from .nostr.event import Event
from .nostr.key import PublicKey
from .nostr.message_pool import EndOfStoredEventsMessage, EventMessage, NoticeMessage from .nostr.message_pool import EndOfStoredEventsMessage, EventMessage, NoticeMessage
from .nostr.relay_manager import RelayManager
from .services import ( from .services import (
nostr, nostr,
received_subscription_eosenotices, received_subscription_eosenotices,

View file

@ -1,5 +1,4 @@
import asyncio import asyncio
import json
from http import HTTPStatus from http import HTTPStatus
from typing import List, Optional from typing import List, Optional