mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-06-11 11:56:18 +00:00
G3: N11 — document transport connect() return contract
The three transports had inconsistent connect() return contracts: TCP returned an asyncio.Future (fixed by F01), serial returned self.port (always truthy), BLE returned self.address or None. ConnectionManager's success check `if result is not None:` was tautological for TCP and serial. With F01 fixed, the check is now meaningful for all three. Add a comprehensive docstring to ConnectionProtocol documenting the contract: return truthy on success (included in CONNECTED event payload), return None for soft failure (retry), or raise for hard failure (also retry, logged). Also import Awaitable for the F02 reconnect_callback type hint that follows. Refs: Forensics report finding N11
This commit is contained in:
@@ -4,14 +4,23 @@ Connection manager that orchestrates reconnection logic for any connection type.
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
from typing import Optional, Any, Callable, Protocol
|
from typing import Optional, Any, Awaitable, Callable, Protocol
|
||||||
from .events import Event, EventType
|
from .events import Event, EventType
|
||||||
|
|
||||||
logger = logging.getLogger("meshcore")
|
logger = logging.getLogger("meshcore")
|
||||||
|
|
||||||
|
|
||||||
class ConnectionProtocol(Protocol):
|
class ConnectionProtocol(Protocol):
|
||||||
"""Protocol defining the interface that connection classes must implement."""
|
"""Protocol defining the interface that connection classes must implement.
|
||||||
|
|
||||||
|
Return contract for connect():
|
||||||
|
- On success: return a truthy value (typically an address string)
|
||||||
|
that identifies the connection. This value is included in the
|
||||||
|
CONNECTED event payload as ``connection_info``.
|
||||||
|
- On failure: return ``None`` (soft failure — triggers a retry in
|
||||||
|
``_attempt_reconnect``) **or** raise an exception (hard failure —
|
||||||
|
also triggers a retry, logged as an error).
|
||||||
|
"""
|
||||||
|
|
||||||
async def connect(self) -> Optional[Any]:
|
async def connect(self) -> Optional[Any]:
|
||||||
"""Connect and return connection info, or None if failed."""
|
"""Connect and return connection info, or None if failed."""
|
||||||
|
|||||||
Reference in New Issue
Block a user