mirror of
https://gitlab.com/veilid/veilid.git
synced 2024-12-24 06:49:38 -05:00
Additional subkey value size limit
This commit is contained in:
parent
3625225014
commit
d8f395a27d
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user