summaryrefslogtreecommitdiff
path: root/systems/_constants/src/lib.rs
blob: d7e4f07b28507d2027d41c8faf570543251dc8ce (plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#[macro_export]
macro_rules! c {
    ($name:ident = $value:expr) => {
        const $name: &str = $value;
    };
}

/// File and directory path constants for the server root
#[allow(unused)]
pub mod server {
    /// File constants
    #[macros::constants("server_file")]
    pub mod files {
        c! { CONFIG = "./config.toml" }
        c! { JOIN_REQUEST_KEY = "./.temp/join_requests/{member_name}.pem" }
        c! { KEY = "./key/{member_name}.pem" }
        c! { MEMBER_METADATA = "./meta/{member_name}.toml" }
    }

    /// Directory path constants
    #[macros::constants("server_dir")]
    pub mod dirs {
        c! { KEYS = "./key/" }
        c! { JOIN_REQUEST_KEYS = "./.temp/join_requests/" }
        c! { MEMBER_METADATAS = "./meta/" }
        c! { VAULTS = "./v/" }
    }
}

/// File and directory path constants for the vault root
#[allow(unused)]
pub mod vault {
    /// File path constants
    #[macros::constants("vault_file")]
    pub mod files {
        // ### Configs ###
        c! { CONFIG = "./vault.toml" }

        // ### Sheets ###

        // Reference sheet
        c! { REFSHEET = "./ref/{ref_sheet_name}.sheet" }

        // Editable instance of a reference sheet, maintained by one of the vault's Hosts, written back to the sheet file after editing
        c! { REFSHEET_EDIT = "./ref/~{ref_sheet_name}.sheet" }

        // Member sheet backup, only used to temporarily store a member's local workspace file structure, fully controlled by the corresponding member
        c! { MEMBER_SHEET_BACKUP = "./_member/{member_name}/backups/{sheet_name}.sheet" }

        // Share sent to a reference sheet, selectively merged into that reference sheet by a Host
        c! { SHARE_TO_REF = "./req/{ref_sheet_name}/{share_id}.sheet" }

        // Share sent to a specific member, fully controlled by that member, who can optionally merge it into any of their own sheets
        c! { SHARE_TO_MEMBER = "./_member/{member_name}/shares/{share_id}.sheet" }

        // ### Storages ###
        c! { CHANGE_FILE = "./changes/CURRENT" }
        c! { CHANGE_FILE_BACKUP = "./changes/backup.{index}" }

        // Whether an index is locked; if the file exists, the member name written inside is the current holder
        c! { INDEX_LOCK = "./index/{index_slice_1}/{index_slice_2}/{index_name}/LOCK" }

        // Editable instance of an index's version sequence, maintained by the holder, written back to the ver file after editing
        c! { INDEX_VER_EDIT = "./index/{index_slice_1}/{index_slice_2}/{index_name}/~ver" }

        // Index version sequence
        c! { INDEX_VER = "./index/{index_slice_1}/{index_slice_2}/{index_name}/ver" }

        // Index
        c! { INDEX = "./index/{index_slice_1}/{index_slice_2}/{index_name}/{version}.index" }

        // Object, file chunk
        c! { OBJ = "./obj/{obj_hash_slice_1}/{obj_hash_slice_2}/{obj_hash}" }
    }

    /// Directory path constants
    #[macros::constants("vault_dir")]
    pub mod dirs {
        c! { REFSHEETS = "./ref/" }
        c! { SHARES_TO_REF = "./req/{ref_sheet_name}/" }
        c! { MEMBER = "./_member/{member_name}/" }
        c! { MEMBER_SHEET_BACKUPS = "./_member/{member_name}/backups/" }
        c! { MEMBER_SHARES = "./_member/{member_name}/shares/" }
        c! { CHANGES = "./changes/" }
    }
}

/// File and directory path constants for the workspace root
#[allow(unused)]
pub mod workspace {
    /// File path constants
    #[macros::constants("workspace_file")]
    pub mod files {
        // ### Config ###
        c! { CONFIG = "./.jv/workspace.toml" }

        // ### Sheets ###
        // Records the latest state of local physical files, used to calculate deviations
        c! { LOCAL_STATUS = "./.jv/sheets/{account}/{sheet}.local" }

        // Personal sheet, represents the desired file structure, held only by the member, can be backed up to the vault
        c! { SHEET = "./.jv/sheets/{account}/{sheet}.sheet" }

        // Draft file, when switching to another sheet, fully records modified but untracked files
        c! { DRAFTED_FILE = "./.jv/drafts/{account}_{sheet}/{mapping}" }

        // Working file
        c! { WORKING_FILE = "./{mapping}" }
    }

    /// Directory path constants
    #[macros::constants("workspace_dir")]
    pub mod dirs {
        c! { WORKSPACE = "./.jv" }
        c! { VAULT_MIRROR = "./.jv/UPSTREAM/" }
        c! { LOCAL_SHEETS = "./.jv/sheets/{account}/" }
        c! { DRAFT_AREA = "./.jv/drafts/{account}_{sheet}/" }
        c! { WORKING_AREA = "./" }
    }
}

/// File and directory path constants for the user root
#[allow(unused)]
pub mod user {
    /// File path constants
    #[macros::constants("user_file")]
    pub mod files {
        // Upstream public key, stored after initial login, used to verify the trustworthiness of that upstream
        c! { UPSTREAM_PUB = "./upstreams/{upstream_addr}.pem" }

        // Account private key, stored only locally, used for login authentication
        c! { PRIVATE_KEY = "./private/{account}.pem" }

        // Account public key, automatically generated from the private key and stored,
        // will be placed into the server's "join request list" upon initial login (if server.toml permits this action)
        // The server administrator can optionally approve this request
        c! { PUBLIC_KEY = "./public/{account}.pem" }
    }

    /// Directory path constants
    #[macros::constants("user_dir")]
    pub mod dirs {
        c! { UPSTREAM_PUBS = "./upstreams/" }
        c! { PRIVATE_KEYS = "./private/" }
        c! { PUBLIC_KEYS = "./public/" }
    }
}