2020-03-02 01:53:41 -05:00
|
|
|
// This file is part of Moonfire NVR, a security camera network video recorder.
|
2021-02-17 16:28:48 -05:00
|
|
|
// Copyright (C) 2018 The Moonfire NVR Authors; see AUTHORS and LICENSE.txt.
|
|
|
|
// SPDX-License-Identifier: GPL-v3.0-or-later WITH GPL-3.0-linking-exception.';
|
2018-02-15 02:10:10 -05:00
|
|
|
|
2022-12-31 12:08:26 -05:00
|
|
|
// Protobuf portion of the Moonfire NVR schema. In general Moonfire's schema
|
|
|
|
// uses a SQLite3 database with some fields in JSON representation. The protobuf
|
|
|
|
// stuff is just high-cardinality things that must be compact, e.g. permissions
|
|
|
|
// that can be stuffed into every user session.
|
|
|
|
|
2018-02-15 02:10:10 -05:00
|
|
|
syntax = "proto3";
|
|
|
|
|
2021-04-10 20:34:52 -04:00
|
|
|
// Metadata stored in sample file dirs as `<dir>/meta`. This is checked
|
2018-02-15 02:10:10 -05:00
|
|
|
// against the metadata stored within the database to detect inconsistencies
|
2018-03-24 23:51:30 -04:00
|
|
|
// between the directory and database, such as those described in
|
2021-04-10 20:34:52 -04:00
|
|
|
// `design/schema.md`.
|
2019-07-05 00:22:45 -04:00
|
|
|
//
|
|
|
|
// As of schema version 4, the overall file format is as follows: a
|
2021-04-10 20:34:52 -04:00
|
|
|
// varint-encoded length, followed by a serialized `DirMeta` message, followed
|
2019-07-05 00:22:45 -04:00
|
|
|
// by NUL bytes padding to a total length of 512 bytes. This message never
|
|
|
|
// exceeds that length.
|
|
|
|
//
|
|
|
|
// The goal of this format is to allow atomically rewriting a meta file
|
|
|
|
// in-place. I hope that on modern OSs and hardware, a single-sector
|
|
|
|
// rewrite is atomic, though POSIX frustratingly doesn't seem to guarantee
|
|
|
|
// this. There's some discussion of that here:
|
|
|
|
// <https://stackoverflow.com/a/2068608/23584>. At worst, there's a short
|
|
|
|
// window during which the meta file can be corrupted. As the file's purpose
|
|
|
|
// is to check for inconsistencies, it can be reconstructed if you assume no
|
|
|
|
// inconsistency exists.
|
|
|
|
//
|
|
|
|
// Schema version 3 wrote a serialized DirMeta message with no length or
|
|
|
|
// padding, and renamed new meta files over the top of old. This scheme
|
|
|
|
// requires extra space while opening the directory. If the filesystem is
|
|
|
|
// completely full, it requires freeing space manually, an undocumented and
|
|
|
|
// error-prone administrator procedure.
|
2018-02-15 02:10:10 -05:00
|
|
|
message DirMeta {
|
|
|
|
// A uuid associated with the database, in binary form. dir_uuid is strictly
|
|
|
|
// more powerful, but it improves diagnostics to know if the directory
|
|
|
|
// belongs to the expected database at all or not.
|
|
|
|
bytes db_uuid = 1;
|
|
|
|
|
|
|
|
// A uuid associated with the directory itself.
|
|
|
|
bytes dir_uuid = 2;
|
|
|
|
|
|
|
|
// Corresponds to an entry in the `open` database table.
|
|
|
|
message Open {
|
|
|
|
uint32 id = 1;
|
|
|
|
bytes uuid = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The last open that was known to be recorded in the database as completed.
|
2018-03-01 15:24:32 -05:00
|
|
|
// Absent if this has never happened. Note this can backtrack in exactly one
|
|
|
|
// scenario: when deleting the directory, after all associated files have
|
|
|
|
// been deleted, last_complete_open can be moved to in_progress_open.
|
2018-02-15 02:10:10 -05:00
|
|
|
Open last_complete_open = 3;
|
|
|
|
|
|
|
|
// The last run which is in progress, if different from last_complete_open.
|
|
|
|
// This may or may not have been recorded in the database, but it's
|
|
|
|
// guaranteed that no data has yet been written by this open.
|
|
|
|
Open in_progress_open = 4;
|
|
|
|
}
|
2019-06-19 18:17:50 -04:00
|
|
|
|
2023-01-06 12:40:41 -05:00
|
|
|
// Permissions to perform actions. See description in ref/api.md.
|
2019-06-19 18:17:50 -04:00
|
|
|
//
|
2022-12-31 12:08:26 -05:00
|
|
|
// This protobuf form is stored in user and session rows.
|
2019-06-19 18:17:50 -04:00
|
|
|
message Permissions {
|
|
|
|
bool view_video = 1;
|
|
|
|
bool read_camera_configs = 2;
|
|
|
|
bool update_signals = 3;
|
2022-12-23 15:43:00 -05:00
|
|
|
bool admin_users = 4;
|
2019-06-19 18:17:50 -04:00
|
|
|
}
|