Files
umn/Sources/umnd/DaemonConfig.swift
T
2026-08-31 15:55:09 -05:00

20 lines
709 B
Swift

import Foundation
import UltraMeshCore
struct DaemonConfig: Codable {
var aliases: [String: MeshAddress] = [:]
var firewall: Set<FirewallRule> = []
var lsaSequence: UInt64?
static func load(from url: URL) -> DaemonConfig {
guard let data = try? Data(contentsOf: url), let value = try? JSONDecoder().decode(Self.self, from: data) else { return .init() }
return value
}
func save(to url: URL) throws {
let encoder = JSONEncoder(); encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
try encoder.encode(self).write(to: url, options: .atomic)
try FileManager.default.setAttributes([.posixPermissions: 0o600], ofItemAtPath: url.path)
}
}