2016-07-04 10:40:29 +00:00
|
|
|
syntax = "proto3";
|
|
|
|
|
|
|
|
package protocol;
|
|
|
|
|
2020-10-02 06:07:05 +00:00
|
|
|
import "ext.proto";
|
2018-12-18 11:36:38 +00:00
|
|
|
import "repos/protobuf/gogoproto/gogo.proto";
|
2016-07-04 10:40:29 +00:00
|
|
|
|
|
|
|
// --- Pre-auth ---
|
|
|
|
|
|
|
|
message Hello {
|
2023-09-06 10:52:01 +00:00
|
|
|
string device_name = 1;
|
|
|
|
string client_name = 2;
|
|
|
|
string client_version = 3;
|
|
|
|
int32 num_connections = 4;
|
|
|
|
int64 timestamp = 5;
|
2016-07-04 10:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// --- Header ---
|
|
|
|
|
|
|
|
message Header {
|
|
|
|
MessageType type = 1;
|
|
|
|
MessageCompression compression = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum MessageType {
|
2020-10-02 06:07:05 +00:00
|
|
|
MESSAGE_TYPE_CLUSTER_CONFIG = 0;
|
|
|
|
MESSAGE_TYPE_INDEX = 1;
|
|
|
|
MESSAGE_TYPE_INDEX_UPDATE = 2;
|
|
|
|
MESSAGE_TYPE_REQUEST = 3;
|
|
|
|
MESSAGE_TYPE_RESPONSE = 4;
|
|
|
|
MESSAGE_TYPE_DOWNLOAD_PROGRESS = 5;
|
|
|
|
MESSAGE_TYPE_PING = 6;
|
|
|
|
MESSAGE_TYPE_CLOSE = 7;
|
2016-07-04 10:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum MessageCompression {
|
2020-10-02 06:07:05 +00:00
|
|
|
MESSAGE_COMPRESSION_NONE = 0;
|
|
|
|
MESSAGE_COMPRESSION_LZ4 = 1 [(ext.enumgoname) = "MessageCompressionLZ4"];
|
2016-07-04 10:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// --- Actual messages ---
|
|
|
|
|
|
|
|
// Cluster Config
|
|
|
|
|
|
|
|
message ClusterConfig {
|
2023-09-06 10:52:01 +00:00
|
|
|
repeated Folder folders = 1;
|
|
|
|
bool secondary = 2;
|
2016-07-04 10:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
message Folder {
|
2020-10-02 06:07:05 +00:00
|
|
|
string id = 1 [(ext.goname) = "ID"];
|
2016-07-04 10:40:29 +00:00
|
|
|
string label = 2;
|
|
|
|
bool read_only = 3;
|
|
|
|
bool ignore_permissions = 4;
|
|
|
|
bool ignore_delete = 5;
|
|
|
|
bool disable_temp_indexes = 6;
|
2016-12-21 18:41:25 +00:00
|
|
|
bool paused = 7;
|
2016-07-04 10:40:29 +00:00
|
|
|
|
2020-10-02 06:07:05 +00:00
|
|
|
repeated Device devices = 16;
|
2016-07-04 10:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
message Device {
|
2020-10-02 06:07:05 +00:00
|
|
|
bytes id = 1 [(ext.goname) = "ID", (ext.device_id) = true];
|
2016-11-07 16:40:48 +00:00
|
|
|
string name = 2;
|
|
|
|
repeated string addresses = 3;
|
|
|
|
Compression compression = 4;
|
|
|
|
string cert_name = 5;
|
|
|
|
int64 max_sequence = 6;
|
|
|
|
bool introducer = 7;
|
2020-10-02 06:07:05 +00:00
|
|
|
uint64 index_id = 8 [(ext.goname) = "IndexID", (ext.gotype) = "IndexID"];
|
2016-11-07 16:40:48 +00:00
|
|
|
bool skip_introduction_removals = 9;
|
2020-11-09 14:33:32 +00:00
|
|
|
bytes encryption_password_token = 10;
|
2016-07-04 10:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum Compression {
|
2020-10-02 06:07:05 +00:00
|
|
|
COMPRESSION_METADATA = 0;
|
|
|
|
COMPRESSION_NEVER = 1;
|
|
|
|
COMPRESSION_ALWAYS = 2;
|
2016-07-04 10:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Index and Index Update
|
|
|
|
|
|
|
|
message Index {
|
|
|
|
string folder = 1;
|
2020-10-02 06:07:05 +00:00
|
|
|
repeated FileInfo files = 2;
|
2016-07-04 10:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
message IndexUpdate {
|
|
|
|
string folder = 1;
|
2020-10-02 06:07:05 +00:00
|
|
|
repeated FileInfo files = 2;
|
2016-07-04 10:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
message FileInfo {
|
|
|
|
option (gogoproto.goproto_stringer) = false;
|
2019-12-08 12:31:26 +00:00
|
|
|
|
|
|
|
// The field ordering here optimizes for struct size / alignment --
|
|
|
|
// large types come before smaller ones.
|
|
|
|
|
2018-06-24 07:50:18 +00:00
|
|
|
string name = 1;
|
|
|
|
int64 size = 3;
|
|
|
|
int64 modified_s = 5;
|
2020-10-02 06:07:05 +00:00
|
|
|
uint64 modified_by = 12 [(ext.gotype) = "ShortID"];
|
|
|
|
Vector version = 9;
|
2018-06-24 07:50:18 +00:00
|
|
|
int64 sequence = 10;
|
2020-10-02 06:07:05 +00:00
|
|
|
repeated BlockInfo blocks = 16;
|
2016-12-09 18:02:18 +00:00
|
|
|
string symlink_target = 17;
|
lib/db: Deduplicate block lists in database (fixes #5898) (#6283)
* lib/db: Deduplicate block lists in database (fixes #5898)
This moves the block list in the database out from being just a field on
the FileInfo to being an object of its own. When putting a FileInfo we
marshal the block list separately and store it keyed by the sha256 of
the marshalled block list. When getting, if we are not doing a
"truncated" get, we do an extra read and unmarshal for the block list.
Old block lists are cleared out by a periodic GC sweep. The alternative
would be to use refcounting, but:
- There is a larger risk of getting that wrong and either dropping a
block list in error or keeping them around forever.
- It's tricky with our current database, as we don't have dirty reads.
This means that if we update two FileInfos with identical block lists in
the same transaction we can't just do read/modify/write for the ref
counters as we wouldn't see our own first update. See above about
tracking this and risks about getting it wrong.
GC uses a bloom filter for keys to avoid heavy RAM usage. GC can't run
concurrently with FileInfo updates so there is a new lock around those
operation at the lowlevel.
The end result is a much more compact database, especially for setups
with many peers where files get duplicated many times.
This is per-key-class stats for a large database I'm currently working
with, under the current schema:
```
0x00: 9138161 items, 870876 KB keys + 7397482 KB data, 95 B + 809 B avg, 1637651 B max
0x01: 185656 items, 10388 KB keys + 1790909 KB data, 55 B + 9646 B avg, 924525 B max
0x02: 916890 items, 84795 KB keys + 3667 KB data, 92 B + 4 B avg, 192 B max
0x03: 384 items, 27 KB keys + 5 KB data, 72 B + 15 B avg, 87 B max
0x04: 1109 items, 17 KB keys + 17 KB data, 15 B + 15 B avg, 69 B max
0x06: 383 items, 3 KB keys + 0 KB data, 9 B + 2 B avg, 18 B max
0x07: 510 items, 4 KB keys + 12 KB data, 9 B + 24 B avg, 41 B max
0x08: 1349 items, 12 KB keys + 10 KB data, 9 B + 8 B avg, 17 B max
0x09: 194 items, 0 KB keys + 123 KB data, 5 B + 634 B avg, 11484 B max
0x0a: 3 items, 0 KB keys + 0 KB data, 14 B + 7 B avg, 30 B max
0x0b: 181836 items, 2363 KB keys + 10694 KB data, 13 B + 58 B avg, 173 B max
Total 10426475 items, 968490 KB keys + 9202925 KB data.
```
Note 7.4 GB of data in class 00, total size 9.2 GB. After running the
migration we get this instead:
```
0x00: 9138161 items, 870876 KB keys + 2611392 KB data, 95 B + 285 B avg, 4788 B max
0x01: 185656 items, 10388 KB keys + 1790909 KB data, 55 B + 9646 B avg, 924525 B max
0x02: 916890 items, 84795 KB keys + 3667 KB data, 92 B + 4 B avg, 192 B max
0x03: 384 items, 27 KB keys + 5 KB data, 72 B + 15 B avg, 87 B max
0x04: 1109 items, 17 KB keys + 17 KB data, 15 B + 15 B avg, 69 B max
0x06: 383 items, 3 KB keys + 0 KB data, 9 B + 2 B avg, 18 B max
0x07: 510 items, 4 KB keys + 12 KB data, 9 B + 24 B avg, 41 B max
0x09: 194 items, 0 KB keys + 123 KB data, 5 B + 634 B avg, 11484 B max
0x0a: 3 items, 0 KB keys + 0 KB data, 14 B + 17 B avg, 51 B max
0x0b: 181836 items, 2363 KB keys + 10694 KB data, 13 B + 58 B avg, 173 B max
0x0d: 44282 items, 1461 KB keys + 61081 KB data, 33 B + 1379 B avg, 1637399 B max
Total 10469408 items, 969939 KB keys + 4477905 KB data.
```
Class 00 is now down to 2.6 GB, with just 61 MB added in class 0d.
There will be some additional reads in some cases which theoretically
hurts performance, but this will be more than compensated for by smaller
writes and better compaction.
On my own home setup which just has three devices and a handful of
folders the difference is smaller in absolute numbers of course, but
still less than half the old size:
```
0x00: 297122 items, 20894 KB keys + 306860 KB data, 70 B + 1032 B avg, 103237 B max
0x01: 115299 items, 7738 KB keys + 17542 KB data, 67 B + 152 B avg, 419 B max
0x02: 1430537 items, 121223 KB keys + 5722 KB data, 84 B + 4 B avg, 253 B max
...
Total 1947412 items, 151268 KB keys + 337485 KB data.
```
to:
```
0x00: 297122 items, 20894 KB keys + 37038 KB data, 70 B + 124 B avg, 520 B max
0x01: 115299 items, 7738 KB keys + 17542 KB data, 67 B + 152 B avg, 419 B max
0x02: 1430537 items, 121223 KB keys + 5722 KB data, 84 B + 4 B avg, 253 B max
...
0x0d: 18041 items, 595 KB keys + 71964 KB data, 33 B + 3988 B avg, 101109 B max
Total 1965447 items, 151863 KB keys + 139628 KB data.
```
* wip
* wip
* wip
* wip
2020-01-24 07:35:44 +00:00
|
|
|
bytes blocks_hash = 18;
|
2020-11-09 14:33:32 +00:00
|
|
|
bytes encrypted = 19;
|
2019-12-08 12:31:26 +00:00
|
|
|
FileInfoType type = 2;
|
|
|
|
uint32 permissions = 4;
|
|
|
|
int32 modified_ns = 11;
|
2020-10-02 06:07:05 +00:00
|
|
|
int32 block_size = 13 [(ext.goname) = "RawBlockSize"];
|
2022-07-26 06:24:58 +00:00
|
|
|
PlatformData platform = 14;
|
2018-06-24 07:50:18 +00:00
|
|
|
|
|
|
|
// The local_flags fields stores flags that are relevant to the local
|
|
|
|
// host only. It is not part of the protocol, doesn't get sent or
|
|
|
|
// received (we make sure to zero it), nonetheless we need it on our
|
|
|
|
// struct and to be able to serialize it to/from the database.
|
|
|
|
uint32 local_flags = 1000;
|
2022-09-14 07:50:55 +00:00
|
|
|
|
2020-05-13 12:28:42 +00:00
|
|
|
// The version_hash is an implementation detail and not part of the wire
|
|
|
|
// format.
|
|
|
|
bytes version_hash = 1001;
|
2019-12-08 12:31:26 +00:00
|
|
|
|
2022-09-14 07:50:55 +00:00
|
|
|
// The time when the inode was last changed (i.e., permissions, xattrs
|
|
|
|
// etc changed). This is host-local, not sent over the wire.
|
|
|
|
int64 inode_change_ns = 1002;
|
|
|
|
|
2023-03-10 13:14:14 +00:00
|
|
|
// The size of the data appended to the encrypted file on disk. This is
|
|
|
|
// host-local, not sent over the wire.
|
|
|
|
int32 encryption_trailer_size = 1003;
|
|
|
|
|
2019-12-08 12:31:26 +00:00
|
|
|
bool deleted = 6;
|
2020-10-02 06:07:05 +00:00
|
|
|
bool invalid = 7 [(ext.goname) = "RawInvalid"];
|
2019-12-08 12:31:26 +00:00
|
|
|
bool no_permissions = 8;
|
2016-07-04 10:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum FileInfoType {
|
2020-10-02 06:07:05 +00:00
|
|
|
FILE_INFO_TYPE_FILE = 0;
|
|
|
|
FILE_INFO_TYPE_DIRECTORY = 1;
|
|
|
|
FILE_INFO_TYPE_SYMLINK_FILE = 2 [deprecated = true];
|
|
|
|
FILE_INFO_TYPE_SYMLINK_DIRECTORY = 3 [deprecated = true];
|
|
|
|
FILE_INFO_TYPE_SYMLINK = 4;
|
2016-07-04 10:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
message BlockInfo {
|
|
|
|
option (gogoproto.goproto_stringer) = false;
|
2019-12-08 12:31:26 +00:00
|
|
|
bytes hash = 3;
|
2016-12-14 23:30:29 +00:00
|
|
|
int64 offset = 1;
|
|
|
|
int32 size = 2;
|
|
|
|
uint32 weak_hash = 4;
|
2016-07-04 10:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
message Vector {
|
2020-10-02 06:07:05 +00:00
|
|
|
repeated Counter counters = 1;
|
2016-07-04 10:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
message Counter {
|
2020-10-02 06:07:05 +00:00
|
|
|
uint64 id = 1 [(ext.goname) = "ID", (ext.gotype) = "ShortID"];
|
2016-07-04 10:40:29 +00:00
|
|
|
uint64 value = 2;
|
|
|
|
}
|
|
|
|
|
2022-07-26 06:24:58 +00:00
|
|
|
message PlatformData {
|
|
|
|
UnixData unix = 1 [(gogoproto.nullable) = true];
|
|
|
|
WindowsData windows = 2 [(gogoproto.nullable) = true];
|
2022-09-14 07:50:55 +00:00
|
|
|
XattrData linux = 3 [(gogoproto.nullable) = true];
|
|
|
|
XattrData darwin = 4 [(gogoproto.nullable) = true];
|
|
|
|
XattrData freebsd = 5 [(gogoproto.nullable) = true, (ext.goname) = "FreeBSD"];
|
|
|
|
XattrData netbsd = 6 [(gogoproto.nullable) = true, (ext.goname) = "NetBSD"];
|
2022-07-26 06:24:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
message UnixData {
|
|
|
|
// The owner name and group name are set when known (i.e., could be
|
|
|
|
// resolved on the source device), while the UID and GID are always set
|
|
|
|
// as they come directly from the stat() call.
|
|
|
|
string owner_name = 1;
|
|
|
|
string group_name = 2;
|
|
|
|
int32 uid = 3 [(ext.goname) = "UID"];
|
|
|
|
int32 gid = 4 [(ext.goname) = "GID"];
|
|
|
|
}
|
|
|
|
|
|
|
|
message WindowsData {
|
|
|
|
// Windows file objects have a single owner, which may be a user or a
|
|
|
|
// group. We keep the name of that account, and a flag to indicate what
|
|
|
|
// type it is.
|
|
|
|
string owner_name = 1;
|
|
|
|
bool owner_is_group = 2;
|
|
|
|
}
|
|
|
|
|
2022-09-14 07:50:55 +00:00
|
|
|
message XattrData {
|
|
|
|
repeated Xattr xattrs = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
message Xattr {
|
|
|
|
string name = 1;
|
|
|
|
bytes value = 2;
|
|
|
|
}
|
|
|
|
|
2016-07-04 10:40:29 +00:00
|
|
|
// Request
|
|
|
|
|
|
|
|
message Request {
|
2020-10-02 06:07:05 +00:00
|
|
|
int32 id = 1 [(ext.goname) = "ID"];
|
2016-07-04 10:40:29 +00:00
|
|
|
string folder = 2;
|
|
|
|
string name = 3;
|
|
|
|
int64 offset = 4;
|
|
|
|
int32 size = 5;
|
|
|
|
bytes hash = 6;
|
|
|
|
bool from_temporary = 7;
|
2018-05-05 08:24:44 +00:00
|
|
|
uint32 weak_hash = 8;
|
2020-11-09 14:33:32 +00:00
|
|
|
int32 block_no = 9;
|
2016-07-04 10:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Response
|
|
|
|
|
|
|
|
message Response {
|
2020-10-02 06:07:05 +00:00
|
|
|
int32 id = 1 [(ext.goname) = "ID"];
|
2016-07-04 10:40:29 +00:00
|
|
|
bytes data = 2;
|
|
|
|
ErrorCode code = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum ErrorCode {
|
2020-10-02 06:07:05 +00:00
|
|
|
ERROR_CODE_NO_ERROR = 0;
|
|
|
|
ERROR_CODE_GENERIC = 1;
|
|
|
|
ERROR_CODE_NO_SUCH_FILE = 2;
|
|
|
|
ERROR_CODE_INVALID_FILE = 3;
|
2016-07-04 10:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DownloadProgress
|
|
|
|
|
|
|
|
message DownloadProgress {
|
|
|
|
string folder = 1;
|
2020-10-02 06:07:05 +00:00
|
|
|
repeated FileDownloadProgressUpdate updates = 2;
|
2016-07-04 10:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
message FileDownloadProgressUpdate {
|
|
|
|
FileDownloadProgressUpdateType update_type = 1;
|
|
|
|
string name = 2;
|
2020-10-02 06:07:05 +00:00
|
|
|
Vector version = 3;
|
2017-01-03 00:16:21 +00:00
|
|
|
repeated int32 block_indexes = 4 [packed=false];
|
2020-05-11 13:07:06 +00:00
|
|
|
int32 block_size = 5;
|
2016-07-04 10:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum FileDownloadProgressUpdateType {
|
2020-10-02 06:07:05 +00:00
|
|
|
FILE_DOWNLOAD_PROGRESS_UPDATE_TYPE_APPEND = 0;
|
|
|
|
FILE_DOWNLOAD_PROGRESS_UPDATE_TYPE_FORGET = 1;
|
2016-07-04 10:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ping
|
|
|
|
|
|
|
|
message Ping {
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close
|
|
|
|
|
|
|
|
message Close {
|
|
|
|
string reason = 1;
|
|
|
|
}
|
|
|
|
|