Diff
Not logged in

Differences From Artifact [1d7d4c17d1]:

To Artifact [675721187a]:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
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
..
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
...
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
// Copyright 2016 MaidSafe.net limited.
//
// This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License,
// version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which
// licence you accepted on initial access to the Software (the "Licences").
//
// By contributing code to the SAFE Network Software, or to this project generally, you agree to be
// bound by the terms of the MaidSafe Contributor Agreement, version 1.0.  This, along with the
// Licenses can be found in the root directory of this project at LICENSE, COPYING and CONTRIBUTOR.
//
// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed
// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.
//
// Please review the Licences for the specific language governing permissions and limitations
// relating to use of the SAFE Network Software.
................................................................................
use routing::client_errors::{GetError, MutationError};
use std::collections::HashMap;

// This should ideally be replaced with `safe_vault::maid_manager::DEFAULT_ACCOUNT_SIZE`, but that's
// not exported by Vault currently.
pub const DEFAULT_CLIENT_ACCOUNT_SIZE: u64 = 100;

#[derive(RustcEncodable, RustcDecodable)]
pub struct Storage {
    data_store: HashMap<XorName, Vec<u8>>,
    pub client_accounts: HashMap<XorName, ClientAccount>,
}

impl Storage {
    pub fn new() -> Self {
        sync::load().unwrap_or_else(|| {
            Storage {
                data_store: HashMap::new(),
                client_accounts: HashMap::new(),
            }
        })
    }

    // Check if data with the given name is in the storage.
    pub fn contains_data(&self, name: &XorName) -> bool {
        self.data_store.contains_key(name)
    }

................................................................................

    // Synchronize the storage with the disk.
    pub fn sync(&self) {
        sync::save(self)
    }
}

#[derive(RustcEncodable, RustcDecodable)]
pub struct ClientAccount {
    pub data_stored: u64,
    pub space_available: u64,
}

impl Default for ClientAccount {
    fn default() -> ClientAccount {
................................................................................
    }

    pub fn save(_: &Storage) {}
}

#[cfg(not(test))]
mod sync {

    use maidsafe_utilities::serialisation::{deserialise, serialise};
    use std::env;
    use std::fs::File;
    use std::io::{Read, Write};
    use std::path::PathBuf;
    use super::Storage;

    const STORAGE_FILE_NAME: &'static str = "VaultStorageSimulation";

    pub fn load() -> Option<Storage> {
        if let Ok(mut file) = File::open(path()) {
            let mut raw_disk_data = Vec::with_capacity(unwrap!(file.metadata()).len() as usize);
            if let Ok(_) = file.read_to_end(&mut raw_disk_data) {
                if !raw_disk_data.is_empty() {
                    return deserialise(&raw_disk_data).ok();
                }
            }
        }

        None
    }

    pub fn save(storage: &Storage) {







|
|







 







|








|
|
|
|
|







 







|







 







>





<






|
<
|
<







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
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
..
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
...
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
// Copyright 2016 MaidSafe.net limited.
//
// This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License,
// version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which
// licence you accepted on initial access to the Software (the "Licences").
//
// By contributing code to the SAFE Network Software, or to this project generally, you agree to be
// bound by the terms of the MaidSafe Contributor Agreement.  This, along with the Licenses can be
// found in the root directory of this project at LICENSE, COPYING and CONTRIBUTOR.
//
// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed
// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.
//
// Please review the Licences for the specific language governing permissions and limitations
// relating to use of the SAFE Network Software.
................................................................................
use routing::client_errors::{GetError, MutationError};
use std::collections::HashMap;

// This should ideally be replaced with `safe_vault::maid_manager::DEFAULT_ACCOUNT_SIZE`, but that's
// not exported by Vault currently.
pub const DEFAULT_CLIENT_ACCOUNT_SIZE: u64 = 100;

#[derive(Serialize, Deserialize)]
pub struct Storage {
    data_store: HashMap<XorName, Vec<u8>>,
    pub client_accounts: HashMap<XorName, ClientAccount>,
}

impl Storage {
    pub fn new() -> Self {
        sync::load().unwrap_or_else(|| {
                                        Storage {
                                            data_store: HashMap::new(),
                                            client_accounts: HashMap::new(),
                                        }
                                    })
    }

    // Check if data with the given name is in the storage.
    pub fn contains_data(&self, name: &XorName) -> bool {
        self.data_store.contains_key(name)
    }

................................................................................

    // Synchronize the storage with the disk.
    pub fn sync(&self) {
        sync::save(self)
    }
}

#[derive(Serialize, Deserialize)]
pub struct ClientAccount {
    pub data_stored: u64,
    pub space_available: u64,
}

impl Default for ClientAccount {
    fn default() -> ClientAccount {
................................................................................
    }

    pub fn save(_: &Storage) {}
}

#[cfg(not(test))]
mod sync {
    use super::Storage;
    use maidsafe_utilities::serialisation::{deserialise, serialise};
    use std::env;
    use std::fs::File;
    use std::io::{Read, Write};
    use std::path::PathBuf;


    const STORAGE_FILE_NAME: &'static str = "VaultStorageSimulation";

    pub fn load() -> Option<Storage> {
        if let Ok(mut file) = File::open(path()) {
            let mut raw_disk_data = Vec::with_capacity(unwrap!(file.metadata()).len() as usize);
            if file.read_to_end(&mut raw_disk_data).is_ok() && !raw_disk_data.is_empty() {

                return deserialise(&raw_disk_data).ok();

            }
        }

        None
    }

    pub fn save(storage: &Storage) {