+ fn timer_tick_occurred(&self) {
+ let mut message_recipients = self.message_recipients.lock().unwrap();
+
+ // Drop any pending recipients since the last call to avoid retaining buffered messages for
+ // too long.
+ message_recipients.retain(|_, recipient| match recipient {
+ OnionMessageRecipient::PendingConnection(_, None, ticks) => *ticks < MAX_TIMER_TICKS,
+ OnionMessageRecipient::PendingConnection(_, Some(_), _) => true,
+ _ => true,
+ });
+
+ // Increment a timer tick for pending recipients so that their buffered messages are dropped
+ // at MAX_TIMER_TICKS.
+ for recipient in message_recipients.values_mut() {
+ if let OnionMessageRecipient::PendingConnection(_, None, ticks) = recipient {
+ *ticks += 1;
+ }
+ }
+ }
+