mmrelay 1.1.4__py3-none-any.whl → 1.2.1__py3-none-any.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.
Potentially problematic release.
This version of mmrelay might be problematic. Click here for more details.
- mmrelay/__init__.py +1 -1
- mmrelay/cli.py +1205 -80
- mmrelay/cli_utils.py +696 -0
- mmrelay/config.py +578 -17
- mmrelay/constants/app.py +12 -0
- mmrelay/constants/config.py +6 -1
- mmrelay/constants/messages.py +10 -1
- mmrelay/constants/network.py +7 -0
- mmrelay/e2ee_utils.py +392 -0
- mmrelay/log_utils.py +39 -5
- mmrelay/main.py +96 -26
- mmrelay/matrix_utils.py +1059 -84
- mmrelay/meshtastic_utils.py +192 -40
- mmrelay/message_queue.py +205 -54
- mmrelay/plugin_loader.py +76 -44
- mmrelay/plugins/base_plugin.py +16 -4
- mmrelay/plugins/weather_plugin.py +108 -11
- mmrelay/tools/sample-docker-compose-prebuilt.yaml +80 -0
- mmrelay/tools/sample-docker-compose.yaml +34 -8
- mmrelay/tools/sample_config.yaml +31 -5
- {mmrelay-1.1.4.dist-info → mmrelay-1.2.1.dist-info}/METADATA +21 -50
- mmrelay-1.2.1.dist-info/RECORD +45 -0
- mmrelay/config_checker.py +0 -162
- mmrelay-1.1.4.dist-info/RECORD +0 -43
- {mmrelay-1.1.4.dist-info → mmrelay-1.2.1.dist-info}/WHEEL +0 -0
- {mmrelay-1.1.4.dist-info → mmrelay-1.2.1.dist-info}/entry_points.txt +0 -0
- {mmrelay-1.1.4.dist-info → mmrelay-1.2.1.dist-info}/licenses/LICENSE +0 -0
- {mmrelay-1.1.4.dist-info → mmrelay-1.2.1.dist-info}/top_level.txt +0 -0
mmrelay/constants/app.py
CHANGED
|
@@ -13,5 +13,17 @@ APP_AUTHOR = None # No author directory for platformdirs
|
|
|
13
13
|
APP_DISPLAY_NAME = "M<>M Relay"
|
|
14
14
|
APP_FULL_NAME = "Meshtastic Matrix Relay"
|
|
15
15
|
|
|
16
|
+
# Matrix client identification
|
|
17
|
+
MATRIX_DEVICE_NAME = "MMRelay"
|
|
18
|
+
|
|
16
19
|
# Platform-specific constants
|
|
17
20
|
WINDOWS_PLATFORM = "win32"
|
|
21
|
+
|
|
22
|
+
# Package and installation constants
|
|
23
|
+
PACKAGE_NAME_E2E = "mmrelay[e2e]"
|
|
24
|
+
PYTHON_OLM_PACKAGE = "python-olm"
|
|
25
|
+
|
|
26
|
+
# Configuration file names
|
|
27
|
+
CREDENTIALS_FILENAME = "credentials.json"
|
|
28
|
+
CONFIG_FILENAME = "config.yaml"
|
|
29
|
+
STORE_DIRNAME = "store"
|
mmrelay/constants/config.py
CHANGED
|
@@ -17,7 +17,9 @@ CONFIG_SECTION_CUSTOM_PLUGINS = "custom-plugins"
|
|
|
17
17
|
|
|
18
18
|
# Matrix configuration keys
|
|
19
19
|
CONFIG_KEY_HOMESERVER = "homeserver"
|
|
20
|
-
CONFIG_KEY_ACCESS_TOKEN =
|
|
20
|
+
CONFIG_KEY_ACCESS_TOKEN = (
|
|
21
|
+
"access_token" # nosec B105 - This is a config key name, not a hardcoded password
|
|
22
|
+
)
|
|
21
23
|
CONFIG_KEY_BOT_USER_ID = "bot_user_id"
|
|
22
24
|
CONFIG_KEY_PREFIX_ENABLED = "prefix_enabled"
|
|
23
25
|
CONFIG_KEY_PREFIX_FORMAT = "prefix_format"
|
|
@@ -71,3 +73,6 @@ DEFAULT_HEALTH_CHECK_ENABLED = True
|
|
|
71
73
|
DEFAULT_HEARTBEAT_INTERVAL = 60
|
|
72
74
|
DEFAULT_COLOR_ENABLED = True
|
|
73
75
|
DEFAULT_WIPE_ON_RESTART = False
|
|
76
|
+
|
|
77
|
+
# E2EE constants
|
|
78
|
+
E2EE_KEY_SHARING_DELAY_SECONDS = 5
|
mmrelay/constants/messages.py
CHANGED
|
@@ -14,9 +14,18 @@ LOG_SIZE_BYTES_MULTIPLIER = 1024 * 1024 # Convert MB to bytes
|
|
|
14
14
|
PORTNUM_NUMERIC_VALUE = 1 # Numeric equivalent of TEXT_MESSAGE_APP
|
|
15
15
|
DEFAULT_CHANNEL_VALUE = 0
|
|
16
16
|
|
|
17
|
+
# Message formatting constants
|
|
18
|
+
MAX_TRUNCATION_LENGTH = 20 # Maximum characters for variable truncation
|
|
19
|
+
TRUNCATION_LOG_LIMIT = 6 # Only log first N truncations to avoid spam
|
|
20
|
+
DEFAULT_MESSAGE_TRUNCATE_BYTES = 227 # Default message truncation size
|
|
21
|
+
MESHNET_NAME_ABBREVIATION_LENGTH = 4 # Characters for short meshnet names
|
|
22
|
+
SHORTNAME_FALLBACK_LENGTH = 3 # Characters for shortname fallback
|
|
23
|
+
MESSAGE_PREVIEW_LENGTH = 40 # Characters for message preview in logs
|
|
24
|
+
DISPLAY_NAME_DEFAULT_LENGTH = 5 # Default display name truncation
|
|
25
|
+
|
|
17
26
|
# Component logger names
|
|
18
27
|
COMPONENT_LOGGERS = {
|
|
19
|
-
"matrix_nio": ["nio", "nio.client", "nio.http", "nio.crypto"],
|
|
28
|
+
"matrix_nio": ["nio", "nio.client", "nio.http", "nio.crypto", "nio.responses"],
|
|
20
29
|
"bleak": ["bleak", "bleak.backends"],
|
|
21
30
|
"meshtastic": [
|
|
22
31
|
"meshtastic",
|
mmrelay/constants/network.py
CHANGED
|
@@ -25,6 +25,13 @@ DEFAULT_RETRY_ATTEMPTS = 1
|
|
|
25
25
|
INFINITE_RETRIES = 0 # 0 means infinite retries
|
|
26
26
|
MINIMUM_MESSAGE_DELAY = 2.0 # Minimum delay for message queue fallback
|
|
27
27
|
|
|
28
|
+
# Matrix client timeouts
|
|
29
|
+
MATRIX_EARLY_SYNC_TIMEOUT = 2000 # milliseconds
|
|
30
|
+
MATRIX_MAIN_SYNC_TIMEOUT = 5000 # milliseconds
|
|
31
|
+
MATRIX_ROOM_SEND_TIMEOUT = 10.0 # seconds
|
|
32
|
+
MATRIX_LOGIN_TIMEOUT = 30.0 # seconds
|
|
33
|
+
MATRIX_SYNC_OPERATION_TIMEOUT = 60.0 # seconds
|
|
34
|
+
|
|
28
35
|
# Error codes
|
|
29
36
|
ERRNO_BAD_FILE_DESCRIPTOR = 9
|
|
30
37
|
|
mmrelay/e2ee_utils.py
ADDED
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Centralized E2EE (End-to-End Encryption) utilities for consistent status detection and messaging.
|
|
3
|
+
|
|
4
|
+
This module provides a unified approach to E2EE status detection, warning messages, and room
|
|
5
|
+
formatting across all components of the meshtastic-matrix-relay application.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import os
|
|
9
|
+
import sys
|
|
10
|
+
from typing import Any, Dict, List, Literal, Optional, TypedDict
|
|
11
|
+
|
|
12
|
+
from mmrelay.cli_utils import get_command
|
|
13
|
+
from mmrelay.constants.app import (
|
|
14
|
+
CREDENTIALS_FILENAME,
|
|
15
|
+
PACKAGE_NAME_E2E,
|
|
16
|
+
PYTHON_OLM_PACKAGE,
|
|
17
|
+
WINDOWS_PLATFORM,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class E2EEStatus(TypedDict):
|
|
22
|
+
"""Type definition for E2EE status dictionary."""
|
|
23
|
+
|
|
24
|
+
enabled: bool
|
|
25
|
+
available: bool
|
|
26
|
+
configured: bool
|
|
27
|
+
platform_supported: bool
|
|
28
|
+
dependencies_installed: bool
|
|
29
|
+
credentials_available: bool
|
|
30
|
+
overall_status: Literal["ready", "disabled", "unavailable", "incomplete", "unknown"]
|
|
31
|
+
issues: List[str]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def get_e2ee_status(
|
|
35
|
+
config: Dict[str, Any], config_path: Optional[str] = None
|
|
36
|
+
) -> E2EEStatus:
|
|
37
|
+
"""
|
|
38
|
+
Return a consolidated E2EE status summary by inspecting the runtime platform, required crypto dependencies, configuration, and presence of Matrix credentials.
|
|
39
|
+
|
|
40
|
+
This inspects:
|
|
41
|
+
- platform support (disables on Windows/msys/cygwin),
|
|
42
|
+
- presence of Python olm/nio components,
|
|
43
|
+
- whether E2EE is enabled in the provided config (supports legacy `matrix.encryption.enabled`),
|
|
44
|
+
- whether Matrix credentials (credentials.json) can be found (uses config_path directory if provided, otherwise falls back to the application's base directory).
|
|
45
|
+
|
|
46
|
+
Parameters:
|
|
47
|
+
config (Dict[str, Any]): Parsed application configuration; used to read `matrix.e2ee.enabled` (and legacy `matrix.encryption.enabled`).
|
|
48
|
+
config_path (Optional[str]): Optional path to the configuration file directory to prioritize when checking for credentials.json.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
E2EEStatus: A dict with the following keys:
|
|
52
|
+
- enabled (bool): E2EE enabled in configuration.
|
|
53
|
+
- available (bool): Platform + dependencies allow E2EE.
|
|
54
|
+
- configured (bool): Authentication/credentials are present.
|
|
55
|
+
- platform_supported (bool): True unless running on Windows/msys/cygwin.
|
|
56
|
+
- dependencies_installed (bool): True if required olm/nio components are importable.
|
|
57
|
+
- credentials_available (bool): True if credentials.json is discovered.
|
|
58
|
+
- overall_status (str): One of "ready", "disabled", "unavailable", "incomplete", or "unknown".
|
|
59
|
+
- issues (List[str]): Human-readable issues found that prevent full E2EE readiness.
|
|
60
|
+
"""
|
|
61
|
+
status: E2EEStatus = {
|
|
62
|
+
"enabled": False,
|
|
63
|
+
"available": False,
|
|
64
|
+
"configured": False,
|
|
65
|
+
"platform_supported": True,
|
|
66
|
+
"dependencies_installed": False,
|
|
67
|
+
"credentials_available": False,
|
|
68
|
+
"overall_status": "unknown",
|
|
69
|
+
"issues": [],
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
# Check platform support
|
|
73
|
+
if sys.platform == WINDOWS_PLATFORM or sys.platform.startswith(("msys", "cygwin")):
|
|
74
|
+
status["platform_supported"] = False
|
|
75
|
+
status["issues"].append("E2EE is not supported on Windows")
|
|
76
|
+
|
|
77
|
+
# Check dependencies
|
|
78
|
+
try:
|
|
79
|
+
import olm # noqa: F401
|
|
80
|
+
from nio.crypto import OlmDevice # noqa: F401
|
|
81
|
+
from nio.store import SqliteStore # noqa: F401
|
|
82
|
+
|
|
83
|
+
status["dependencies_installed"] = True
|
|
84
|
+
except ImportError:
|
|
85
|
+
status["dependencies_installed"] = False
|
|
86
|
+
status["issues"].append(
|
|
87
|
+
f"E2EE dependencies not installed ({PYTHON_OLM_PACKAGE})"
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
# Check configuration
|
|
91
|
+
matrix_section = config.get("matrix", {})
|
|
92
|
+
e2ee_config = matrix_section.get("e2ee", {})
|
|
93
|
+
encryption_config = matrix_section.get("encryption", {}) # Legacy support
|
|
94
|
+
status["enabled"] = e2ee_config.get("enabled", False) or encryption_config.get(
|
|
95
|
+
"enabled", False
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
if not status["enabled"]:
|
|
99
|
+
status["issues"].append("E2EE is disabled in configuration")
|
|
100
|
+
|
|
101
|
+
# Check credentials
|
|
102
|
+
if config_path:
|
|
103
|
+
status["credentials_available"] = _check_credentials_available(config_path)
|
|
104
|
+
else:
|
|
105
|
+
# Fallback to base directory check only
|
|
106
|
+
from mmrelay.config import get_base_dir
|
|
107
|
+
|
|
108
|
+
base_credentials_path = os.path.join(get_base_dir(), CREDENTIALS_FILENAME)
|
|
109
|
+
status["credentials_available"] = os.path.exists(base_credentials_path)
|
|
110
|
+
|
|
111
|
+
if not status["credentials_available"]:
|
|
112
|
+
status["issues"].append("Matrix authentication not configured")
|
|
113
|
+
|
|
114
|
+
# Determine overall availability and status
|
|
115
|
+
status["available"] = (
|
|
116
|
+
status["platform_supported"] and status["dependencies_installed"]
|
|
117
|
+
)
|
|
118
|
+
status["configured"] = status["credentials_available"]
|
|
119
|
+
|
|
120
|
+
# Determine overall status
|
|
121
|
+
if not status["platform_supported"]:
|
|
122
|
+
status["overall_status"] = "unavailable"
|
|
123
|
+
elif status["enabled"] and status["available"] and status["configured"]:
|
|
124
|
+
status["overall_status"] = "ready"
|
|
125
|
+
elif not status["enabled"]:
|
|
126
|
+
status["overall_status"] = "disabled"
|
|
127
|
+
else:
|
|
128
|
+
status["overall_status"] = "incomplete"
|
|
129
|
+
|
|
130
|
+
return status
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _check_credentials_available(config_path: str) -> bool:
|
|
134
|
+
"""
|
|
135
|
+
Check whether the Matrix credentials file exists in standard locations.
|
|
136
|
+
|
|
137
|
+
Searches for CREDENTIALS_FILENAME in the directory containing the provided configuration file first, then falls back to the application's base directory (via mmrelay.config.get_base_dir()). If the base directory cannot be resolved (ImportError or OSError), the function returns False.
|
|
138
|
+
|
|
139
|
+
Parameters:
|
|
140
|
+
config_path (str): Filesystem path to the configuration file whose directory should be checked.
|
|
141
|
+
|
|
142
|
+
Returns:
|
|
143
|
+
bool: True if the credentials file exists in either the config directory or the base directory; otherwise False.
|
|
144
|
+
"""
|
|
145
|
+
# Check config directory first
|
|
146
|
+
config_dir = os.path.dirname(config_path)
|
|
147
|
+
config_credentials_path = os.path.join(config_dir, CREDENTIALS_FILENAME)
|
|
148
|
+
|
|
149
|
+
if os.path.exists(config_credentials_path):
|
|
150
|
+
return True
|
|
151
|
+
|
|
152
|
+
# Fallback to base directory
|
|
153
|
+
try:
|
|
154
|
+
from mmrelay.config import get_base_dir
|
|
155
|
+
|
|
156
|
+
base_credentials_path = os.path.join(get_base_dir(), CREDENTIALS_FILENAME)
|
|
157
|
+
return os.path.exists(base_credentials_path)
|
|
158
|
+
except (ImportError, OSError):
|
|
159
|
+
# If we can't determine base directory, assume no credentials
|
|
160
|
+
return False
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def get_room_encryption_warnings(
|
|
164
|
+
rooms: Dict[str, Any], e2ee_status: Dict[str, Any]
|
|
165
|
+
) -> List[str]:
|
|
166
|
+
"""
|
|
167
|
+
Return user-facing warnings for encrypted rooms when E2EE is not fully ready.
|
|
168
|
+
|
|
169
|
+
If the provided E2EE status has overall_status == "ready", returns an empty list.
|
|
170
|
+
Scans the given rooms mapping for items whose `encrypted` attribute is truthy and
|
|
171
|
+
produces one or two warning lines per situation:
|
|
172
|
+
- A line noting how many encrypted rooms were detected and the reason (platform unsupported,
|
|
173
|
+
disabled, or incomplete).
|
|
174
|
+
- A follow-up line indicating whether messages to those rooms will be blocked or may be blocked.
|
|
175
|
+
|
|
176
|
+
Parameters:
|
|
177
|
+
rooms: Mapping of room_id -> room object. Room objects are expected to expose
|
|
178
|
+
an `encrypted` attribute and optionally a `display_name` attribute; room_id is
|
|
179
|
+
used as a fallback name.
|
|
180
|
+
e2ee_status: E2EE status dictionary as returned by get_e2ee_status(); this function
|
|
181
|
+
reads the `overall_status` key to decide warning text.
|
|
182
|
+
|
|
183
|
+
Returns:
|
|
184
|
+
List[str]: Formatted warning lines (empty if no relevant warnings).
|
|
185
|
+
"""
|
|
186
|
+
warnings = []
|
|
187
|
+
|
|
188
|
+
if e2ee_status["overall_status"] == "ready":
|
|
189
|
+
# No warnings needed when E2EE is fully ready
|
|
190
|
+
return warnings
|
|
191
|
+
|
|
192
|
+
# Check for encrypted rooms
|
|
193
|
+
encrypted_rooms = []
|
|
194
|
+
|
|
195
|
+
# Handle invalid rooms input
|
|
196
|
+
if not rooms or not hasattr(rooms, "items"):
|
|
197
|
+
return warnings
|
|
198
|
+
|
|
199
|
+
for room_id, room in rooms.items():
|
|
200
|
+
if getattr(room, "encrypted", False):
|
|
201
|
+
room_name = getattr(room, "display_name", room_id)
|
|
202
|
+
encrypted_rooms.append(room_name)
|
|
203
|
+
|
|
204
|
+
if encrypted_rooms:
|
|
205
|
+
overall = e2ee_status["overall_status"]
|
|
206
|
+
if overall == "unavailable":
|
|
207
|
+
warnings.append(
|
|
208
|
+
f"⚠️ {len(encrypted_rooms)} encrypted room(s) detected but E2EE is not supported on Windows"
|
|
209
|
+
)
|
|
210
|
+
elif overall == "disabled":
|
|
211
|
+
warnings.append(
|
|
212
|
+
f"⚠️ {len(encrypted_rooms)} encrypted room(s) detected but E2EE is disabled"
|
|
213
|
+
)
|
|
214
|
+
else:
|
|
215
|
+
warnings.append(
|
|
216
|
+
f"⚠️ {len(encrypted_rooms)} encrypted room(s) detected but E2EE setup is incomplete"
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
# Tail message depends on readiness
|
|
220
|
+
if overall == "incomplete":
|
|
221
|
+
warnings.append(" Messages to encrypted rooms may be blocked")
|
|
222
|
+
else:
|
|
223
|
+
warnings.append(" Messages to encrypted rooms will be blocked")
|
|
224
|
+
|
|
225
|
+
return warnings
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def format_room_list(rooms: Dict[str, Any], e2ee_status: Dict[str, Any]) -> List[str]:
|
|
229
|
+
"""
|
|
230
|
+
Format a list of human-readable room lines with encryption indicators and status-specific warnings.
|
|
231
|
+
|
|
232
|
+
Given a mapping of room_id -> room-like objects, produce one display string per room:
|
|
233
|
+
- If E2EE overall_status == "ready": encrypted rooms are marked "🔒 {name} - Encrypted"; non-encrypted rooms are "✅ {name}".
|
|
234
|
+
- If not ready: encrypted rooms are prefixed with "⚠️" and include a short reason derived from overall_status ("unavailable" -> not supported on Windows, "disabled" -> disabled in config, otherwise "incomplete"); non-encrypted rooms remain "✅ {name}".
|
|
235
|
+
|
|
236
|
+
Parameters:
|
|
237
|
+
rooms: Mapping of room_id to a room-like object. Each room may have attributes:
|
|
238
|
+
- display_name (str): human-friendly name (fallback: room_id)
|
|
239
|
+
- encrypted (bool): whether the room is encrypted (default: False)
|
|
240
|
+
e2ee_status: E2EE status dictionary (as returned by get_e2ee_status()). Only e2ee_status["overall_status"] is used.
|
|
241
|
+
|
|
242
|
+
Returns:
|
|
243
|
+
List[str]: One formatted line per room suitable for user display.
|
|
244
|
+
"""
|
|
245
|
+
room_lines = []
|
|
246
|
+
|
|
247
|
+
# Handle invalid rooms input
|
|
248
|
+
if not rooms or not hasattr(rooms, "items"):
|
|
249
|
+
return room_lines
|
|
250
|
+
|
|
251
|
+
for room_id, room in rooms.items():
|
|
252
|
+
room_name = getattr(room, "display_name", room_id)
|
|
253
|
+
encrypted = getattr(room, "encrypted", False)
|
|
254
|
+
|
|
255
|
+
if e2ee_status["overall_status"] == "ready":
|
|
256
|
+
# Show detailed status when E2EE is fully ready
|
|
257
|
+
if encrypted:
|
|
258
|
+
room_lines.append(f" 🔒 {room_name} - Encrypted")
|
|
259
|
+
else:
|
|
260
|
+
room_lines.append(f" ✅ {room_name}")
|
|
261
|
+
else:
|
|
262
|
+
# Show warnings for encrypted rooms when E2EE is not ready
|
|
263
|
+
if encrypted:
|
|
264
|
+
if e2ee_status["overall_status"] == "unavailable":
|
|
265
|
+
room_lines.append(
|
|
266
|
+
f" ⚠️ {room_name} - Encrypted (E2EE not supported on Windows - messages will be blocked)"
|
|
267
|
+
)
|
|
268
|
+
elif e2ee_status["overall_status"] == "disabled":
|
|
269
|
+
room_lines.append(
|
|
270
|
+
f" ⚠️ {room_name} - Encrypted (E2EE disabled - messages will be blocked)"
|
|
271
|
+
)
|
|
272
|
+
else:
|
|
273
|
+
room_lines.append(
|
|
274
|
+
f" ⚠️ {room_name} - Encrypted (E2EE incomplete - messages may be blocked)"
|
|
275
|
+
)
|
|
276
|
+
else:
|
|
277
|
+
room_lines.append(f" ✅ {room_name}")
|
|
278
|
+
|
|
279
|
+
return room_lines
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
# Standard warning message templates
|
|
283
|
+
def get_e2ee_warning_messages():
|
|
284
|
+
"""
|
|
285
|
+
Return a mapping of standard user-facing E2EE warning messages.
|
|
286
|
+
|
|
287
|
+
Each key is a short status identifier and the value is a ready-to-display message. Messages that reference external tooling or packages are rendered with the module's constants and CLI commands (e.g. PACKAGE_NAME_E2E and get_command).
|
|
288
|
+
Returns:
|
|
289
|
+
dict: Mapping of status keys to formatted warning strings. Keys include:
|
|
290
|
+
- "unavailable", "disabled", "incomplete", "missing_deps",
|
|
291
|
+
"missing_auth", and "missing_config".
|
|
292
|
+
"""
|
|
293
|
+
return {
|
|
294
|
+
"unavailable": "E2EE is not supported on Windows - messages to encrypted rooms will be blocked",
|
|
295
|
+
"disabled": "E2EE is disabled in configuration - messages to encrypted rooms will be blocked",
|
|
296
|
+
"incomplete": "E2EE setup is incomplete - messages to encrypted rooms may be blocked",
|
|
297
|
+
"missing_deps": f"E2EE dependencies not installed - run: pipx install {PACKAGE_NAME_E2E}",
|
|
298
|
+
"missing_auth": f"Matrix authentication not configured - run: {get_command('auth_login')}",
|
|
299
|
+
"missing_config": "E2EE not enabled in configuration - add 'e2ee: enabled: true' under matrix section",
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
def get_e2ee_error_message(e2ee_status: Dict[str, Any]) -> str:
|
|
304
|
+
"""
|
|
305
|
+
Return a single user-facing E2EE error message based on the provided E2EE status.
|
|
306
|
+
|
|
307
|
+
If the status is "ready" this returns an empty string. Otherwise selects one actionable
|
|
308
|
+
message (in priority order) for the first failing condition:
|
|
309
|
+
1. platform not supported
|
|
310
|
+
2. E2EE disabled in config
|
|
311
|
+
3. missing E2EE dependencies
|
|
312
|
+
4. missing Matrix credentials
|
|
313
|
+
5. otherwise, E2EE setup incomplete
|
|
314
|
+
|
|
315
|
+
Parameters:
|
|
316
|
+
e2ee_status (dict): Status dictionary produced by get_e2ee_status().
|
|
317
|
+
Expected keys used: "overall_status", "platform_supported", "enabled",
|
|
318
|
+
"dependencies_installed", and "credentials_available".
|
|
319
|
+
|
|
320
|
+
Returns:
|
|
321
|
+
str: A single formatted warning/instruction string, or an empty string when ready.
|
|
322
|
+
"""
|
|
323
|
+
if e2ee_status.get("overall_status") == "ready":
|
|
324
|
+
return "" # No error
|
|
325
|
+
|
|
326
|
+
# Get current warning messages
|
|
327
|
+
warning_messages = get_e2ee_warning_messages()
|
|
328
|
+
|
|
329
|
+
# Build error message based on specific issues
|
|
330
|
+
if not e2ee_status.get("platform_supported", True):
|
|
331
|
+
return warning_messages["unavailable"]
|
|
332
|
+
elif not e2ee_status.get("enabled", False):
|
|
333
|
+
return warning_messages["disabled"]
|
|
334
|
+
elif not e2ee_status.get("dependencies_installed", False):
|
|
335
|
+
return warning_messages["missing_deps"]
|
|
336
|
+
elif not e2ee_status.get("credentials_available", False):
|
|
337
|
+
return warning_messages["missing_auth"]
|
|
338
|
+
else:
|
|
339
|
+
return warning_messages["incomplete"]
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
def get_e2ee_fix_instructions(e2ee_status: Dict[str, Any]) -> List[str]:
|
|
343
|
+
"""
|
|
344
|
+
Return ordered, user-facing instructions to resolve E2EE setup problems.
|
|
345
|
+
|
|
346
|
+
If E2EE is already ready, returns a single confirmation line. If the platform is unsupported,
|
|
347
|
+
returns platform-specific guidance. Otherwise returns a numbered sequence of actionable steps
|
|
348
|
+
(as separate list lines) to install required E2EE dependencies, provision Matrix credentials,
|
|
349
|
+
enable E2EE in the configuration, and finally verify the configuration. Command and config
|
|
350
|
+
snippets appear as indented lines in the returned list.
|
|
351
|
+
|
|
352
|
+
Parameters:
|
|
353
|
+
e2ee_status (dict): Status mapping produced by get_e2ee_status(). The function reads the
|
|
354
|
+
following keys to decide which steps to include: "overall_status",
|
|
355
|
+
"platform_supported", "dependencies_installed", "credentials_available", and "enabled".
|
|
356
|
+
|
|
357
|
+
Returns:
|
|
358
|
+
List[str]: Ordered, human-readable instruction lines. Each step is a separate string;
|
|
359
|
+
related commands or configuration snippets are returned as additional indented strings.
|
|
360
|
+
"""
|
|
361
|
+
if e2ee_status["overall_status"] == "ready":
|
|
362
|
+
return ["✅ E2EE is fully configured and ready"]
|
|
363
|
+
|
|
364
|
+
instructions = []
|
|
365
|
+
|
|
366
|
+
if not e2ee_status["platform_supported"]:
|
|
367
|
+
instructions.append("❌ E2EE is not supported on Windows")
|
|
368
|
+
instructions.append(" Use Linux or macOS for E2EE support")
|
|
369
|
+
return instructions
|
|
370
|
+
|
|
371
|
+
step = 1
|
|
372
|
+
if not e2ee_status["dependencies_installed"]:
|
|
373
|
+
instructions.append(f"{step}. Install E2EE dependencies:")
|
|
374
|
+
instructions.append(f" pipx install {PACKAGE_NAME_E2E}")
|
|
375
|
+
step += 1
|
|
376
|
+
|
|
377
|
+
if not e2ee_status["credentials_available"]:
|
|
378
|
+
instructions.append(f"{step}. Set up Matrix authentication:")
|
|
379
|
+
instructions.append(f" {get_command('auth_login')}")
|
|
380
|
+
step += 1
|
|
381
|
+
|
|
382
|
+
if not e2ee_status["enabled"]:
|
|
383
|
+
instructions.append(f"{step}. Enable E2EE in configuration:")
|
|
384
|
+
instructions.append(" Edit config.yaml and add under matrix section:")
|
|
385
|
+
instructions.append(" e2ee:")
|
|
386
|
+
instructions.append(" enabled: true")
|
|
387
|
+
step += 1
|
|
388
|
+
|
|
389
|
+
instructions.append(f"{step}. Verify configuration:")
|
|
390
|
+
instructions.append(f" {get_command('check_config')}")
|
|
391
|
+
|
|
392
|
+
return instructions
|
mmrelay/log_utils.py
CHANGED
|
@@ -38,7 +38,14 @@ _component_debug_configured = False
|
|
|
38
38
|
|
|
39
39
|
# Component logger mapping for data-driven configuration
|
|
40
40
|
_COMPONENT_LOGGERS = {
|
|
41
|
-
"matrix_nio": [
|
|
41
|
+
"matrix_nio": [
|
|
42
|
+
"nio",
|
|
43
|
+
"nio.client",
|
|
44
|
+
"nio.http",
|
|
45
|
+
"nio.crypto",
|
|
46
|
+
"nio.responses",
|
|
47
|
+
"nio.rooms",
|
|
48
|
+
],
|
|
42
49
|
"bleak": ["bleak", "bleak.backends"],
|
|
43
50
|
"meshtastic": [
|
|
44
51
|
"meshtastic",
|
|
@@ -51,9 +58,14 @@ _COMPONENT_LOGGERS = {
|
|
|
51
58
|
|
|
52
59
|
def configure_component_debug_logging():
|
|
53
60
|
"""
|
|
54
|
-
|
|
61
|
+
Configure log levels for external component loggers based on config["logging"]["debug"].
|
|
62
|
+
|
|
63
|
+
Reads per-component entries under `config["logging"]["debug"]` and applies one of:
|
|
64
|
+
- falsy or missing: silence the component by setting its loggers to CRITICAL+1
|
|
65
|
+
- boolean True: enable DEBUG for the component's loggers
|
|
66
|
+
- string: interpret as a logging level name (case-insensitive); invalid names fall back to DEBUG
|
|
55
67
|
|
|
56
|
-
This function
|
|
68
|
+
This function mutates the levels of loggers listed in _COMPONENT_LOGGERS and runs only once per process; no-op if called again or if global `config` is None.
|
|
57
69
|
"""
|
|
58
70
|
global _component_debug_configured, config
|
|
59
71
|
|
|
@@ -64,9 +76,31 @@ def configure_component_debug_logging():
|
|
|
64
76
|
debug_config = config.get("logging", {}).get("debug", {})
|
|
65
77
|
|
|
66
78
|
for component, loggers in _COMPONENT_LOGGERS.items():
|
|
67
|
-
|
|
79
|
+
component_config = debug_config.get(component)
|
|
80
|
+
|
|
81
|
+
if component_config:
|
|
82
|
+
# Component debug is enabled - check if it's a boolean or a log level
|
|
83
|
+
if isinstance(component_config, bool):
|
|
84
|
+
# Legacy boolean format - default to DEBUG
|
|
85
|
+
log_level = logging.DEBUG
|
|
86
|
+
elif isinstance(component_config, str):
|
|
87
|
+
# String log level format (e.g., "warning", "error", "debug")
|
|
88
|
+
try:
|
|
89
|
+
log_level = getattr(logging, component_config.upper())
|
|
90
|
+
except AttributeError:
|
|
91
|
+
# Invalid log level, fall back to DEBUG
|
|
92
|
+
log_level = logging.DEBUG
|
|
93
|
+
else:
|
|
94
|
+
# Invalid config, fall back to DEBUG
|
|
95
|
+
log_level = logging.DEBUG
|
|
96
|
+
|
|
97
|
+
for logger_name in loggers:
|
|
98
|
+
logging.getLogger(logger_name).setLevel(log_level)
|
|
99
|
+
else:
|
|
100
|
+
# Component debug is disabled - completely suppress external library logging
|
|
101
|
+
# Use a level higher than CRITICAL to effectively disable all messages
|
|
68
102
|
for logger_name in loggers:
|
|
69
|
-
logging.getLogger(logger_name).setLevel(logging.
|
|
103
|
+
logging.getLogger(logger_name).setLevel(logging.CRITICAL + 1)
|
|
70
104
|
|
|
71
105
|
_component_debug_configured = True
|
|
72
106
|
|