mirror of
https://github.com/fluencelabs/trust-graph
synced 2024-12-04 15:20:19 +00:00
init storage for wasm, add sqlite to project WIP
This commit is contained in:
parent
d3a03248b2
commit
0b1b0a82a7
21
bin/Cargo.lock
generated
21
bin/Cargo.lock
generated
@ -102,6 +102,12 @@ dependencies = [
|
||||
"byte-tools",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "boolinator"
|
||||
version = "2.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cfa8873f51c92e232f9bac4065cddef41b714152812bfc5f7672ba16d6ef8cd9"
|
||||
|
||||
[[package]]
|
||||
name = "bs58"
|
||||
version = "0.3.1"
|
||||
@ -283,6 +289,15 @@ version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
|
||||
|
||||
[[package]]
|
||||
name = "fce-sqlite-connector"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8165090ee52453a5c14bd42212bfc6516860c4aaa2315fd568c0198b46b52901"
|
||||
dependencies = [
|
||||
"fluence",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fixedbitset"
|
||||
version = "0.2.0"
|
||||
@ -1396,8 +1411,14 @@ dependencies = [
|
||||
name = "trust-graph-wasm"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"boolinator",
|
||||
"fce-sqlite-connector",
|
||||
"fluence",
|
||||
"fluence-identity",
|
||||
"log",
|
||||
"once_cell",
|
||||
"parking_lot",
|
||||
"trust-graph",
|
||||
]
|
||||
|
||||
|
@ -12,5 +12,11 @@ path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
trust-graph = { path = "../" }
|
||||
fluence-identity = { path = "../identity" }
|
||||
log = "0.4.8"
|
||||
fluence = { version = "0.2.18", features = ["logger"] }
|
||||
fluence = { version = "0.2.18", features = ["logger"] }
|
||||
anyhow = "1.0.31"
|
||||
boolinator = "2.4.0"
|
||||
once_cell = "1.4.1"
|
||||
parking_lot = "0.11.1"
|
||||
fce-sqlite-connector = "0.1.3"
|
@ -1,5 +1,8 @@
|
||||
use fluence::WasmLoggerBuilder;
|
||||
|
||||
mod storage_impl;
|
||||
mod service_api;
|
||||
|
||||
pub fn main() {
|
||||
WasmLoggerBuilder::new()
|
||||
.with_log_level(log::Level::Info)
|
||||
|
@ -0,0 +1,6 @@
|
||||
use fluence::{fce, CallParameters};
|
||||
|
||||
#[fce]
|
||||
fn test(a: String) -> String {
|
||||
a
|
||||
}
|
@ -1,3 +1,67 @@
|
||||
// store list of trusts
|
||||
// check if trust is already in list before adding
|
||||
// if there is an older trust - don't add received trust
|
||||
// if there is an older trust - don't add received trust
|
||||
|
||||
use trust_graph::{Storage, TrustGraph, PublicKeyHashable, TrustNode, Weight, Auth, Revoke};
|
||||
use fluence_identity::public_key::PublicKey;
|
||||
use once_cell::sync::OnceCell;
|
||||
use parking_lot::Mutex;
|
||||
use std::time::Duration;
|
||||
use fce_sqlite_connector;
|
||||
use fce_sqlite_connector::{State, Connection};
|
||||
|
||||
static INSTANCE: OnceCell<Mutex<TrustGraph>> = OnceCell::new();
|
||||
|
||||
fn get_data() -> &'static Mutex<TrustGraph> {
|
||||
INSTANCE.get_or_init(|| {
|
||||
let db_path = "/var/folders/ww/v__xg0cj17x7h7sf3bgwpx8h0000gn/T/4589ab6f-5440-4933-ace5-a62714784142/tmp/users.sqlite";
|
||||
let connection = fce_sqlite_connector::open(db_path).unwrap();
|
||||
Mutex::new(TrustGraph::new(Box::new(SqliteStorage {connection})))
|
||||
})
|
||||
}
|
||||
|
||||
struct SqliteStorage {
|
||||
connection: Connection,
|
||||
}
|
||||
|
||||
impl SqliteStorage {
|
||||
pub fn init(&self) {
|
||||
let init_sql = "CREATE TABLE IF NOT EXISTS trusts(\
|
||||
peer_id TEXT PRIMARY KEY,\
|
||||
relay TEXT NOT NULL,\
|
||||
sig TEXT NOT NULL,\
|
||||
name TEXT NOT NULL\
|
||||
);";
|
||||
}
|
||||
}
|
||||
|
||||
impl Storage for SqliteStorage {
|
||||
fn get(&self, pk: &PublicKeyHashable) -> Option<&TrustNode> {
|
||||
None
|
||||
}
|
||||
fn insert(&mut self, pk: PublicKeyHashable, node: TrustNode) {
|
||||
|
||||
}
|
||||
|
||||
fn get_root_weight(&self, pk: &PublicKeyHashable) -> Option<&Weight> {
|
||||
None
|
||||
}
|
||||
fn add_root_weight(&mut self, pk: PublicKeyHashable, weight: Weight) {
|
||||
|
||||
}
|
||||
fn root_keys(&self) -> Vec<PublicKeyHashable> {
|
||||
vec![]
|
||||
}
|
||||
fn revoke(&mut self, pk: &PublicKeyHashable, revoke: Revoke) -> Result<(), String> {
|
||||
Err("not implemented".to_string())
|
||||
}
|
||||
fn update_auth(
|
||||
&mut self,
|
||||
pk: &PublicKeyHashable,
|
||||
auth: Auth,
|
||||
issued_for: &PublicKey,
|
||||
cur_time: Duration,
|
||||
) {
|
||||
|
||||
}
|
||||
}
|
@ -40,4 +40,7 @@ pub use crate::certificate::Certificate;
|
||||
pub use crate::misc::current_time;
|
||||
pub use crate::public_key_hashable::PublicKeyHashable;
|
||||
pub use crate::trust::Trust;
|
||||
pub use crate::trust_graph::TrustGraph;
|
||||
pub use crate::revoke::Revoke;
|
||||
pub use crate::trust_node::{TrustNode, Auth};
|
||||
pub use crate::trust_graph::{TrustGraph, Weight};
|
||||
pub use crate::trust_graph_storage::Storage;
|
||||
|
@ -33,12 +33,12 @@ pub type Weight = u32;
|
||||
/// TODO export a certificate from graph
|
||||
#[allow(dead_code)]
|
||||
pub struct TrustGraph {
|
||||
storage: Box<dyn Storage>,
|
||||
storage: Box<dyn Storage + Send + Sync>,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl TrustGraph {
|
||||
pub fn new(storage: Box<dyn Storage>) -> Self {
|
||||
pub fn new(storage: Box<dyn Storage + Send + Sync>) -> Self {
|
||||
Self { storage: storage }
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user