mirror of
https://github.com/fluencelabs/trust-graph-test
synced 2025-04-25 11:32:37 +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",
|
"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]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.2.1"
|
version = "1.2.1"
|
||||||
@ -848,6 +838,15 @@ version = "0.8.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1255076139a83bb467426e7f8d0134968a8118844faa755985e077cf31850333"
|
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]]
|
[[package]]
|
||||||
name = "num_cpus"
|
name = "num_cpus"
|
||||||
version = "1.13.0"
|
version = "1.13.0"
|
||||||
@ -1235,6 +1234,27 @@ dependencies = [
|
|||||||
"winapi",
|
"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]]
|
[[package]]
|
||||||
name = "rustc-demangle"
|
name = "rustc-demangle"
|
||||||
version = "0.1.18"
|
version = "0.1.18"
|
||||||
@ -1504,7 +1524,6 @@ name = "trust-graph-wasm"
|
|||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bincode",
|
|
||||||
"boolinator",
|
"boolinator",
|
||||||
"bs58 0.3.1",
|
"bs58 0.3.1",
|
||||||
"fce-sqlite-connector",
|
"fce-sqlite-connector",
|
||||||
@ -1513,6 +1532,7 @@ dependencies = [
|
|||||||
"log",
|
"log",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
|
"rmp-serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"trust-graph",
|
"trust-graph",
|
||||||
]
|
]
|
||||||
|
@ -22,4 +22,4 @@ parking_lot = "0.11.1"
|
|||||||
fce-sqlite-connector = "0.1.3"
|
fce-sqlite-connector = "0.1.3"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
bs58 = "0.3.1"
|
bs58 = "0.3.1"
|
||||||
bincode = "1.3.1"
|
rmp-serde = "0.15.0"
|
||||||
|
@ -9,3 +9,11 @@ pub fn main() {
|
|||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.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 crate::storage_impl::get_data;
|
||||||
use fluence::{fce, CallParameters};
|
use fluence::fce;
|
||||||
use fluence_identity::KeyPair;
|
use fluence_identity::KeyPair;
|
||||||
use std::ops::Deref;
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use trust_graph::Certificate;
|
use trust_graph::Certificate;
|
||||||
|
|
||||||
|
@ -3,12 +3,12 @@
|
|||||||
// if there is an older trust - don't add received trust
|
// if there is an older trust - don't add received trust
|
||||||
|
|
||||||
use core::convert::TryFrom;
|
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 fluence_identity::public_key::PublicKey;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
use sqlite;
|
||||||
|
use sqlite::Connection;
|
||||||
|
use sqlite::Value;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use trust_graph::{Auth, PublicKeyHashable, Revoke, Storage, TrustGraph, TrustNode, Weight};
|
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> {
|
pub fn get_data() -> &'static Mutex<TrustGraph> {
|
||||||
INSTANCE.get_or_init(|| {
|
INSTANCE.get_or_init(|| {
|
||||||
let db_path = "/tmp/users.sqlite";
|
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(
|
let init_sql = "CREATE TABLE IF NOT EXISTS trustnodes(
|
||||||
public_key TEXT PRIMARY KEY,
|
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");
|
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,
|
connection: Connection,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SqliteStorage {}
|
impl SqliteStorage {
|
||||||
|
pub fn new(connection: Connection) -> SqliteStorage {
|
||||||
|
SqliteStorage { connection }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Storage for SqliteStorage {
|
impl Storage for SqliteStorage {
|
||||||
fn get(&self, pk: &PublicKeyHashable) -> Option<TrustNode> {
|
fn get(&self, pk: &PublicKeyHashable) -> Option<TrustNode> {
|
||||||
@ -57,10 +61,10 @@ impl Storage for SqliteStorage {
|
|||||||
Some(r) => {
|
Some(r) => {
|
||||||
let tn_bin = r[0]
|
let tn_bin = r[0]
|
||||||
.as_binary()
|
.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)
|
let trust_node: TrustNode = rmp_serde::from_read_ref(tn_bin)
|
||||||
.expect("unexpected: 'trustnode' should be as correct json");
|
.expect("unexpected: 'trustnode' should be as correct binary");
|
||||||
|
|
||||||
log::info!("trustnode: {:?}", trust_node);
|
log::info!("trustnode: {:?}", trust_node);
|
||||||
|
|
||||||
@ -74,11 +78,13 @@ impl Storage for SqliteStorage {
|
|||||||
fn insert(&mut self, pk: PublicKeyHashable, node: TrustNode) {
|
fn insert(&mut self, pk: PublicKeyHashable, node: TrustNode) {
|
||||||
let mut cursor = self
|
let mut cursor = self
|
||||||
.connection
|
.connection
|
||||||
.prepare("INSERT INTO trustnodes VALUES (?, ?)")
|
.prepare("INSERT OR REPLACE INTO trustnodes VALUES (?, ?)")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.cursor();
|
.cursor();
|
||||||
|
|
||||||
let tn_vec = bincode::serialize(&node).unwrap();
|
log::info!("insert trustnode: {:?}", node);
|
||||||
|
|
||||||
|
let tn_vec = rmp_serde::to_vec(&node).unwrap();
|
||||||
|
|
||||||
cursor
|
cursor
|
||||||
.bind(&[Value::String(format!("{}", pk)), Value::Binary(tn_vec)])
|
.bind(&[Value::String(format!("{}", pk)), Value::Binary(tn_vec)])
|
||||||
@ -111,7 +117,7 @@ impl Storage for SqliteStorage {
|
|||||||
log::info!("add root: {} weight: {}", pk, weight);
|
log::info!("add root: {} weight: {}", pk, weight);
|
||||||
let mut cursor = self
|
let mut cursor = self
|
||||||
.connection
|
.connection
|
||||||
.prepare("INSERT INTO roots VALUES (?, ?)")
|
.prepare("INSERT OR REPLACE INTO roots VALUES (?, ?)")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.cursor();
|
.cursor();
|
||||||
|
|
||||||
@ -146,7 +152,14 @@ impl Storage for SqliteStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn revoke(&mut self, pk: &PublicKeyHashable, revoke: Revoke) -> Result<(), String> {
|
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(
|
fn update_auth(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user