server: add ddos protection

This commit is contained in:
nym21
2025-06-08 17:06:36 +02:00
parent e6934cd5e2
commit 5a6b71cbeb
16 changed files with 85 additions and 12 deletions
+1
View File
@@ -13,6 +13,7 @@ pub trait AnyVec: Send + Sync {
}
fn modified_time(&self) -> Result<Duration>;
fn index_type_to_string(&self) -> String;
fn value_type_to_size_of(&self) -> usize;
}
pub trait AnyIterableVec<I, T>: AnyVec {
+6
View File
@@ -34,6 +34,12 @@ where
}
}
fn range_count(from: Option<i64>, to: Option<i64>, len: usize) -> usize {
let from = from.map(|i| Self::i64_to_usize(i, len));
let to = to.map(|i| Self::i64_to_usize(i, len));
(from.unwrap_or_default()..to.unwrap_or(len)).count()
}
#[doc(hidden)]
fn collect_signed_range(&self, from: Option<i64>, to: Option<i64>) -> Result<Vec<T>> {
let len = self.len();
@@ -361,6 +361,11 @@ where
fn index_type_to_string(&self) -> String {
I::to_string()
}
#[inline]
fn value_type_to_size_of(&self) -> usize {
size_of::<T>()
}
}
impl<I, T> Clone for CompressedVec<I, T> {
+5
View File
@@ -255,6 +255,11 @@ where
ComputedVec::LazyFrom3(v) => v.modified_time(),
}
}
#[inline]
fn value_type_to_size_of(&self) -> usize {
size_of::<T>()
}
}
pub enum ComputedVecIterator<'a, I, T, S1I, S1T, S2I, S2T, S3I, S3T> {
+5
View File
@@ -1298,6 +1298,11 @@ where
fn index_type_to_string(&self) -> String {
I::to_string()
}
#[inline]
fn value_type_to_size_of(&self) -> usize {
size_of::<T>()
}
}
impl<I, T> AnyIterableVec<I, T> for EagerVec<I, T>
+5
View File
@@ -127,6 +127,11 @@ where
fn index_type_to_string(&self) -> String {
I::to_string()
}
#[inline]
fn value_type_to_size_of(&self) -> usize {
size_of::<T>()
}
}
pub trait AnyIndexedVec: AnyVec {
+5
View File
@@ -146,6 +146,11 @@ where
fn modified_time(&self) -> Result<std::time::Duration> {
self.source.modified_time()
}
#[inline]
fn value_type_to_size_of(&self) -> usize {
size_of::<T>()
}
}
impl<I, T, S1I, S1T> AnyIterableVec<I, T> for LazyVecFrom1<I, T, S1I, S1T>
+5
View File
@@ -194,6 +194,11 @@ where
.modified_time()?
.min(self.source2.modified_time()?))
}
#[inline]
fn value_type_to_size_of(&self) -> usize {
size_of::<T>()
}
}
impl<I, T, S1I, S1T, S2I, S2T> AnyIterableVec<I, T> for LazyVecFrom2<I, T, S1I, S1T, S2I, S2T>
+5
View File
@@ -229,6 +229,11 @@ where
.min(self.source2.modified_time()?)
.min(self.source3.modified_time()?))
}
#[inline]
fn value_type_to_size_of(&self) -> usize {
size_of::<T>()
}
}
impl<I, T, S1I, S1T, S2I, S2T, S3I, S3T> AnyIterableVec<I, T>
+5
View File
@@ -195,6 +195,11 @@ where
fn index_type_to_string(&self) -> String {
I::to_string()
}
#[inline]
fn value_type_to_size_of(&self) -> usize {
size_of::<T>()
}
}
impl<I, T> Clone for RawVec<I, T> {
+5
View File
@@ -149,6 +149,11 @@ where
StoredVec::Compressed(v) => v.name(),
}
}
#[inline]
fn value_type_to_size_of(&self) -> usize {
size_of::<T>()
}
}
#[derive(Debug)]