chore: code clean-up
This commit is contained in:
parent
414ae16cb0
commit
4238be498f
5 changed files with 2 additions and 15 deletions
|
|
@ -47,7 +47,6 @@ class Relay:
|
|||
self.queue = Queue()
|
||||
|
||||
def connect(self, ssl_options: dict = None, proxy: dict = None):
|
||||
print("### relay.connect", self.url)
|
||||
self.ws = WebSocketApp(
|
||||
self.url,
|
||||
on_open=self._on_open,
|
||||
|
|
@ -84,7 +83,6 @@ class Relay:
|
|||
|
||||
@property
|
||||
def ping(self):
|
||||
print("### ping: ", self.url)
|
||||
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
|
||||
|
||||
|
|
@ -98,21 +96,17 @@ class Relay:
|
|||
self.publish(json_str)
|
||||
|
||||
def queue_worker(self):
|
||||
print("#### IN !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", self.url)
|
||||
while True:
|
||||
if self.connected:
|
||||
try:
|
||||
message = self.queue.get(timeout=1)
|
||||
print("#### queue_worker", message)
|
||||
self.num_sent_events += 1
|
||||
self.ws.send(message)
|
||||
except Exception as e:
|
||||
if self.shutdown:
|
||||
print("#### !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! e [", e, self.url, self.shutdown," ]###")
|
||||
break
|
||||
else:
|
||||
time.sleep(0.1)
|
||||
print("#### OUT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", self.url)
|
||||
|
||||
def add_subscription(self, id, filters: Filters):
|
||||
with self.lock:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
import ssl
|
||||
import threading
|
||||
|
||||
from .event import Event
|
||||
from .filter import Filters
|
||||
from .message_pool import MessagePool
|
||||
from .relay import Relay, RelayPolicy
|
||||
|
|
|
|||
|
|
@ -81,12 +81,10 @@ class NostrRouter:
|
|||
|
||||
|
||||
async def _handle_received_subscription_eosenotices(self, s):
|
||||
my_event = received_subscription_eosenotices[s]
|
||||
s_original = self.original_subscription_ids[s]
|
||||
event_to_forward = ["EOSE", s_original]
|
||||
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))
|
||||
|
||||
async def _handle_received_subscription_events(self, s):
|
||||
|
|
@ -114,7 +112,7 @@ class NostrRouter:
|
|||
my_event = received_subscription_notices.pop(0)
|
||||
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
|
||||
logger.debug("Nostrclient: Received notice", event_to_forward[1])
|
||||
logger.debug("Nostrclient: Received notice: ", event_to_forward[1])
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
3
tasks.py
3
tasks.py
|
|
@ -4,10 +4,7 @@ import ssl
|
|||
import threading
|
||||
|
||||
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.relay_manager import RelayManager
|
||||
from .services import (
|
||||
nostr,
|
||||
received_subscription_eosenotices,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import asyncio
|
||||
import json
|
||||
from http import HTTPStatus
|
||||
from typing import List, Optional
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue