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,97 @@
1
+ """Frames submitted to a gateway and not yet answered.
2
+
3
+ A port of ``GatewayVerdictTracker.swift`` and ``GatewayVerdictTracker.kt``.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import threading
9
+
10
+
11
+ class GatewayVerdictTracker:
12
+ """Tracks submitted frames until the gateway's verdict settles them.
13
+
14
+ The gateway answers every ``SendMessage`` with exactly one
15
+ ``MessageSent`` or ``DeliveryError``, correlated by ``message_id``. This
16
+ holds the ids between the two, so the manager can bound how many are
17
+ outstanding, notice the ones a gateway never answered, and settle every
18
+ one of them when a connection dies.
19
+
20
+ Three rules it exists to enforce, each of which was a real defect on
21
+ some implementation of this contract before it was written down:
22
+
23
+ 1. **An id already in flight is not sent again.** The core re-queues an
24
+ unconfirmed frame under the same id after its own acknowledgement
25
+ timeout, and a verdict can honestly take longer than that on a slow
26
+ backbone. Sending it twice forwards the frame twice and, when the
27
+ second copy times out, fails an id the gateway already confirmed.
28
+ 2. **Every id is settled exactly once.** :meth:`settle` returns whether
29
+ this call was the one that removed it, so a duplicate verdict cannot
30
+ report a second outcome for a frame the core has already moved on
31
+ from.
32
+ 3. **Nothing is left waiting on a dead connection.** :meth:`drain_all`
33
+ hands back every outstanding id so the manager can fail them; a frame
34
+ nobody answers for costs the core its full 120-second expiry.
35
+
36
+ Thread-safe: the manager confines its own calls to the event loop, but
37
+ the core's wake callback arrives on a Rust thread and the mobile
38
+ trackers are shared between queues, so the lock is kept for parity.
39
+ """
40
+
41
+ def __init__(self) -> None:
42
+ self._lock = threading.Lock()
43
+ self._in_flight: dict[str, float] = {}
44
+
45
+ @property
46
+ def count(self) -> int:
47
+ """Frames outstanding right now."""
48
+ with self._lock:
49
+ return len(self._in_flight)
50
+
51
+ def begin(self, message_id: str, now: float) -> bool:
52
+ """Records ``message_id`` as submitted at ``now`` (seconds).
53
+
54
+ Returns ``False`` when it was already in flight, in which case the
55
+ caller must **not** send it again. Popping it from the core's outbox
56
+ was enough: the attempt already outstanding is what settles that
57
+ id, and the core's pending entry is refreshed by the pop.
58
+ """
59
+ with self._lock:
60
+ if message_id in self._in_flight:
61
+ return False
62
+ self._in_flight[message_id] = now
63
+ return True
64
+
65
+ def settle(self, message_id: str) -> bool:
66
+ """Settles ``message_id``. Returns ``False`` if it was not
67
+ outstanding, which is how a duplicate or unsolicited verdict is
68
+ ignored."""
69
+ with self._lock:
70
+ return self._in_flight.pop(message_id, None) is not None
71
+
72
+ def expired(self, now: float, timeout: float) -> list[str]:
73
+ """Removes and returns every id submitted more than ``timeout``
74
+ seconds ago.
75
+
76
+ A gateway that answers nothing is a contract violation, but it is
77
+ also indistinguishable from one whose socket is wedged, and the core
78
+ cannot retry a frame nobody has failed. Removing them here is what
79
+ turns silence back into a retry.
80
+ """
81
+ with self._lock:
82
+ stale = [
83
+ message_id
84
+ for message_id, began in self._in_flight.items()
85
+ if now - began > timeout
86
+ ]
87
+ for message_id in stale:
88
+ del self._in_flight[message_id]
89
+ return stale
90
+
91
+ def drain_all(self) -> list[str]:
92
+ """Removes and returns everything outstanding, for a connection
93
+ that is going away."""
94
+ with self._lock:
95
+ ids = list(self._in_flight)
96
+ self._in_flight.clear()
97
+ return ids