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
use crate::StorageService;
use bytes::Bytes;
use openvet_common::{rust::*, storage::*, tree::Node};
use semver::Version;
use std::{
    collections::{BTreeMap, BTreeSet},
    sync::Arc,
};
use tarpc::context::Context;
use tokio::sync::Mutex;
use tracing::*;

#[derive(Clone, Debug)]
pub struct StorageHandler {
    service: StorageService,
}

impl StorageHandler {
    pub fn new(service: StorageService) -> Self {
        Self { service }
    }
}

impl Storage for StorageHandler {
    async fn ping(self, _: Context, message: String) -> String {
        message
    }

    async fn version(self, _: Context) -> Version {
        // TODO: make this version of openvet_common crate
        env!("CARGO_PKG_VERSION").parse().unwrap()
    }

    async fn crate_list(self, _: Context) -> BTreeSet<CrateName> {
        Default::default()
    }

    async fn crate_info(self, _: Context, krate: CrateName) -> Option<CrateInfo> {
        Default::default()
    }

    #[instrument(skip(self, info))]
    async fn crate_write(self, _: Context, info: CrateInfo) {
        let result = self.service.crate_sync(info).await;
        if let Err(error) = result {
            error!("{error}");
        }
    }

    async fn object_get(self, _: Context, hash: Checksum) -> Option<Bytes> {
        Default::default()
    }

    async fn object_exists(self, _: Context, hash: Checksum) -> bool {
        false
    }

    async fn object_write(self, _: Context, bytes: Bytes) -> Checksum {
        todo!()
    }

    async fn object_gc(self, _: Context) {}

    async fn sources_missing(self, _: Context, limit: usize) -> BTreeSet<CrateVersion> {
        Default::default()
    }

    async fn crate_tree_write(self, _: Context, krate: CrateVersion, root: Node) {}
}