-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: dont store sent/received fragments unless explicitly enabled
- Loading branch information
Showing
6 changed files
with
72 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
// Copyright 2021 - Nym Technologies SA <[email protected]> | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::sync::LazyLock; | ||
|
||
use crate::fragment::{linked_fragment_payload_max_len, unlinked_fragment_payload_max_len}; | ||
use dashmap::DashMap; | ||
use fragment::{Fragment, FragmentHeader}; | ||
use fragment::FragmentHeader; | ||
use nym_crypto::asymmetric::ed25519::PublicKey; | ||
use serde::Serialize; | ||
pub use set::split_into_sets; | ||
|
@@ -29,6 +26,59 @@ pub mod fragment; | |
pub mod reconstruction; | ||
pub mod set; | ||
|
||
pub mod monitoring { | ||
use crate::fragment::Fragment; | ||
use crate::{ReceivedFragment, SentFragment}; | ||
use dashmap::DashMap; | ||
use nym_crypto::asymmetric::ed25519::PublicKey; | ||
use std::sync::atomic::{AtomicBool, Ordering}; | ||
use std::sync::LazyLock; | ||
|
||
pub static ENABLED: AtomicBool = AtomicBool::new(false); | ||
|
||
pub static FRAGMENTS_RECEIVED: LazyLock<DashMap<i32, Vec<ReceivedFragment>>> = | ||
LazyLock::new(DashMap::new); | ||
|
||
pub static FRAGMENTS_SENT: LazyLock<DashMap<i32, Vec<SentFragment>>> = | ||
LazyLock::new(DashMap::new); | ||
|
||
pub fn enable() { | ||
ENABLED.store(true, Ordering::Relaxed) | ||
} | ||
|
||
pub fn enabled() -> bool { | ||
ENABLED.load(Ordering::Relaxed) | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! now { | ||
() => { | ||
match std::time::SystemTime::now().duration_since(std::time::SystemTime::UNIX_EPOCH) { | ||
Ok(n) => n.as_secs(), | ||
Err(_) => 0, | ||
} | ||
}; | ||
} | ||
|
||
pub fn fragment_received(fragment: &Fragment) { | ||
if enabled() { | ||
let id = fragment.fragment_identifier().set_id(); | ||
let mut entry = FRAGMENTS_RECEIVED.entry(id).or_default(); | ||
let r = ReceivedFragment::new(fragment.header(), now!()); | ||
entry.push(r); | ||
} | ||
} | ||
|
||
pub fn fragment_sent(fragment: &Fragment, client_nonce: i32, destination: PublicKey, hops: u8) { | ||
if enabled() { | ||
let id = fragment.fragment_identifier().set_id(); | ||
let mut entry = FRAGMENTS_SENT.entry(id).or_default(); | ||
let s = SentFragment::new(fragment.header(), now!(), client_nonce, destination, hops); | ||
entry.push(s); | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct FragmentMixParams { | ||
destination: PublicKey, | ||
|
@@ -112,35 +162,6 @@ impl ReceivedFragment { | |
} | ||
} | ||
|
||
pub static FRAGMENTS_RECEIVED: LazyLock<DashMap<i32, Vec<ReceivedFragment>>> = | ||
LazyLock::new(DashMap::new); | ||
|
||
pub static FRAGMENTS_SENT: LazyLock<DashMap<i32, Vec<SentFragment>>> = LazyLock::new(DashMap::new); | ||
|
||
#[macro_export] | ||
macro_rules! now { | ||
() => { | ||
match std::time::SystemTime::now().duration_since(std::time::SystemTime::UNIX_EPOCH) { | ||
Ok(n) => n.as_secs(), | ||
Err(_) => 0, | ||
} | ||
}; | ||
} | ||
|
||
pub fn fragment_received(fragment: &Fragment) { | ||
let id = fragment.fragment_identifier().set_id(); | ||
let mut entry = FRAGMENTS_RECEIVED.entry(id).or_default(); | ||
let r = ReceivedFragment::new(fragment.header(), now!()); | ||
entry.push(r); | ||
} | ||
|
||
pub fn fragment_sent(fragment: &Fragment, client_nonce: i32, destination: PublicKey, hops: u8) { | ||
let id = fragment.fragment_identifier().set_id(); | ||
let mut entry = FRAGMENTS_SENT.entry(id).or_default(); | ||
let s = SentFragment::new(fragment.header(), now!(), client_nonce, destination, hops); | ||
entry.push(s); | ||
} | ||
|
||
/// The idea behind the process of chunking is to incur as little data overhead as possible due | ||
/// to very computationally costly sphinx encapsulation procedure. | ||
/// | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// Copyright 2021 - Nym Technologies SA <[email protected]> | ||
// SPDX-License-Identifier: Apache-2.0 | ||
use crate::fragment::Fragment; | ||
use crate::{fragment_received, ChunkingError}; | ||
use crate::{monitoring, ChunkingError}; | ||
use log::*; | ||
use std::collections::HashMap; | ||
|
||
|
@@ -110,7 +110,7 @@ impl ReconstructionBuffer { | |
} | ||
}); | ||
|
||
fragment_received(&fragment); | ||
monitoring::fragment_received(&fragment); | ||
|
||
let fragment_index = fragment.current_fragment() as usize - 1; | ||
if self.fragments[fragment_index].is_some() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters