Dead-Code Cleaning

This commit is contained in:
Alexey
2026-10-31 12:19:16 +03:00
parent 61afd6c702
commit cecc8df758
40 changed files with 104 additions and 306 deletions
+2
View File
@@ -297,6 +297,7 @@ impl Drop for UserIpPermit {
impl UserConnectionReservation {
/// Creates an active reservation after both admission counters were acquired.
#[cfg(test)]
pub(crate) fn new(
stats: Arc<Stats>,
ip_tracker: Arc<UserIpTracker>,
@@ -375,6 +376,7 @@ impl Drop for UserConnectionReservation {
}
/// Applies user quota, connection, and source-IP admission atomically.
#[cfg(test)]
pub(crate) async fn acquire_user_connection_reservation(
user: &str,
config: &ProxyConfig,
+3 -3
View File
@@ -71,9 +71,9 @@ mod authenticated;
use handshake_support::*;
#[cfg(test)]
pub use stream_entry::handle_client_stream;
pub use stream_entry::{
handle_client_stream_with_shared, handle_client_stream_with_shared_and_pool_runtime,
};
#[cfg(test)]
pub use stream_entry::handle_client_stream_with_shared;
pub use stream_entry::handle_client_stream_with_shared_and_pool_runtime;
pub struct ClientHandler;
+2 -1
View File
@@ -41,7 +41,8 @@ where
}
#[allow(clippy::too_many_arguments)]
#[allow(dead_code)]
/// Runs a client stream with shared process state in tests.
#[cfg(test)]
pub async fn handle_client_stream_with_shared<S>(
stream: S,
peer: SocketAddr,
+1
View File
@@ -269,6 +269,7 @@ impl DirectBufferBudget {
}
/// Returns the conservative ceiling used when memory discovery is unavailable.
#[cfg(test)]
pub(crate) fn fallback_direct_buffer_hard_limit() -> usize {
AUTO_HARD_FALLBACK_BYTES
}
+3 -3
View File
@@ -43,9 +43,9 @@ mod relay;
// Telegram DC resolution and upstream handshake.
mod routing;
pub(crate) use relay::{
handle_via_direct, handle_via_direct_with_shared, handle_via_direct_with_shared_and_conntrack,
};
#[cfg(test)]
pub(crate) use relay::handle_via_direct;
pub(crate) use relay::handle_via_direct_with_shared_and_conntrack;
use routing::*;
const UNKNOWN_DC_LOG_DISTINCT_LIMIT: usize = 1024;
static LOGGED_UNKNOWN_DCS: OnceLock<Mutex<HashSet<i16>>> = OnceLock::new();
+2 -1
View File
@@ -1,7 +1,7 @@
use super::*;
#[allow(dead_code)]
/// Runs Direct relay with standalone cancellation and shared-state defaults.
#[cfg(test)]
pub(crate) async fn handle_via_direct<R, W>(
client_reader: CryptoReader<R>,
client_writer: CryptoWriter<W>,
@@ -39,6 +39,7 @@ where
}
/// Runs Direct relay for a kernel-backed TCP client tuple.
#[cfg(test)]
pub(crate) async fn handle_via_direct_with_shared<R, W>(
client_reader: CryptoReader<R>,
client_writer: CryptoWriter<W>,
+4 -3
View File
@@ -77,15 +77,16 @@ mod relay;
pub use backend_setup::handle_bad_client;
use backend_setup::*;
use copy::*;
#[cfg(test)]
pub(crate) use handler::handle_bad_client_with_shared;
pub(in crate::proxy) use handler::handle_bad_client_with_shared_resolver;
use interfaces::*;
use relay::*;
use target::*;
pub(crate) use timing::sample_lognormal_percentile_bounded;
use timing::{
mask_outcome_target_budget, wait_mask_connect_budget_if_needed, wait_mask_outcome_budget,
};
#[cfg(test)]
use timing::mask_outcome_target_budget;
use timing::{wait_mask_connect_budget_if_needed, wait_mask_outcome_budget};
#[cfg(test)]
#[path = "tests/masking_security_tests.rs"]
+1
View File
@@ -1,6 +1,7 @@
use super::*;
/// Handles a bad client with shared pre-auth fallback admission state.
#[cfg(test)]
pub(crate) async fn handle_bad_client_with_shared<R, W>(
reader: R,
writer: W,
-1
View File
@@ -1,4 +1,3 @@
use std::sync::Arc;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use tokio::sync::watch;
+13 -1
View File
@@ -8,7 +8,9 @@ use std::time::Instant;
use dashmap::DashMap;
use tokio::sync::{OwnedSemaphorePermit, Semaphore, mpsc};
use crate::proxy::direct_buffer_budget::{DirectBufferBudget, fallback_direct_buffer_hard_limit};
use crate::proxy::direct_buffer_budget::DirectBufferBudget;
#[cfg(test)]
use crate::proxy::direct_buffer_budget::fallback_direct_buffer_hard_limit;
use crate::proxy::handshake::{AuthProbeSaturationState, AuthProbeState};
use crate::proxy::middle_relay::{DesyncDedupRotationState, RelayIdleCandidateRegistry};
use crate::proxy::traffic_limiter::TrafficLimiter;
@@ -103,6 +105,8 @@ pub(crate) struct ProxySharedState {
}
impl ProxySharedState {
/// Creates isolated process authorities for tests.
#[cfg(test)]
pub(crate) fn new() -> Arc<Self> {
Self::new_with_direct_buffer_budget(DirectBufferBudget::new(
fallback_direct_buffer_hard_limit(),
@@ -110,6 +114,7 @@ impl ProxySharedState {
}
/// Creates process state with the startup-resolved Direct buffer envelope.
#[cfg(test)]
pub(crate) fn new_with_direct_buffer_budget(
direct_buffer_budget: Arc<DirectBufferBudget>,
) -> Arc<Self> {
@@ -120,6 +125,7 @@ impl ProxySharedState {
}
/// Creates generation state around one process-owned user authority.
#[cfg(test)]
pub(crate) fn new_with_direct_buffer_budget_and_user_admission(
direct_buffer_budget: Arc<DirectBufferBudget>,
user_admission: Arc<UserAdmissionAuthority>,
@@ -203,6 +209,7 @@ impl ProxySharedState {
}
/// Reconciles the complete user authentication policy from configuration.
#[cfg(test)]
pub(crate) fn apply_user_config(
&self,
users: &HashMap<String, String>,
@@ -255,6 +262,7 @@ impl ProxySharedState {
}
/// Applies one persisted user mutation before asynchronous config reload.
#[cfg(test)]
pub(crate) fn stage_user(
&self,
user: &str,
@@ -299,6 +307,8 @@ impl ProxySharedState {
self.user_admission.claim_authenticated(user, credential_id)
}
/// Registers a test session without an authenticated credential.
#[cfg(test)]
pub(crate) fn register_user_session(
self: &Arc<Self>,
user: &str,
@@ -319,6 +329,8 @@ impl ProxySharedState {
Some(registration)
}
/// Cancels all owners of a user in lifecycle tests.
#[cfg(test)]
pub(crate) fn cancel_user_sessions(&self, user: &str) -> usize {
self.user_admission.cancel_user_owners(user)
}
+14
View File
@@ -96,8 +96,16 @@ pub(crate) struct UserMutationResult {
/// Incarnation invalidated or created by the mutation.
pub(crate) incarnation: UserIncarnation,
/// Number of live owners cancelled by the mutation.
#[cfg_attr(
not(test),
expect(dead_code, reason = "Mutation results are asserted by admission regression tests")
)]
pub(crate) cancelled: usize,
/// Whether the effective enabled state changed from enabled to disabled.
#[cfg_attr(
not(test),
expect(dead_code, reason = "Mutation results are asserted by admission regression tests")
)]
pub(crate) newly_disabled: bool,
}
@@ -109,6 +117,7 @@ pub(crate) struct UserAdmissionAuthority {
impl UserAdmissionAuthority {
/// Creates an uninitialized authority for isolated tests and startup wiring.
#[cfg(test)]
pub(crate) fn new() -> Arc<Self> {
Self::new_with_quota_store(Arc::new(QuotaStore::default()))
}
@@ -173,6 +182,7 @@ impl UserAdmissionAuthority {
}
/// Reconciles the complete configured user set into the process authority.
#[cfg(test)]
pub(crate) fn apply_config(
&self,
users: &HashMap<String, String>,
@@ -204,6 +214,7 @@ impl UserAdmissionAuthority {
}
/// Returns the number of rejected updates from non-owning generations.
#[cfg(test)]
pub(crate) fn stale_config_source_rejections(&self) -> u64 {
self.state.lock().stale_config_source_rejections
}
@@ -338,6 +349,7 @@ impl UserAdmissionAuthority {
}
/// Applies one persisted user value ahead of asynchronous runtime reload.
#[cfg(test)]
pub(crate) fn stage_user(
&self,
user: &str,
@@ -502,6 +514,7 @@ impl UserAdmissionAuthority {
}
/// Registers a legacy owner when no credential snapshot is available.
#[cfg(test)]
pub(crate) fn register_legacy(self: &Arc<Self>, user: &str) -> Option<UserSessionRegistration> {
let credential_id = {
let state = self.state.lock();
@@ -518,6 +531,7 @@ impl UserAdmissionAuthority {
}
/// Cancels all current owners without changing admission policy.
#[cfg(test)]
pub(crate) fn cancel_user_owners(&self, user: &str) -> usize {
let tokens = self.state.lock().owner_tokens(user);
let count = tokens.len();