mirror of
https://gitlab.com/veilid/veilid.git
synced 2024-11-24 09:50:16 -06:00
Merge branch 'limit-subkey-value-size' into 'main'
Additional subkey value size limit See merge request veilid/veilid!321
This commit is contained in:
commit
f8c17177f7
@ -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
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value too big
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrong writer
|
// Wrong writer
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -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,11 +101,22 @@ 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 {
|
||||||
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
|
// Wrong writer
|
||||||
return false;
|
return false;
|
||||||
@ -117,7 +129,13 @@ 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 {
|
||||||
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
|
// Wrong writer
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user