writeHubState function
Persists {masterSecret, clients} (0600 — the file carries secrets).
Best-effort: IO failures never take the hub down.
Implementation
Future<void> writeHubState(
File file, {
required String? masterSecret,
required Map<String, String> clients,
}) async {
try {
if (!await file.parent.exists()) {
await file.parent.create(recursive: true);
}
await file.writeAsString(
jsonEncode({'masterSecret': masterSecret, 'clients': clients}),
);
// dart:io has no chmod API — best-effort via the shell (on platforms
// without chmod we just skip).
await Process.run('chmod', ['600', file.path]);
} on Object {
// Persistence is best-effort; the in-memory state still serves.
}
}