cargo update

This commit is contained in:
Sebastian Moser
2023-04-13 14:49:11 +02:00
parent 04787827f4
commit e9af27f6f1
6 changed files with 833 additions and 1538 deletions

2322
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -16,7 +16,7 @@ itertools = "0.10.5"
lazy_static = "1.4.0" lazy_static = "1.4.0"
serde = "1.0.152" serde = "1.0.152"
serde_json = "1.0.91" serde_json = "1.0.91"
surrealdb = "1.0.0-beta.7" surrealdb = { version = "1.0.0-beta.7", features = ["kv-rocksdb"] }
tokio = {version = "1.21.0", features = ["full"]} tokio = {version = "1.21.0", features = ["full"]}
tokio-stream = "0.1.9" tokio-stream = "0.1.9"
toml = "0.5.10" toml = "0.5.10"

View File

@@ -221,9 +221,9 @@ impl From<FromUtf8Error> for MizeError {
} }
} }
impl From<surrealdb::Error> for MizeError { impl From<surrealdb::error::Db> for MizeError {
fn from(sur_err: surrealdb::Error) -> MizeError { fn from(sur_err: surrealdb::error::Db) -> MizeError {
MizeError::new(129) MizeError::new(129).extra_msg(format!("surrealdb Error: {}", sur_err))
} }
} }

View File

@@ -461,13 +461,23 @@ async fn handle_websocket_connection(
} }
_ => { Message::Ping(_) => {
let err = MizeError::new(11) let err = MizeError::new(11)
.extra_msg("unhandeld WebSocket-Message type") .extra_msg("unhandeld WebSocket-Message type: Ping")
.handle(); .handle();
msg_tx.send(proto::MizeMessage::Json(err.to_json_message())).await; msg_tx.send(proto::MizeMessage::Json(err.to_json_message())).await;
}, },
Message::Pong(_) => {
let err = MizeError::new(11)
.extra_msg("unhandeld WebSocket-Message type: Pong")
.handle();
msg_tx.send(proto::MizeMessage::Json(err.to_json_message())).await;
},
}; };
}; };
} }
@@ -543,6 +553,14 @@ fn load_mr(mize_folder: String) -> Result<Vec<Render>, MizeError> {
} }
async fn init_server(mize_folder: String) -> Result<(Uuid, Itemstore, Vec<Render>), MizeError> { async fn init_server(mize_folder: String) -> Result<(Uuid, Itemstore, Vec<Render>), MizeError> {
/*
* This function initializes the server.
* - create a mize folder if not there yet
* - get or generate the uuid for the server
* - load the renders and modules from the <mize-folder>/mr folder
* - create a surrealdb::Datastore inside the <mize-folder>/db folder
*
*/
let server_uuid; let server_uuid;
@@ -589,9 +607,10 @@ async fn init_server(mize_folder: String) -> Result<(Uuid, Itemstore, Vec<Render
}, },
}; };
//create the itemstore // create the itemstore
let itemstore = crate::server::itemstore::Itemstore::new(mize_folder.clone() + "/rocksdb").await.expect("error creating itemstore"); let itemstore = crate::server::itemstore::Itemstore::new(mize_folder.clone() + "/db").await.expect("error creating itemstore");
// load the modules and renders from <mize-folder>/mr
let renders = load_mr(mize_folder.clone()) let renders = load_mr(mize_folder.clone())
.map_err(|e| MizeError::new(11)) .map_err(|e| MizeError::new(11))
.extra_msg("Error loading Modules and Renders")?; .extra_msg("Error loading Modules and Renders")?;

View File

@@ -1,7 +1,7 @@
use std::net::ToSocketAddrs; use std::net::ToSocketAddrs;
use std::{io, fmt::format, vec}; use std::{io, fmt::format, vec};
use surrealdb::{Datastore, Key, Val}; use surrealdb::kvs::{Datastore, Key, Val};
use itertools::Itertools; use itertools::Itertools;
use crate::error; use crate::error;
use crate::error::MizeError; use crate::error::MizeError;
@@ -17,7 +17,7 @@ use super::proto::Delta;
// is responsible, that no illegal states can occur in the storage, by using transactions // is responsible, that no illegal states can occur in the storage, by using transactions
// currently it's just a surrealdb Datastore. should be replaced by a completely custom File-System in the future. // currently it's just a surrealdb Datastore. should be replaced by a completely custom File-System in the future.
pub struct Itemstore { pub struct Itemstore {
db: surrealdb::Datastore, db: Datastore,
} }
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
@@ -93,8 +93,9 @@ impl Item {
impl Itemstore { impl Itemstore {
pub async fn new(path: String) -> Result<Itemstore, MizeError> { pub async fn new(path: String) -> Result<Itemstore, MizeError> {
let ds = Datastore::new(&(String::from("file://") + &path[..] + "/db")[..]).await println!("PATH of DB: {}", path);
.map_err(|_| MizeError::new(30).format(vec![&path]))?; let ds = Datastore::new(&(String::from("file://") + &path[..])[..]).await
.map_err(|e| MizeError::new(30).extra_msg(format!("surrealdb Error: {}", e)).extra_msg(format!("Trying to create at Location: {}", path)))?;
let mut tr = ds.transaction(true, false).await?; let mut tr = ds.transaction(true, false).await?;

View File

@@ -332,7 +332,10 @@ pub async fn handle_json_msg(msg: JsonMessage, origin: Peer, mutexes: Mutexes) -
for (id, delta) in new_update { for (id, delta) in new_update {
//send that delta to every origin that is subbed the item //send that delta to every origin that is subbed the item
let peers = subs.get(&id).ok_or(MizeError::new(11))?; let peers = match subs.get(&id) {
Some(vec) => vec,
None => continue,
};
let message = UpdateMessage{id, delta}; let message = UpdateMessage{id, delta};
for peer in peers { for peer in peers {