change sessionId to u64, enforce serde_bytes on all serialized buffers

pull/19/head
Niko PLP 7 months ago
parent f4c9db5d26
commit 4259277d8f
  1. 15
      nextgraph/src/local_broker.rs
  2. 1
      ng-net/src/actors/noise.rs
  3. 2
      ng-net/src/actors/start.rs
  4. 1
      ng-repo/src/types.rs
  5. 15
      ng-verifier/src/types.rs
  6. 11
      ng-wallet/src/types.rs

@ -379,7 +379,7 @@ struct LocalBroker {
pub sessions: HashMap<UserId, SessionPeerStorageV0>, pub sessions: HashMap<UserId, SessionPeerStorageV0>,
pub opened_sessions: HashMap<UserId, u8>, pub opened_sessions: HashMap<UserId, u64>,
pub opened_sessions_list: Vec<Option<Session>>, pub opened_sessions_list: Vec<Option<Session>>,
} }
@ -518,7 +518,7 @@ impl LocalBroker {
} else { } else {
#[cfg(not(target_family = "wasm"))] #[cfg(not(target_family = "wasm"))]
{ {
let mut key_material = wallet let key_material = wallet
.client() .client()
.as_ref() .as_ref()
.unwrap() .unwrap()
@ -529,8 +529,9 @@ impl LocalBroker {
"block{}", "block{}",
wallet.client().as_ref().unwrap().id.to_hash_string() wallet.client().as_ref().unwrap().id.to_hash_string()
))?; ))?;
let mut key: [u8; 32] = let key: [u8; 32] =
derive_key("NextGraph Client BlockStorage BLAKE3 key", key_material); derive_key("NextGraph Client BlockStorage BLAKE3 key", key_material);
Arc::new(std::sync::RwLock::new(RocksDbBlockStorage::open( Arc::new(std::sync::RwLock::new(RocksDbBlockStorage::open(
&path, key, &path, key,
)?)) )?))
@ -761,10 +762,10 @@ impl LocalBroker {
verifier, verifier,
})); }));
let idx = broker.opened_sessions_list.len() - 1; let idx = broker.opened_sessions_list.len() - 1;
broker.opened_sessions.insert(user_id, idx as u8); broker.opened_sessions.insert(user_id, idx as u64);
Ok(SessionInfo { Ok(SessionInfo {
session_id: idx as u8, session_id: idx as u64,
user: user_id, user: user_id,
}) })
} }
@ -1414,7 +1415,7 @@ pub async fn wallet_remove(wallet_name: String) -> Result<(), NgError> {
/// fetches a document's content, or performs a mutation on the document. /// fetches a document's content, or performs a mutation on the document.
pub async fn doc_fetch( pub async fn doc_fetch(
session_id: u8, session_id: u64,
nuri: String, nuri: String,
payload: Option<AppRequestPayload>, payload: Option<AppRequestPayload>,
) -> Result<(Receiver<AppResponse>, CancelFn), NgError> { ) -> Result<(Receiver<AppResponse>, CancelFn), NgError> {
@ -1433,7 +1434,7 @@ pub async fn doc_fetch(
} }
/// retrieves the ID of one of the 3 stores of a the personal Site (3P: public, protected, or private) /// retrieves the ID of one of the 3 stores of a the personal Site (3P: public, protected, or private)
pub async fn personal_site_store(session_id: u8, store: SiteStoreType) -> Result<PubKey, NgError> { pub async fn personal_site_store(session_id: u64, store: SiteStoreType) -> Result<PubKey, NgError> {
let broker = match LOCAL_BROKER.get() { let broker = match LOCAL_BROKER.get() {
None | Some(Err(_)) => return Err(NgError::LocalBrokerNotInitialized), None | Some(Err(_)) => return Err(NgError::LocalBrokerNotInitialized),
Some(Ok(broker)) => broker.read().await, Some(Ok(broker)) => broker.read().await,

@ -20,6 +20,7 @@ use std::any::{Any, TypeId};
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct NoiseV0 { pub struct NoiseV0 {
// contains the handshake messages or the encrypted content of a ProtocolMessage // contains the handshake messages or the encrypted content of a ProtocolMessage
#[serde(with = "serde_bytes")]
pub data: Vec<u8>, pub data: Vec<u8>,
} }

@ -67,6 +67,7 @@ pub struct CoreHello {
pub noise: Noise, pub noise: Noise,
/// Noise encrypted payload (a CoreMessage::CoreRequest::BrokerConnect) /// Noise encrypted payload (a CoreMessage::CoreRequest::BrokerConnect)
#[serde(with = "serde_bytes")]
pub payload: Vec<u8>, pub payload: Vec<u8>,
} }
@ -132,6 +133,7 @@ pub struct ExtHello {
pub noise: Noise, pub noise: Noise,
/// Noise encrypted payload (an ExtRequest) /// Noise encrypted payload (an ExtRequest)
#[serde(with = "serde_bytes")]
pub payload: Vec<u8>, pub payload: Vec<u8>,
} }

@ -1723,6 +1723,7 @@ pub enum RemoveSignerCap {
/// DEPS are the last HEAD of wallet updates. /// DEPS are the last HEAD of wallet updates.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct WalletUpdateV0 { pub struct WalletUpdateV0 {
#[serde(with = "serde_bytes")]
pub op: Vec<u8>, pub op: Vec<u8>,
/// Metadata /// Metadata

@ -215,10 +215,14 @@ pub struct GraphUpdate {
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub enum DiscreteUpdate { pub enum DiscreteUpdate {
/// A yrs::Update /// A yrs::Update
#[serde(with = "serde_bytes")]
YMap(Vec<u8>), YMap(Vec<u8>),
#[serde(with = "serde_bytes")]
YXml(Vec<u8>), YXml(Vec<u8>),
#[serde(with = "serde_bytes")]
YText(Vec<u8>), YText(Vec<u8>),
/// An automerge::Patch /// An automerge::Patch
#[serde(with = "serde_bytes")]
Automerge(Vec<u8>), Automerge(Vec<u8>),
} }
@ -249,7 +253,7 @@ pub enum AppRequestPayloadV0 {
Delete(AppDelete), Delete(AppDelete),
SmallFilePut(SmallFile), SmallFilePut(SmallFile),
RandomAccessFilePut(String), // content_type RandomAccessFilePut(String), // content_type
RandomAccessFilePutChunk((ObjectId, Vec<u8>)), // end the upload with an empty vec RandomAccessFilePutChunk((ObjectId, serde_bytes::ByteBuf)), // end the upload with an empty vec
} }
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
@ -260,10 +264,14 @@ pub enum AppRequestPayload {
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub enum DiscretePatch { pub enum DiscretePatch {
/// A yrs::Update /// A yrs::Update
#[serde(with = "serde_bytes")]
YMap(Vec<u8>), YMap(Vec<u8>),
#[serde(with = "serde_bytes")]
YXml(Vec<u8>), YXml(Vec<u8>),
#[serde(with = "serde_bytes")]
YText(Vec<u8>), YText(Vec<u8>),
/// An automerge::Patch /// An automerge::Patch
#[serde(with = "serde_bytes")]
Automerge(Vec<u8>), Automerge(Vec<u8>),
} }
@ -277,10 +285,14 @@ pub struct GraphPatch {
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub enum DiscreteState { pub enum DiscreteState {
/// A yrs::StateVector /// A yrs::StateVector
#[serde(with = "serde_bytes")]
YMap(Vec<u8>), YMap(Vec<u8>),
#[serde(with = "serde_bytes")]
YXml(Vec<u8>), YXml(Vec<u8>),
#[serde(with = "serde_bytes")]
YText(Vec<u8>), YText(Vec<u8>),
// the output of Automerge::save() // the output of Automerge::save()
#[serde(with = "serde_bytes")]
Automerge(Vec<u8>), Automerge(Vec<u8>),
} }
@ -314,6 +326,7 @@ pub enum AppResponseV0 {
Patch(AppPatch), Patch(AppPatch),
Text(String), Text(String),
File(FileName), File(FileName),
#[serde(with = "serde_bytes")]
FileBinary(Vec<u8>), FileBinary(Vec<u8>),
QueryResult, // see sparesults QueryResult, // see sparesults
} }

@ -128,7 +128,7 @@ impl SessionWalletStorageV0 {
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct SessionInfo { pub struct SessionInfo {
pub session_id: u8, pub session_id: u64,
pub user: UserId, pub user: UserId,
} }
@ -214,6 +214,7 @@ pub struct LocalWalletStorageV0 {
pub client_id: ClientId, pub client_id: ClientId,
pub client_auto_open: Vec<PubKey>, pub client_auto_open: Vec<PubKey>,
pub client_name: Option<String>, pub client_name: Option<String>,
#[serde(with = "serde_bytes")]
pub encrypted_client_storage: Vec<u8>, pub encrypted_client_storage: Vec<u8>,
} }
@ -440,7 +441,7 @@ pub struct SensitiveWalletV0 {
/// third parties data saved in the wallet. the string (key) in the hashmap should be unique among vendors. /// third parties data saved in the wallet. the string (key) in the hashmap should be unique among vendors.
/// the format of the byte array (value) is up to the vendor, to serde as needed. /// the format of the byte array (value) is up to the vendor, to serde as needed.
#[zeroize(skip)] #[zeroize(skip)]
pub third_parties: HashMap<String, Vec<u8>>, pub third_parties: HashMap<String, serde_bytes::ByteBuf>,
#[zeroize(skip)] #[zeroize(skip)]
pub log: Option<WalletLogV0>, pub log: Option<WalletLogV0>,
@ -745,7 +746,7 @@ impl WalletLogV0 {
WalletOperation::RemoveSiteBootstrapV0(_) => {} WalletOperation::RemoveSiteBootstrapV0(_) => {}
WalletOperation::AddThirdPartyDataV0((key, value)) => { WalletOperation::AddThirdPartyDataV0((key, value)) => {
if self.is_last_and_not_deleted_afterwards(op, "RemoveThirdPartyDataV0") { if self.is_last_and_not_deleted_afterwards(op, "RemoveThirdPartyDataV0") {
let _ = wallet.third_parties.insert(key.to_string(), value.to_vec()); let _ = wallet.third_parties.insert(key.to_string(), value.clone());
} }
} }
WalletOperation::RemoveThirdPartyDataV0(_) => {} // WalletOperation::SetSiteRBDRefV0((site, store_type, rbdr)) => { WalletOperation::RemoveThirdPartyDataV0(_) => {} // WalletOperation::SetSiteRBDRefV0((site, store_type, rbdr)) => {
@ -894,7 +895,7 @@ pub enum WalletOperation {
RemoveSiteCoreV0((PubKey, PubKey)), RemoveSiteCoreV0((PubKey, PubKey)),
AddSiteBootstrapV0((PubKey, PubKey)), AddSiteBootstrapV0((PubKey, PubKey)),
RemoveSiteBootstrapV0((PubKey, PubKey)), RemoveSiteBootstrapV0((PubKey, PubKey)),
AddThirdPartyDataV0((String, Vec<u8>)), AddThirdPartyDataV0((String, serde_bytes::ByteBuf)),
RemoveThirdPartyDataV0(String), RemoveThirdPartyDataV0(String),
//SetSiteRBDRefV0((PubKey, SiteStoreType, ObjectRef)), //SetSiteRBDRefV0((PubKey, SiteStoreType, ObjectRef)),
//SetSiteRepoSecretV0((PubKey, SiteStoreType, RepoWriteCapSecret)), //SetSiteRepoSecretV0((PubKey, SiteStoreType, RepoWriteCapSecret)),
@ -1284,7 +1285,7 @@ pub struct CreateWalletResultV0 {
/// is this an in_memory wallet that should not be saved to disk by the LocalBroker? /// is this an in_memory wallet that should not be saved to disk by the LocalBroker?
pub in_memory: bool, pub in_memory: bool,
pub session_id: u8, pub session_id: u64,
} }
impl CreateWalletResultV0 { impl CreateWalletResultV0 {

Loading…
Cancel
Save