mirror of
https://github.com/fluencelabs/trust-graph
synced 2024-12-04 23:30:19 +00:00
fixes
This commit is contained in:
parent
b821984e78
commit
802e294ba1
42
bin/Cargo.lock
generated
42
bin/Cargo.lock
generated
@ -66,16 +66,6 @@ dependencies = [
|
||||
"rustc-demangle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bincode"
|
||||
version = "1.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f30d3a39baa26f9651f17b375061f3233dde33424a8b72b0dbe93a68a0bc896d"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.2.1"
|
||||
@ -848,6 +838,15 @@ version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1255076139a83bb467426e7f8d0134968a8118844faa755985e077cf31850333"
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_cpus"
|
||||
version = "1.13.0"
|
||||
@ -1235,6 +1234,27 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rmp"
|
||||
version = "0.8.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0f10b46df14cf1ee1ac7baa4d2fbc2c52c0622a4b82fa8740e37bc452ac0184f"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rmp-serde"
|
||||
version = "0.15.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f74489002493a9984ee753ebd049552a1c82f0740e347ee9fc57c907fb19f83"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"rmp",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.18"
|
||||
@ -1504,7 +1524,6 @@ name = "trust-graph-wasm"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bincode",
|
||||
"boolinator",
|
||||
"bs58 0.3.1",
|
||||
"fce-sqlite-connector",
|
||||
@ -1513,6 +1532,7 @@ dependencies = [
|
||||
"log",
|
||||
"once_cell",
|
||||
"parking_lot",
|
||||
"rmp-serde",
|
||||
"serde_json",
|
||||
"trust-graph",
|
||||
]
|
||||
|
@ -22,4 +22,4 @@ parking_lot = "0.11.1"
|
||||
fce-sqlite-connector = "0.1.3"
|
||||
serde_json = "1.0"
|
||||
bs58 = "0.3.1"
|
||||
bincode = "1.3.1"
|
||||
rmp-serde = "0.15.0"
|
||||
|
@ -9,3 +9,11 @@ pub fn main() {
|
||||
.build()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
// only option for now is to copy tests from trust graph,
|
||||
// change connector to sqlite and fix compilation -_-
|
||||
// TODO: fix it
|
||||
/*#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
}*/
|
||||
|
@ -1,7 +1,6 @@
|
||||
use crate::storage_impl::get_data;
|
||||
use fluence::{fce, CallParameters};
|
||||
use fluence::fce;
|
||||
use fluence_identity::KeyPair;
|
||||
use std::ops::Deref;
|
||||
use std::time::Duration;
|
||||
use trust_graph::Certificate;
|
||||
|
||||
|
@ -3,12 +3,12 @@
|
||||
// if there is an older trust - don't add received trust
|
||||
|
||||
use core::convert::TryFrom;
|
||||
use fce_sqlite_connector;
|
||||
use fce_sqlite_connector::Value;
|
||||
use fce_sqlite_connector::{Connection, State};
|
||||
use fluence_identity::public_key::PublicKey;
|
||||
use once_cell::sync::OnceCell;
|
||||
use parking_lot::Mutex;
|
||||
use sqlite;
|
||||
use sqlite::Connection;
|
||||
use sqlite::Value;
|
||||
use std::str::FromStr;
|
||||
use std::time::Duration;
|
||||
use trust_graph::{Auth, PublicKeyHashable, Revoke, Storage, TrustGraph, TrustNode, Weight};
|
||||
@ -18,7 +18,7 @@ static INSTANCE: OnceCell<Mutex<TrustGraph>> = OnceCell::new();
|
||||
pub fn get_data() -> &'static Mutex<TrustGraph> {
|
||||
INSTANCE.get_or_init(|| {
|
||||
let db_path = "/tmp/users.sqlite";
|
||||
let connection = fce_sqlite_connector::open(db_path).unwrap();
|
||||
let connection = sqlite::open(db_path).unwrap();
|
||||
|
||||
let init_sql = "CREATE TABLE IF NOT EXISTS trustnodes(
|
||||
public_key TEXT PRIMARY KEY,
|
||||
@ -31,15 +31,19 @@ pub fn get_data() -> &'static Mutex<TrustGraph> {
|
||||
|
||||
connection.execute(init_sql).expect("cannot connect to db");
|
||||
|
||||
Mutex::new(TrustGraph::new(Box::new(SqliteStorage { connection })))
|
||||
Mutex::new(TrustGraph::new(Box::new(SqliteStorage::new(connection))))
|
||||
})
|
||||
}
|
||||
|
||||
struct SqliteStorage {
|
||||
pub struct SqliteStorage {
|
||||
connection: Connection,
|
||||
}
|
||||
|
||||
impl SqliteStorage {}
|
||||
impl SqliteStorage {
|
||||
pub fn new(connection: Connection) -> SqliteStorage {
|
||||
SqliteStorage { connection }
|
||||
}
|
||||
}
|
||||
|
||||
impl Storage for SqliteStorage {
|
||||
fn get(&self, pk: &PublicKeyHashable) -> Option<TrustNode> {
|
||||
@ -57,10 +61,10 @@ impl Storage for SqliteStorage {
|
||||
Some(r) => {
|
||||
let tn_bin = r[0]
|
||||
.as_binary()
|
||||
.expect("unexpected: 'trustnode' in a table should be as string");
|
||||
.expect("unexpected: 'trustnode' in a table should be as binary");
|
||||
|
||||
let trust_node: TrustNode = bincode::deserialize(tn_bin)
|
||||
.expect("unexpected: 'trustnode' should be as correct json");
|
||||
let trust_node: TrustNode = rmp_serde::from_read_ref(tn_bin)
|
||||
.expect("unexpected: 'trustnode' should be as correct binary");
|
||||
|
||||
log::info!("trustnode: {:?}", trust_node);
|
||||
|
||||
@ -74,11 +78,13 @@ impl Storage for SqliteStorage {
|
||||
fn insert(&mut self, pk: PublicKeyHashable, node: TrustNode) {
|
||||
let mut cursor = self
|
||||
.connection
|
||||
.prepare("INSERT INTO trustnodes VALUES (?, ?)")
|
||||
.prepare("INSERT OR REPLACE INTO trustnodes VALUES (?, ?)")
|
||||
.unwrap()
|
||||
.cursor();
|
||||
|
||||
let tn_vec = bincode::serialize(&node).unwrap();
|
||||
log::info!("insert trustnode: {:?}", node);
|
||||
|
||||
let tn_vec = rmp_serde::to_vec(&node).unwrap();
|
||||
|
||||
cursor
|
||||
.bind(&[Value::String(format!("{}", pk)), Value::Binary(tn_vec)])
|
||||
@ -111,7 +117,7 @@ impl Storage for SqliteStorage {
|
||||
log::info!("add root: {} weight: {}", pk, weight);
|
||||
let mut cursor = self
|
||||
.connection
|
||||
.prepare("INSERT INTO roots VALUES (?, ?)")
|
||||
.prepare("INSERT OR REPLACE INTO roots VALUES (?, ?)")
|
||||
.unwrap()
|
||||
.cursor();
|
||||
|
||||
@ -146,7 +152,14 @@ impl Storage for SqliteStorage {
|
||||
}
|
||||
|
||||
fn revoke(&mut self, pk: &PublicKeyHashable, revoke: Revoke) -> Result<(), String> {
|
||||
Err("not implemented".to_string())
|
||||
match self.get(&pk) {
|
||||
Some(mut trust_node) => {
|
||||
trust_node.update_revoke(revoke);
|
||||
self.insert(pk.clone(), trust_node);
|
||||
Ok(())
|
||||
}
|
||||
None => Err("There is no trust with such PublicKey".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
fn update_auth(
|
||||
|
Loading…
Reference in New Issue
Block a user