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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
use crate::{prelude::*, GlobalStateAccessMode};
use crate::zone::ZoneRole;
use cyfs_base::*;
use cyfs_core::ZoneId;
use cyfs_core::*;
use cyfs_bdt::SnStatus;
use std::convert::TryFrom;
use serde::{Deserialize, Serialize};
use std::fmt::{self, Display};
use std::path::PathBuf;
use std::str::FromStr;
#[derive(Debug, Clone)]
pub struct UtilOutputRequestCommon {
pub req_path: Option<String>,
pub dec_id: Option<ObjectId>,
pub target: Option<ObjectId>,
pub flags: u32,
}
impl Default for UtilOutputRequestCommon {
fn default() -> Self {
Self {
req_path: None,
dec_id: None,
target: None,
flags: 0,
}
}
}
impl fmt::Display for UtilOutputRequestCommon {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "req_path: {:?}", self.req_path)?;
if let Some(dec_id) = &self.dec_id {
write!(f, ", dec_id: {}", dec_id)?;
}
if let Some(target) = &self.target {
write!(f, ", target: {}", target.to_string())?;
}
write!(f, ", flags: {}", self.flags)?;
Ok(())
}
}
#[derive(Debug, Clone)]
pub struct UtilGetDeviceOutputRequest {
pub common: UtilOutputRequestCommon,
}
impl Display for UtilGetDeviceOutputRequest {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "common: {}", self.common)
}
}
impl UtilGetDeviceOutputRequest {
pub fn new() -> Self {
Self {
common: UtilOutputRequestCommon::default(),
}
}
}
#[derive(Debug, Clone)]
pub struct UtilGetDeviceOutputResponse {
pub device_id: DeviceId,
pub device: Device,
}
impl Display for UtilGetDeviceOutputResponse {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "device_id: {}", self.device_id)
}
}
#[derive(Debug, Clone)]
pub struct UtilGetZoneOutputRequest {
pub common: UtilOutputRequestCommon,
pub object_id: Option<ObjectId>,
pub object_raw: Option<Vec<u8>>,
}
impl UtilGetZoneOutputRequest {
pub fn new(object_id: Option<ObjectId>, object_raw: Option<Vec<u8>>) -> Self {
Self {
common: UtilOutputRequestCommon::default(),
object_id,
object_raw,
}
}
}
impl Display for UtilGetZoneOutputRequest {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "common: {}", self.common)?;
write!(f, "object_id: {:?}", self.object_id)
}
}
#[derive(Debug, Clone)]
pub struct UtilGetZoneOutputResponse {
pub zone_id: ZoneId,
pub zone: Zone,
pub device_id: DeviceId,
}
impl Display for UtilGetZoneOutputResponse {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "zone_id: {}", self.zone_id)?;
write!(f, "device_id: {:?}", self.device_id)
}
}
#[derive(Debug, Clone)]
pub struct UtilResolveOODOutputRequest {
pub common: UtilOutputRequestCommon,
pub object_id: ObjectId,
pub owner_id: Option<ObjectId>,
}
impl UtilResolveOODOutputRequest {
pub fn new(object_id: ObjectId, owner_id: Option<ObjectId>) -> Self {
Self {
common: UtilOutputRequestCommon::default(),
object_id,
owner_id,
}
}
}
impl Display for UtilResolveOODOutputRequest {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "common: {}", self.common)?;
write!(f, "object_id: {:?}", self.object_id)?;
if let Some(owner_id) = &self.owner_id {
write!(f, "owner_id: {:?}", owner_id)?;
}
Ok(())
}
}
#[derive(Debug, Clone)]
pub struct UtilResolveOODOutputResponse {
pub device_list: Vec<DeviceId>,
}
impl Display for UtilResolveOODOutputResponse {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "device_list: {:?}", self.device_list)
}
}
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub enum OODNetworkType {
Unknown,
Intranet,
Extranet,
}
impl Display for OODNetworkType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let v = match self {
Self::Unknown => "unknown",
Self::Intranet => "intranet",
Self::Extranet => "extranet",
};
write!(f, "{}", v)
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct OODStatus {
pub network: OODNetworkType,
pub first_ping: u64,
pub first_success_ping: u64,
pub last_success_ping: u64,
pub last_ping: u64,
pub last_ping_result: u16,
pub ping_count: u32,
pub ping_success_count: u64,
pub cont_fail_count: u64,
pub ping_avg_during: u64,
pub ping_max_during: u64,
pub ping_min_during: u64,
pub ood_device_id: DeviceId,
pub enable_sync: bool,
pub device_root_state: ObjectId,
pub device_root_state_revision: u64,
pub zone_root_state: Option<ObjectId>,
pub zone_root_state_revision: u64,
}
#[derive(Debug, Clone)]
pub struct UtilGetOODStatusOutputRequest {
pub common: UtilOutputRequestCommon,
}
impl Display for UtilGetOODStatusOutputRequest {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "common: {}", self.common)
}
}
impl UtilGetOODStatusOutputRequest {
pub fn new() -> Self {
Self {
common: UtilOutputRequestCommon::default(),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct UtilGetOODStatusOutputResponse {
pub status: OODStatus,
}
impl Display for UtilGetOODStatusOutputResponse {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "status: {:?}", self.status)
}
}
#[derive(Debug, Clone)]
pub struct UtilGetNOCInfoOutputRequest {
pub common: UtilOutputRequestCommon,
}
impl Display for UtilGetNOCInfoOutputRequest {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "common: {}", self.common)
}
}
impl UtilGetNOCInfoOutputRequest {
pub fn new() -> Self {
Self {
common: UtilOutputRequestCommon::default(),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct UtilGetNOCInfoOutputResponse {
pub stat: NamedObjectCacheStat,
}
impl Display for UtilGetNOCInfoOutputResponse {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "stat: {:?}", self.stat)
}
}
#[derive(Debug, Clone)]
pub struct DeviceStaticInfo {
pub device_id: DeviceId,
pub device: Device,
pub is_ood_device: bool,
pub ood_work_mode: OODWorkMode,
pub zone_role: ZoneRole,
pub root_state_access_mode: GlobalStateAccessMode,
pub local_cache_access_mode: GlobalStateAccessMode,
pub ood_device_id: DeviceId,
pub zone_id: ZoneId,
pub owner_id: Option<ObjectId>,
pub cyfs_root: String,
}
#[derive(Debug, Clone)]
pub struct UtilGetDeviceStaticInfoOutputRequest {
pub common: UtilOutputRequestCommon,
}
impl Display for UtilGetDeviceStaticInfoOutputRequest {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "common: {}", self.common)
}
}
impl UtilGetDeviceStaticInfoOutputRequest {
pub fn new() -> Self {
Self {
common: UtilOutputRequestCommon::default(),
}
}
}
#[derive(Debug, Clone)]
pub struct UtilGetDeviceStaticInfoOutputResponse {
pub info: DeviceStaticInfo,
}
impl Display for UtilGetDeviceStaticInfoOutputResponse {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "info: {:?}", self.info)
}
}
#[derive(Debug, Eq, PartialEq, Clone)]
pub enum BdtNetworkAccessType {
NAT,
WAN,
}
impl fmt::Display for BdtNetworkAccessType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let v = match self {
Self::NAT => "nat",
Self::WAN => "wan",
};
write!(f, "{}", v)
}
}
impl FromStr for BdtNetworkAccessType {
type Err = BuckyError;
fn from_str(s: &str) -> BuckyResult<Self> {
match s {
"nat" => Ok(Self::NAT),
"wan" => Ok(Self::WAN),
_ => {
let msg = format!("unknown BdtNetworkAccessType value: {}", s);
error!("{}", msg);
Err(BuckyError::new(BuckyErrorCode::InvalidData, msg))
}
}
}
}
#[derive(Debug, Eq, PartialEq, Clone)]
pub struct BdtNetworkAccessEndpoint {
pub lan_ep: Endpoint,
pub wan_ep: Endpoint,
pub access_type: BdtNetworkAccessType,
}
#[derive(Debug, Eq, PartialEq, Clone)]
pub struct BdtNetworkAccessSn {
pub sn: DeviceId,
pub sn_status: SnStatus,
}
#[derive(Debug, Clone)]
pub struct BdtNetworkAccessInfo {
pub v4: Vec<BdtNetworkAccessEndpoint>,
pub v6: Vec<BdtNetworkAccessEndpoint>,
pub sn: Vec<BdtNetworkAccessSn>,
}
impl Default for BdtNetworkAccessInfo {
fn default() -> Self {
Self {
v4: Vec::new(),
v6: Vec::new(),
sn: Vec::new(),
}
}
}
#[derive(Debug, Clone)]
pub struct UtilGetNetworkAccessInfoOutputRequest {
pub common: UtilOutputRequestCommon,
}
impl Display for UtilGetNetworkAccessInfoOutputRequest {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "common: {}", self.common)
}
}
impl UtilGetNetworkAccessInfoOutputRequest {
pub fn new() -> Self {
Self {
common: UtilOutputRequestCommon::default(),
}
}
}
#[derive(Debug, Clone)]
pub struct UtilGetNetworkAccessInfoOutputResponse {
pub info: BdtNetworkAccessInfo,
}
impl Display for UtilGetNetworkAccessInfoOutputResponse {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "info: {:?}", self.info)
}
}
#[derive(Debug, Clone)]
pub struct UtilGetSystemInfoOutputRequest {
pub common: UtilOutputRequestCommon,
}
impl Display for UtilGetSystemInfoOutputRequest {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "common: {}", self.common)
}
}
impl UtilGetSystemInfoOutputRequest {
pub fn new() -> Self {
Self {
common: UtilOutputRequestCommon::default(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UtilGetSystemInfoOutputResponse {
pub info: cyfs_util::SystemInfo,
}
impl Display for UtilGetSystemInfoOutputResponse {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "info: {:?}", self.info)
}
}
#[derive(Debug, Clone)]
pub struct VersionInfo {
pub version: String,
pub channel: CyfsChannel,
pub target: String,
}
#[derive(Debug, Clone)]
pub struct UtilGetVersionInfoOutputRequest {
pub common: UtilOutputRequestCommon,
}
impl Display for UtilGetVersionInfoOutputRequest {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "common: {}", self.common)
}
}
impl UtilGetVersionInfoOutputRequest {
pub fn new() -> Self {
Self {
common: UtilOutputRequestCommon::default(),
}
}
}
#[derive(Debug, Clone)]
pub struct UtilGetVersionInfoOutputResponse {
pub info: VersionInfo,
}
impl Display for UtilGetVersionInfoOutputResponse {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "info: {:?}", self.info)
}
}
#[derive(Debug, Clone)]
pub struct UtilBuildFileOutputRequest {
pub common: UtilOutputRequestCommon,
pub local_path: PathBuf,
pub owner: ObjectId,
pub chunk_size: u32,
}
pub struct UtilBuildFileOutputResponse {
pub object_id: ObjectId,
pub object_raw: Vec<u8>,
}
#[derive(Debug, Clone, Copy)]
#[repr(u16)]
pub enum BuildDirType {
Zip,
}
impl TryFrom<u16> for BuildDirType {
type Error = BuckyError;
fn try_from(value: u16) -> Result<Self, Self::Error> {
match value {
0 => Ok(BuildDirType::Zip),
v @ _ => {
let msg = format!("unknown build dir type value {}", v);
log::error!("{}", msg.as_str());
Err(BuckyError::new(BuckyErrorCode::InvalidParam, msg))
}
}
}
}
#[derive(Debug, Clone)]
pub struct UtilBuildDirFromObjectMapOutputRequest {
pub common: UtilOutputRequestCommon,
pub object_map_id: ObjectId,
pub dir_type: BuildDirType,
}
pub struct UtilBuildDirFromObjectMapOutputResponse {
pub object_id: ObjectId,
}