Clean up structure a bit

This commit is contained in:
Nadja Reitzenstein 2021-11-26 02:25:48 +01:00
parent 32894300f4
commit b16c660058
14 changed files with 156 additions and 63 deletions

View File

@ -9,7 +9,9 @@ fn is_hidden(entry: &DirEntry) -> bool {
fn main() {
let mut compile_command = ::capnpc::CompilerCommand::new();
compile_command.src_prefix("schema");
compile_command
.src_prefix("schema")
.default_parent_module(vec!["schema".to_string()]);
for entry in WalkDir::new("schema")
.max_depth(2)
@ -25,7 +27,8 @@ fn main() {
)
{
println!("Collecting schema file {}", entry.path().display());
compile_command.file(entry.path());
compile_command
.file(entry.path());
}
println!("Compiling schemas...");

View File

@ -1,41 +1,56 @@
pub use capnpc::schema_capnp;
#[allow(dead_code)]
pub mod auth_capnp {
include!(concat!(env!("OUT_DIR"), "/auth_capnp.rs"));
//! FabAccess generated API bindings
//!
//! This crate contains slightly nicer and better documented bindings for the FabAccess API.
mod schema;
/// Authentication subsystem
pub mod auth {
/// Session authentication
///
/// Authentication uses a SASL exchange. To bootstrap a connection you will need to call
/// `step` until you get a successful result
pub mod authentication {
pub use crate::schema::auth_capnp::authentication::*;
}
#[allow(dead_code)]
pub mod main_capnp {
include!(concat!(env!("OUT_DIR"), "/main_capnp.rs"));
pub mod response {
pub use crate::schema::auth_capnp::response::*;
}
}
#[allow(dead_code)]
pub mod utils_capnp {
include!(concat!(env!("OUT_DIR"), "/utils_capnp.rs"));
pub mod resource {
pub use crate::schema::resource_capnp::*;
}
#[allow(dead_code)]
pub mod resource_capnp {
include!(concat!(env!("OUT_DIR"), "/resource_capnp.rs"));
pub mod resources {
pub use crate::schema::resources_capnp::*;
}
#[allow(dead_code)]
pub mod resources_capnp {
include!(concat!(env!("OUT_DIR"), "/resources_capnp.rs"));
pub mod role {
pub use crate::schema::role_capnp::*;
}
#[allow(dead_code)]
pub mod role_capnp {
include!(concat!(env!("OUT_DIR"), "/role_capnp.rs"));
pub mod user {
pub use crate::schema::user_capnp::*;
}
#[allow(dead_code)]
pub mod user_capnp {
include!(concat!(env!("OUT_DIR"), "/user_capnp.rs"));
pub mod users {
pub use crate::schema::users_capnp::*;
}
#[allow(dead_code)]
pub mod users_capnp {
include!(concat!(env!("OUT_DIR"), "/users_capnp.rs"));
pub mod utils {
pub mod uuid {
pub use crate::schema::utils_capnp::u_u_i_d::*;
}
/// Localization String
///
/// This is a specialized string that allows to access the string contents in different
/// languages
pub mod l10n_string {
pub use crate::schema::utils_capnp::l10_n_string::*;
}
}

41
api/src/schema.rs Normal file
View File

@ -0,0 +1,41 @@
pub use capnpc::schema_capnp;
#[allow(dead_code)]
pub mod auth_capnp {
include!(concat!(env!("OUT_DIR"), "/auth_capnp.rs"));
}
#[allow(dead_code)]
pub mod main_capnp {
include!(concat!(env!("OUT_DIR"), "/main_capnp.rs"));
}
#[allow(dead_code)]
pub mod utils_capnp {
include!(concat!(env!("OUT_DIR"), "/utils_capnp.rs"));
}
#[allow(dead_code)]
pub mod resource_capnp {
include!(concat!(env!("OUT_DIR"), "/resource_capnp.rs"));
}
#[allow(dead_code)]
pub mod resources_capnp {
include!(concat!(env!("OUT_DIR"), "/resources_capnp.rs"));
}
#[allow(dead_code)]
pub mod role_capnp {
include!(concat!(env!("OUT_DIR"), "/role_capnp.rs"));
}
#[allow(dead_code)]
pub mod user_capnp {
include!(concat!(env!("OUT_DIR"), "/user_capnp.rs"));
}
#[allow(dead_code)]
pub mod users_capnp {
include!(concat!(env!("OUT_DIR"), "/users_capnp.rs"));
}

View File

@ -65,11 +65,11 @@ use std::sync::Arc;
use std::path::Path;
use crate::db::user::User;
use std::collections::HashMap;
use crate::state::{OwnedEntry, State};
use crate::resource::state::{OwnedEntry, State};
use std::iter::FromIterator;
use std::ops::Deref;
use crate::oid::{ArchivedObjectIdentifier, ObjectIdentifier};
use crate::state::value::SerializeValue;
use crate::utils::oid::{ArchivedObjectIdentifier, ObjectIdentifier};
use crate::resource::state::value::SerializeValue;
#[derive(Debug)]
pub enum DBError {

View File

@ -24,7 +24,7 @@ use super::{
LMDBorrow,
};
use crate::state::State;
use crate::resource::state::State;
type StateAdapter = AllocAdapter<State>;
@ -162,8 +162,8 @@ impl StateAccessor {
mod tests {
use super::*;
use crate::state::value::Vec3u8;
use crate::state::value::{OID_COLOUR, OID_POWERED, OID_INTENSITY};
use crate::resource::state::value::Vec3u8;
use crate::resource::state::value::{OID_COLOUR, OID_POWERED, OID_INTENSITY};
use std::ops::Deref;
#[test]

View File

@ -11,14 +11,15 @@
/// Internal Databases build on top of LMDB, a mmap()'ed B-tree DB optimized for reads
pub mod db;
/// Shared error type
pub mod error;
pub mod oid;
/// Policy decision engine
pub mod permissions;
/// Resources
pub mod resource;
/// State of Resources
pub mod state;
/// Varints
pub mod varint;
pub mod resources;
pub mod utils;

23
bffhd/resource/claim.rs Normal file
View File

@ -0,0 +1,23 @@
use async_channel::Sender;
use crate::resource::Update;
#[derive(Debug)]
/// A claim on a resource grants permission to update state
///
/// This permission is not necessarily exclusive, depending on the resource in question.
pub struct Claim {
/// Sending end that can be used to send state updates to a resource.
pub tx: Sender<Update>,
}
#[derive(Debug)]
/// An interest on a resource indicates that an user wants a resource to be in a specific state
pub struct Interest {
}
#[derive(Debug)]
/// A notify indicates that an user wants to be informed about changes in a resources' state
pub struct Notify {
}

View File

@ -5,11 +5,14 @@ use futures_signals::signal::Mutable;
use async_oneshot::Sender;
use async_channel::Receiver;
use crate::state::State;
use state::State;
use crate::db::{
state::StateAccessor,
};
pub mod state;
pub mod claim;
/// A resource in BFFH has to contain several different parts;
/// - Currently set state
/// - Execution state of attached actors (⇒ BFFH's job)
@ -121,7 +124,7 @@ mod tests {
#[futures_test::test]
async fn test_passthrough_is_id() {
let inp = crate::state::tests::gen_random();
let inp = state::tests::gen_random();
let mut res = Passthrough;
let out = res.on_update(&inp).await.unwrap();

View File

@ -1,34 +1,31 @@
use std::{
collections::hash_map::DefaultHasher,
fmt,
collections::{
hash_map::DefaultHasher
},
hash::{
Hash,
Hasher
},
};
use std::fmt::Formatter;
use std::ops::Deref;
use rkyv::{
Archive,
Archived,
Serialize,
Deserialize,
out_field,
Serialize,
};
use serde::de::{Error, MapAccess};
use serde::Deserializer;
use serde::ser::SerializeMap;
use value::{RegisteredImpl, SerializeValue};
use crate::utils::oid::ObjectIdentifier;
use crate::resource::state::value::{DynOwnedVal, DynVal, TypeOid, };
pub mod value;
use value::{SerializeValue, RegisteredImpl};
use crate::state::value::{TypeOid, DynVal, DynOwnedVal, };
use crate::oid::ObjectIdentifier;
use serde::ser::SerializeMap;
use std::ops::Deref;
use std::fmt::Formatter;
use serde::Deserializer;
use serde::de::{Error, MapAccess};
#[derive(serde::Serialize, serde::Deserialize)]
#[derive(Archive, Serialize, Deserialize)]
@ -177,14 +174,14 @@ impl<'de> serde::de::Visitor<'de> for OwnedEntryVisitor {
#[cfg(test)]
pub mod tests {
use super::*;
use crate::state::value::*;
use super::value::*;
pub(crate) fn gen_random() -> State {
let amt: u8 = rand::random::<u8>() % 20;
let mut sb = State::build();
for _ in 0..amt {
let oid = crate::oid::tests::gen_random();
let oid = crate::utils::oid::tests::gen_random();
sb = match rand::random::<u32>()%12 {
0 => sb.add(oid, Box::new(rand::random::<bool>())),
1 => sb.add(oid, Box::new(rand::random::<u8>())),

View File

@ -14,7 +14,7 @@ use rkyv_typename::TypeName;
use ptr_meta::{DynMetadata, Pointee};
use inventory;
use crate::oid::{ObjectIdentifier};
use crate::utils::oid::{ObjectIdentifier};
use rkyv::ser::{Serializer, ScratchSpace};
use std::collections::HashMap;
use std::alloc::Layout;
@ -577,10 +577,10 @@ oidvalue!(OID_VEC3U8, Vec3u8, ArchivedVec3u8);
#[cfg(test)]
mod tests {
use super::*;
use rand::Rng;
use rand::distributions::Standard;
use rand::prelude::Distribution;
use crate::state::value::Vec3u8;
impl Distribution<Vec3u8> for Standard {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Vec3u8 {

5
bffhd/resources.rs Normal file
View File

@ -0,0 +1,5 @@
#[derive(Debug)]
pub struct Resources {
}

5
bffhd/utils/mod.rs Normal file
View File

@ -0,0 +1,5 @@
/// ITU Object Identifier implementation
pub mod oid;
/// Variable sized integer types
pub mod varint;

View File

@ -1,4 +1,4 @@
//! oid crate by <https://github.com/UnnecessaryEngineering/oid> turned into vendore'd module
//! oid crate by <https://github.com/UnnecessaryEngineering/oid> turned into vendored module
//!
//! [Object Identifiers] are a standard of the [ITU] used to reference objects, things, and
//! concepts in a globally unique way. This crate provides for data structures and methods
@ -61,7 +61,7 @@ use std::fmt;
use std::fmt::Formatter;
use rkyv::ser::Serializer;
use std::str::FromStr;
use crate::varint::VarU128;
use crate::utils::varint::VarU128;
use std::convert::TryInto;
type Node = u128;