Merge branch 'limit-subkey-value-size' into 'main'

Additional subkey value size limit

See merge request veilid/veilid!321
This commit is contained in:
Christien Rioux 2024-10-18 14:10:54 +00:00
commit f8c17177f7
3 changed files with 33 additions and 4 deletions

View File

@ -18,9 +18,9 @@ pub use record_store::{WatchParameters, WatchResult};
pub use types::*; pub use types::*;
/// The maximum size of a single subkey /// The maximum size of a single subkey
const MAX_SUBKEY_SIZE: usize = ValueData::MAX_LEN; pub(crate) const MAX_SUBKEY_SIZE: usize = ValueData::MAX_LEN;
/// The maximum total size of all subkeys of a record /// The maximum total size of all subkeys of a record
const MAX_RECORD_DATA_SIZE: usize = 1_048_576; pub(crate) const MAX_RECORD_DATA_SIZE: usize = 1_048_576;
/// Frequency to flush record stores to disk /// Frequency to flush record stores to disk
const FLUSH_RECORD_STORES_INTERVAL_SECS: u32 = 1; const FLUSH_RECORD_STORES_INTERVAL_SECS: u32 = 1;
/// Frequency to check for offline subkeys writes to send to the network /// Frequency to check for offline subkeys writes to send to the network

View File

@ -1,4 +1,5 @@
use super::*; use super::*;
use crate::storage_manager::{MAX_RECORD_DATA_SIZE, MAX_SUBKEY_SIZE};
/// Default DHT Schema (DFLT) /// Default DHT Schema (DFLT)
#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Serialize, Deserialize, JsonSchema)] #[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Serialize, Deserialize, JsonSchema)]
@ -64,8 +65,18 @@ impl DHTSchemaDFLT {
if subkey < (self.o_cnt as usize) { if subkey < (self.o_cnt as usize) {
// Check value data has valid writer // Check value data has valid writer
if value_data.writer() == owner { if value_data.writer() == owner {
let max_value_len =
usize::min(MAX_SUBKEY_SIZE, MAX_RECORD_DATA_SIZE / self.o_cnt as usize);
// Ensure value size is within additional limit
if value_data.data_size() <= max_value_len {
return true; return true;
} }
// Value too big
return true;
}
// Wrong writer // Wrong writer
return false; return false;
} }

View File

@ -1,4 +1,5 @@
use super::*; use super::*;
use crate::storage_manager::{MAX_RECORD_DATA_SIZE, MAX_SUBKEY_SIZE};
/// Simple DHT Schema (SMPL) Member /// Simple DHT Schema (SMPL) Member
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, JsonSchema)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, JsonSchema)]
@ -100,12 +101,23 @@ impl DHTSchemaSMPL {
) -> bool { ) -> bool {
let mut cur_subkey = subkey as usize; let mut cur_subkey = subkey as usize;
let max_value_len = usize::min(
MAX_SUBKEY_SIZE,
MAX_RECORD_DATA_SIZE / (self.max_subkey() + 1) as usize,
);
// Check if subkey is in owner range // Check if subkey is in owner range
if cur_subkey < (self.o_cnt as usize) { if cur_subkey < (self.o_cnt as usize) {
// Check value data has valid writer // Check value data has valid writer
if value_data.writer() == owner { if value_data.writer() == owner {
// Ensure value size is within additional limit
if value_data.data_size() <= max_value_len {
return true; return true;
} }
// Value too big
return false;
}
// Wrong writer // Wrong writer
return false; return false;
} }
@ -117,8 +129,14 @@ impl DHTSchemaSMPL {
if cur_subkey < (m.m_cnt as usize) { if cur_subkey < (m.m_cnt as usize) {
// Check value data has valid writer // Check value data has valid writer
if value_data.writer() == &m.m_key { if value_data.writer() == &m.m_key {
// Ensure value size is in allowed range
if value_data.data_size() <= max_value_len {
return true; return true;
} }
// Value too big
return false;
}
// Wrong writer // Wrong writer
return false; return false;
} }