offline-protocol-sdk 0.28.0__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. offline_protocol_sdk/__init__.py +22 -0
  2. offline_protocol_sdk/_callback_reentrancy.py +64 -0
  3. offline_protocol_sdk/address_declaration.py +207 -0
  4. offline_protocol_sdk/ble_manager.py +595 -0
  5. offline_protocol_sdk/ble_peripheral.py +673 -0
  6. offline_protocol_sdk/dnssd_bridge.py +614 -0
  7. offline_protocol_sdk/gateway_attach_policy.py +437 -0
  8. offline_protocol_sdk/gateway_manager.py +1217 -0
  9. offline_protocol_sdk/gateway_verdict_tracker.py +97 -0
  10. offline_protocol_sdk/internet_manager.py +1444 -0
  11. offline_protocol_sdk/legacy_store_adoption.py +184 -0
  12. offline_protocol_sdk/local_api/__init__.py +34 -0
  13. offline_protocol_sdk/local_api/authz.py +180 -0
  14. offline_protocol_sdk/local_api/cli.py +171 -0
  15. offline_protocol_sdk/local_api/codec.py +210 -0
  16. offline_protocol_sdk/local_api/dispatch.py +537 -0
  17. offline_protocol_sdk/local_api/mux.py +239 -0
  18. offline_protocol_sdk/local_api/server.py +546 -0
  19. offline_protocol_sdk/local_api/session.py +86 -0
  20. offline_protocol_sdk/local_api/table.py +849 -0
  21. offline_protocol_sdk/offline_protocol.py +13508 -0
  22. offline_protocol_sdk/peer_stream_manager.py +1303 -0
  23. offline_protocol_sdk/presence_watch_policy.py +102 -0
  24. offline_protocol_sdk/protocol_manager.py +1108 -0
  25. offline_protocol_sdk/relay_answer_prefixes.py +61 -0
  26. offline_protocol_sdk/secure_storage.py +551 -0
  27. offline_protocol_sdk/services.py +195 -0
  28. offline_protocol_sdk/state_storage.py +452 -0
  29. offline_protocol_sdk/storage_namespace.py +33 -0
  30. offline_protocol_sdk/transport_manager.py +138 -0
  31. offline_protocol_sdk/uniffi.dll +0 -0
  32. offline_protocol_sdk-0.28.0.dist-info/METADATA +519 -0
  33. offline_protocol_sdk-0.28.0.dist-info/RECORD +40 -0
  34. offline_protocol_sdk-0.28.0.dist-info/WHEEL +5 -0
  35. offline_protocol_sdk-0.28.0.dist-info/entry_points.txt +2 -0
  36. offline_protocol_sdk-0.28.0.dist-info/licenses/EXPORT.md +68 -0
  37. offline_protocol_sdk-0.28.0.dist-info/licenses/LICENSE +661 -0
  38. offline_protocol_sdk-0.28.0.dist-info/licenses/LICENSE-COMMERCIAL.md +89 -0
  39. offline_protocol_sdk-0.28.0.dist-info/licenses/THIRD-PARTY-NOTICES.md +6645 -0
  40. offline_protocol_sdk-0.28.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,102 @@
1
+ """Decides which peers to query for gateway presence (``CheckPresence``)
2
+ each tick.
3
+
4
+ A port of ``PresenceWatchPolicy.swift`` and ``PresenceWatchPolicy.kt``.
5
+
6
+ Watch sources: recipients the gateway reported unreachable
7
+ (``DeliveryError``) plus the core watchlist (peers with undelivered or
8
+ session-unproven MLS welcomes) merged at tick time. A peer leaves the set on
9
+ an online presence answer, on inbound traffic from the peer, or after the
10
+ idle TTL.
11
+
12
+ Queries rotate round-robin so a large watch set is fully covered across
13
+ ticks while staying far under a gateway's per-connection rate budget.
14
+
15
+ The three defaults are hand-mirrored in Swift and Kotlin (C5, the eighth
16
+ set); ``test_presence_watch_policy.py`` pins them as literals and the Rust
17
+ guard ``presence_watch_defaults_match_across_both_bridges`` reads this file
18
+ beside the other two. A tick interval that drifted apart would give the
19
+ platforms different presence latency, which reads in the field as a device
20
+ problem rather than as a constant.
21
+ """
22
+
23
+ from __future__ import annotations
24
+
25
+ import threading
26
+
27
+ #: Milliseconds a watched peer stays in the set without a reason to.
28
+ DEFAULT_IDLE_TTL_MS = 10 * 60_000
29
+ #: Peers asked about per tick.
30
+ DEFAULT_MAX_QUERIES_PER_TICK = 10
31
+ #: Seconds between ticks.
32
+ DEFAULT_TICK_INTERVAL = 20.0
33
+
34
+
35
+ class PresenceWatchPolicy:
36
+ def __init__(
37
+ self,
38
+ idle_ttl_ms: int = DEFAULT_IDLE_TTL_MS,
39
+ max_queries_per_tick: int = DEFAULT_MAX_QUERIES_PER_TICK,
40
+ ) -> None:
41
+ self._idle_ttl_ms = idle_ttl_ms
42
+ self._max_queries_per_tick = max_queries_per_tick
43
+ self._last_relevant_at_ms: dict[str, int] = {}
44
+ self._rotation: list[str] = []
45
+ self._lock = threading.Lock()
46
+
47
+ def watch(self, peer_id: str, now_ms: int) -> None:
48
+ """Adds a peer to the watch set (or refreshes its idle clock)."""
49
+ if not peer_id:
50
+ return
51
+ with self._lock:
52
+ self._watch_locked(peer_id, now_ms)
53
+
54
+ def unwatch(self, peer_id: str) -> None:
55
+ """Removes a peer (an online answer or inbound traffic proved
56
+ reachability)."""
57
+ with self._lock:
58
+ self._unwatch_locked(peer_id)
59
+
60
+ def watched_peers(self) -> set[str]:
61
+ with self._lock:
62
+ return set(self._last_relevant_at_ms)
63
+
64
+ def peers_to_query(self, core_watchlist: list[str], now_ms: int) -> list[str]:
65
+ """Merges the core watchlist (authoritatively still-pending peers
66
+ refresh their idle clock), evicts idle entries, and returns up to
67
+ ``max_queries_per_tick`` peers to query this tick, round-robin."""
68
+ with self._lock:
69
+ for peer in core_watchlist:
70
+ if peer:
71
+ self._watch_locked(peer, now_ms)
72
+ expired = [
73
+ peer
74
+ for peer, last in self._last_relevant_at_ms.items()
75
+ if now_ms - last > self._idle_ttl_ms
76
+ ]
77
+ for peer in expired:
78
+ self._unwatch_locked(peer)
79
+
80
+ if not self._rotation:
81
+ return []
82
+ count = min(self._max_queries_per_tick, len(self._rotation))
83
+ result: list[str] = []
84
+ for _ in range(count):
85
+ peer = self._rotation.pop(0)
86
+ self._rotation.append(peer)
87
+ result.append(peer)
88
+ return result
89
+
90
+ def clear(self) -> None:
91
+ with self._lock:
92
+ self._last_relevant_at_ms.clear()
93
+ self._rotation.clear()
94
+
95
+ def _watch_locked(self, peer_id: str, now_ms: int) -> None:
96
+ if peer_id not in self._last_relevant_at_ms:
97
+ self._rotation.append(peer_id)
98
+ self._last_relevant_at_ms[peer_id] = now_ms
99
+
100
+ def _unwatch_locked(self, peer_id: str) -> None:
101
+ if self._last_relevant_at_ms.pop(peer_id, None) is not None:
102
+ self._rotation = [p for p in self._rotation if p != peer_id]