switching ngd to rocksdb storage

Niko PLP 1 year ago
parent 019062d126
commit 1fd3e8a213
  1. 2
      Cargo.lock
  2. 2
      ngcli/src/main.rs
  3. 2
      p2p-broker/Cargo.toml
  4. 26
      p2p-broker/src/server_storage.rs
  5. 6
      p2p-broker/src/server_ws.rs
  6. 2
      p2p-net/src/server_storage.rs

2
Cargo.lock generated

@ -3265,7 +3265,7 @@ dependencies = [
"serde_bare",
"serde_bytes",
"serde_json",
"stores-lmdb",
"stores-rocksdb",
"tempfile",
]

@ -25,8 +25,6 @@ use std::io::ErrorKind;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use std::path::PathBuf;
use std::str::FromStr;
use stores_lmdb::kcv_store::LmdbKCVStore;
use stores_lmdb::repo_store::LmdbRepoStore;
use zeroize::Zeroize;
use p2p_client_ws::remote_ws::ConnectionWebSocket;

@ -11,7 +11,7 @@ repository = "https://git.nextgraph.org/NextGraph/nextgraph-rs"
p2p-repo = { path = "../p2p-repo" }
p2p-net = { path = "../p2p-net" }
p2p-client-ws = { path = "../p2p-client-ws" }
stores-lmdb = { path = "../stores-lmdb" }
stores-rocksdb = { path = "../stores-rocksdb" }
chacha20 = "0.9.0"
serde = { version = "1.0", features = ["derive"] }
serde_bare = "0.5.0"

@ -22,17 +22,15 @@ use p2p_repo::kcv_store::KCVStore;
use p2p_repo::log::*;
use p2p_repo::store::StorageError;
use p2p_repo::types::{PubKey, SymKey};
use stores_lmdb::kcv_store::LmdbKCVStore;
use stores_lmdb::repo_store::LmdbRepoStore;
use stores_rocksdb::kcv_store::RocksdbKCVStore;
#[derive(Debug)]
pub struct LmdbServerStorage {
wallet_storage: LmdbKCVStore,
accounts_storage: LmdbKCVStore,
peers_storage: LmdbKCVStore,
pub struct RocksdbServerStorage {
wallet_storage: RocksdbKCVStore,
accounts_storage: RocksdbKCVStore,
peers_storage: RocksdbKCVStore,
}
impl LmdbServerStorage {
impl RocksdbServerStorage {
pub fn open(
path: &mut PathBuf,
master_key: SymKey,
@ -44,7 +42,7 @@ impl LmdbServerStorage {
std::fs::create_dir_all(wallet_path.clone()).unwrap();
log_debug!("opening wallet DB");
//TODO redo the whole key passing mechanism in RKV so it uses zeroize all the way
let wallet_storage = LmdbKCVStore::open(&wallet_path, master_key.slice().clone())?;
let wallet_storage = RocksdbKCVStore::open(&wallet_path, master_key.slice().clone())?;
let wallet = Wallet::open(&wallet_storage);
// create/open the ACCOUNTS storage
@ -56,7 +54,7 @@ impl LmdbServerStorage {
accounts_key = wallet.create_accounts_key()?;
std::fs::create_dir_all(accounts_path.clone()).unwrap();
let accounts_storage =
LmdbKCVStore::open(&accounts_path, accounts_key.slice().clone())?;
RocksdbKCVStore::open(&accounts_path, accounts_key.slice().clone())?;
let symkey = SymKey::random();
let invite_code = InvitationCode::Admin(symkey.clone());
let _ = Invitation::create(
@ -83,7 +81,7 @@ impl LmdbServerStorage {
log_debug!("opening accounts DB");
std::fs::create_dir_all(accounts_path.clone()).unwrap();
//TODO redo the whole key passing mechanism in RKV so it uses zeroize all the way
let accounts_storage = LmdbKCVStore::open(&accounts_path, accounts_key.slice().clone())?;
let accounts_storage = RocksdbKCVStore::open(&accounts_path, accounts_key.slice().clone())?;
// create/open the PEERS storage
log_debug!("opening peers DB");
@ -92,9 +90,9 @@ impl LmdbServerStorage {
peers_path.push("peers");
std::fs::create_dir_all(peers_path.clone()).unwrap();
//TODO redo the whole key passing mechanism in RKV so it uses zeroize all the way
let peers_storage = LmdbKCVStore::open(&peers_path, peers_key.slice().clone())?;
let peers_storage = RocksdbKCVStore::open(&peers_path, peers_key.slice().clone())?;
Ok(LmdbServerStorage {
Ok(RocksdbServerStorage {
wallet_storage,
accounts_storage,
peers_storage,
@ -102,7 +100,7 @@ impl LmdbServerStorage {
}
}
impl ServerStorage for LmdbServerStorage {
impl ServerStorage for RocksdbServerStorage {
fn get_user(&self, user_id: PubKey) -> Result<bool, ProtocolError> {
log_debug!("get_user {user_id}");
Ok(Account::open(&user_id, &self.accounts_storage)?.is_admin()?)

@ -12,7 +12,7 @@
//! WebSocket implementation of the Broker
use crate::interfaces::*;
use crate::server_storage::LmdbServerStorage;
use crate::server_storage::RocksdbServerStorage;
use crate::types::*;
use async_std::io::ReadExt;
use async_std::net::{TcpListener, TcpStream};
@ -586,7 +586,7 @@ pub async fn run_server_accept_one(
// let master_key: [u8; 32] = [0; 32];
// std::fs::create_dir_all(root.path()).unwrap();
// log_debug!("data directory: {}", root.path().to_str().unwrap());
// let store = LmdbKCVStore::open(root.path(), master_key);
// let store = RocksdbKCVStore::open(root.path(), master_key);
let socket = TcpListener::bind(addrs.as_str()).await?;
log_debug!("Listening on {}", addrs.as_str());
@ -768,7 +768,7 @@ pub async fn run_server_v0(
std::fs::create_dir_all(path.clone()).unwrap();
// opening the server storage (that contains the encryption keys for each store/overlay )
let broker_storage = LmdbServerStorage::open(
let broker_storage = RocksdbServerStorage::open(
&mut path,
wallet_master_key,
if admin_invite {

@ -12,7 +12,7 @@
use crate::{errors::ProtocolError, types::*};
use p2p_repo::{kcv_store::KCVStore, types::PubKey};
pub trait ServerStorage: Send + Sync + std::fmt::Debug {
pub trait ServerStorage: Send + Sync {
fn get_user(&self, user_id: PubKey) -> Result<bool, ProtocolError>;
fn add_user(&self, user_id: PubKey, is_admin: bool) -> Result<(), ProtocolError>;
fn del_user(&self, user_id: PubKey) -> Result<(), ProtocolError>;

Loading…
Cancel
Save