From 702d7c5dc4dfff8bb591bc87f33c968bb52cd33c Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Tue, 17 Sep 2019 17:15:58 +0200 Subject: store: Rename store::Store to Mapping. - Fixes #88. --- store/src/backend/log.rs | 44 +++--- store/src/backend/mod.rs | 136 ++++++++--------- store/src/lib.rs | 339 ++++++++++++++++++++--------------------- store/src/store_protocol.capnp | 12 +- 4 files changed, 265 insertions(+), 266 deletions(-) (limited to 'store/src') 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, + mapping: Option, binding: Option, key: Option, } @@ -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, refers: Refers, slug: &str, message: &str, error: Option<&str>) -> Result { 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, 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::()); } 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::())); + node::mapping::ToClient::new(mapping).into_client::())); 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::())); + node::mapping_iter::ToClient::new(iter).into_client::())); Promise::ok(()) } @@ -261,14 +261,14 @@ impl node::Server for NodeServer { } } -struct StoreServer { +struct MappingServer { c: Rc, 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 { Ok(format!("{}:{}", row.get::<_, String>(0)?, @@ -293,9 +293,9 @@ impl Query for StoreServer { } } -impl StoreServer { - fn new(c: Rc, id: ID) -> StoreServer { - StoreServer{c: c, id: id} +impl MappingServer { + fn new(c: Rc, id: ID) -> MappingServer { + MappingServer{c: c, id: id} } fn open(c: Rc, 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::())); 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 { 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, prefix: String, n: ID, } -impl StoreIterServer { +impl MappingIterServer { fn new(c: Rc, 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::()); + entry.set_mapping(node::mapping::ToClient::new( + MappingServer::new(self.c.clone(), id)).into_client::()); self.n = id; Promise::ok(()) } @@ -1171,13 +1171,13 @@ impl node::store_iter::Server for StoreIterServer { struct BindingIterServer { c: Rc, - store_id: ID, + mapping_id: ID, n: ID, } impl BindingIterServer { - fn new(c: Rc, store_id: ID) -> Self { - BindingIterServer{c: c, store_id: store_id, n: ID::null()} + fn new(c: Rc, 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 { - 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 { - 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 { - 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 { + 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 { + 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>, - 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 { - 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>, name: &str, store: node::store::Client) -> Self { - Store{core: core, name: name.into(), store: store} + fn new(core: Rc>, name: &str, mapping: node::mapping::Client) -> Self { + Mapping{core: core, name: name.into(), mapping: mapping} } - /// Lists all stores with the given prefix. - pub fn list(c: &Context, realm_prefix: &str) -> Result { - let (mut core, client) = Self::connect(c)?; + /// Lists all mappings with the given prefix. + pub fn list(c: &Context, realm_prefix: &str) -> Result { + let (mut core, client) = Pool::connect(c)?; let mut request = client.iter_request(); request.get().set_realm_prefix(realm_prefix); let iter = make_request!(&mut core, request)?; - Ok(StoreIter{core: Rc::new(RefCell::new(core)), iter: iter}) - } - - /// Lists all keys in the common key pool. - pub fn list_keys(c: &Context) -> Result { - 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 { - 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}) + Ok(MappingIter{core: Rc::new(RefCell::new(core)), iter: iter}) } - /// Adds a key identified by fingerprint to the store. + /// Adds a key identified by fingerprint to the mapping. /// /// # Example /// @@ -380,21 +379,21 @@ impl Store { /// # .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"); - /// store.add("Mister B.", &fp)?; + /// mapping.add("Mister B.", &fp)?; /// # Ok(()) /// # } /// ``` pub fn add(&self, label: &str, fingerprint: &Fingerprint) -> Result { - let mut request = self.store.add_request(); + let mut request = self.mapping.add_request(); request.get().set_label(label); request.get().set_fingerprint(fingerprint.to_hex().as_ref()); let binding = make_request!(self.core.borrow_mut(), request)?; Ok(Binding::new(self.core.clone(), Some(label), binding)) } - /// Imports a key into the store. + /// Imports a key into the mapping. /// /// # Example /// @@ -414,14 +413,14 @@ impl Store { /// # .ephemeral().build()?; /// # let tpk = TPK::from_bytes( /// # include_bytes!("../../openpgp/tests/data/keys/testy.pgp")).unwrap(); - /// let store = Store::open(&ctx, REALM_CONTACTS, "default")?; - /// store.import("Testy McTestface", &tpk)?; + /// let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default")?; + /// mapping.import("Testy McTestface", &tpk)?; /// # Ok(()) /// # } /// ``` pub fn import(&self, label: &str, tpk: &TPK) -> Result { let fingerprint = tpk.fingerprint(); - let mut request = self.store.add_request(); + let mut request = self.mapping.add_request(); request.get().set_label(label); request.get().set_fingerprint(fingerprint.to_hex().as_ref()); let binding = make_request!(self.core.borrow_mut(), request)?; @@ -446,18 +445,18 @@ impl Store { /// # .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"); - /// store.add("Mister B.", &fp)?; - /// drop(store); + /// mapping.add("Mister B.", &fp)?; + /// drop(mapping); /// // ... - /// let store = Store::open(&ctx, REALM_CONTACTS, "default")?; - /// let binding = store.lookup("Mister B.")?; + /// let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default")?; + /// let binding = mapping.lookup("Mister B.")?; /// # Ok(()) /// # } /// ``` pub fn lookup(&self, label: &str) -> Result { - let mut request = self.store.lookup_request(); + let mut request = self.mapping.lookup_request(); request.get().set_label(label); let binding = make_request!(self.core.borrow_mut(), request)?; Ok(Binding::new(self.core.clone(), Some(label), binding)) @@ -486,23 +485,23 @@ impl Store { /// # let tpk = TPK::from_bytes( /// # include_bytes!("../../openpgp/tests/data/keys/emmelie-dorothea-dina-samantha-awina-ed25519.pgp")) /// # .unwrap(); - /// let store = Store::open(&ctx, REALM_CONTACTS, "default")?; - /// store.import("Emmelie", &tpk)?; + /// let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default")?; + /// mapping.import("Emmelie", &tpk)?; /// /// // Lookup by the primary key's KeyID. - /// let tpk_ = store.lookup_by_subkeyid(&"069C0C348DD82C19".parse()?)? + /// let tpk_ = mapping.lookup_by_subkeyid(&"069C0C348DD82C19".parse()?)? /// .tpk()?; /// assert_eq!(tpk, tpk_); /// /// // Lookup by the subkey's KeyID. - /// let tpk_ = store.lookup_by_subkeyid(&"22E3FAFE96B56C32".parse()?)? + /// let tpk_ = mapping.lookup_by_subkeyid(&"22E3FAFE96B56C32".parse()?)? /// .tpk()?; /// assert_eq!(tpk, tpk_); /// # Ok(()) /// # } /// ``` pub fn lookup_by_subkeyid(&self, keyid: &KeyID) -> Result { - let mut request = self.store.lookup_by_subkeyid_request(); + let mut request = self.mapping.lookup_by_subkeyid_request(); request.get().set_keyid(keyid.as_u64()?); let binding = make_request!(self.core.borrow_mut(), request)?; let mut binding = Binding::new(self.core.clone(), None, binding); @@ -510,7 +509,7 @@ impl Store { Ok(binding) } - /// Deletes this store. + /// Deletes this mapping. /// /// # Example /// @@ -527,32 +526,32 @@ impl Store { /// # .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"); - /// store.add("Mister B.", &fp)?; - /// store.delete()?; + /// mapping.add("Mister B.", &fp)?; + /// mapping.delete()?; /// // ... - /// let store = Store::open(&ctx, REALM_CONTACTS, "default")?; - /// let binding = store.lookup("Mister B."); + /// let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default")?; + /// let binding = mapping.lookup("Mister B."); /// assert!(binding.is_err()); // not found /// # Ok(()) /// # } /// ``` pub fn delete(self) -> Result<()> { - let request = self.store.delete_request(); + let request = self.mapping.delete_request(); make_request_map!(self.core.borrow_mut(), request, |_| Ok(())) } /// Lists all bindings. pub fn iter(&self) -> Result { - let request = self.store.iter_request(); + let request = self.mapping.iter_request(); let iter = make_request!(self.core.borrow_mut(), request)?; Ok(BindingIter{core: self.core.clone(), iter: iter}) } - /// Lists all log entries related to this store. + /// Lists all log entries related to this mapping. pub fn log(&self) -> Result { - let request = self.store.log_request(); + let request = self.mapping.log_request(); let iter = make_request!(self.core.borrow_mut(), request)?; Ok(LogIter{core: self.core.clone(), iter: iter}) } @@ -578,9 +577,9 @@ macro_rules! make_stats_request { }} } -/// Represents an entry in a Store. +/// Represents an entry in a Mapping. /// -/// Stores map labels to TPKs. A `Binding` represents a pair in this +/// Mappings map labels to TPKs. A `Binding` represents a pair in this /// relation. We make this explicit because we associate metadata /// with these pairs. pub struct Binding { @@ -619,10 +618,10 @@ impl Binding { /// # .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: @@ -687,10 +686,10 @@ impl Binding { /// # include_bytes!("../../openpgp/tests/data/keys/testy.pgp")).unwrap(); /// # let new = TPK::from_bytes( /// # include_bytes!("../../openpgp/tests/data/keys/testy-new.pgp")).unwrap(); - /// let store = Store::open(&ctx, REALM_CONTACTS, "default")?; - /// store.import("Testy McTestface", &old)?; + /// let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default")?; + /// mapping.import("Testy McTestface", &old)?; /// // later... - /// let binding = store.lookup("Testy McTestface")?; + /// let binding = mapping.lookup("Testy McTestface")?; /// let r = binding.import(&new); /// assert!(r.is_err()); // Conflict! /// # Ok(()) @@ -742,10 +741,10 @@ impl Binding { /// # include_bytes!("../../openpgp/tests/data/keys/testy.pgp")).unwrap(); /// # let new = TPK::from_bytes( /// # include_bytes!("../../openpgp/tests/data/keys/testy-new.pgp")).unwrap(); - /// let store = Store::open(&ctx, REALM_CONTACTS, "default")?; - /// store.import("Testy McTestface", &old)?; + /// let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default")?; + /// mapping.import("Testy McTestface", &old)?; /// // later... - /// let binding = store.lookup("Testy McTestface")?; + /// let binding = mapping.lookup("Testy McTestface")?; /// let r = binding.import(&new); /// assert!(r.is_err()); // Conflict! /// let r = binding.rotate(&new)?; @@ -782,11 +781,11 @@ impl Binding { /// # .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)?; /// binding.delete()?; - /// let binding = store.lookup("Mister B."); + /// let binding = mapping.lookup("Mister B."); /// assert!(binding.is_err()); // not found /// # Ok(()) /// # } @@ -830,7 +829,7 @@ impl Binding { } } -/// Represents a key in a store. +/// Represents a key in the store. /// /// A `Key` is a handle to a stored TPK. We make this explicit /// because we associate metadata with TPKs. @@ -894,9 +893,9 @@ impl Key { /// # include_bytes!("../../openpgp/tests/data/keys/testy.pgp")).unwrap(); /// # let new = TPK::from_bytes( /// # include_bytes!("../../openpgp/tests/data/keys/testy-new.pgp")).unwrap(); - /// let store = Store::open(&ctx, REALM_CONTACTS, "default")?; + /// let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default")?; /// let fp = Fingerprint::from_hex("3E8877C877274692975189F5D03F6F865226FE8B").unwrap(); - /// let binding = store.add("Testy McTestface", &fp)?; + /// let binding = mapping.add("Testy McTestface", &fp)?; /// let key = binding.key()?; /// let r = key.import(&old)?; /// assert_eq!(r.fingerprint(), old.fingerprint()); @@ -960,8 +959,8 @@ pub struct Log { /// Records the time of the entry. pub timestamp: Timespec, - /// Relates the entry to a store. - pub store: Option, + /// Relates the entry to a mapping. + pub mapping: Option, /// Relates the entry to a binding. pub binding: Option, @@ -983,14 +982,14 @@ pub struct Log { impl Log { fn new(timestamp: i64, - store: Option, binding: Option, key: Option, + mapping: Option, binding: Option, key: Option, slug: &str, message: &str, error: Option<&str>) -> Option { let timestamp = from_unix(timestamp)?; Some(Log{ timestamp: timestamp, - store: store, + mapping: mapping, binding: binding, key: key, slug: slug.into(), @@ -1058,32 +1057,32 @@ impl Stamps { /* Iterators. */ -/// Iterates over stores. -pub struct StoreIter { +/// Iterates over mappings. +pub struct MappingIter { core: Rc>, - iter: node::store_iter::Client, + iter: node::mapping_iter::Client, } -impl Iterator for StoreIter { - type Item = (String, String, core::NetworkPolicy, Store); +impl Iterator for MappingIter { + type Item = (String, String, core::NetworkPolicy, Mapping); fn next(&mut self) -> Option { let request = self.iter.next_request(); let doit = || { make_request_map!( self.core.borrow_mut(), request, - |r: node::store_iter::item::Reader| + |r: node::mapping_iter::item::Reader| Ok(( r.get_realm()?.into(), r.get_name()?.into(), r.get_network_policy()?.into(), - Store::new(self.core.clone(), r.get_name()?, r.get_store()?)))) + Mapping::new(self.core.clone(), r.get_name()?, r.get_mapping()?)))) }; doit().ok() } } -/// Iterates over bindings in a store. +/// Iterates over bindings in a mapping. pub struct BindingIter { core: Rc>, iter: node::binding_iter::Client, @@ -1145,8 +1144,8 @@ impl Iterator for LogIter { self.core.borrow_mut(), request, |r: node::log_iter::entry::Reader| Log::new(r.get_timestamp(), - r.get_store().ok().map( - |cap| Store::new(self.core.clone(), &"", cap)), + r.get_mapping().ok().map( + |cap| Mapping::new(self.core.clone(), &"", cap)), r.get_binding().ok().map( |cap| Binding::new(self.core.clone(), None, cap)), r.get_key().ok().map( @@ -1241,23 +1240,23 @@ mod test { } #[test] - fn store_network_policy_mismatch() { + fn mapping_network_policy_mismatch() { let ctx = core::Context::configure() .ephemeral() .network_policy(core::NetworkPolicy::Offline) .ipc_policy(core::IPCPolicy::Internal) .build().unwrap(); - // Create store. - Store::open(&ctx, REALM_CONTACTS, "default").unwrap(); + // Create mapping. + Mapping::open(&ctx, REALM_CONTACTS, "default").unwrap(); let ctx2 = core::Context::configure() .home(ctx.home()) .network_policy(core::NetworkPolicy::Encrypted) .ipc_policy(core::IPCPolicy::Internal) .build().unwrap(); - let store = Store::open(&ctx2, REALM_CONTACTS, "default"); + let mapping = Mapping::open(&ctx2, REALM_CONTACTS, "default"); assert_match!(core::Error::NetworkPolicyViolation(_) - = store.err().unwrap().downcast::().unwrap()); + = mapping.err().unwrap().downcast::().unwrap()); } #[test] @@ -1267,10 +1266,10 @@ mod test { .network_policy(core::NetworkPolicy::Offline) .ipc_policy(core::IPCPolicy::Internal) .build().unwrap(); - let store = Store::open(&ctx, REALM_CONTACTS, "default").unwrap(); + let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default").unwrap(); let tpk = TPK::from_bytes(bytes!("testy.pgp")).unwrap(); - store.import("Mr. McTestface", &tpk).unwrap(); - let binding = store.lookup("Mr. McTestface").unwrap(); + mapping.import("Mr. McTestface", &tpk).unwrap(); + let binding = mapping.lookup("Mr. McTestface").unwrap(); let tpk_retrieved = binding.tpk().unwrap(); assert_eq!(tpk.fingerprint(), tpk_retrieved.fingerprint()); } @@ -1282,8 +1281,8 @@ mod test { .network_policy(core::NetworkPolicy::Offline) .ipc_policy(core::IPCPolicy::Internal) .build().unwrap(); - let store = Store::open(&ctx, REALM_CONTACTS, "default").unwrap(); - let r = store.lookup("I do not exist"); + let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default").unwrap(); + let r = mapping.lookup("I do not exist"); assert_match!(Error::NotFound = r.err().unwrap().downcast::().unwrap()); } @@ -1295,10 +1294,10 @@ mod test { .network_policy(core::NetworkPolicy::Offline) .ipc_policy(core::IPCPolicy::Internal) .build().unwrap(); - let store = Store::open(&ctx, REALM_CONTACTS, "default").unwrap(); + let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default").unwrap(); let tpk = TPK::from_bytes(bytes!("testy.pgp")).unwrap(); let fp = Fingerprint::from_bytes(b"bbbbbbbbbbbbbbbbbbbb"); - let binding = store.add("Mister B.", &fp).unwrap(); + let binding = mapping.add("Mister B.", &fp).unwrap(); let r = binding.import(&tpk); assert_match!(Error::Conflict = r.err().unwrap().downcast::().unwrap()); @@ -1311,37 +1310,37 @@ mod test { .network_policy(core::NetworkPolicy::Offline) .ipc_policy(core::IPCPolicy::Internal) .build().unwrap(); - let store = Store::open(&ctx, REALM_CONTACTS, "default").unwrap(); + let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default").unwrap(); let b = Fingerprint::from_bytes(b"bbbbbbbbbbbbbbbbbbbb"); - store.add("Mister B.", &b).unwrap(); + mapping.add("Mister B.", &b).unwrap(); let c = Fingerprint::from_bytes(b"cccccccccccccccccccc"); assert_match!(Error::Conflict - = store.add("Mister B.", &c) + = mapping.add("Mister B.", &c) .err().unwrap().downcast::().unwrap()); } #[test] - fn delete_store_twice() { + fn delete_mapping_twice() { let ctx = core::Context::configure() .ephemeral() .network_policy(core::NetworkPolicy::Offline) .ipc_policy(core::IPCPolicy::Internal) .build().unwrap(); - let s0 = Store::open(&ctx, REALM_CONTACTS, "default").unwrap(); - let s1 = Store::open(&ctx, REALM_CONTACTS, "default").unwrap(); + let s0 = Mapping::open(&ctx, REALM_CONTACTS, "default").unwrap(); + let s1 = Mapping::open(&ctx, REALM_CONTACTS, "default").unwrap(); s0.delete().unwrap(); s1.delete().unwrap(); } #[test] - fn delete_store_then_use() { + fn delete_mapping_then_use() { let ctx = core::Context::configure() .ephemeral() .network_policy(core::NetworkPolicy::Offline) .ipc_policy(core::IPCPolicy::Internal) .build().unwrap(); - let s0 = Store::open(&ctx, REALM_CONTACTS, "default").unwrap(); - let s1 = Store::open(&ctx, REALM_CONTACTS, "default").unwrap(); + let s0 = Mapping::open(&ctx, REALM_CONTACTS, "default").unwrap(); + let s1 = Mapping::open(&ctx, REALM_CONTACTS, "default").unwrap(); s0.delete().unwrap(); let binding = s1.lookup("Foobarbaz"); assert_match!(Error::NotFound @@ -1359,10 +1358,10 @@ mod test { .network_policy(core::NetworkPolicy::Offline) .ipc_policy(core::IPCPolicy::Internal) .build().unwrap(); - let store = Store::open(&ctx, REALM_CONTACTS, "default").unwrap(); + let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default").unwrap(); let fp = Fingerprint::from_bytes(b"bbbbbbbbbbbbbbbbbbbb"); - let b0 = store.add("Mister B.", &fp).unwrap(); - let b1 = store.lookup("Mister B.").unwrap(); + let b0 = mapping.add("Mister B.", &fp).unwrap(); + let b1 = mapping.lookup("Mister B.").unwrap(); b0.delete().unwrap(); b1.delete().unwrap(); } @@ -1374,10 +1373,10 @@ mod test { .network_policy(core::NetworkPolicy::Offline) .ipc_policy(core::IPCPolicy::Internal) .build().unwrap(); - let store = Store::open(&ctx, REALM_CONTACTS, "default").unwrap(); + let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default").unwrap(); let fp = Fingerprint::from_bytes(b"bbbbbbbbbbbbbbbbbbbb"); - let b0 = store.add("Mister B.", &fp).unwrap(); - let b1 = store.lookup("Mister B.").unwrap(); + let b0 = mapping.add("Mister B.", &fp).unwrap(); + let b1 = mapping.lookup("Mister B.").unwrap(); b0.delete().unwrap(); assert_match!(Error::NotFound = b1.stats().err().unwrap().downcast::().unwrap()); @@ -1385,38 +1384,38 @@ mod test { = b1.key().err().unwrap().downcast::().unwrap()); } - fn make_some_stores() -> core::Context { + fn make_some_mappings() -> core::Context { let ctx0 = core::Context::configure() .ephemeral() .network_policy(core::NetworkPolicy::Offline) .ipc_policy(core::IPCPolicy::Internal) .build().unwrap(); - let store = Store::open(&ctx0, REALM_CONTACTS, "default").unwrap(); + let mapping = Mapping::open(&ctx0, REALM_CONTACTS, "default").unwrap(); let fp = Fingerprint::from_bytes(b"bbbbbbbbbbbbbbbbbbbb"); - store.add("Mister B.", &fp).unwrap(); - store.add("B4", &fp).unwrap(); + mapping.add("Mister B.", &fp).unwrap(); + mapping.add("B4", &fp).unwrap(); - Store::open(&ctx0, REALM_CONTACTS, "another store").unwrap(); + Mapping::open(&ctx0, REALM_CONTACTS, "another mapping").unwrap(); let ctx1 = core::Context::configure() .home(ctx0.home()) .network_policy(core::NetworkPolicy::Offline) .ipc_policy(core::IPCPolicy::Internal) .build().unwrap(); - let store = - Store::open(&ctx1, REALM_SOFTWARE_UPDATES, "default").unwrap(); + let mapping = + Mapping::open(&ctx1, REALM_SOFTWARE_UPDATES, "default").unwrap(); let fp = Fingerprint::from_bytes(b"cccccccccccccccccccc"); - store.add("Mister C.", &fp).unwrap(); + mapping.add("Mister C.", &fp).unwrap(); ctx0 } #[test] fn stats() { - let ctx = make_some_stores(); - let store = Store::open(&ctx, REALM_CONTACTS, "default").unwrap(); + let ctx = make_some_mappings(); + let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default").unwrap(); let fp = Fingerprint::from_bytes(b"bbbbbbbbbbbbbbbbbbbb"); - let binding = store.add("Mister B.", &fp).unwrap(); + let binding = mapping.add("Mister B.", &fp).unwrap(); let stats0 = binding.stats().unwrap(); assert_match!(Some(_) = stats0.created); @@ -1448,28 +1447,28 @@ mod test { #[test] - fn store_iterator() { - let ctx = make_some_stores(); - let mut iter = Store::list(&ctx, REALM_CONTACTS).unwrap(); - let (realm, name, network_policy, store) = iter.next().unwrap(); + fn mapping_iterator() { + let ctx = make_some_mappings(); + let mut iter = Mapping::list(&ctx, REALM_CONTACTS).unwrap(); + let (realm, name, network_policy, mapping) = iter.next().unwrap(); assert_eq!(realm, REALM_CONTACTS); assert_eq!(name, "default"); assert_eq!(network_policy, core::NetworkPolicy::Offline); let fp = Fingerprint::from_bytes(b"bbbbbbbbbbbbbbbbbbbb"); - store.add("Mister B.", &fp).unwrap(); - let (realm, name, network_policy, store) = iter.next().unwrap(); + mapping.add("Mister B.", &fp).unwrap(); + let (realm, name, network_policy, mapping) = iter.next().unwrap(); assert_eq!(realm, REALM_CONTACTS); - assert_eq!(name, "another store"); + assert_eq!(name, "another mapping"); assert_eq!(network_policy, core::NetworkPolicy::Offline); - store.add("Mister B.", &fp).unwrap(); + mapping.add("Mister B.", &fp).unwrap(); assert!(iter.next().is_none()); } #[test] fn binding_iterator() { - let ctx = make_some_stores(); - let store = Store::open(&ctx, REALM_CONTACTS, "default").unwrap(); - let mut iter = store.iter().unwrap(); + let ctx = make_some_mappings(); + let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default").unwrap(); + let mut iter = mapping.iter().unwrap(); let (label, fingerprint, binding) = iter.next().unwrap(); let fp = Fingerprint::from_bytes(b"bbbbbbbbbbbbbbbbbbbb"); assert_eq!(label, "Mister B."); @@ -1484,8 +1483,8 @@ mod test { #[test] fn key_iterator() { - let ctx = make_some_stores(); - let mut iter = Store::list_keys(&ctx).unwrap(); + let ctx = make_some_mappings(); + let mut iter = Pool::list_keys(&ctx).unwrap(); let (fingerprint, key) = iter.next().unwrap(); assert_eq!(fingerprint, Fingerprint::from_bytes(b"bbbbbbbbbbbbbbbbbbbb")); key.stats().unwrap(); diff --git a/store/src/store_protocol.capnp b/store/src/store_protocol.capnp index 3afe2bab..8d50fe43 100644 --- a/store/src/store_protocol.capnp +++ b/store/src/store_protocol.capnp @@ -2,8 +2,8 @@ interface Node { open @0 (realm: Text, networkPolicy: NetworkPolicy, ephemeral: Bool, name: Text) - -> (result: Result(Store)); - iter @1 (realmPrefix: Text) -> (result: Result(StoreIter)); + -> (result: Result(Mapping)); + iter @1 (realmPrefix: Text) -> (result: Result(MappingIter)); iterKeys @2 () -> (result: Result(KeyIter)); log @3 () -> (result: Result(LogIter)); import @4 (key: Data) -> (result: Result(Key)); @@ -11,7 +11,7 @@ interface Node { lookupByFingerprint @6 (fingerprint: Text) -> (result: Result(Key)); lookupBySubkeyid @7 (keyid: UInt64) -> (result: Result(Key)); - interface Store { + interface Mapping { add @0 (label: Text, fingerprint: Text) -> (result: Result(Binding)); lookup @1 (label: Text) -> (result: Result(Binding)); delete @2 () -> (result: Result(Unit)); @@ -39,14 +39,14 @@ interface Node { } # Iterators. - interface StoreIter { + interface MappingIter { next @0 () -> (result: Result(Item)); struct Item { realm @0 :Text; name @1 :Text; networkPolicy @2 :NetworkPolicy; - store @3 :Store; + mapping @3 :Mapping; } } @@ -74,7 +74,7 @@ interface Node { struct Entry { timestamp @0 :Int64; - store @1 :Store; + mapping @1 :Mapping; binding @2 :Binding; key @3 :Key; slug @4 :Text; -- cgit v1.2.3