-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathkeydb.h
More file actions
61 lines (53 loc) · 1.91 KB
/
keydb.h
File metadata and controls
61 lines (53 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
key database structure
*/
#pragma once
#include <stdint.h>
#include <stddef.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <tdb.h>
#define KEY_FILE "keys.tdb"
#define KEY_MAGIC 0x6b73e867a72cdd1fULL
/*
Append-only forward-compatible record layout.
- New fields are appended at the end. Existing field offsets/sizes never change.
- Readers accept any record of size >= KEYENTRY_MIN_SIZE (the size of the
pre-flags layout). Bytes beyond what the reader's sizeof(KeyEntry) covers
are ignored on read; bytes missing from the on-disk record are zero-padded.
- Writers preserve any trailing bytes the on-disk record had beyond their
sizeof(KeyEntry), so older code never truncates fields added by newer code.
*/
#define KEYENTRY_MIN_SIZE 96
/*
flag bits
*/
#define KEY_FLAG_ADMIN (1u << 0)
#define KEY_FLAG_BIDI_SIGN (1u << 1) // require signed MAVLink on the user side too
#define KEY_FLAG_TLOG (1u << 2) // record per-connection MAVProxy-format tlogs
#define KEY_FLAG_BINLOG (1u << 3) // record ArduPilot bin logs over MAVLink
struct KeyEntry {
uint64_t magic;
uint64_t timestamp;
uint8_t secret_key[32];
int port1;
uint32_t connections;
uint32_t count1;
uint32_t count2;
char name[32];
uint32_t flags;
float log_retention_days; // tlog + bin; 0.0 = forever; fractional values allowed for tests
uint32_t fc_sysid; // 0 = match any; otherwise only monitor packets from this MAVLink sysid (binlog reboot detection)
uint32_t reserved[15];
};
/*
open DB with or without a transaction
*/
TDB_CONTEXT *db_open(void);
void db_close(TDB_CONTEXT *db);
TDB_CONTEXT *db_open_transaction(void);
void db_close_cancel(TDB_CONTEXT *db);
void db_close_commit(TDB_CONTEXT *db);
bool db_load_key(TDB_CONTEXT *tdb, int port2, struct KeyEntry &key);
bool db_save_key(TDB_CONTEXT *tdb, int port2, const struct KeyEntry &key);