Additional subkey value size limit

This commit is contained in:
neequ57 2024-10-18 14:10:54 +00:00 committed by Christien Rioux
parent 3625225014
commit d8f395a27d
3 changed files with 33 additions and 4 deletions

View File

@ -18,9 +18,9 @@ pub use record_store::{WatchParameters, WatchResult};
pub use types::*;
/// 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
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
const FLUSH_RECORD_STORES_INTERVAL_SECS: u32 = 1;
/// Frequency to check for offline subkeys writes to send to the network

View File

@ -1,4 +1,5 @@
use super::*;
use crate::storage_manager::{MAX_RECORD_DATA_SIZE, MAX_SUBKEY_SIZE};
/// Default DHT Schema (DFLT)
#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Serialize, Deserialize, JsonSchema)]
@ -64,8 +65,18 @@ impl DHTSchemaDFLT {
if subkey < (self.o_cnt as usize) {
// Check value data has valid writer
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;
}
// Value too big
return true;
}
// Wrong writer
return false;
}

View File

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