hostel-protocol-python 0.4.1__tar.gz → 0.4.2__tar.gz
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.
- {hostel_protocol_python-0.4.1 → hostel_protocol_python-0.4.2}/PKG-INFO +1 -1
- {hostel_protocol_python-0.4.1 → hostel_protocol_python-0.4.2}/pyproject.toml +1 -1
- {hostel_protocol_python-0.4.1 → hostel_protocol_python-0.4.2}/src/hostel/transport/__init__.py +2 -1
- {hostel_protocol_python-0.4.1 → hostel_protocol_python-0.4.2}/src/hostel/transport/transport.py +8 -0
- {hostel_protocol_python-0.4.1 → hostel_protocol_python-0.4.2}/src/hostel/transport/zeromq.py +17 -2
- {hostel_protocol_python-0.4.1 → hostel_protocol_python-0.4.2}/.github/workflows/ci.yml +0 -0
- {hostel_protocol_python-0.4.1 → hostel_protocol_python-0.4.2}/.github/workflows/publish.yml +0 -0
- {hostel_protocol_python-0.4.1 → hostel_protocol_python-0.4.2}/.gitignore +0 -0
- {hostel_protocol_python-0.4.1 → hostel_protocol_python-0.4.2}/Makefile +0 -0
- {hostel_protocol_python-0.4.1 → hostel_protocol_python-0.4.2}/src/hostel/client/__init__.py +0 -0
- {hostel_protocol_python-0.4.1 → hostel_protocol_python-0.4.2}/src/hostel/client/client.py +0 -0
- {hostel_protocol_python-0.4.1 → hostel_protocol_python-0.4.2}/src/hostel/protocol/__init__.py +0 -0
- {hostel_protocol_python-0.4.1 → hostel_protocol_python-0.4.2}/src/hostel/protocol/converter.py +0 -0
- {hostel_protocol_python-0.4.1 → hostel_protocol_python-0.4.2}/src/hostel/protocol/models.py +0 -0
- {hostel_protocol_python-0.4.1 → hostel_protocol_python-0.4.2}/src/hostel/py.typed +0 -0
- {hostel_protocol_python-0.4.1 → hostel_protocol_python-0.4.2}/tests/__init__.py +0 -0
- {hostel_protocol_python-0.4.1 → hostel_protocol_python-0.4.2}/tests/test_client.py +0 -0
- {hostel_protocol_python-0.4.1 → hostel_protocol_python-0.4.2}/tests/test_converter.py +0 -0
- {hostel_protocol_python-0.4.1 → hostel_protocol_python-0.4.2}/tests/test_models.py +0 -0
- {hostel_protocol_python-0.4.1 → hostel_protocol_python-0.4.2}/tests/test_transport.py +0 -0
{hostel_protocol_python-0.4.1 → hostel_protocol_python-0.4.2}/src/hostel/transport/__init__.py
RENAMED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"""hostel.transport — Transport abstractions and implementations."""
|
|
2
2
|
|
|
3
|
-
from hostel.transport.transport import ClientId, ServerTransport, Transport
|
|
3
|
+
from hostel.transport.transport import ClientDisconnectedError, ClientId, ServerTransport, Transport
|
|
4
4
|
|
|
5
5
|
__all__ = [
|
|
6
|
+
"ClientDisconnectedError",
|
|
6
7
|
"ClientId",
|
|
7
8
|
"Transport",
|
|
8
9
|
"ServerTransport",
|
{hostel_protocol_python-0.4.1 → hostel_protocol_python-0.4.2}/src/hostel/transport/transport.py
RENAMED
|
@@ -7,6 +7,14 @@ from hostel.protocol.models import HostelMessage
|
|
|
7
7
|
ClientId = bytes
|
|
8
8
|
|
|
9
9
|
|
|
10
|
+
class ClientDisconnectedError(Exception):
|
|
11
|
+
"""Raised when a send targets a peer that is no longer connected."""
|
|
12
|
+
|
|
13
|
+
def __init__(self, client_id: ClientId) -> None:
|
|
14
|
+
self.client_id = client_id
|
|
15
|
+
super().__init__(f"Client {client_id!r} is not connected")
|
|
16
|
+
|
|
17
|
+
|
|
10
18
|
class Transport(ABC):
|
|
11
19
|
|
|
12
20
|
@abstractmethod
|
{hostel_protocol_python-0.4.1 → hostel_protocol_python-0.4.2}/src/hostel/transport/zeromq.py
RENAMED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""ZeroMQ transport implementations for Hostel."""
|
|
2
2
|
|
|
3
|
+
import asyncio
|
|
3
4
|
import logging
|
|
4
5
|
import uuid
|
|
5
6
|
|
|
@@ -9,7 +10,7 @@ from hostel.protocol.v1 import message_pb2
|
|
|
9
10
|
|
|
10
11
|
from hostel.protocol.converter import proto_to_pydantic, pydantic_to_proto
|
|
11
12
|
from hostel.protocol.models import HostelMessage
|
|
12
|
-
from hostel.transport.transport import ClientId, ServerTransport, Transport
|
|
13
|
+
from hostel.transport.transport import ClientDisconnectedError, ClientId, ServerTransport, Transport
|
|
13
14
|
|
|
14
15
|
logger = logging.getLogger(__name__)
|
|
15
16
|
|
|
@@ -76,9 +77,11 @@ class ZmqRouterTransport(ServerTransport):
|
|
|
76
77
|
endpoint: str,
|
|
77
78
|
*,
|
|
78
79
|
linger_ms: int = 0,
|
|
80
|
+
send_timeout: float = 5.0,
|
|
79
81
|
):
|
|
80
82
|
self.endpoint = endpoint
|
|
81
83
|
self.linger_ms = linger_ms
|
|
84
|
+
self.send_timeout = send_timeout
|
|
82
85
|
|
|
83
86
|
self._ctx: zmq.asyncio.Context | None = None
|
|
84
87
|
self._socket: zmq.asyncio.Socket | None = None
|
|
@@ -90,6 +93,7 @@ class ZmqRouterTransport(ServerTransport):
|
|
|
90
93
|
self._ctx = zmq.asyncio.Context.instance()
|
|
91
94
|
self._socket = self._ctx.socket(zmq.ROUTER)
|
|
92
95
|
self._socket.setsockopt(zmq.LINGER, self.linger_ms)
|
|
96
|
+
self._socket.setsockopt(zmq.ROUTER_MANDATORY, 1)
|
|
93
97
|
self._socket.bind(self.endpoint)
|
|
94
98
|
|
|
95
99
|
async def receive(self) -> tuple[ClientId, HostelMessage]:
|
|
@@ -111,7 +115,18 @@ class ZmqRouterTransport(ServerTransport):
|
|
|
111
115
|
|
|
112
116
|
proto = pydantic_to_proto(message)
|
|
113
117
|
raw = proto.SerializeToString()
|
|
114
|
-
|
|
118
|
+
try:
|
|
119
|
+
await asyncio.wait_for(
|
|
120
|
+
self._socket.send_multipart([client_id, b"", raw]),
|
|
121
|
+
timeout=self.send_timeout,
|
|
122
|
+
)
|
|
123
|
+
except asyncio.TimeoutError:
|
|
124
|
+
logger.warning("send to client %r timed out after %ss", client_id, self.send_timeout)
|
|
125
|
+
raise
|
|
126
|
+
except zmq.ZMQError as exc:
|
|
127
|
+
if exc.errno == zmq.EHOSTUNREACH:
|
|
128
|
+
raise ClientDisconnectedError(client_id) from exc
|
|
129
|
+
raise
|
|
115
130
|
|
|
116
131
|
async def close(self) -> None:
|
|
117
132
|
if self._socket is not None:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hostel_protocol_python-0.4.1 → hostel_protocol_python-0.4.2}/src/hostel/protocol/__init__.py
RENAMED
|
File without changes
|
{hostel_protocol_python-0.4.1 → hostel_protocol_python-0.4.2}/src/hostel/protocol/converter.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|