Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_o3db_sync/src/base/iop.rs

5.1 KiB, 29 runs

created by r1870400018:727, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1use crate::{
2 O3db,
3 prelude::*,
4};
5
6use oxedyne_fe2o3_core::prelude::*;
7use oxedyne_fe2o3_iop_crypto::enc::Encrypter;
8use oxedyne_fe2o3_iop_db::api::{
9 Meta,
10 Database,
11 RestSchemesOverride,
12 ScanOpts,
13};
14use oxedyne_fe2o3_iop_hash::{
15 api::Hasher,
16 csum::Checksummer,
17};
18use oxedyne_fe2o3_jdat::{
19 prelude::*,
20 id::NumIdDat,
21};
22use oxedyne_fe2o3_namex::id::{
23 InNamex,
24 NamexId,
25};
26
27use std::{
28 sync::{
29 Arc,
30 RwLock,
31 },
32};
33
34
35impl<
36 const UIDL: usize, // User identifier byte length.
37 UID: NumIdDat<UIDL> + 'static, // User identifier.
38 ENC: Encrypter + 'static, // Symmetric encryption of data at rest.
39 KH: Hasher + 'static, // Hashes database keys.
40 PR: Hasher + 'static, // Pseudo-randomiser hash to distribute cache data.
41 CS: Checksummer + 'static, // Checks integrity of data at rest.
42>
43 Database<UIDL, UID, ENC, KH> for O3db<UIDL, UID, ENC, KH, PR, CS>
44{
45 fn insert(
46 &self,
47 key: Dat,
48 val: Dat,
49 user: UID,
50 or: Option<&RestSchemesOverride<ENC, KH>>,
51 )
52 -> Outcome<(bool, usize)>
53 {
54 let resp = res!(self.api().put(
55 key,
56 val,
57 user,
58 or,
59 ));
60 resp.recv_store_ack()
61 }
62
63 fn get(
64 &self,
65 key: &Dat,
66 or: Option<&RestSchemesOverride<ENC, KH>>,
67 )
68 -> Outcome<Option<(Dat, Meta<UIDL, UID>)>>
69 {
70 self.api().get_wait(
71 key,
72 or,
73 )
74 }
75
76 fn delete(
77 &self,
78 key: &Dat,
79 user: UID,
80 or: Option<&RestSchemesOverride<ENC, KH>>,
81 )
82 -> Outcome<bool>
83 {
84 let resp = self.api().responder();
85 res!(self.api().delete_using_responder(
86 key,
87 user,
88 or,
89 resp.clone(),
90 ));
91 resp.recv_delete_ack()
92 }
93
94 fn scan(
95 &self,
96 opts: &ScanOpts,
97 or: Option<&RestSchemesOverride<ENC, KH>>,
98 )
99 -> Outcome<Vec<(Dat, Dat, Meta<UIDL, UID>)>>
100 {
101 self.api().scan(opts, or)
102 }
103}
104
105/// `LocalOzoneApi` is unfortunately necessary to satisfy the compiler regarding E0210.
106#[derive(Debug)]
107struct LocalOzoneApi<
108 const UIDL: usize,
109 UID: NumIdDat<UIDL> + 'static,
110 ENC: Encrypter + 'static,
111 KH: Hasher + 'static,
112 PR: Hasher + 'static,
113 CS: Checksummer + 'static,
114>(Arc<RwLock<OzoneApi<UIDL, UID, ENC, KH, PR, CS>>>);
115
116impl<
117 const UIDL: usize,
118 UID: NumIdDat<UIDL> + 'static,
119 ENC: Encrypter + 'static,
120 KH: Hasher + 'static,
121 PR: Hasher + 'static,
122 CS: Checksummer + 'static,
123>
124 InNamex for LocalOzoneApi<UIDL, UID, ENC, KH, PR, CS>
125{
126 fn name_id(&self) -> Outcome<NamexId> {
127 let unlocked_api = lock_read!(self.0);
128 unlocked_api.name_id()
129 }
130}
131
132impl<
133 const UIDL: usize,
134 UID: NumIdDat<UIDL> + 'static,
135 ENC: Encrypter + 'static,
136 KH: Hasher + 'static,
137 PR: Hasher + 'static,
138 CS: Checksummer + 'static,
139>
140 std::ops::Deref for LocalOzoneApi<UIDL, UID, ENC, KH, PR, CS>
141{
142 type Target = Arc<RwLock<OzoneApi<UIDL, UID, ENC, KH, PR, CS>>>;
143
144 fn deref(&self) -> &Self::Target {
145 &self.0
146 }
147}
148
149impl<
150 const UIDL: usize, // User identifier byte length.
151 UID: NumIdDat<UIDL> + 'static, // User identifier.
152 ENC: Encrypter + 'static, // Symmetric encryption of data at rest.
153 KH: Hasher + 'static, // Hashes database keys.
154 PR: Hasher + 'static, // Pseudo-randomiser hash to distribute cache data.
155 CS: Checksummer + 'static, // Checks integrity of data at rest.
156>
157 Database<UIDL, UID, ENC, KH> for LocalOzoneApi<UIDL, UID, ENC, KH, PR, CS>
158{
159 fn insert(
160 &self,
161 key: Dat,
162 val: Dat,
163 user: UID,
164 or: Option<&RestSchemesOverride<ENC, KH>>,
165 )
166 -> Outcome<(bool, usize)>
167 {
168 let unlocked_api = lock_read!(self.0);
169 let resp = res!(unlocked_api.put(
170 key,
171 val,
172 user,
173 or,
174 ));
175 resp.recv_store_ack()
176 }
177
178 fn get(
179 &self,
180 key: &Dat,
181 or: Option<&RestSchemesOverride<ENC, KH>>,
182 )
183 -> Outcome<Option<(Dat, Meta<UIDL, UID>)>>
184 {
185 let unlocked_api = lock_read!(self.0);
186 unlocked_api.get_wait(
187 key,
188 or,
189 )
190 }
191
192 fn delete(
193 &self,
194 key: &Dat,
195 user: UID,
196 or: Option<&RestSchemesOverride<ENC, KH>>,
197 )
198 -> Outcome<bool>
199 {
200 let unlocked_api = lock_read!(self.0);
201 let resp = unlocked_api.responder();
202 res!(unlocked_api.delete_using_responder(
203 key,
204 user,
205 or,
206 resp.clone(),
207 ));
208 resp.recv_delete_ack()
209 }
210
211 fn scan(
212 &self,
213 opts: &ScanOpts,
214 or: Option<&RestSchemesOverride<ENC, KH>>,
215 )
216 -> Outcome<Vec<(Dat, Dat, Meta<UIDL, UID>)>>
217 {
218 let unlocked_api = lock_read!(self.0);
219 unlocked_api.scan(opts, or)
220 }
221}