Skip to content

Commit

Permalink
rate limit debug output in allow_untrustable_code()
Browse files Browse the repository at this point in the history
  • Loading branch information
bunnie committed Jan 25, 2024
1 parent 8703764 commit 73b6d91
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions services/gam/src/tokens.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::cell::RefCell;

use gam::{EXPECTED_APP_CONTEXTS, EXPECTED_BOOT_CONTEXTS};

/*
Expand All @@ -21,14 +23,20 @@ pub(crate) struct TokenManager {
#[cfg(feature = "unsafe-app-loading")]
extra_names: Vec<String>,
trng: trng::Trng,
tt: ticktimer_server::Ticktimer,
last_time: RefCell<u64>,
}
const REPEAT_MSG_INTERVAL_MS: u64 = 5000;

impl<'a> TokenManager {
pub(crate) fn new(xns: &xous_names::XousNames) -> TokenManager {
TokenManager {
tokens: Vec::new(),
#[cfg(feature = "unsafe-app-loading")]
extra_names: Vec::new(),
trng: trng::Trng::new(&xns).unwrap(),
tt: ticktimer_server::Ticktimer::new().unwrap(),
last_time: RefCell::new(0),
}
}

Expand All @@ -45,20 +53,24 @@ impl<'a> TokenManager {
} else {
// throw a bone to the dev who has to debug this error. This typically only triggers after a major
// refactor and some UX element was removed and we forgot to update it in this table here.
log::info!("Occupied token slots: ***");
for t in self.tokens.iter() {
log::info!(" {}", t.name);
}
log::info!("Expected token slots:");
for t in EXPECTED_BOOT_CONTEXTS.iter() {
log::info!(" {}", t);
}
for t in EXPECTED_APP_CONTEXTS.iter() {
log::info!(" {}", t);
}
#[cfg(feature = "unsafe-app-loading")]
for t in self.extra_names.iter() {
log::info!("{}", t);
let now = self.tt.elapsed_ms();
if *self.last_time.borrow() < now - REPEAT_MSG_INTERVAL_MS {
log::info!("Occupied token slots: ***");
for t in self.tokens.iter() {
log::info!(" {}", t.name);
}
log::info!("Expected token slots:");
for t in EXPECTED_BOOT_CONTEXTS.iter() {
log::info!(" {}", t);
}
for t in EXPECTED_APP_CONTEXTS.iter() {
log::info!(" {}", t);
}
#[cfg(feature = "unsafe-app-loading")]
for t in self.extra_names.iter() {
log::info!("{}", t);
}
self.last_time.replace(now);
}
false
}
Expand Down

0 comments on commit 73b6d91

Please sign in to comment.