diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-09-17 17:15:58 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-09-18 10:14:15 +0200 |
commit | 702d7c5dc4dfff8bb591bc87f33c968bb52cd33c (patch) | |
tree | 5a3b94b47209fff400fff4b0b3c6ad5b4856abb3 /store | |
parent | f356ef30a2ccfee2b63db8b9439d5b1898f97d9a (diff) |
store: Rename store::Store to Mapping.
- Fixes #88.
Diffstat (limited to 'store')
-rw-r--r-- | store/src/backend/log.rs | 44 | ||||
-rw-r--r-- | store/src/backend/mod.rs | 136 | ||||
-rw-r--r-- | store/src/lib.rs | 339 | ||||
-rw-r--r-- | store/src/store_protocol.capnp | 12 | ||||
-rw-r--r-- | store/tests/ipc-policy.rs | 10 |
5 files changed, 270 insertions, 271 deletions
diff --git a/store/src/backend/log.rs b/store/src/backend/log.rs index a2ddcf4b..b853fa28 100644 --- a/store/src/backend/log.rs +++ b/store/src/backend/log.rs @@ -4,13 +4,13 @@ use rusqlite::{Connection, types::ToSql}; use super::{ ID, Timestamp, Rc, Result, node, - StoreServer, BindingServer, KeyServer, + MappingServer, BindingServer, KeyServer, Promise, capnp, capnp_rpc }; /// Models entries referring to other objects. pub struct Refers { - store: Option<ID>, + mapping: Option<ID>, binding: Option<ID>, key: Option<ID>, } @@ -18,12 +18,12 @@ pub struct Refers { impl Refers { /// Builds an empty object. pub fn to() -> Self { - Refers{store: None, binding: None, key: None} + Refers{mapping: None, binding: None, key: None} } - /// Makes log refer a store. - pub fn store(mut self, id: ID) -> Self { - self.store = Some(id); + /// Makes log refer a mapping. + pub fn mapping(mut self, id: ID) -> Self { + self.mapping = Some(id); self } @@ -59,10 +59,10 @@ fn log(c: &Rc<Connection>, refers: Refers, slug: &str, message: &str, error: Option<&str>) -> Result<ID> { c.execute("INSERT INTO log - (timestamp, level, store, binding, key, slug, message, error) + (timestamp, level, mapping, binding, key, slug, message, error) VALUES (?1, 0, ?2, ?3, ?4, ?5, ?6, ?7)", &[&Timestamp::now() as &ToSql, - &refers.store, &refers.binding, &refers.key, + &refers.mapping, &refers.binding, &refers.key, &slug, &message, &error])?; Ok(c.last_insert_rowid().into()) } @@ -70,7 +70,7 @@ fn log(c: &Rc<Connection>, refers: Refers, /// Selects log entries to iterate over. pub enum Selector { All, - Store(ID), + Mapping(ID), Binding(ID), Key(ID), } @@ -97,7 +97,7 @@ impl node::log_iter::Server for IterServer { let ( id, timestamp, - store, binding, key, + mapping, binding, key, slug, message, error ): ( ID, Timestamp, @@ -107,7 +107,7 @@ impl node::log_iter::Server for IterServer { Selector::All => self.c.query_row( "SELECT id, timestamp, - store, binding, key, + mapping, binding, key, slug, message, error FROM log WHERE id < ?1 @@ -117,18 +117,18 @@ impl node::log_iter::Server for IterServer { row.get(2)?, row.get(3)?, row.get(4)?, row.get(5)?, row.get(6)?, row.get(7)?))), - Selector::Store(store) => + Selector::Mapping(mapping) => self.c.query_row( "SELECT id, timestamp, - store, binding, key, + mapping, binding, key, slug, message, error FROM log WHERE id < ?1 - AND (store = ?2 - OR binding IN (SELECT id FROM bindings WHERE store = ?2) - OR key IN (SELECT key FROM bindings WHERE store = ?2)) + AND (mapping = ?2 + OR binding IN (SELECT id FROM bindings WHERE mapping = ?2) + OR key IN (SELECT key FROM bindings WHERE mapping = ?2)) ORDER BY id DESC LIMIT 1", - &[&self.n, &store], + &[&self.n, &mapping], |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?, row.get(3)?, row.get(4)?, row.get(5)?, row.get(6)?, row.get(7)?))), @@ -136,7 +136,7 @@ impl node::log_iter::Server for IterServer { Selector::Binding(binding) => self.c.query_row( "SELECT id, timestamp, - store, binding, key, + mapping, binding, key, slug, message, error FROM log WHERE id < ?1 @@ -151,7 +151,7 @@ impl node::log_iter::Server for IterServer { Selector::Key(key) => self.c.query_row( "SELECT id, timestamp, - store, binding, key, + mapping, binding, key, slug, message, error FROM log WHERE id < ?1 @@ -166,9 +166,9 @@ impl node::log_iter::Server for IterServer { let mut entry = pry!(results.get().get_result()).init_ok(); entry.set_timestamp(timestamp.unix()); - if let Some(store) = store { - entry.set_store(node::store::ToClient::new( - StoreServer::new(self.c.clone(), store)) + if let Some(mapping) = mapping { + entry.set_mapping(node::mapping::ToClient::new( + MappingServer::new(self.c.clone(), mapping)) .into_client::<capnp_rpc::Server>()); } diff --git a/store/src/backend/mod.rs b/store/src/backend/mod.rs index d9b3b62c..64c066fb 100644 --- a/store/src/backend/mod.rs +++ b/store/src/backend/mod.rs @@ -149,12 +149,12 @@ impl node::Server for NodeServer { // XXX maybe check ephemeral and use in-core sqlite db - let store = sry!(StoreServer::open(self.c.clone(), + let mapping = sry!(MappingServer::open(self.c.clone(), pry!(params.get_realm()), pry!(params.get_network_policy()).into(), pry!(params.get_name()))); pry!(pry!(results.get().get_result()).set_ok( - node::store::ToClient::new(store).into_client::<capnp_rpc::Server>())); + node::mapping::ToClient::new(mapping).into_client::<capnp_rpc::Server>())); Promise::ok(()) } @@ -164,9 +164,9 @@ impl node::Server for NodeServer { -> Promise<(), capnp::Error> { bind_results!(results); let prefix = pry!(pry!(params.get()).get_realm_prefix()); - let iter = StoreIterServer::new(self.c.clone(), prefix); + let iter = MappingIterServer::new(self.c.clone(), prefix); pry!(pry!(results.get().get_result()).set_ok( - node::store_iter::ToClient::new(iter).into_client::<capnp_rpc::Server>())); + node::mapping_iter::ToClient::new(iter).into_client::<capnp_rpc::Server>())); Promise::ok(()) } @@ -261,14 +261,14 @@ impl node::Server for NodeServer { } } -struct StoreServer { +struct MappingServer { c: Rc<Connection>, id: ID, } -impl Query for StoreServer { +impl Query for MappingServer { fn table_name() -> &'static str { - "stores" + "mappings" } fn id(&self) -> ID { @@ -281,7 +281,7 @@ impl Query for StoreServer { fn slug(&self) -> String { self.c.query_row( - "SELECT realm, name FROM stores WHERE id = ?1", + "SELECT realm, name FROM mappings WHERE id = ?1", &[&self.id], |row| -> rusqlite::Result<String> { Ok(format!("{}:{}", row.get::<_, String>(0)?, @@ -293,9 +293,9 @@ impl Query for StoreServer { } } -impl StoreServer { - fn new(c: Rc<Connection>, id: ID) -> StoreServer { - StoreServer{c: c, id: id} +impl MappingServer { + fn new(c: Rc<Connection>, id: ID) -> MappingServer { + MappingServer{c: c, id: id} } fn open(c: Rc<Connection>, realm: &str, policy: core::NetworkPolicy, name: &str) @@ -305,22 +305,22 @@ impl StoreServer { let p: u8 = (&policy).into(); c.execute( - "INSERT OR IGNORE INTO stores (realm, network_policy, name) VALUES (?1, ?2, ?3)", + "INSERT OR IGNORE INTO mappings (realm, network_policy, name) VALUES (?1, ?2, ?3)", &[&realm as &ToSql, &p, &name])?; - let (id, store_policy): (ID, i64) = c.query_row( - "SELECT id, network_policy FROM stores WHERE realm = ?1 AND name = ?2", + let (id, mapping_policy): (ID, i64) = c.query_row( + "SELECT id, network_policy FROM mappings WHERE realm = ?1 AND name = ?2", &[&realm, &name], |row| Ok((row.get(0)?, row.get(1)?)))?; // We cannot implement FromSql and friends for // core::NetworkPolicy, hence we need to do it by foot. - if store_policy < 0 || store_policy > 3 { + if mapping_policy < 0 || mapping_policy > 3 { return Err(super::Error::ProtocolError.into()); } - let store_policy = core::NetworkPolicy::from(store_policy as u8); + let mapping_policy = core::NetworkPolicy::from(mapping_policy as u8); - if store_policy != policy { - return Err(core::Error::NetworkPolicyViolation(store_policy) + if mapping_policy != policy { + return Err(core::Error::NetworkPolicyViolation(mapping_policy) .into()); } @@ -328,10 +328,10 @@ impl StoreServer { } } -impl node::store::Server for StoreServer { +impl node::mapping::Server for MappingServer { fn add(&mut self, - params: node::store::AddParams, - mut results: node::store::AddResults) + params: node::mapping::AddParams, + mut results: node::mapping::AddResults) -> Promise<(), capnp::Error> { bind_results!(results); let params = pry!(params.get()); @@ -346,7 +346,7 @@ impl node::store::Server for StoreServer { if created { sry!(log::message( &self.c, - log::Refers::to().store(self.id).binding(binding_id).key(key_id), + log::Refers::to().mapping(self.id).binding(binding_id).key(key_id), &self.slug(), &format!("New binding {} -> {}", label, fp.to_keyid()))); } @@ -360,15 +360,15 @@ impl node::store::Server for StoreServer { } fn lookup(&mut self, - params: node::store::LookupParams, - mut results: node::store::LookupResults) + params: node::mapping::LookupParams, + mut results: node::mapping::LookupResults) -> Promise<(), capnp::Error> { bind_results!(results); let label = pry!(pry!(params.get()).get_label()); let binding_id: ID = sry!( self.c.query_row( - "SELECT id FROM bindings WHERE store = ?1 AND label = ?2", + "SELECT id FROM bindings WHERE mapping = ?1 AND label = ?2", &[&self.id as &ToSql, &label], |row| row.get(0))); pry!(pry!(results.get().get_result()).set_ok( @@ -379,8 +379,8 @@ impl node::store::Server for StoreServer { } fn lookup_by_subkeyid(&mut self, - params: node::store::LookupBySubkeyidParams, - mut results: node::store::LookupBySubkeyidResults) + params: node::mapping::LookupBySubkeyidParams, + mut results: node::mapping::LookupBySubkeyidResults) -> Promise<(), capnp::Error> { bind_results!(results); let keyid = pry!(params.get()).get_keyid(); @@ -400,18 +400,18 @@ impl node::store::Server for StoreServer { } fn delete(&mut self, - _: node::store::DeleteParams, - mut results: node::store::DeleteResults) + _: node::mapping::DeleteParams, + mut results: node::mapping::DeleteResults) -> Promise<(), capnp::Error> { bind_results!(results); - sry!(self.c.execute("DELETE FROM stores WHERE id = ?1", + sry!(self.c.execute("DELETE FROM mappings WHERE id = ?1", &[&self.id])); Promise::ok(()) } fn iter(&mut self, - _: node::store::IterParams, - mut results: node::store::IterResults) + _: node::mapping::IterParams, + mut results: node::mapping::IterResults) -> Promise<(), capnp::Error> { bind_results!(results); let iter = BindingIterServer::new(self.c.clone(), self.id); @@ -421,11 +421,11 @@ impl node::store::Server for StoreServer { } fn log(&mut self, - _: node::store::LogParams, - mut results: node::store::LogResults) + _: node::mapping::LogParams, + mut results: node::mapping::LogResults) -> Promise<(), capnp::Error> { bind_results!(results); - let iter = log::IterServer::new(self.c.clone(), log::Selector::Store(self.id)); + let iter = log::IterServer::new(self.c.clone(), log::Selector::Mapping(self.id)); pry!(pry!(results.get().get_result()).set_ok( node::log_iter::ToClient::new(iter).into_client::<capnp_rpc::Server>())); Promise::ok(()) @@ -454,12 +454,12 @@ impl BindingServer { /// /// On success, the id of the binding and the key is returned, and /// whether or not the entry was just created. - fn lookup_or_create(c: &Connection, store: ID, label: &str, fp: &Fingerprint) + fn lookup_or_create(c: &Connection, mapping: ID, label: &str, fp: &Fingerprint) -> Result<(ID, ID, bool)> { let key_id = KeyServer::lookup_or_create(c, fp)?; if let Ok((binding, key)) = c.query_row( - "SELECT id, key FROM bindings WHERE store = ?1 AND label = ?2", - &[&store as &ToSql, &label], + "SELECT id, key FROM bindings WHERE mapping = ?1 AND label = ?2", + &[&mapping as &ToSql, &label], |row| -> rusqlite::Result<(ID, ID)> { Ok((row.get(0)?, row.get(1)?)) }) @@ -471,9 +471,9 @@ impl BindingServer { } } else { let r = c.execute( - "INSERT INTO bindings (store, label, key, created) + "INSERT INTO bindings (mapping, label, key, created) VALUES (?, ?, ?, ?)", - &[&store as &ToSql, &label, &key_id, &Timestamp::now()]); + &[&mapping as &ToSql, &label, &key_id, &Timestamp::now()]); // Some other mutator might race us to the insertion. match r { @@ -481,8 +481,8 @@ impl BindingServer { // We lost. Retry the lookup. rusqlite::ErrorCode::ConstraintViolation => { let (binding, key): (ID, ID) = c.query_row( - "SELECT id, key FROM bindings WHERE store = ?1 AND label = ?2", - &[&store as &ToSql, &label], + "SELECT id, key FROM bindings WHERE mapping = ?1 AND label = ?2", + &[&mapping as &ToSql, &label], |row| Ok((row.get(0)?, row.get(1)?)))?; if key == key_id { Ok((binding, key_id, false)) @@ -863,8 +863,8 @@ impl KeyServer { c.query_row( "SELECT keys.update_at FROM keys JOIN bindings on keys.id = bindings.key - JOIN stores on stores.id = bindings.store - WHERE stores.network_policy = ?1 + JOIN mappings on mappings.id = bindings.mapping + WHERE mappings.network_policy = ?1 ORDER BY keys.update_at LIMIT 1", &[&network_policy_u8], |row| -> rusqlite::Result<Timestamp> { row.get(0) @@ -879,8 +879,8 @@ impl KeyServer { let count: i64 = c.query_row( "SELECT COUNT(*) FROM keys JOIN bindings on keys.id = bindings.key - JOIN stores on stores.id = bindings.store - WHERE stores.network_policy >= ?1", + JOIN mappings on mappings.id = bindings.mapping + WHERE mappings.network_policy >= ?1", &[&network_policy_u8], |row| row.get(0))?; assert!(count >= 0); Ok(count as i32) @@ -899,8 +899,8 @@ impl KeyServer { let (id, fingerprint): (ID, String) = c.query_row( "SELECT keys.id, keys.fingerprint FROM keys JOIN bindings on keys.id = bindings.key - JOIN stores on stores.id = bindings.store - WHERE stores.network_policy >= ?1 + JOIN mappings on mappings.id = bindings.mapping + WHERE mappings.network_policy >= ?1 AND keys.update_at < ?2 ORDER BY keys.update_at LIMIT 1", &[&network_policy_u8 as &ToSql, &Timestamp::now()], @@ -1125,27 +1125,27 @@ trait Query { /* Iterators. */ -struct StoreIterServer { +struct MappingIterServer { c: Rc<Connection>, prefix: String, n: ID, } -impl StoreIterServer { +impl MappingIterServer { fn new(c: Rc<Connection>, prefix: &str) -> Self { - StoreIterServer{c: c, prefix: String::from(prefix) + "%", n: ID::null()} + MappingIterServer{c: c, prefix: String::from(prefix) + "%", n: ID::null()} } } -impl node::store_iter::Server for StoreIterServer { +impl node::mapping_iter::Server for MappingIterServer { fn next(&mut self, - _: node::store_iter::NextParams, - mut results: node::store_iter::NextResults) + _: node::mapping_iter::NextParams, + mut results: node::mapping_iter::NextResults) -> Promise<(), capnp::Error> { bind_results!(results); let (id, realm, name, network_policy): (ID, String, String, i64) = sry!(self.c.query_row( - "SELECT id, realm, name, network_policy FROM stores + "SELECT id, realm, name, network_policy FROM mappings WHERE id > ?1 AND realm like ?2 ORDER BY id LIMIT 1", &[&self.n as &ToSql, &self.prefix], @@ -1162,8 +1162,8 @@ impl node::store_iter::Server for StoreIterServer { entry.set_realm(&realm); entry.set_name(&name); entry.set_network_policy(network_policy.into()); - entry.set_store(node::store::ToClient::new( - StoreServer::new(self.c.clone(), id)).into_client::<capnp_rpc::Server>()); + entry.set_mapping(node::mapping::ToClient::new( + MappingServer::new(self.c.clone(), id)).into_client::<capnp_rpc::Server>()); self.n = id; Promise::ok(()) } @@ -1171,13 +1171,13 @@ impl node::store_iter::Server for StoreIterServer { struct BindingIterServer { c: Rc<Connection>, - store_id: ID, + mapping_id: ID, n: ID, } impl BindingIterServer { - fn new(c: Rc<Connection>, store_id: ID) -> Self { - BindingIterServer{c: c, store_id: store_id, n: ID::null()} + fn new(c: Rc<Connection>, mapping_id: ID) -> Self { + BindingIterServer{c: c, mapping_id: mapping_id, n: ID::null()} } } @@ -1191,9 +1191,9 @@ impl node::binding_iter::Server for BindingIterServer { sry!(self.c.query_row( "SELECT bindings.id, bindings.label, keys.fingerprint FROM bindings JOIN keys ON bindings.key = keys.id - WHERE bindings.id > ?1 AND bindings.store = ?2 + WHERE bindings.id > ?1 AND bindings.mapping = ?2 ORDER BY bindings.id LIMIT 1", - &[&self.n, &self.store_id], + &[&self.n, &self.mapping_id], |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)))); let mut entry = pry!(results.get().get_result()).init_ok(); @@ -1371,7 +1371,7 @@ CREATE TABLE version ( INSERT INTO version (id, version) VALUES (1, 1); -CREATE TABLE stores ( +CREATE TABLE mappings ( id INTEGER PRIMARY KEY, realm TEXT NOT NULL, network_policy INTEGER NOT NULL, @@ -1380,7 +1380,7 @@ CREATE TABLE stores ( CREATE TABLE bindings ( id INTEGER PRIMARY KEY, - store INTEGER NOT NULL, + mapping INTEGER NOT NULL, label TEXT NOT NULL, key INTEGER NOT NULL, @@ -1394,8 +1394,8 @@ CREATE TABLE bindings ( verification_first INTEGER NULL, verification_last INTEGER NULL, - UNIQUE(store, label), - FOREIGN KEY (store) REFERENCES stores(id) ON DELETE CASCADE, + UNIQUE(mapping, label), + FOREIGN KEY (mapping) REFERENCES mappings(id) ON DELETE CASCADE, FOREIGN KEY (key) REFERENCES keys(id) ON DELETE CASCADE); CREATE TABLE keys ( @@ -1428,13 +1428,13 @@ CREATE TABLE log ( id INTEGER PRIMARY KEY, timestamp INTEGER NOT NULL, level INTEGER NOT NULL, - store INTEGER NULL, + mapping INTEGER NULL, binding INTEGER NULL, key INTEGER NULL, slug TEXT NOT NULL, message TEXT NOT NULL, error TEXT NULL, - FOREIGN KEY (store) REFERENCES stores(id) ON DELETE CASCADE, + FOREIGN KEY (mapping) REFERENCES mappings(id) ON DELETE CASCADE, FOREIGN KEY (binding) REFERENCES bindings(id) ON DELETE CASCADE, FOREIGN KEY (key) REFERENCES keys(id) ON DELETE CASCADE); "; diff --git a/store/src/lib.rs b/store/src/lib.rs index 54fc8661..fdb52439 100644 --- a/store/src/lib.rs +++ b/store/src/lib.rs @@ -12,7 +12,7 @@ //! of scope for Sequoia. Please take the necessary precautions. //! //! Sequoia updates keys in compliance with the [network policy] used -//! to create the store. +//! to create the mapping. //! //! [network policy]: ../sequoia_core/enum.NetworkPolicy.html //! @@ -31,10 +31,10 @@ //! # .network_policy(NetworkPolicy::Offline) //! # .ipc_policy(IPCPolicy::Internal) //! # .ephemeral().build()?; -//! let store = Store::open(&ctx, REALM_CONTACTS, "default")?; +//! let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default")?; //! //! let fp = Fingerprint::from_bytes(b"bbbbbbbbbbbbbbbbbbbb"); -//! let binding = store.add("Mister B.", &fp)?; +//! let binding = mapping.add("Mister B.", &fp)?; //! //! println!("Binding {:?}", binding.stats()?); //! // prints: @@ -120,6 +120,24 @@ pub struct Pool { } impl Pool { + /// Establishes a connection to the backend. + fn connect(c: &Context) -> Result<(Core, node::Client)> { + let descriptor = descriptor(c); + let core = Core::new()?; + let handle = core.handle(); + + let mut rpc_system + = match descriptor.connect(&handle) { + Ok(r) => r, + Err(e) => return Err(e.into()), + }; + + let client: node::Client = rpc_system.bootstrap(Side::Server); + handle.spawn(rpc_system.map_err(|_e| ())); + + Ok((core, client)) + } + /// Imports a key into the common key pool. /// /// # Example @@ -149,7 +167,7 @@ impl Pool { let mut blob = vec![]; tpk.serialize(&mut blob)?; - let (mut core, client) = Store::connect(c)?; + let (mut core, client) = Self::connect(c)?; let mut request = client.import_request(); request.get().set_key(&blob); let key = make_request!(&mut core, request)?; @@ -183,7 +201,7 @@ impl Pool { /// # } /// ``` pub fn lookup(c: &Context, fp: &Fingerprint) -> Result<Key> { - let (mut core, client) = Store::connect(c)?; + let (mut core, client) = Self::connect(c)?; let mut request = client.lookup_by_fingerprint_request(); let fp = fp.to_hex(); request.get().set_fingerprint(&fp); @@ -218,7 +236,7 @@ impl Pool { /// # } /// ``` pub fn lookup_by_keyid(c: &Context, keyid: &KeyID) -> Result<Key> { - let (mut core, client) = Store::connect(c)?; + let (mut core, client) = Self::connect(c)?; let mut request = client.lookup_by_keyid_request(); request.get().set_keyid(keyid.as_u64()?); let key = make_request!(&mut core, request)?; @@ -269,60 +287,57 @@ impl Pool { /// # } /// ``` pub fn lookup_by_subkeyid(c: &Context, keyid: &KeyID) -> Result<Key> { - let (mut core, client) = Store::connect(c)?; + let (mut core, client) = Self::connect(c)?; let mut request = client.lookup_by_subkeyid_request(); request.get().set_keyid(keyid.as_u64()?); let key = make_request!(&mut core, request)?; Ok(Key::new(Rc::new(RefCell::new(core)), key)) } + /// Lists all keys in the common key pool. + pub fn list_keys(c: &Context) -> Result<KeyIter> { + let (mut core, client) = Self::connect(c)?; + let request = client.iter_keys_request(); + let iter = make_request!(&mut core, request)?; + Ok(KeyIter{core: Rc::new(RefCell::new(core)), iter: iter}) + } + + /// Lists all log entries. + pub fn server_log(c: &Context) -> Result<LogIter> { + let (mut core, client) = Self::connect(c)?; + let request = client.log_request(); + let iter = make_request!(&mut core, request)?; + Ok(LogIter{core: Rc::new(RefCell::new(core)), iter: iter}) + } } /// A public key store. -pub struct Store { +pub struct Mapping { name: String, core: Rc<RefCell<Core>>, - store: node::store::Client, + mapping: node::mapping::Client, } -impl fmt::Debug for Store { +impl fmt::Debug for Mapping { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "Store {{ name: {} }}", self.name) + write!(f, "Mapping {{ name: {} }}", self.name) } } -impl Store { - /// Establishes a connection to the backend. - fn connect(c: &Context) -> Result<(Core, node::Client)> { - let descriptor = descriptor(c); - let core = Core::new()?; - let handle = core.handle(); - - let mut rpc_system - = match descriptor.connect(&handle) { - Ok(r) => r, - Err(e) => return Err(e.into()), - }; - - let client: node::Client = rpc_system.bootstrap(Side::Server); - handle.spawn(rpc_system.map_err(|_e| ())); - - Ok((core, client)) - } - - /// Opens a store. +impl Mapping { + /// Opens a mapping. /// - /// Opens a store with the given name. If the store does not - /// exist, it is created. Stores are handles for objects + /// Opens a mapping with the given name. If the mapping does not + /// exist, it is created. Mappings are handles for objects /// maintained by a background service. The background service /// associates state with this name. /// /// The store updates TPKs in compliance with the network policy - /// of the context that created the store in the first place. - /// Opening the store with a different network policy is + /// of the context that created the mapping in the first place. + /// Opening the mapping with a different network policy is /// forbidden. pub fn open(c: &Context, realm: &str, name: &str) -> Result<Self> { - let (mut core, client) = Self::connect(c)?; + let (mut core, client) = Pool::connect(c)?; let mut request = client.open_request(); request.get().set_realm(realm); @@ -330,40 +345,24 @@ impl Store { request.get().set_ephemeral(c.ephemeral()); request.get().set_name(name); - let store = make_request!(&mut core, request)?; - Ok(Self::new(Rc::new(RefCell::new(core)), name, store)) + let mapping = make_request!(&mut core, request)?; + Ok(Self::new(Rc::new(RefCell::new(core)), name, mapping)) } - fn new(core: Rc<RefCell<Core>>, name: &str, store: node::store::Client) -> Self { - Store{core: core, name: name.into(), store: store} + fn new(core: Rc<RefCell<Core>>, name: &str, mapping: node::mapping::Client) -> Self { + Mapping{core: core, name: name.into(), mapping: mapping} < |