Compare commits

..

1 Commits

Author SHA1 Message Date
Alexander Whitestone
571475a749 fix: closes #716
Some checks failed
CI / test (pull_request) Failing after 9s
CI / validate (pull_request) Failing after 18s
Review Approval Gate / verify-review (pull_request) Failing after 3s
2026-04-12 12:44:37 -04:00
2 changed files with 13 additions and 15 deletions

View File

@@ -66,12 +66,7 @@ class NostrIdentity:
if privkey_hex:
self.privkey = int(privkey_hex, 16)
else:
# Rejection sampling: avoid modulo bias from % N
while True:
candidate = int.from_bytes(os.urandom(32), 'big')
if 0 < candidate < N:
self.privkey = candidate
break
self.privkey = int.from_bytes(os.urandom(32), 'big') % N
self.pubkey = get_pubkey(self.privkey)
def sign_event(self, event):

View File

@@ -50,21 +50,24 @@ async def broadcast_handler(websocket: websockets.WebSocketServerProtocol):
# Broadcast to all OTHER clients
if not clients:
continue
disconnected = set()
# Track (client, task) pairs so failed clients are identified directly
send_jobs = []
# Create broadcast tasks, tracking which client each task targets
task_client_pairs = []
for client in clients:
if client != websocket and client.open:
send_jobs.append((client, asyncio.create_task(client.send(message))))
task = asyncio.create_task(client.send(message))
task_client_pairs.append((task, client))
if send_jobs:
results = await asyncio.gather(*[job[1] for job in send_jobs], return_exceptions=True)
for (target_client, _), result in zip(send_jobs, results):
if task_client_pairs:
tasks = [pair[0] for pair in task_client_pairs]
results = await asyncio.gather(*tasks, return_exceptions=True)
for i, result in enumerate(results):
if isinstance(result, Exception):
logger.error(f"Failed to send to a client {target_client.remote_address}: {result}")
target_client = task_client_pairs[i][1]
logger.error(f"Failed to send to client {target_client.remote_address}: {result}")
disconnected.add(target_client)
if disconnected:
clients.difference_update(disconnected)