mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-09 15:58:48 +00:00
Ensure thread-safe NostrClient state reads
This commit is contained in:
@@ -554,8 +554,9 @@ class NostrClient:
|
|||||||
)
|
)
|
||||||
if hasattr(created_at, "secs"):
|
if hasattr(created_at, "secs"):
|
||||||
created_at = created_at.secs
|
created_at = created_at.secs
|
||||||
if self.current_manifest is not None:
|
manifest_event = None
|
||||||
with self._state_lock:
|
with self._state_lock:
|
||||||
|
if self.current_manifest is not None:
|
||||||
self.current_manifest.delta_since = int(created_at)
|
self.current_manifest.delta_since = int(created_at)
|
||||||
manifest_json = json.dumps(
|
manifest_json = json.dumps(
|
||||||
{
|
{
|
||||||
@@ -573,9 +574,9 @@ class NostrClient:
|
|||||||
.build(self.keys.public_key())
|
.build(self.keys.public_key())
|
||||||
.sign_with_keys(self.keys)
|
.sign_with_keys(self.keys)
|
||||||
)
|
)
|
||||||
await self.client.send_event(manifest_event)
|
|
||||||
with self._state_lock:
|
|
||||||
self._delta_events.append(delta_id)
|
self._delta_events.append(delta_id)
|
||||||
|
if manifest_event is not None:
|
||||||
|
await self.client.send_event(manifest_event)
|
||||||
return delta_id
|
return delta_id
|
||||||
|
|
||||||
async def fetch_deltas_since(self, version: int) -> list[bytes]:
|
async def fetch_deltas_since(self, version: int) -> list[bytes]:
|
||||||
@@ -597,8 +598,9 @@ class NostrClient:
|
|||||||
for ev in events:
|
for ev in events:
|
||||||
deltas.append(base64.b64decode(ev.content().encode("utf-8")))
|
deltas.append(base64.b64decode(ev.content().encode("utf-8")))
|
||||||
|
|
||||||
if self.current_manifest is not None:
|
manifest = self.get_current_manifest()
|
||||||
snap_size = sum(c.size for c in self.current_manifest.chunks)
|
if manifest is not None:
|
||||||
|
snap_size = sum(c.size for c in manifest.chunks)
|
||||||
if (
|
if (
|
||||||
len(deltas) >= self.delta_threshold
|
len(deltas) >= self.delta_threshold
|
||||||
or sum(len(d) for d in deltas) > snap_size
|
or sum(len(d) for d in deltas) > snap_size
|
||||||
|
Reference in New Issue
Block a user