Skip to content

Commit 6023021

Browse files
Giu PlataniaGiu Platania
authored andcommitted
feat: add support for shared-instance RPC configuration in client and gateway
1 parent 85fadd2 commit 6023021

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

examples/EmergencyManagement/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Both the CLI demo and the FastAPI gateway read [`client/client_config.json`](cli
7878
- Override the location of the configuration file with `NORTH_API_CONFIG_PATH` or provide JSON directly through `NORTH_API_CONFIG_JSON`.
7979
- Requests can target different LXMF services by supplying an `X-Server-Identity` header or a `server_identity` query parameter to the gateway.
8080
- The repository ships with a sample Reticulum directory at [`examples/EmergencyManagement/.reticulum`](./.reticulum) that pins `rpc_key` to `F1E2D3C4B5A697887766554433221100`. When the gateway and LXMF service use this directory (or any config with the same key) they can attach to the same shared instance without prompting.
81+
- Remote deployments should set `use_shared_instance_rpc` to `false` to avoid attempting shared-instance RPC connections on hosts that only communicate over the mesh.
8182

8283
| Key | Purpose |
8384
| --- | --- |
@@ -87,6 +88,7 @@ Both the CLI demo and the FastAPI gateway read [`client/client_config.json`](cli
8788
| `lxmf_config_path` | Optional override for the Reticulum configuration directory. |
8889
| `lxmf_storage_path` | Optional override for the LXMF storage directory. |
8990
| `shared_instance_rpc_key` | RPC key used when attaching to a shared Reticulum instance. |
91+
| `use_shared_instance_rpc` | Set to `true` to use the shared-instance RPC key (local clients); set to `false` on remote hosts that should not attach via RPC. |
9092
| `generate_test_messages` | When `true`, the CLI seeds random emergency messages and events during startup. |
9193
| `enable_interactive_menu` | Enables the interactive CLI menu after the initial demo run. Disable when scripting automated flows. |
9294
| `test_message_count` | Number of emergency messages to seed when `generate_test_messages` is enabled. |

examples/EmergencyManagement/client/client_config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"generate_test_messages": true,
88
"enable_interactive_menu": true,
99
"shared_instance_rpc_key": "F1E2D3C4B5A697887766554433221100",
10+
"use_shared_instance_rpc": true,
1011
"test_message_count": 5,
1112
"test_event_count": 5
1213
}

examples/EmergencyManagement/client/client_emergency.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
LXMF_CONFIG_PATH_KEY = "lxmf_config_path"
2727
LXMF_STORAGE_PATH_KEY = "lxmf_storage_path"
2828
SHARED_INSTANCE_RPC_KEY = "shared_instance_rpc_key"
29+
USE_SHARED_INSTANCE_RPC_KEY = "use_shared_instance_rpc"
2930
ENABLE_INTERACTIVE_MENU_KEY = "enable_interactive_menu"
3031
DEFAULT_DISPLAY_NAME = "OpenAPIClient"
3132
DEFAULT_TIMEOUT_SECONDS = 30.0
@@ -124,6 +125,7 @@
124125
"load_client_config",
125126
"write_client_config",
126127
"SHARED_INSTANCE_RPC_KEY",
128+
"USE_SHARED_INSTANCE_RPC_KEY",
127129
]
128130

129131

@@ -238,6 +240,15 @@ def _coerce_positive_int(value, default: int) -> int:
238240
return default
239241

240242

243+
def _is_shared_instance_rpc_enabled(config: Mapping[str, Any]) -> bool:
244+
"""Return ``True`` when shared-instance RPC access should be used."""
245+
246+
flag = config.get(USE_SHARED_INSTANCE_RPC_KEY)
247+
if isinstance(flag, bool):
248+
return flag
249+
return bool(config.get(SHARED_INSTANCE_RPC_KEY))
250+
251+
241252
def _normalise_config_directory(path_value: Optional[str]) -> Optional[str]:
242253
"""Return a directory path suitable for Reticulum configuration."""
243254

@@ -665,6 +676,8 @@ async def main():
665676
rpc_key_value = None
666677
else:
667678
rpc_key_value = None
679+
if not _is_shared_instance_rpc_enabled(config_data):
680+
rpc_key_value = None
668681

669682
identity_config_dir = Path(identity_config_path)
670683
try:

examples/EmergencyManagement/web_gateway/app.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
LXMF_STORAGE_PATH_KEY,
3838
REQUEST_TIMEOUT_KEY,
3939
SHARED_INSTANCE_RPC_KEY,
40+
USE_SHARED_INSTANCE_RPC_KEY,
4041
load_client_config,
4142
read_server_identity_from_config,
4243
write_client_config,
@@ -357,6 +358,15 @@ def _normalise_optional_hex(value: Optional[str]) -> Optional[str]:
357358
return None
358359

359360

361+
def _is_shared_instance_rpc_enabled(config: ConfigDict) -> bool:
362+
"""Return True when shared-instance RPC access should be used."""
363+
364+
flag = config.get(USE_SHARED_INSTANCE_RPC_KEY)
365+
if isinstance(flag, bool):
366+
return flag
367+
return bool(_normalise_optional_hex(config.get(SHARED_INSTANCE_RPC_KEY)))
368+
369+
360370
def _resolve_timeout(config: ConfigDict) -> float:
361371
"""Return the timeout value configured for the client."""
362372

@@ -389,6 +399,8 @@ def _create_client_from_config() -> LXMFClient:
389399
rpc_key_override = _normalise_optional_hex(
390400
_CONFIG_DATA.get(SHARED_INSTANCE_RPC_KEY)
391401
)
402+
if not _is_shared_instance_rpc_enabled(_CONFIG_DATA):
403+
rpc_key_override = None
392404
timeout_seconds = _resolve_timeout(_CONFIG_DATA)
393405
display_name = _resolve_display_name(_CONFIG_DATA)
394406

0 commit comments

Comments
 (0)